This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
widget.ts
274 lines (254 loc) · 6.68 KB
/
widget.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
import { WidgetShowCondition, WidgetTypes, WidgetOptions, WidgetFormField, WidgetListField, WidgetInfoField } from '@tesler-ui/schema'
import { ComponentType } from 'react'
export {
WidgetShowCondition,
WidgetTypes,
WidgetOptions,
LayoutRow,
LayoutCol,
WidgetOperations,
TableOperations,
PositionTypes,
WidgetTableHierarchy,
WidgetFieldBase,
WidgetListFieldBase,
WidgetFormFieldBase,
AllWidgetTypeFieldBase,
NumberFieldMeta,
DateFieldMeta,
CheckboxFieldMeta,
DateTimeFieldMeta,
DateTimeWithSecondsFieldMeta,
DictionaryFieldMeta,
TextFieldMeta,
InputFieldMeta,
MultiFieldMeta,
MultivalueFieldMeta,
PickListFieldMeta,
InlinePickListFieldMeta,
FileUploadFieldMeta,
WidgetFormField,
WidgetListField,
HiddenFieldMeta,
RadioButtonFieldMeta,
WidgetField,
WidgetInfoField
} from '@tesler-ui/schema'
/**
* Different widget types that are considered `tables` in nature for purposes of applying some shared features.
* For example, autofocus on missing required field should work for tables but not forms.
*
* TODO: Make extension point
*
* @category Components
*/
export const TableLikeWidgetTypes = [
WidgetTypes.List,
WidgetTypes.DataGrid,
WidgetTypes.AssocListPopup,
WidgetTypes.PickListPopup,
WidgetTypes.FlatTree,
WidgetTypes.FlatTreePopup
] as const
/**
* Widgets that are considered `popups` and usually excluded from widgets layout grid
*/
export const PopupWidgetTypes: string[] = [WidgetTypes.PickListPopup, WidgetTypes.AssocListPopup, WidgetTypes.FlatTreePopup]
/**
* All widget types that display table-like data
*/
type TableLikeWidgetType = typeof TableLikeWidgetTypes[number]
export interface WidgetInfoOptions {
fieldBorderBottom?: boolean
footer?: string
}
export interface WidgetMeta {
name: string
type: WidgetTypes | string // TODO: Как учитывать типы клиентских виджетов кроме string?
title: string // отображаемое название,
bcName: string
/**
* Business components ancestors hierarchy
*
* TODO: Will be mandatory (but nullable) in 2.0.0
*
* It is declared in `WidgetDTO` of Tesler API, can be null for widgets without
* business component (headers, navigation tabs, etc.)
*/
url?: string | null
position: number
limit?: number
gridWidth: number // 1-24
fields: unknown[]
options?: WidgetOptions
showCondition?: WidgetShowCondition
description?: string // description for documentation
}
/**
* Description of the list of fields of block type.
*
* @deprecated Used to create a block grouping of fields
*/
export interface WidgetFieldBlock<T> {
/**
* Block ID
*/
blockId: number
/**
* Name of the block
*/
name: string
/**
* Fields contained in the block
*/
fields: T[]
/**
* @deprecated TODO: Remove in 2.0.0, used to denote a new row in old layout system for forms
*/
newRow?: boolean
/**
* @deprecated TODO: Remove in 2.0.0, used to ...
*/
break?: boolean
}
export type WidgetFieldsOrBlocks<T> = Array<T | WidgetFieldBlock<T>>
/**
* Configuration for widgets dislaying form data
*/
export interface WidgetFormMeta extends WidgetMeta {
/**
* Unambiguous marker for JSON file specifing widget type
*/
type: WidgetTypes.Form
/**
* Descriptor for fields or block of fields on the form
*/
fields: WidgetFieldsOrBlocks<WidgetFormField>
}
/**
* Configuration for widgets displaying table-like data
*/
export interface WidgetTableMeta extends WidgetMeta {
/**
* Unambiguous marker for JSON file specifing widget type
*/
type: TableLikeWidgetType
/**
* Descriptor for table columns
*/
fields: WidgetListField[]
}
/**
* Configuration for widgets displaying read-only table data
*/
export interface WidgetInfoMeta extends WidgetMeta {
/**
* Unambiguous marker for JSON file specifying widget type
*/
type: WidgetTypes.Info
/**
* Descriptor for fields or block of fields on the form
*/
fields: WidgetFieldsOrBlocks<WidgetInfoField>
/**
* Options for customizing widget
*/
options?: WidgetOptions & WidgetInfoOptions
}
/**
* Configuration for widgets displaying markdown text
*/
export interface WidgetTextMeta extends WidgetMeta {
/**
* Unambiguous marker for JSON file specifying widget type
*/
type: WidgetTypes.Text
/**
* Text to display
*/
description: string
/**
* Title text
*/
descriptionTitle: string
}
/**
* Options configuration for widgets displaying NavigationTabs
*/
export interface NavigationOptions extends WidgetOptions {
/**
* Level of menu
*/
navigationLevel?: number
}
/**
* Configuration for widgets displaying NavigationTabs
*/
export interface NavigationWidgetMeta extends WidgetMeta {
/**
* Unambiguous marker for JSON file specifying widget type
*/
type: WidgetTypes.NavigationTabs | WidgetTypes.ViewNavigation
/**
* Options for customizing widget
*/
options: NavigationOptions
}
/**
* A widget configuration of any known type
*/
export type WidgetMetaAny = WidgetFormMeta | WidgetTableMeta | WidgetTextMeta | WidgetInfoMeta | NavigationWidgetMeta
/**
* Component of custom widget
*
* @deprecated TODO: Remove in 2.0.0
*/
export type CustomWidget = ComponentType<any>
/**
* Configuration of custom widget
*/
export interface CustomWidgetConfiguration {
/**
* Whether widget is popup
*/
isPopup?: boolean
/**
* Component of custom widget
*/
component: ComponentType<any>
/**
* Card of widget
*/
card?: ComponentType<any> | null
}
export type CustomWidgetDescriptor = CustomWidget | CustomWidgetConfiguration
/**
* Check if descriptor is just a widget, or it has additional data
*/
export function isCustomWidget(descriptor: CustomWidgetDescriptor): descriptor is CustomWidget {
return !!descriptor && !('component' in descriptor)
}
/**
* Checks whether @param descriptor is an instance of `CustomWidgetConfiguration`
*
* @param descriptor custom widget descriptor
*/
export function isCustomWidgetConfiguration(descriptor: CustomWidgetDescriptor): descriptor is CustomWidgetConfiguration {
return descriptor && 'component' in descriptor
}
/**
* TODO
*
* @param item
* @category Type Guards
*/
export function isWidgetFieldBlock(item: any): item is WidgetFieldBlock<any> {
return !!item && 'blockId' in item
}
/**
* Type of pagination, either page numbers or "Load More" button
*/
export enum PaginationMode {
page = 'page',
loadMore = 'loadMore'
}