2023-02-01 09:00:02 +00:00
|
|
|
import { PropertyEnum } from "utils/types";
|
|
|
|
|
|
|
|
export type FieldType =
|
|
|
|
| 'Data'
|
|
|
|
| 'Select'
|
|
|
|
| 'Link'
|
|
|
|
| 'Date'
|
|
|
|
| 'Datetime'
|
|
|
|
| 'Table'
|
|
|
|
| 'AutoComplete'
|
|
|
|
| 'Check'
|
|
|
|
| 'AttachImage'
|
|
|
|
| 'DynamicLink'
|
|
|
|
| 'Int'
|
|
|
|
| 'Float'
|
|
|
|
| 'Currency'
|
|
|
|
| 'Text'
|
|
|
|
| 'Color'
|
|
|
|
| 'Attachment';
|
|
|
|
|
|
|
|
export const FieldTypeEnum: PropertyEnum<Record<FieldType, FieldType>> = {
|
|
|
|
Data: 'Data',
|
|
|
|
Select: 'Select',
|
|
|
|
Link: 'Link',
|
|
|
|
Date: 'Date',
|
|
|
|
Datetime: 'Datetime',
|
|
|
|
Table: 'Table',
|
|
|
|
AutoComplete: 'AutoComplete',
|
|
|
|
Check: 'Check',
|
|
|
|
AttachImage: 'AttachImage',
|
|
|
|
DynamicLink: 'DynamicLink',
|
|
|
|
Int: 'Int',
|
|
|
|
Float: 'Float',
|
|
|
|
Currency: 'Currency',
|
|
|
|
Text: 'Text',
|
|
|
|
Color: 'Color',
|
|
|
|
Attachment: 'Attachment',
|
|
|
|
};
|
|
|
|
|
|
|
|
type OptionFieldType = 'Select' | 'AutoComplete' | 'Color';
|
|
|
|
type TargetFieldType = 'Table' | 'Link';
|
|
|
|
type NumberFieldType = 'Int' | 'Float';
|
|
|
|
type DynamicLinkFieldType = 'DynamicLink';
|
|
|
|
type BaseFieldType = Exclude<
|
|
|
|
FieldType,
|
|
|
|
TargetFieldType | DynamicLinkFieldType | OptionFieldType | NumberFieldType
|
|
|
|
>;
|
2022-03-23 08:37:00 +00:00
|
|
|
|
2022-03-31 09:04:30 +00:00
|
|
|
export type RawValue = string | number | boolean | null;
|
2022-03-23 08:37:00 +00:00
|
|
|
|
|
|
|
export interface BaseField {
|
2023-02-01 09:00:02 +00:00
|
|
|
fieldname: string; // Column name in the db
|
|
|
|
fieldtype: BaseFieldType; // UI Descriptive field types that map to column types
|
2022-03-23 14:46:19 +00:00
|
|
|
label: string; // Translateable UI facing name
|
2022-04-26 10:12:33 +00:00
|
|
|
schemaName?: string; // Convenient access to schemaName incase just the field is passed
|
2022-03-23 14:46:19 +00:00
|
|
|
required?: boolean; // Implies Not Null
|
|
|
|
hidden?: boolean; // UI Facing config, whether field is shown in a form
|
|
|
|
readOnly?: boolean; // UI Facing config, whether field is editable
|
|
|
|
description?: string; // UI Facing, translateable, used for inline documentation
|
|
|
|
default?: RawValue; // Default value of a field, should match the db type
|
|
|
|
placeholder?: string; // UI Facing config, form field placeholder
|
|
|
|
groupBy?: string; // UI Facing used in dropdowns fields
|
2022-03-23 16:40:36 +00:00
|
|
|
meta?: boolean; // Field is a meta field, i.e. only for the db, not UI
|
2022-07-30 10:36:14 +00:00
|
|
|
filter?: boolean; // UI Facing config, whether to be used to filter the List.
|
2022-07-12 10:23:41 +00:00
|
|
|
computed?: boolean; // Computed values are not stored in the database.
|
2023-02-17 15:35:06 +00:00
|
|
|
section?: string; // UI Facing config, for grouping by sections
|
|
|
|
tab?: string; // UI Facing config, for grouping by tabs
|
2023-02-21 06:42:06 +00:00
|
|
|
abstract?: string; // Uused to mark the location of a field in an Abstract schema
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type SelectOption = { value: string; label: string };
|
2023-02-01 09:00:02 +00:00
|
|
|
export interface OptionField extends Omit<BaseField, 'fieldtype'> {
|
|
|
|
fieldtype: OptionFieldType;
|
2022-03-23 08:37:00 +00:00
|
|
|
options: SelectOption[];
|
2022-05-13 13:51:26 +00:00
|
|
|
emptyMessage?: string;
|
2022-04-27 08:37:06 +00:00
|
|
|
allowCustom?: boolean;
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 09:00:02 +00:00
|
|
|
export interface TargetField extends Omit<BaseField, 'fieldtype'> {
|
|
|
|
fieldtype: TargetFieldType;
|
2022-03-24 09:50:40 +00:00
|
|
|
target: string; // Name of the table or group of tables to fetch values
|
2022-05-18 16:55:24 +00:00
|
|
|
create?: boolean; // Whether to show Create in the dropdown
|
2022-07-11 08:45:37 +00:00
|
|
|
edit?: boolean; // Whether the Table has quick editable columns
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 09:00:02 +00:00
|
|
|
export interface DynamicLinkField extends Omit<BaseField, 'fieldtype'> {
|
|
|
|
fieldtype: DynamicLinkFieldType;
|
2022-05-13 13:51:26 +00:00
|
|
|
emptyMessage?: string;
|
2022-03-23 14:46:19 +00:00
|
|
|
references: string; // Reference to an option field that links to schema
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 09:00:02 +00:00
|
|
|
export interface NumberField extends Omit<BaseField, 'fieldtype'> {
|
|
|
|
fieldtype: NumberFieldType;
|
2022-03-23 14:46:19 +00:00
|
|
|
minvalue?: number; // UI Facing used to restrict lower bound
|
|
|
|
maxvalue?: number; // UI Facing used to restrict upper bound
|
2022-03-23 08:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Field =
|
|
|
|
| BaseField
|
|
|
|
| OptionField
|
|
|
|
| TargetField
|
|
|
|
| DynamicLinkField
|
|
|
|
| NumberField;
|
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
export type Naming = 'autoincrement' | 'random' | 'numberSeries' | 'manual';
|
2022-03-23 14:46:19 +00:00
|
|
|
|
2022-03-23 08:37:00 +00:00
|
|
|
export interface Schema {
|
2022-03-28 10:01:29 +00:00
|
|
|
name: string; // Table name
|
2022-03-23 14:46:19 +00:00
|
|
|
label: string; // Translateable UI facing name
|
2023-02-01 09:00:02 +00:00
|
|
|
fields: Field[]; // Maps to database columns
|
2022-03-23 14:46:19 +00:00
|
|
|
isTree?: boolean; // Used for nested set, eg for Chart of Accounts
|
|
|
|
extends?: string; // Value points to an Abstract schema. Indicates Subclass schema
|
|
|
|
isChild?: boolean; // Indicates a child table, i.e table with "parent" FK column
|
|
|
|
isSingle?: boolean; // Fields will be values in SingleValue, i.e. an Entity Attr. Value
|
|
|
|
isAbstract?: boolean; // Not entered into db, used to extend a Subclass schema
|
2022-03-28 10:01:29 +00:00
|
|
|
tableFields?: string[] // Used for displaying childTableFields
|
2022-03-23 14:46:19 +00:00
|
|
|
isSubmittable?: boolean; // For transactional types, values considered only after submit
|
2022-03-25 12:32:37 +00:00
|
|
|
keywordFields?: string[]; // Used to get fields that are to be used for search.
|
|
|
|
quickEditFields?: string[]; // Used to get fields for the quickEditForm
|
2023-03-02 08:12:16 +00:00
|
|
|
linkDisplayField?:string;// Display field if inline editable
|
2022-04-08 06:10:04 +00:00
|
|
|
naming?: Naming; // Used for assigning name, default is 'random' else 'numberSeries' if present
|
2022-04-26 10:12:33 +00:00
|
|
|
titleField?: string; // Main display field
|
2022-04-14 05:24:11 +00:00
|
|
|
removeFields?: string[]; // Used by the builder to remove fields.
|
2022-03-23 14:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface SchemaStub extends Partial<Schema> {
|
2022-03-23 08:37:00 +00:00
|
|
|
name: string;
|
|
|
|
}
|
2022-04-07 06:20:14 +00:00
|
|
|
export type SchemaMap = Record<string, Schema | undefined>;
|
2022-03-23 14:46:19 +00:00
|
|
|
export type SchemaStubMap = Record<string, SchemaStub>;
|