import { LoadOptionsFn, Option } from "../../components"; import { FormField, getFormFieldTypeByFieldType } from "../form"; import { typeByDataArray } from "./data"; import { isPrimitive } from "./primitive"; /** * The default URL fields, */ export const DEFAULT_URL_FIELDS = [ "absolute_url", "get_absolute_url", "href", "get_href", "url", "get_url", ]; /** A key in an object. */ export type Field = keyof T; /** A key in object annotated with its type and optionally meta information. */ export type TypedField = { /** The field name. */ name: keyof T; /** The field's values type. */ type: FieldType; /** Whether the field should be active by default. */ active?: boolean; /** Whether the field should be editable. */ editable?: boolean; /** Whether the field should be filterable. */ filterable?: boolean; /** * The "lookup" (query parameter) to use for this field while filtering (e.g. * "omschrijving__icontains"). */ filterLookup?: string; /** The value for this field's filter. */ filterValue?: string | number; /** Whether a value is required. */ required?: boolean; /** Used by DataGrid to determine whether the field should be sortable. */ sortable?: boolean; /** * The "lookup" (dot separated) to use for this field while filtering (e.g. * "._expand.zaaktype.omschrijving"). */ valueLookup?: string; /** * A function transforming `T` to a value. * This can be used to compute values dynamically. */ valueTransform?: (value: T) => unknown; /** Used by AttributeTable/DataGrid when editable=true. */ options?: Option[] | LoadOptionsFn; /** Whether to fetch options on mount. Used by forms. */ fetchOnMount?: boolean; /** Whether it's a multiple choice field. Used by forms. */ multiple?: boolean; /** The placeholder shown when there's no value */ placeholder?: string; /** Used by DataGrid to set column width. */ width?: string; }; /** Known options for TypedField["type"] */ export type FieldType = | "boolean" | "date" | "daterange" | "duration" | "null" | "number" | "string" | "text" // Similar to string but when rendered uses