mirror of
https://github.com/docmost/docmost.git
synced 2026-08-28 09:17:06 +08:00
feat(base): render formula cells with error badge support
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
import { Badge, Tooltip } from "@mantine/core";
|
||||||
|
import {
|
||||||
|
IBaseProperty,
|
||||||
|
isFormulaErrorCell,
|
||||||
|
} from "@/features/base/types/base.types";
|
||||||
|
import { CellText } from "./cell-text";
|
||||||
|
import { CellNumber } from "./cell-number";
|
||||||
|
import { CellCheckbox } from "./cell-checkbox";
|
||||||
|
import { CellDate } from "./cell-date";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
value: unknown;
|
||||||
|
property: IBaseProperty;
|
||||||
|
rowId: string;
|
||||||
|
isEditing: boolean;
|
||||||
|
onCommit: (value: unknown) => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CellFormula(props: Props) {
|
||||||
|
const { value, property } = props;
|
||||||
|
if (isFormulaErrorCell(value)) {
|
||||||
|
return (
|
||||||
|
<Tooltip label={`${value.__err}: ${value.msg}`}>
|
||||||
|
<Badge color="red" variant="light" size="sm">
|
||||||
|
#ERROR
|
||||||
|
</Badge>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const opts = (property.typeOptions ?? {}) as { resultType?: string };
|
||||||
|
const resultType = opts.resultType ?? "null";
|
||||||
|
const readOnlyProps = { ...props, isEditing: false };
|
||||||
|
if (resultType === "number") return <CellNumber {...readOnlyProps} />;
|
||||||
|
if (resultType === "boolean") return <CellCheckbox {...readOnlyProps} />;
|
||||||
|
if (resultType === "date") return <CellDate {...readOnlyProps} />;
|
||||||
|
return <CellText {...readOnlyProps} />;
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import { CellPage } from "@/features/base/components/cells/cell-page";
|
|||||||
import { CellCreatedAt } from "@/features/base/components/cells/cell-created-at";
|
import { CellCreatedAt } from "@/features/base/components/cells/cell-created-at";
|
||||||
import { CellLastEditedAt } from "@/features/base/components/cells/cell-last-edited-at";
|
import { CellLastEditedAt } from "@/features/base/components/cells/cell-last-edited-at";
|
||||||
import { CellLastEditedBy } from "@/features/base/components/cells/cell-last-edited-by";
|
import { CellLastEditedBy } from "@/features/base/components/cells/cell-last-edited-by";
|
||||||
|
import { CellFormula } from "@/features/base/components/cells/cell-formula";
|
||||||
import { RowNumberCell } from "./row-number-cell";
|
import { RowNumberCell } from "./row-number-cell";
|
||||||
import classes from "@/features/base/styles/grid.module.css";
|
import classes from "@/features/base/styles/grid.module.css";
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ const cellComponents: Record<
|
|||||||
createdAt: CellCreatedAt,
|
createdAt: CellCreatedAt,
|
||||||
lastEditedAt: CellLastEditedAt,
|
lastEditedAt: CellLastEditedAt,
|
||||||
lastEditedBy: CellLastEditedBy,
|
lastEditedBy: CellLastEditedBy,
|
||||||
|
formula: CellFormula,
|
||||||
};
|
};
|
||||||
|
|
||||||
type RowDragProps = {
|
type RowDragProps = {
|
||||||
|
|||||||
Reference in New Issue
Block a user