/
interfaces.ts
154 lines (131 loc) · 4.01 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { ClassValue } from 'classnames/types';
import { ColProps } from 'antd/es/col';
import { ColumnProps } from 'antd/es/table';
import { RowProps } from 'antd/es/row';
import { FormItemProps } from 'antd/es/form';
import { Rule } from 'rc-field-form/lib/interface';
import { IModel, IValue } from './props';
import { FormManager, ITableModel } from './utilities';
interface IFieldConfigBase {
className?: ClassValue;
colProps?: ColProps;
disabled: boolean;
editComponent: any;
editProps: { [key: string]: any };
field: string;
fieldConfigProp: boolean;
formItemProps?: Partial<FormItemProps>;
formItemRenderExtra?: (value: IValue) => React.ReactNode;
formValidationRules: { [ruleName: string]: Rule };
fromForm: (value: IValue, fieldConfig: IFieldConfig) => IValue;
icon?: string;
insertIf?: (model: any) => boolean;
key: string;
label: string | null;
name: string[];
nullify: boolean;
populateFromSearch: boolean;
populateNameFromSearch: boolean;
readOnly: boolean;
render: (value: IValue, fieldConfig: IFieldConfig, model: IModel) => React.ReactNode;
required: boolean;
showLabel: boolean;
skipFieldDecorator: boolean;
tableColumnProps?: Partial<ColumnProps<ITableModel>>;
toForm: (value: IValue, fieldConfig: IFieldConfig) => IValue;
tooltip?: string;
type: string;
value?: string | number | boolean;
writeOnly: boolean;
}
export interface IAntFormField {
disabled: boolean;
id: string;
onChange: (value: IValue) => void;
value: IValue;
}
/*
FIELD CONFIG: SINGLE-TYPE DEFINITIONS
*/
export interface IOption {
disabled?: boolean;
name: string;
value: string;
}
export interface IFieldConfigOptionSelect extends IFieldConfigBase {
getOptions?: (optionType: string) => IOption[];
options?: IOption[];
optionType?: string;
showSearch?: boolean;
sorted?: boolean;
}
export interface IFieldConfigAddress extends IFieldConfigBase {
stateProps?: Partial<IFieldConfigOptionSelect>;
}
export interface IFieldConfigObjectSearchCreate extends IFieldConfigBase {
createFields: IFieldSet;
endpoint: string;
renderOption: (option: IEndpointOption) => React.ReactNode;
renderSelected: (option: IEndpointOption) => string;
searchFilters?: { [key: string]: any };
}
/*
END SINGLE-TYPE DEFINITIONS
*/
// These combine to form the core building block, the fieldConfig:
export type IFieldConfig =
| IFieldConfigBase
| IFieldConfigAddress
| IFieldConfigObjectSearchCreate
| IFieldConfigOptionSelect;
/*
A set of fieldConfigs, or fieldSet
Has a simple list form and a more complex object form;
Is often used throughout the library as FieldSet[]
*/
export type IFieldSetSimple = IFieldConfig[];
export interface IFieldSetComplex {
fields: IFieldSetSimple;
legend?: string;
rowProps?: RowProps;
tooltip?: string;
}
// fieldSets: IFieldSet[]
export type IFieldSet = IFieldSetSimple | IFieldSetComplex;
/*
Usually, you won't directly import fill interfaces. Components take partial
definitions and then fill them in with the defaults for their type. See the
utilities page for more.
fillInFieldSets(fieldSets: IFieldSetPartial[]): IFieldSet[] {
*/
export type IFieldConfigPartial = Partial<IFieldConfig> & { field: string };
export type IFieldSetSimplePartial = IFieldConfigPartial[];
export type IFieldSetPartial = IFieldSetSimplePartial | IFieldSetComplexPartial;
export interface IFieldSetComplexPartial {
fields: IFieldSetSimplePartial;
legend?: string;
rowProps?: RowProps;
tooltip?: string;
}
export type IGetOptions = (optionType: string) => IOption[];
export interface IInjected {
getEndpoint: (endpoint: string) => Promise<any>;
getOptions: IGetOptions;
}
export interface IFormFieldProps {
fieldConfig: IFieldConfig;
formManager: FormManager;
formModel: IModel;
}
export interface ICheckboxProps extends IFormFieldProps {
description?: string;
disabledText?: string;
}
export interface IEndpointOption {
id: string;
}
export type ILayout = 'horizontal' | 'inline' | 'vertical';
export interface IFormatProps {
layout?: ILayout;
colon?: boolean;
}