import { forwardRef } from "react"; import { Checkbox } from "@mantine/core"; import { IconLock } from "@tabler/icons-react"; import clsx from "clsx"; import { IBaseProperty, IBaseRow } from "@/ee/base/types/base.types"; import { getDescriptor } from "@/ee/base/property-types/property-type.registry"; import { FieldText } from "./field-text"; import { FieldLongText } from "./field-long-text"; import { FieldNumber } from "./field-number"; import { FieldDate } from "./field-date"; import { FieldChoice } from "./field-choice"; import { FieldCellAdapter } from "./field-cell-adapter"; import classes from "@/ee/base/styles/row-detail-modal.module.css"; export type FieldProps = { property: IBaseProperty; value: unknown; rowId: string; readOnly: boolean; onChange: (value: unknown) => void; }; type FieldShellProps = { /** Visual + cursor treatment: text caret, pointer (opens a picker), or none. */ cursor?: "text" | "pointer" | "default"; /** Popover open — keeps the focus ring while focus is in the portal. */ active?: boolean; locked?: boolean; alignTop?: boolean; children?: React.ReactNode; } & React.HTMLAttributes; // forwardRef is load-bearing: Popover.Target anchors its dropdown through a // ref injected into this element; without it the picker renders at (0,0). export const FieldShell = forwardRef( function FieldShell( { cursor = "default", active, locked, alignTop, className, children, ...rest }, ref, ) { return (
{locked && } {children}
); }, ); function FieldCheckbox({ value, readOnly, onChange }: FieldProps) { const checked = value === true; return ( onChange(!checked)} /> ); } function FieldReadonlyCell({ property, value, rowId }: FieldProps) { const CellComponent = getDescriptor(property.type)?.cellComponent; return (
{CellComponent && ( {}} onValueChange={() => {}} onCancel={() => {}} /> )}
); } type DetailFieldProps = { property: IBaseProperty; row: IBaseRow; readOnly: boolean; onUpdate: (propertyId: string, value: unknown) => void; }; export function DetailField({ property, row, readOnly, onUpdate }: DetailFieldProps) { const descriptor = getDescriptor(property.type); const value = descriptor?.systemAccessor ? descriptor.systemAccessor(row) : (row.cells ?? {})[property.id]; const fieldProps: FieldProps = { property, value, rowId: row.id, readOnly, onChange: (next: unknown) => onUpdate(property.id, next), }; switch (property.type) { case "text": case "url": case "email": return ; case "longText": return ; case "number": return ; case "checkbox": return ; case "date": return ; case "select": case "status": case "multiSelect": return ; case "person": case "file": case "page": return ; default: // createdAt, lastEditedAt, lastEditedBy, formula and future types. return ; } }