fix : update
CI / Verify (push) Successful in 1m12s
CI / Build immutable images and deploy (push) Successful in 1m53s

This commit is contained in:
2026-09-05 18:45:57 +07:00 Unverified
parent 2429b9d319
commit 75e3e22e9b
4 changed files with 21 additions and 7 deletions
+1 -1
View File
@@ -223,7 +223,7 @@ export function ExtraSheetEditor({
type="color" type="color"
aria-label="เลือกสีพื้นหลังเซลล์" aria-label="เลือกสีพื้นหลังเซลล์"
className="absolute inset-0 cursor-pointer opacity-0" className="absolute inset-0 cursor-pointer opacity-0"
value={activeRow?.backgrounds[activeColumn?.id ?? ""] ?? DEFAULT_CELL_BACKGROUND} value={activeRow?.backgrounds?.[activeColumn?.id ?? ""] ?? DEFAULT_CELL_BACKGROUND}
onChange={(event) => onChange(updateExtraSheetCells(value, selectedPoints(), { onChange={(event) => onChange(updateExtraSheetCells(value, selectedPoints(), {
backgroundColor: event.target.value, backgroundColor: event.target.value,
}))} }))}
+1 -1
View File
@@ -1288,7 +1288,7 @@ function ExtraSectionContent({
<TableCell <TableCell
key={column.id} key={column.id}
className="border-l first:border-l-0 whitespace-normal" className="border-l first:border-l-0 whitespace-normal"
style={sheetRow.backgrounds[column.id] style={sheetRow.backgrounds?.[column.id]
? { backgroundColor: sheetRow.backgrounds[column.id] } ? { backgroundColor: sheetRow.backgrounds[column.id] }
: undefined} : undefined}
> >
+14
View File
@@ -14,6 +14,7 @@ import {
normalizeExtraSheetRichText, normalizeExtraSheetRichText,
updateExtraSheetCell, updateExtraSheetCell,
updateExtraSheetCells, updateExtraSheetCells,
type ExtraSheet,
} from "@/lib/guides/extra-sheet"; } from "@/lib/guides/extra-sheet";
function idFactory() { function idFactory() {
@@ -122,4 +123,17 @@ describe("Extra sheet", () => {
expect(updateExtraSheetCells(updated, [{ row: 0, column: 0 }], { backgroundColor: null }) expect(updateExtraSheetCells(updated, [{ row: 0, column: 0 }], { backgroundColor: null })
.rows[0].backgrounds).toEqual({}); .rows[0].backgrounds).toEqual({});
}); });
it("renders legacy sheets that do not have background metadata yet", () => {
const sheet = createExtraSheet(idFactory());
const legacy = {
...sheet,
rows: sheet.rows.map((row) => ({ id: row.id, cells: row.cells })),
} as ExtraSheet;
expect(extraSheetToMatrix(legacy)[0][0]).toEqual({
value: "",
backgroundColor: undefined,
});
});
}); });
+5 -5
View File
@@ -28,7 +28,7 @@ export const extraSheetSchema = z.strictObject({
context.addIssue({ code: "custom", path: ["rows"], message: "รหัสแถวต้องไม่ซ้ำกัน" }); context.addIssue({ code: "custom", path: ["rows"], message: "รหัสแถวต้องไม่ซ้ำกัน" });
} }
sheet.rows.forEach((row, rowIndex) => { sheet.rows.forEach((row, rowIndex) => {
[...Object.keys(row.cells), ...Object.keys(row.backgrounds)].forEach((columnId) => { [...Object.keys(row.cells), ...Object.keys(row.backgrounds ?? {})].forEach((columnId) => {
if (!columnIds.has(columnId)) { if (!columnIds.has(columnId)) {
context.addIssue({ context.addIssue({
code: "custom", code: "custom",
@@ -72,7 +72,7 @@ export function extraSheetToMatrix(sheet: ExtraSheet): ExtraSheetMatrix {
return sheet.rows.map((row) => return sheet.rows.map((row) =>
sheet.columns.map((column) => ({ sheet.columns.map((column) => ({
value: row.cells[column.id] ?? "", value: row.cells[column.id] ?? "",
backgroundColor: row.backgrounds[column.id], backgroundColor: row.backgrounds?.[column.id],
})), })),
); );
} }
@@ -102,7 +102,7 @@ export function matrixToExtraSheet(
])), ])),
backgrounds: Object.fromEntries(columns.flatMap((column, columnIndex) => { backgrounds: Object.fromEntries(columns.flatMap((column, columnIndex) => {
const backgroundColor = matrix[rowIndex]?.[columnIndex]?.backgroundColor const backgroundColor = matrix[rowIndex]?.[columnIndex]?.backgroundColor
?? sheet.rows[rowIndex]?.backgrounds[column.id]; ?? sheet.rows[rowIndex]?.backgrounds?.[column.id];
return backgroundColor ? [[column.id, backgroundColor]] : []; return backgroundColor ? [[column.id, backgroundColor]] : [];
})), })),
})); }));
@@ -164,7 +164,7 @@ export function deleteExtraSheetColumn(sheet: ExtraSheet, index: number): ExtraS
rows: sheet.rows.map((row) => ({ rows: sheet.rows.map((row) => ({
...row, ...row,
cells: Object.fromEntries(Object.entries(row.cells).filter(([key]) => key !== columnId)), cells: Object.fromEntries(Object.entries(row.cells).filter(([key]) => key !== columnId)),
backgrounds: Object.fromEntries(Object.entries(row.backgrounds).filter(([key]) => key !== columnId)), backgrounds: Object.fromEntries(Object.entries(row.backgrounds ?? {}).filter(([key]) => key !== columnId)),
})), })),
}; };
} }
@@ -201,7 +201,7 @@ export function updateExtraSheetCells(
...sheet, ...sheet,
rows: sheet.rows.map((row, rowIndex) => { rows: sheet.rows.map((row, rowIndex) => {
const cells = { ...row.cells }; const cells = { ...row.cells };
const backgrounds = { ...row.backgrounds }; const backgrounds = { ...(row.backgrounds ?? {}) };
sheet.columns.forEach((column, columnIndex) => { sheet.columns.forEach((column, columnIndex) => {
if (!selected.has(`${rowIndex}:${columnIndex}`)) return; if (!selected.has(`${rowIndex}:${columnIndex}`)) return;
if (update.value !== undefined) cells[column.id] = update.value; if (update.value !== undefined) cells[column.id] = update.value;