fix(mongodb): null cell display and inline editing
This commit is contained in:
5 files changed
+41
-12
No files matched your search
@@ -103,9 +103,10 @@ describe("data grid cell text visual priority", () => {
|
||||
expect(dataGridSource).toContain("'cursor-text hover:bg-gray-200 hover:text-foreground dark:hover:bg-gray-800':");
|
||||
});
|
||||
|
||||
it("returns before reading cell state when type colors are disabled", () => {
|
||||
expect(dataGridSource).toContain('function gridCellTextColorClass(item: RowItem, actualColIdx: number, visibleColIdx: number): string {\n if (!colorizeDataGridCellTypes.value) return "text-foreground";\n const value = item.data[actualColIdx];');
|
||||
expect(dataGridSource).toContain('function transposeCellTextColorClass(recordIndex: number, actualColIdx: number): string {\n if (!colorizeDataGridCellTypes.value) return "text-foreground";\n const item = displayItems.value[recordIndex];');
|
||||
it("keeps Mongo BSON null muted when type colors are disabled", () => {
|
||||
const mongoNullPriority = 'const isMongoDocumentNull = props.mongoCollectionGrid === true && value === MONGO_DOCUMENT_GRID_NULL;\n if (isMongoDocumentNull) return "text-muted-foreground italic";\n if (!colorizeDataGridCellTypes.value) return "text-foreground";';
|
||||
|
||||
expect(dataGridSource.split(mongoNullPriority)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("places data-grid type selectors in the components layer", () => {
|
||||
|
||||
@@ -80,6 +80,7 @@ export interface DrawCanvasDataGridOptions {
|
||||
searchMatchKeys: ReadonlySet<number>;
|
||||
currentSearchMatch: CanvasSearchMatch | null;
|
||||
formatCell: (value: CellValue, columnIndex: number, row: CanvasDataGridRow) => string;
|
||||
isNullValue?: (value: CellValue) => boolean;
|
||||
columnIsBoolean?: (columnIndex: number) => boolean;
|
||||
newRowCellPlaceholder?: (row: CanvasDataGridRow, columnIndex: number) => string | null;
|
||||
isRowActive: (rowIndex: number) => boolean;
|
||||
@@ -345,6 +346,7 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
|
||||
searchMatchKeys,
|
||||
currentSearchMatch,
|
||||
formatCell,
|
||||
isNullValue,
|
||||
newRowCellPlaceholder,
|
||||
isRowActive,
|
||||
rowCellsUseSelectionVisual,
|
||||
@@ -558,6 +560,7 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
|
||||
ctx.rect(clippedX, y, Math.min(cellPaintWidth, width - clippedX), CANVAS_DATA_GRID_ROW_HEIGHT);
|
||||
ctx.clip();
|
||||
const value = item.data[actualColIdx];
|
||||
const isNullCell = isNullValue?.(value) ?? value === null;
|
||||
const isBooleanCell = columnIsBoolean?.(actualColIdx) === true && isBooleanCellValue(value);
|
||||
const isRightAlign = columnAligns?.[visibleColIdx] === "right";
|
||||
const isEditingThisCell = editingCell?.rowId === item.id && editingCell.col === actualColIdx;
|
||||
@@ -567,7 +570,7 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
|
||||
const textRole = resolveDataGridCellTextRole({
|
||||
colorizeTypes: colorizeDataTypes,
|
||||
typeKind,
|
||||
isNull: value === null,
|
||||
isNull: isNullCell,
|
||||
isDraft: item.isDraft && value === null,
|
||||
isEditing: isEditingThisCell,
|
||||
isControl: shouldRenderBooleanCheckbox,
|
||||
@@ -580,8 +583,8 @@ export function drawCanvasDataGrid(options: DrawCanvasDataGridOptions) {
|
||||
const cellTextColor = textRole === "muted" ? theme.mutedForeground : textRole === "type" ? dataGridTypeForeground(theme, typeKind) : theme.foreground;
|
||||
ctx.textAlign = isBooleanNullCell ? "center" : isRightAlign ? "right" : "left";
|
||||
ctx.fillStyle = cellTextColor;
|
||||
ctx.font = value === null ? italicFont : tabularFont;
|
||||
setCanvasNumericVariant(ctx, value === null ? "normal" : "tabular-nums");
|
||||
ctx.font = isNullCell ? italicFont : tabularFont;
|
||||
setCanvasNumericVariant(ctx, isNullCell ? "normal" : "tabular-nums");
|
||||
const reservedWidth = rightAlignedActionCell?.rowIndex === item.displayIndex && rightAlignedActionCell.visibleColIdx === visibleColIdx ? rightAlignedActionCell.reservedWidth : 0;
|
||||
const { textAnchorX, maxWidth: cellMaxWidth } = resolveCanvasCellTextLayout({ drawX, colWidth, dpr: scaleX, isRightAlign, reservedWidth });
|
||||
if (shouldRenderBooleanCheckbox) {
|
||||
|
||||
@@ -145,10 +145,18 @@ function mongoDocumentGridEscapedString(value: unknown): string | undefined {
|
||||
|
||||
/** Returns the text presented in a collection-grid editor, when customized. */
|
||||
export function mongoDocumentGridEditorText(value: unknown): string | undefined {
|
||||
if (value === MONGO_DOCUMENT_GRID_NULL) return "NULL";
|
||||
// An existing BSON null is represented as NULL in the grid, but editing it
|
||||
// starts with an empty input. The private marker must never be user-facing.
|
||||
if (value === MONGO_DOCUMENT_GRID_NULL) return "";
|
||||
return mongoDocumentGridEscapedString(value);
|
||||
}
|
||||
|
||||
/** Returns the text used when copying a collection-grid cell. */
|
||||
export function mongoDocumentGridClipboardText(value: unknown): string | undefined {
|
||||
if (value === MONGO_DOCUMENT_GRID_NULL) return "NULL";
|
||||
return mongoDocumentGridEditorText(value);
|
||||
}
|
||||
|
||||
/** Returns the custom display text required by collection-grid BSON values. */
|
||||
export function mongoDocumentGridDisplayText(value: unknown): string | undefined {
|
||||
if (value === MONGO_DOCUMENT_GRID_NULL) return "NULL";
|
||||
|
||||
Reference in new issue
Block a user