feat(grid): show column defaults in new row placeholders

Closes #3096
This commit is contained in:
t8y2 committed 2026-08-24 18:22:10 +00:00
1 parent 9e135f7609
commit 6b5b33540f
6 files changed
+117 -17

No files matched your search

@@ -80,7 +80,7 @@ export interface DrawCanvasDataGridOptions {
currentSearchMatch: CanvasSearchMatch | null;
formatCell: (value: CellValue, columnIndex: number, row: CanvasDataGridRow) => string;
columnIsBoolean?: (columnIndex: number) => boolean;
draftCellPlaceholder?: string;
newRowCellPlaceholder?: (row: CanvasDataGridRow, columnIndex: number) => string | null;
isRowActive: (rowIndex: number) => boolean;
rowCellsUseSelectionVisual: (rowId: number) => boolean;
cellIsSelected: (rowIndex: number, visibleColIdx: number) => boolean;
@@ -340,7 +340,7 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
searchMatchKeys,
currentSearchMatch,
formatCell,
draftCellPlaceholder,
newRowCellPlaceholder,
isRowActive,
rowCellsUseSelectionVisual,
cellIsSelected,
@@ -577,7 +577,7 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
ctx.stroke();
}
} else {
const rawDisplayText = item.isDraft && value === null ? (draftCellPlaceholder ?? "") : formatCell(value, actualColIdx, item);
const rawDisplayText = (value === null ? newRowCellPlaceholder?.(item, actualColIdx) : null) ?? formatCell(value, actualColIdx, item);
const displayText = isEditingThisCell ? "" : firstLineCellDisplayValue(rawDisplayText, flatteningMultiLineEnabled);
const text = isEditingThisCell ? displayText : fitCanvasText(ctx, displayText, cellMaxWidth, isBooleanNullCell ? "left" : isRightAlign ? "right" : "left");
const anchorX = isBooleanNullCell ? alignCanvasPixel(drawX + colWidth / 2, scaleX) : textAnchorX;
@@ -14,7 +14,7 @@ export function resolveDataGridColumnsByResultIndex(options: { resultColumns: re
if (!columnsByName.has(key)) columnsByName.set(key, column);
}
return options.resultColumns.map((resultColumn, index) => {
const columnName = options.sourceColumns?.[index] ?? resultColumn;
const columnName = options.sourceColumns ? options.sourceColumns[index] : resultColumn;
return columnName ? columnsByName.get(columnName.toLowerCase()) : undefined;
});
}
@@ -0,0 +1,21 @@
import type { CellValue } from "@/lib/dataGrid/cellValue";
import type { ColumnInfo } from "@/types/database";
export interface DataGridNewRowPlaceholderRow {
data: readonly CellValue[];
isNew: boolean;
isDraft?: boolean;
}
export function resolveDataGridNewRowCellPlaceholder(options: { row: DataGridNewRowPlaceholderRow | undefined; columnIndex: number; column: Pick<ColumnInfo, "column_default"> | undefined; draftFallback: string }): string | null {
const { row, columnIndex, column, draftFallback } = options;
if (!row || (!row.isNew && !row.isDraft) || row.data[columnIndex] !== null) return null;
const rawDefault = column?.column_default;
if (rawDefault != null) {
const normalizedDefault = rawDefault.trim();
if (normalizedDefault && normalizedDefault.toUpperCase() !== "NULL") return rawDefault;
}
return row.isDraft ? draftFallback : null;
}