namirasoft-account-react 1.4.430 → 1.4.431

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.env.template +15 -15
  2. package/SKILLS.md +514 -514
  3. package/config-overrides.js +72 -72
  4. package/dist/App.css +32 -0
  5. package/dist/App.d.ts +1 -1
  6. package/dist/UseParams.d.ts +1 -1
  7. package/dist/components/NSAAccessListDialog.d.ts +2 -2
  8. package/dist/components/NSAAccessListDialog.module.css +71 -71
  9. package/dist/components/NSAMasterMenu.d.ts +1 -1
  10. package/dist/components/NSAMasterMenu.module.css +248 -248
  11. package/dist/components/NSAMasterMenuItem.d.ts +1 -1
  12. package/dist/components/NSAMessageListDialog.d.ts +1 -1
  13. package/dist/components/NSAMessageListDialog.module.css +99 -99
  14. package/dist/components/NSAProductListDialog.d.ts +1 -1
  15. package/dist/components/NSAProductListDialog.module.css +44 -44
  16. package/dist/components/NSAReorderDialog.d.ts +1 -1
  17. package/dist/components/NSAReorderDialog.module.css +49 -49
  18. package/dist/components/NSASortDialog.d.ts +1 -1
  19. package/dist/components/NSAUserDialog.d.ts +1 -1
  20. package/dist/components/NSAUserDialog.module.css +67 -67
  21. package/dist/components/NSAWorkspaceListDialog.d.ts +1 -1
  22. package/dist/components/NSAWorkspaceListDialog.module.css +41 -41
  23. package/dist/components/NSBoxSecret.d.ts +1 -1
  24. package/dist/components/NSBoxSecret.module.css +23 -23
  25. package/dist/components/NSLabelSecret.d.ts +1 -1
  26. package/dist/components/quickfilter/NSAFilterBoxEnum.module.css +45 -0
  27. package/dist/components/quickfilter/NSAQuickFilterBar.d.ts +1 -1
  28. package/dist/components/quickfilter/NSAQuickFilterBar.module.css +20 -0
  29. package/dist/components/quickfilter/NSAQuickFilterDialog.d.ts +1 -1
  30. package/dist/components/quickfilter/NSAQuickFilterDialog.module.css +75 -0
  31. package/dist/index.css +0 -0
  32. package/dist/layouts/NSALayout.d.ts +1 -1
  33. package/dist/layouts/NSASectionEdit.d.ts +1 -1
  34. package/dist/layouts/NSASectionEditTabPage.d.ts +1 -1
  35. package/dist/layouts/NSASectionEditTabPage.module.css +4 -4
  36. package/dist/layouts/NSASectionList.d.ts +1 -1
  37. package/dist/layouts/NSASectionList.module.css +31 -31
  38. package/dist/layouts/NSASectionView.d.ts +1 -1
  39. package/dist/layouts/NSASectionViewTabMore.d.ts +1 -1
  40. package/dist/layouts/NSASectionViewTabPage.d.ts +1 -1
  41. package/dist/layouts/NSASectionViewTabPage.module.css +47 -47
  42. package/dist/pages/NSAConsentPage.module.css +26 -26
  43. package/dist/pages/NSAEmailVerificationPage.d.ts +1 -1
  44. package/dist/pages/NSAHomePage.d.ts +1 -1
  45. package/dist/pages/NSAHomePage.module.css +41 -41
  46. package/dist/pages/NSALoginPage.d.ts +1 -1
  47. package/dist/pages/NSALoginPage.module.css +26 -26
  48. package/dist/pages/NSAPhoneVerificationPage.d.ts +1 -1
  49. package/dist/pages/NSAVerificationPage.d.ts +1 -1
  50. package/dist/pages/NSAVerificationPage.module.css +31 -31
  51. package/package.json +94 -94
  52. package/public/index.html +21 -21
  53. package/src/App.css +31 -31
  54. package/src/App.tsx +19 -19
  55. package/src/CTFRow.ts +7 -7
  56. package/src/IEntityInfo.ts +33 -33
  57. package/src/NSACacheService.ts +120 -120
  58. package/src/NSAFilterOperators.ts +92 -92
  59. package/src/NSARouterMaker.tsx +139 -139
  60. package/src/NSARouterMakerConfig.ts +15 -15
  61. package/src/NSARouterMakerProps.ts +22 -22
  62. package/src/Router.tsx +45 -45
  63. package/src/UseParams.tsx +18 -18
  64. package/src/components/NSAAccessListDialog.module.css +71 -71
  65. package/src/components/NSAAccessListDialog.tsx +178 -178
  66. package/src/components/NSAMasterMenu.module.css +248 -248
  67. package/src/components/NSAMasterMenu.tsx +169 -169
  68. package/src/components/NSAMasterMenuItem.tsx +250 -250
  69. package/src/components/NSAMessageListDialog.module.css +99 -99
  70. package/src/components/NSAMessageListDialog.tsx +141 -141
  71. package/src/components/NSAProductListDialog.module.css +44 -44
  72. package/src/components/NSAProductListDialog.tsx +88 -88
  73. package/src/components/NSAReorderDialog.module.css +49 -49
  74. package/src/components/NSAReorderDialog.tsx +149 -149
  75. package/src/components/NSASortDialog.tsx +117 -117
  76. package/src/components/NSATable.tsx +489 -489
  77. package/src/components/NSAUserDialog.module.css +67 -67
  78. package/src/components/NSAUserDialog.tsx +122 -122
  79. package/src/components/NSAWorkspaceListDialog.module.css +41 -41
  80. package/src/components/NSAWorkspaceListDialog.tsx +147 -147
  81. package/src/components/NSBoxSecret.module.css +23 -23
  82. package/src/components/NSBoxSecret.tsx +258 -258
  83. package/src/components/NSLabelSecret.tsx +37 -37
  84. package/src/components/quickfilter/NSAFilterBoxBase.tsx +55 -55
  85. package/src/components/quickfilter/NSAFilterBoxBoolean.tsx +54 -54
  86. package/src/components/quickfilter/NSAFilterBoxDate.tsx +104 -104
  87. package/src/components/quickfilter/NSAFilterBoxDateTime.tsx +105 -105
  88. package/src/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  89. package/src/components/quickfilter/NSAFilterBoxEnum.tsx +79 -79
  90. package/src/components/quickfilter/NSAFilterBoxNumber.tsx +136 -136
  91. package/src/components/quickfilter/NSAFilterBoxString.tsx +81 -81
  92. package/src/components/quickfilter/NSAFilterBoxTime.tsx +101 -101
  93. package/src/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  94. package/src/components/quickfilter/NSAQuickFilterBar.tsx +114 -114
  95. package/src/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  96. package/src/components/quickfilter/NSAQuickFilterDialog.tsx +260 -260
  97. package/src/css.d.ts +13 -13
  98. package/src/formatters/SecretFormatter.tsx +24 -24
  99. package/src/index.tsx +24 -24
  100. package/src/layouts/Actions.ts +145 -145
  101. package/src/layouts/CFTUtil.ts +18 -18
  102. package/src/layouts/NSALayout.tsx +841 -841
  103. package/src/layouts/NSASectionEdit.tsx +260 -260
  104. package/src/layouts/NSASectionEditTabPage.module.css +4 -4
  105. package/src/layouts/NSASectionEditTabPage.tsx +250 -250
  106. package/src/layouts/NSASectionList.module.css +31 -31
  107. package/src/layouts/NSASectionList.tsx +149 -149
  108. package/src/layouts/NSASectionView.tsx +100 -100
  109. package/src/layouts/NSASectionViewTabMore.tsx +77 -77
  110. package/src/layouts/NSASectionViewTabPage.module.css +47 -47
  111. package/src/layouts/NSASectionViewTabPage.tsx +419 -419
  112. package/src/main.ts +46 -46
  113. package/src/pages/NSAConsentPage.module.css +26 -26
  114. package/src/pages/NSAConsentPage.tsx +120 -120
  115. package/src/pages/NSAEmailVerificationPage.tsx +30 -30
  116. package/src/pages/NSAHomePage.module.css +41 -41
  117. package/src/pages/NSAHomePage.tsx +102 -102
  118. package/src/pages/NSALoginPage.module.css +26 -26
  119. package/src/pages/NSALoginPage.tsx +87 -87
  120. package/src/pages/NSAPhoneVerificationPage.tsx +94 -94
  121. package/src/pages/NSAVerificationPage.module.css +31 -31
  122. package/src/pages/NSAVerificationPage.tsx +186 -186
  123. package/src/pages/PaymentRequired.tsx +74 -74
  124. package/tsconfig.json +43 -43
@@ -1,490 +1,490 @@
1
- import { FilterItem, FilterItemColumnType, NamingConvention, ObjectService, SearchOperation, SortItem } from "namirasoft-core";
2
- import { CategoryRow, FieldRow } from "namirasoft-field";
3
- import { FilterItemColumnTypeBuilder, VariableType } from "namirasoft-schema";
4
- import { IBaseComponentProps, NSButtonProps, NSFilterBox, NSFilterBoxItems, NSFilterBoxProps_Table, NSTable, TableColumnInfo, TableRowInfo } from "namirasoft-site-react";
5
- import { Component, ReactNode, createRef } from "react";
6
- import { IEntityInfo } from "../IEntityInfo";
7
- import { NSACacheService } from "../NSACacheService";
8
- import { NSAQuickFilterBar } from "./quickfilter/NSAQuickFilterBar";
9
- import { NSAQuickFilterDialog, QuickFilterConfig } from "./quickfilter/NSAQuickFilterDialog";
10
- import { NSAReorderDialog } from "./NSAReorderDialog";
11
- import { NSASortDialog } from "./NSASortDialog";
12
-
13
- export interface NSATableUIProps<RowType>
14
- {
15
- getRowAttributes?: (row_value: RowType, row_index: number, res: { rows: RowType[]; count: number; } | null) => { [key: string]: any };
16
- getColumnAttributes?: (column: TableColumnInfo) => { [key: string]: any };
17
- getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<RowType>) => any;
18
- search_box?: {
19
- exclude?: {
20
- show?: {
21
- table?: (table: string) => boolean;
22
- column?: (table: string, column: string) => boolean;
23
- },
24
- load_value?: (table: string, column: string) => boolean;
25
- }
26
- };
27
- }
28
-
29
- export interface NSATableProps<RowType extends { id: string }, RowTypeInput = RowType> extends IBaseComponentProps
30
- {
31
- entity: IEntityInfo<RowType, RowTypeInput>;
32
- ctf: {
33
- enabled: boolean;
34
- fields: FieldRow[] | null;
35
- categories: CategoryRow[] | null;
36
- };
37
- url: { getQuery(name: string, base64?: boolean, remove?: boolean): string };
38
- ui?: NSATableUIProps<RowType>;
39
- checkbox?: boolean;
40
- buttons?: NSButtonProps[];
41
- onSelectionChanged?: () => void;
42
- }
43
-
44
- interface NSATableState<RowType>
45
- {
46
- res: { rows: RowType[]; count: number; } | null;
47
- sorts: SortItem[];
48
- visible_column_keys: string[];
49
- quick_filter_configs: QuickFilterConfig[];
50
- show_sort_dialog: boolean;
51
- show_reorder_dialog: boolean;
52
- show_quick_filter_dialog: boolean;
53
- filter_revision: number;
54
- }
55
-
56
- export class NSATable<RowType extends { id: string }, RowTypeInput = RowType>
57
- extends Component<NSATableProps<RowType, RowTypeInput>, NSATableState<RowType>>
58
- {
59
- public NSTable_Main = createRef<NSTable<RowType>>();
60
- public NSFilterBox_Top = createRef<NSFilterBox>();
61
- public NSAQuickFilterBar_Ref = createRef<NSAQuickFilterBar>();
62
-
63
- constructor(props: NSATableProps<RowType, RowTypeInput>)
64
- {
65
- super(props);
66
- this.state = {
67
- res: null,
68
- sorts: [],
69
- visible_column_keys: [],
70
- quick_filter_configs: [],
71
- show_sort_dialog: false,
72
- show_reorder_dialog: false,
73
- show_quick_filter_dialog: false,
74
- filter_revision: 0,
75
- };
76
- }
77
-
78
- override componentDidMount()
79
- {
80
- const visible = this.NSTable_Main.current?.getVisibleColumns() ?? [];
81
- if (visible.length > 0)
82
- this.setState({ visible_column_keys: visible.map(v => v.table + "." + v.column) });
83
-
84
- let quick_filter_configs = NSACacheService.loadQuickFilters(this.props.entity.name);
85
- if (quick_filter_configs.length === 0)
86
- quick_filter_configs = this.buildDefaultQuickFilters();
87
- // Re-render so the filter chips reflect any incoming filter items.
88
- this.setState(prev => ({ quick_filter_configs, filter_revision: prev.filter_revision + 1 }));
89
- }
90
-
91
- private getColumns(): TableColumnInfo[]
92
- {
93
- let columns = Object.values(this.props.entity.client.getColumns()).flat();
94
- columns.forEach(col =>
95
- {
96
- col.text = NamingConvention.auto.convert(col.text, NamingConvention.Pascal_Case_Space);
97
- });
98
- return columns;
99
- }
100
-
101
- private buildDefaultQuickFilters(): QuickFilterConfig[]
102
- {
103
- const getDefaults = this.props.entity.client.getQuickFilters;
104
- if (!getDefaults)
105
- return [];
106
-
107
- const columns = this.getColumns();
108
- const ans: QuickFilterConfig[] = [];
109
- for (const def of getDefaults())
110
- {
111
- const col = columns.find(c => c.name === def.column);
112
- if (!col)
113
- continue;
114
- const columnType = new ObjectService(col.type).getEnum(VariableType, VariableType.Any);
115
- ans.push({
116
- id: `default-${col.table.name}-${col.name}`,
117
- column: {
118
- table: { name: col.table.name, text: col.table.text },
119
- name: col.name,
120
- text: col.text,
121
- type: col.type,
122
- columnType,
123
- },
124
- operatorName: (def as { operator?: string }).operator,
125
- });
126
- }
127
- return ans;
128
- }
129
-
130
- private filterItemTypeConverter(type: string): FilterItemColumnType
131
- {
132
- let t = new ObjectService(type).getEnum(VariableType, VariableType.Any);
133
- let builder = new FilterItemColumnTypeBuilder(t);
134
- return builder.runSynch(() => { }) ?? FilterItemColumnType.Unknown;
135
- }
136
-
137
- private getIncomingFilterItems(): FilterItem[] | undefined
138
- {
139
- try
140
- {
141
- let encoded = this.props.url.getQuery("filters");
142
- if (encoded)
143
- return FilterItem.decode(encoded) ?? undefined;
144
- } catch (error)
145
- {
146
- }
147
- return undefined;
148
- }
149
-
150
- public reload(page: number | null, size: number | null): Promise<void> | undefined
151
- {
152
- return this.NSTable_Main.current?.reload(page, size);
153
- }
154
- public getSelectedIDs(): string[]
155
- {
156
- return this.NSTable_Main.current?.getSelectedIDs() ?? [];
157
- }
158
- public getSelectedRows(): RowType[]
159
- {
160
- return this.NSTable_Main.current?.getSelectedRows() ?? [];
161
- }
162
- public setSelectedIDs(ids: string[], rows: RowType[], callback?: () => void)
163
- {
164
- this.NSTable_Main.current?.setSelectedIDs(ids, rows, callback);
165
- }
166
- public getSortItems(): SortItem[]
167
- {
168
- return this.NSTable_Main.current?.getSortItems() ?? [];
169
- }
170
- public setSortItems(items: SortItem[] | null)
171
- {
172
- this.NSTable_Main.current?.setSortItems(items);
173
- }
174
- public getVisibleColumns(): { table: string, column: string }[]
175
- {
176
- return this.NSTable_Main.current?.getVisibleColumns() ?? [];
177
- }
178
- public setVisibleColumns(visible_columns: { table: string, column: string }[])
179
- {
180
- this.NSTable_Main.current?.setVisibleColumns(visible_columns);
181
- }
182
- public getFilterBoxItems(): FilterItem[]
183
- {
184
- return this.NSFilterBox_Top.current?.getFilterItems() ?? [];
185
- }
186
- public getQuickFilterItems(): FilterItem[]
187
- {
188
- return this.NSAQuickFilterBar_Ref.current?.getFilterItems() ?? [];
189
- }
190
- public getFilterItems(): FilterItem[]
191
- {
192
- return [...this.getFilterBoxItems(), ...this.getQuickFilterItems()];
193
- }
194
-
195
- private reloadFromFilters()
196
- {
197
- this.NSTable_Main.current?.setSelectedIDs([], []);
198
- this.NSTable_Main.current?.reload(null, null);
199
- }
200
-
201
- private onFilterBoxChanged = () =>
202
- {
203
- this.reloadFromFilters();
204
- this.setState(prev => ({ filter_revision: prev.filter_revision + 1 }));
205
- };
206
-
207
- private buildButtons(): NSButtonProps[]
208
- {
209
- const buttons: NSButtonProps[] = [
210
- {
211
- title: "",
212
- icon: { src: "https://static.namirasoft.com/image/concept/grip-vertical/blue.svg", alt: "reorder" },
213
- attributes: { title: "Reorder" },
214
- onClick: {
215
- action: () => this.setState({ show_reorder_dialog: true, visible_column_keys: this.getVisibleColumns().map(c => c.table + "." + c.column) }),
216
- showLoading: false,
217
- },
218
- },
219
- {
220
- title: "",
221
- icon: { src: "https://static.namirasoft.com/image/concept/arrow-down-short-wide/blue.svg", alt: "sort" },
222
- attributes: { title: "Sort" },
223
- onClick: {
224
- action: () => this.setState({ show_sort_dialog: true, sorts: this.getSortItems() }),
225
- showLoading: false,
226
- },
227
- },
228
- {
229
- title: "",
230
- icon: { src: "https://static.namirasoft.com/image/concept/sliders/blue.svg", alt: "filter" },
231
- attributes: { title: "Quick Filters" },
232
- onClick: {
233
- action: () => this.setState({ show_quick_filter_dialog: true }),
234
- showLoading: false,
235
- },
236
- },
237
- ];
238
- return [...buttons, ...(this.props.buttons ?? [])];
239
- }
240
-
241
- private renderFilterHeader(): ReactNode
242
- {
243
- return (
244
- <NSFilterBox
245
- ref={this.NSFilterBox_Top}
246
- filterItems={this.getIncomingFilterItems()}
247
- getTables={() =>
248
- {
249
- return this.props.entity.tables.map(table =>
250
- {
251
- let columns = table.table.getColumns().map(c => ({ id: c.name, ...c, type: this.filterItemTypeConverter(c.type) }));
252
- columns = columns.filter(c =>
253
- {
254
- if (this.props.ui?.search_box?.exclude?.show?.column)
255
- if (this.props.ui?.search_box?.exclude.show?.column(table.table.name, c.name))
256
- return false;
257
- return true;
258
- });
259
- return { name: table.table.name, text: table.table.text, columns, required: table.required };
260
- }).filter(t =>
261
- {
262
- if (this.props.ui?.search_box?.exclude?.show?.table)
263
- if (this.props.ui?.search_box?.exclude.show.table(t.name))
264
- return false;
265
- return true;
266
- });
267
- }}
268
- getMoreTables={async () =>
269
- {
270
- let ans: NSFilterBoxProps_Table[] = [];
271
- if (this.props.ctf.enabled)
272
- try
273
- {
274
- if (this.props.ctf.fields)
275
- if (this.props.ctf.fields.length > 0)
276
- {
277
- let name = this.props.entity.name + "_field";
278
- ans.push({
279
- name,
280
- text: "Fields",
281
- columns: [{
282
- id: "field_id",
283
- name: "field_id",
284
- text: "ID",
285
- type: FilterItemColumnType.Unknown,
286
- getValues: async (search) =>
287
- {
288
- return this.props.ctf.fields?.filter(c => SearchOperation.match(c.id, search)).map(c => { return { value: c.id, title: c.id } }) ?? [];
289
- }
290
- }, {
291
- id: "field_name",
292
- name: "field_id",
293
- text: "Name",
294
- type: FilterItemColumnType.Unknown,
295
- getValues: async (search) =>
296
- {
297
- return this.props.ctf.fields?.filter(c => SearchOperation.match(c.name, search)).map(c => { return { value: c.id, title: c.name } }) ?? [];
298
- }
299
- }, {
300
- id: "field_value",
301
- name: "value",
302
- text: "Value",
303
- type: FilterItemColumnType.Unknown
304
- },
305
- ...this.props.ctf.fields.map(f =>
306
- {
307
- return {
308
- id: f.id,
309
- name: f.id,
310
- text: f.name,
311
- type: this.filterItemTypeConverter(f.type.type.type),
312
- getValues: async (search: string) =>
313
- {
314
- let values = await this.props.entity.server.value_list(name, "value", search, f.id, null);
315
- return values.map(v => { return { value: v, title: v } });
316
- }
317
- };
318
- }),],
319
- required: false
320
- });
321
- }
322
-
323
- if (this.props.ctf.categories)
324
- if (this.props.ctf.categories.length > 0)
325
- ans.push({
326
- name: this.props.entity.name + "_category",
327
- text: "Categories",
328
- columns: [{
329
- id: "category_id",
330
- name: "category_id",
331
- text: "ID",
332
- type: FilterItemColumnType.Unknown,
333
- getValues: async (search) =>
334
- {
335
- return this.props.ctf.categories?.filter(c => SearchOperation.match(c.id, search)).map(c => { return { value: c.id, title: c.id } }) ?? [];
336
- }
337
- }, {
338
- id: "category_name",
339
- name: "category_id",
340
- text: "Name",
341
- type: FilterItemColumnType.Unknown,
342
- getValues: async (search) =>
343
- {
344
- return this.props.ctf.categories?.filter(c => SearchOperation.match(c.name, search)).map(c => { return { value: c.id, title: c.name } }) ?? [];
345
- }
346
- }],
347
- required: false
348
- });
349
-
350
- } catch (error)
351
- {
352
- }
353
- // todo add tags
354
- return ans;
355
- }}
356
- getValues={async (table, column, value) =>
357
- {
358
- if (this.props.ui?.search_box?.exclude?.load_value)
359
- if (this.props.ui?.search_box?.exclude?.load_value(table.name, column.name))
360
- return [];
361
- let values = await this.props.entity.server.value_list(table.name, column.name, value, null, null);
362
- return values.map(v => { return { value: v, title: v } });
363
- }}
364
- onChanged={this.onFilterBoxChanged}
365
- />
366
- );
367
- }
368
-
369
- private getOrderedColumns(): TableColumnInfo[]
370
- {
371
- const all = this.getColumns();
372
- const vk = this.state.visible_column_keys;
373
- if (vk.length === 0)
374
- return all;
375
- const ordered = vk.map(k => all.find(c => c.table.name + "." + c.name === k)).filter((c): c is TableColumnInfo => !!c);
376
- const rest = all.filter(c => !vk.includes(c.table.name + "." + c.name));
377
- return [...ordered, ...rest];
378
- }
379
-
380
- override render(): ReactNode
381
- {
382
- const filterBoxItems = this.NSFilterBox_Top.current?.getFilterItems() ?? [];
383
- const filterChips = filterBoxItems.length > 0 && (
384
- <NSFilterBoxItems
385
- filterItems={filterBoxItems}
386
- onClearFilterItems={() => this.NSFilterBox_Top.current?.setFilterItems([])}
387
- onRemoveFilterItem={(item) => this.NSFilterBox_Top.current?.removeFilterItem(item)}
388
- />
389
- );
390
-
391
- const quickFilterBar = this.state.quick_filter_configs.length > 0 && (
392
- <NSAQuickFilterBar
393
- key={this.state.quick_filter_configs.map(c => c.id).join("-")}
394
- ref={this.NSAQuickFilterBar_Ref}
395
- configs={this.state.quick_filter_configs}
396
- getValues={async (tableName, columnName, search) =>
397
- {
398
- const values = await this.props.entity.server.value_list(tableName, columnName, search, null, null);
399
- const col = this.getColumns().find(c => c.table.name === tableName && c.name === columnName);
400
- return values.map(v =>
401
- {
402
- const formatted = col ? col.formatter.format(v, col, { value: {} } as any, true) : null;
403
- return { value: v, title: formatted != null ? String(formatted) : v };
404
- });
405
- }}
406
- onChanged={() => this.reloadFromFilters()}
407
- />
408
- );
409
-
410
- return (
411
- <>
412
- <NSTable<RowType>
413
- id={this.props.id}
414
- classList={this.props.classList}
415
- style={this.props.style}
416
- ref={this.NSTable_Main}
417
- name={NamingConvention.lower_case_dash.convert(this.props.entity.name, NamingConvention.Pascal_Case_Space)}
418
- checkbox={this.props.checkbox ?? true}
419
- headerChildren={this.renderFilterHeader()}
420
- buttons={this.buildButtons()}
421
- columns={this.getOrderedColumns()}
422
- getRows={async (page, size, sorts) =>
423
- {
424
- let res: { rows: RowType[], count: number } = { rows: [], count: 0 };
425
- if (this.props.entity.server.list)
426
- res = await this.props.entity.server.list(this.getFilterItems(), page, size, sorts, null);
427
- this.setState({ res });
428
- return res;
429
- }}
430
- getRowKey={(row) => row.value.id.toString()}
431
- getRowAttributes={(row_value, row_index) => this.props.ui?.getRowAttributes?.(row_value, row_index, this.state.res) ?? {}}
432
- getColumnAttributes={this.props.ui?.getColumnAttributes}
433
- getCellFormattedValue={this.props.ui?.getCellFormattedValue}
434
- onVisibleColumnsChanged={(visible_columns) => this.setState({ visible_column_keys: visible_columns.map(c => c.table + "." + c.column) })}
435
- onSelectedIDsChanged={() => this.props.onSelectionChanged?.()}
436
- >
437
- {filterChips}
438
- {quickFilterBar}
439
- </NSTable>
440
- {
441
- this.state.show_sort_dialog &&
442
- <NSASortDialog
443
- sorts={this.state.sorts}
444
- getColumns={() => this.getColumns()}
445
- onCancel={() => this.setState({ show_sort_dialog: false })}
446
- onApply={sorts =>
447
- {
448
- this.setSortItems(sorts);
449
- this.setState({ show_sort_dialog: false, sorts: sorts ?? [] });
450
- }}
451
- />
452
- }
453
- {
454
- this.state.show_reorder_dialog &&
455
- <NSAReorderDialog
456
- visibleColumnKeys={this.state.visible_column_keys}
457
- getColumns={() => this.getColumns()}
458
- onCancel={() => this.setState({ show_reorder_dialog: false })}
459
- onApply={orderedKeys =>
460
- {
461
- const cs_all = this.getColumns();
462
- const cs = orderedKeys.map((v: string) => cs_all.find((c: TableColumnInfo) => v === c.table.name + "." + c.name)).filter(Boolean) as TableColumnInfo[];
463
- this.setVisibleColumns(cs.map(c => ({ table: c.table.name, column: c.name })));
464
- this.setState({ show_reorder_dialog: false, visible_column_keys: orderedKeys });
465
- }}
466
- />
467
- }
468
- {
469
- this.state.show_quick_filter_dialog &&
470
- <NSAQuickFilterDialog
471
- configs={this.state.quick_filter_configs}
472
- getColumns={() => this.getColumns()}
473
- typeConverter={(type: string) => new ObjectService(type).getEnum(VariableType, VariableType.Any)}
474
- onSave={configs =>
475
- {
476
- NSACacheService.saveQuickFilters(this.props.entity.name, configs);
477
- this.setState({ quick_filter_configs: configs }, () => this.reloadFromFilters());
478
- }}
479
- onConfirm={configs =>
480
- {
481
- NSACacheService.saveQuickFilters(this.props.entity.name, configs);
482
- this.setState({ quick_filter_configs: configs, show_quick_filter_dialog: false }, () => this.reloadFromFilters());
483
- }}
484
- onClose={() => this.setState({ show_quick_filter_dialog: false })}
485
- />
486
- }
487
- </>
488
- );
489
- }
1
+ import { FilterItem, FilterItemColumnType, NamingConvention, ObjectService, SearchOperation, SortItem } from "namirasoft-core";
2
+ import { CategoryRow, FieldRow } from "namirasoft-field";
3
+ import { FilterItemColumnTypeBuilder, VariableType } from "namirasoft-schema";
4
+ import { IBaseComponentProps, NSButtonProps, NSFilterBox, NSFilterBoxItems, NSFilterBoxProps_Table, NSTable, TableColumnInfo, TableRowInfo } from "namirasoft-site-react";
5
+ import { Component, ReactNode, createRef } from "react";
6
+ import { IEntityInfo } from "../IEntityInfo";
7
+ import { NSACacheService } from "../NSACacheService";
8
+ import { NSAQuickFilterBar } from "./quickfilter/NSAQuickFilterBar";
9
+ import { NSAQuickFilterDialog, QuickFilterConfig } from "./quickfilter/NSAQuickFilterDialog";
10
+ import { NSAReorderDialog } from "./NSAReorderDialog";
11
+ import { NSASortDialog } from "./NSASortDialog";
12
+
13
+ export interface NSATableUIProps<RowType>
14
+ {
15
+ getRowAttributes?: (row_value: RowType, row_index: number, res: { rows: RowType[]; count: number; } | null) => { [key: string]: any };
16
+ getColumnAttributes?: (column: TableColumnInfo) => { [key: string]: any };
17
+ getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<RowType>) => any;
18
+ search_box?: {
19
+ exclude?: {
20
+ show?: {
21
+ table?: (table: string) => boolean;
22
+ column?: (table: string, column: string) => boolean;
23
+ },
24
+ load_value?: (table: string, column: string) => boolean;
25
+ }
26
+ };
27
+ }
28
+
29
+ export interface NSATableProps<RowType extends { id: string }, RowTypeInput = RowType> extends IBaseComponentProps
30
+ {
31
+ entity: IEntityInfo<RowType, RowTypeInput>;
32
+ ctf: {
33
+ enabled: boolean;
34
+ fields: FieldRow[] | null;
35
+ categories: CategoryRow[] | null;
36
+ };
37
+ url: { getQuery(name: string, base64?: boolean, remove?: boolean): string };
38
+ ui?: NSATableUIProps<RowType>;
39
+ checkbox?: boolean;
40
+ buttons?: NSButtonProps[];
41
+ onSelectionChanged?: () => void;
42
+ }
43
+
44
+ interface NSATableState<RowType>
45
+ {
46
+ res: { rows: RowType[]; count: number; } | null;
47
+ sorts: SortItem[];
48
+ visible_column_keys: string[];
49
+ quick_filter_configs: QuickFilterConfig[];
50
+ show_sort_dialog: boolean;
51
+ show_reorder_dialog: boolean;
52
+ show_quick_filter_dialog: boolean;
53
+ filter_revision: number;
54
+ }
55
+
56
+ export class NSATable<RowType extends { id: string }, RowTypeInput = RowType>
57
+ extends Component<NSATableProps<RowType, RowTypeInput>, NSATableState<RowType>>
58
+ {
59
+ public NSTable_Main = createRef<NSTable<RowType>>();
60
+ public NSFilterBox_Top = createRef<NSFilterBox>();
61
+ public NSAQuickFilterBar_Ref = createRef<NSAQuickFilterBar>();
62
+
63
+ constructor(props: NSATableProps<RowType, RowTypeInput>)
64
+ {
65
+ super(props);
66
+ this.state = {
67
+ res: null,
68
+ sorts: [],
69
+ visible_column_keys: [],
70
+ quick_filter_configs: [],
71
+ show_sort_dialog: false,
72
+ show_reorder_dialog: false,
73
+ show_quick_filter_dialog: false,
74
+ filter_revision: 0,
75
+ };
76
+ }
77
+
78
+ override componentDidMount()
79
+ {
80
+ const visible = this.NSTable_Main.current?.getVisibleColumns() ?? [];
81
+ if (visible.length > 0)
82
+ this.setState({ visible_column_keys: visible.map(v => v.table + "." + v.column) });
83
+
84
+ let quick_filter_configs = NSACacheService.loadQuickFilters(this.props.entity.name);
85
+ if (quick_filter_configs.length === 0)
86
+ quick_filter_configs = this.buildDefaultQuickFilters();
87
+ // Re-render so the filter chips reflect any incoming filter items.
88
+ this.setState(prev => ({ quick_filter_configs, filter_revision: prev.filter_revision + 1 }));
89
+ }
90
+
91
+ private getColumns(): TableColumnInfo[]
92
+ {
93
+ let columns = Object.values(this.props.entity.client.getColumns()).flat();
94
+ columns.forEach(col =>
95
+ {
96
+ col.text = NamingConvention.auto.convert(col.text, NamingConvention.Pascal_Case_Space);
97
+ });
98
+ return columns;
99
+ }
100
+
101
+ private buildDefaultQuickFilters(): QuickFilterConfig[]
102
+ {
103
+ const getDefaults = this.props.entity.client.getQuickFilters;
104
+ if (!getDefaults)
105
+ return [];
106
+
107
+ const columns = this.getColumns();
108
+ const ans: QuickFilterConfig[] = [];
109
+ for (const def of getDefaults())
110
+ {
111
+ const col = columns.find(c => c.name === def.column);
112
+ if (!col)
113
+ continue;
114
+ const columnType = new ObjectService(col.type).getEnum(VariableType, VariableType.Any);
115
+ ans.push({
116
+ id: `default-${col.table.name}-${col.name}`,
117
+ column: {
118
+ table: { name: col.table.name, text: col.table.text },
119
+ name: col.name,
120
+ text: col.text,
121
+ type: col.type,
122
+ columnType,
123
+ },
124
+ operatorName: (def as { operator?: string }).operator,
125
+ });
126
+ }
127
+ return ans;
128
+ }
129
+
130
+ private filterItemTypeConverter(type: string): FilterItemColumnType
131
+ {
132
+ let t = new ObjectService(type).getEnum(VariableType, VariableType.Any);
133
+ let builder = new FilterItemColumnTypeBuilder(t);
134
+ return builder.runSynch(() => { }) ?? FilterItemColumnType.Unknown;
135
+ }
136
+
137
+ private getIncomingFilterItems(): FilterItem[] | undefined
138
+ {
139
+ try
140
+ {
141
+ let encoded = this.props.url.getQuery("filters");
142
+ if (encoded)
143
+ return FilterItem.decode(encoded) ?? undefined;
144
+ } catch (error)
145
+ {
146
+ }
147
+ return undefined;
148
+ }
149
+
150
+ public reload(page: number | null, size: number | null): Promise<void> | undefined
151
+ {
152
+ return this.NSTable_Main.current?.reload(page, size);
153
+ }
154
+ public getSelectedIDs(): string[]
155
+ {
156
+ return this.NSTable_Main.current?.getSelectedIDs() ?? [];
157
+ }
158
+ public getSelectedRows(): RowType[]
159
+ {
160
+ return this.NSTable_Main.current?.getSelectedRows() ?? [];
161
+ }
162
+ public setSelectedIDs(ids: string[], rows: RowType[], callback?: () => void)
163
+ {
164
+ this.NSTable_Main.current?.setSelectedIDs(ids, rows, callback);
165
+ }
166
+ public getSortItems(): SortItem[]
167
+ {
168
+ return this.NSTable_Main.current?.getSortItems() ?? [];
169
+ }
170
+ public setSortItems(items: SortItem[] | null)
171
+ {
172
+ this.NSTable_Main.current?.setSortItems(items);
173
+ }
174
+ public getVisibleColumns(): { table: string, column: string }[]
175
+ {
176
+ return this.NSTable_Main.current?.getVisibleColumns() ?? [];
177
+ }
178
+ public setVisibleColumns(visible_columns: { table: string, column: string }[])
179
+ {
180
+ this.NSTable_Main.current?.setVisibleColumns(visible_columns);
181
+ }
182
+ public getFilterBoxItems(): FilterItem[]
183
+ {
184
+ return this.NSFilterBox_Top.current?.getFilterItems() ?? [];
185
+ }
186
+ public getQuickFilterItems(): FilterItem[]
187
+ {
188
+ return this.NSAQuickFilterBar_Ref.current?.getFilterItems() ?? [];
189
+ }
190
+ public getFilterItems(): FilterItem[]
191
+ {
192
+ return [...this.getFilterBoxItems(), ...this.getQuickFilterItems()];
193
+ }
194
+
195
+ private reloadFromFilters()
196
+ {
197
+ this.NSTable_Main.current?.setSelectedIDs([], []);
198
+ this.NSTable_Main.current?.reload(null, null);
199
+ }
200
+
201
+ private onFilterBoxChanged = () =>
202
+ {
203
+ this.reloadFromFilters();
204
+ this.setState(prev => ({ filter_revision: prev.filter_revision + 1 }));
205
+ };
206
+
207
+ private buildButtons(): NSButtonProps[]
208
+ {
209
+ const buttons: NSButtonProps[] = [
210
+ {
211
+ title: "",
212
+ icon: { src: "https://static.namirasoft.com/image/concept/grip-vertical/blue.svg", alt: "reorder" },
213
+ attributes: { title: "Reorder" },
214
+ onClick: {
215
+ action: () => this.setState({ show_reorder_dialog: true, visible_column_keys: this.getVisibleColumns().map(c => c.table + "." + c.column) }),
216
+ showLoading: false,
217
+ },
218
+ },
219
+ {
220
+ title: "",
221
+ icon: { src: "https://static.namirasoft.com/image/concept/arrow-down-short-wide/blue.svg", alt: "sort" },
222
+ attributes: { title: "Sort" },
223
+ onClick: {
224
+ action: () => this.setState({ show_sort_dialog: true, sorts: this.getSortItems() }),
225
+ showLoading: false,
226
+ },
227
+ },
228
+ {
229
+ title: "",
230
+ icon: { src: "https://static.namirasoft.com/image/concept/sliders/blue.svg", alt: "filter" },
231
+ attributes: { title: "Quick Filters" },
232
+ onClick: {
233
+ action: () => this.setState({ show_quick_filter_dialog: true }),
234
+ showLoading: false,
235
+ },
236
+ },
237
+ ];
238
+ return [...buttons, ...(this.props.buttons ?? [])];
239
+ }
240
+
241
+ private renderFilterHeader(): ReactNode
242
+ {
243
+ return (
244
+ <NSFilterBox
245
+ ref={this.NSFilterBox_Top}
246
+ filterItems={this.getIncomingFilterItems()}
247
+ getTables={() =>
248
+ {
249
+ return this.props.entity.tables.map(table =>
250
+ {
251
+ let columns = table.table.getColumns().map(c => ({ id: c.name, ...c, type: this.filterItemTypeConverter(c.type) }));
252
+ columns = columns.filter(c =>
253
+ {
254
+ if (this.props.ui?.search_box?.exclude?.show?.column)
255
+ if (this.props.ui?.search_box?.exclude.show?.column(table.table.name, c.name))
256
+ return false;
257
+ return true;
258
+ });
259
+ return { name: table.table.name, text: table.table.text, columns, required: table.required };
260
+ }).filter(t =>
261
+ {
262
+ if (this.props.ui?.search_box?.exclude?.show?.table)
263
+ if (this.props.ui?.search_box?.exclude.show.table(t.name))
264
+ return false;
265
+ return true;
266
+ });
267
+ }}
268
+ getMoreTables={async () =>
269
+ {
270
+ let ans: NSFilterBoxProps_Table[] = [];
271
+ if (this.props.ctf.enabled)
272
+ try
273
+ {
274
+ if (this.props.ctf.fields)
275
+ if (this.props.ctf.fields.length > 0)
276
+ {
277
+ let name = this.props.entity.name + "_field";
278
+ ans.push({
279
+ name,
280
+ text: "Fields",
281
+ columns: [{
282
+ id: "field_id",
283
+ name: "field_id",
284
+ text: "ID",
285
+ type: FilterItemColumnType.Unknown,
286
+ getValues: async (search) =>
287
+ {
288
+ return this.props.ctf.fields?.filter(c => SearchOperation.match(c.id, search)).map(c => { return { value: c.id, title: c.id } }) ?? [];
289
+ }
290
+ }, {
291
+ id: "field_name",
292
+ name: "field_id",
293
+ text: "Name",
294
+ type: FilterItemColumnType.Unknown,
295
+ getValues: async (search) =>
296
+ {
297
+ return this.props.ctf.fields?.filter(c => SearchOperation.match(c.name, search)).map(c => { return { value: c.id, title: c.name } }) ?? [];
298
+ }
299
+ }, {
300
+ id: "field_value",
301
+ name: "value",
302
+ text: "Value",
303
+ type: FilterItemColumnType.Unknown
304
+ },
305
+ ...this.props.ctf.fields.map(f =>
306
+ {
307
+ return {
308
+ id: f.id,
309
+ name: f.id,
310
+ text: f.name,
311
+ type: this.filterItemTypeConverter(f.type.type.type),
312
+ getValues: async (search: string) =>
313
+ {
314
+ let values = await this.props.entity.server.value_list(name, "value", search, f.id, null);
315
+ return values.map(v => { return { value: v, title: v } });
316
+ }
317
+ };
318
+ }),],
319
+ required: false
320
+ });
321
+ }
322
+
323
+ if (this.props.ctf.categories)
324
+ if (this.props.ctf.categories.length > 0)
325
+ ans.push({
326
+ name: this.props.entity.name + "_category",
327
+ text: "Categories",
328
+ columns: [{
329
+ id: "category_id",
330
+ name: "category_id",
331
+ text: "ID",
332
+ type: FilterItemColumnType.Unknown,
333
+ getValues: async (search) =>
334
+ {
335
+ return this.props.ctf.categories?.filter(c => SearchOperation.match(c.id, search)).map(c => { return { value: c.id, title: c.id } }) ?? [];
336
+ }
337
+ }, {
338
+ id: "category_name",
339
+ name: "category_id",
340
+ text: "Name",
341
+ type: FilterItemColumnType.Unknown,
342
+ getValues: async (search) =>
343
+ {
344
+ return this.props.ctf.categories?.filter(c => SearchOperation.match(c.name, search)).map(c => { return { value: c.id, title: c.name } }) ?? [];
345
+ }
346
+ }],
347
+ required: false
348
+ });
349
+
350
+ } catch (error)
351
+ {
352
+ }
353
+ // todo add tags
354
+ return ans;
355
+ }}
356
+ getValues={async (table, column, value) =>
357
+ {
358
+ if (this.props.ui?.search_box?.exclude?.load_value)
359
+ if (this.props.ui?.search_box?.exclude?.load_value(table.name, column.name))
360
+ return [];
361
+ let values = await this.props.entity.server.value_list(table.name, column.name, value, null, null);
362
+ return values.map(v => { return { value: v, title: v } });
363
+ }}
364
+ onChanged={this.onFilterBoxChanged}
365
+ />
366
+ );
367
+ }
368
+
369
+ private getOrderedColumns(): TableColumnInfo[]
370
+ {
371
+ const all = this.getColumns();
372
+ const vk = this.state.visible_column_keys;
373
+ if (vk.length === 0)
374
+ return all;
375
+ const ordered = vk.map(k => all.find(c => c.table.name + "." + c.name === k)).filter((c): c is TableColumnInfo => !!c);
376
+ const rest = all.filter(c => !vk.includes(c.table.name + "." + c.name));
377
+ return [...ordered, ...rest];
378
+ }
379
+
380
+ override render(): ReactNode
381
+ {
382
+ const filterBoxItems = this.NSFilterBox_Top.current?.getFilterItems() ?? [];
383
+ const filterChips = filterBoxItems.length > 0 && (
384
+ <NSFilterBoxItems
385
+ filterItems={filterBoxItems}
386
+ onClearFilterItems={() => this.NSFilterBox_Top.current?.setFilterItems([])}
387
+ onRemoveFilterItem={(item) => this.NSFilterBox_Top.current?.removeFilterItem(item)}
388
+ />
389
+ );
390
+
391
+ const quickFilterBar = this.state.quick_filter_configs.length > 0 && (
392
+ <NSAQuickFilterBar
393
+ key={this.state.quick_filter_configs.map(c => c.id).join("-")}
394
+ ref={this.NSAQuickFilterBar_Ref}
395
+ configs={this.state.quick_filter_configs}
396
+ getValues={async (tableName, columnName, search) =>
397
+ {
398
+ const values = await this.props.entity.server.value_list(tableName, columnName, search, null, null);
399
+ const col = this.getColumns().find(c => c.table.name === tableName && c.name === columnName);
400
+ return values.map(v =>
401
+ {
402
+ const formatted = col ? col.formatter.format(v, col, { value: {} } as any, true) : null;
403
+ return { value: v, title: formatted != null ? String(formatted) : v };
404
+ });
405
+ }}
406
+ onChanged={() => this.reloadFromFilters()}
407
+ />
408
+ );
409
+
410
+ return (
411
+ <>
412
+ <NSTable<RowType>
413
+ id={this.props.id}
414
+ classList={this.props.classList}
415
+ style={this.props.style}
416
+ ref={this.NSTable_Main}
417
+ name={NamingConvention.lower_case_dash.convert(this.props.entity.name, NamingConvention.Pascal_Case_Space)}
418
+ checkbox={this.props.checkbox ?? true}
419
+ headerChildren={this.renderFilterHeader()}
420
+ buttons={this.buildButtons()}
421
+ columns={this.getOrderedColumns()}
422
+ getRows={async (page, size, sorts) =>
423
+ {
424
+ let res: { rows: RowType[], count: number } = { rows: [], count: 0 };
425
+ if (this.props.entity.server.list)
426
+ res = await this.props.entity.server.list(this.getFilterItems(), page, size, sorts, null);
427
+ this.setState({ res });
428
+ return res;
429
+ }}
430
+ getRowKey={(row) => row.value.id.toString()}
431
+ getRowAttributes={(row_value, row_index) => this.props.ui?.getRowAttributes?.(row_value, row_index, this.state.res) ?? {}}
432
+ getColumnAttributes={this.props.ui?.getColumnAttributes}
433
+ getCellFormattedValue={this.props.ui?.getCellFormattedValue}
434
+ onVisibleColumnsChanged={(visible_columns) => this.setState({ visible_column_keys: visible_columns.map(c => c.table + "." + c.column) })}
435
+ onSelectedIDsChanged={() => this.props.onSelectionChanged?.()}
436
+ >
437
+ {filterChips}
438
+ {quickFilterBar}
439
+ </NSTable>
440
+ {
441
+ this.state.show_sort_dialog &&
442
+ <NSASortDialog
443
+ sorts={this.state.sorts}
444
+ getColumns={() => this.getColumns()}
445
+ onCancel={() => this.setState({ show_sort_dialog: false })}
446
+ onApply={sorts =>
447
+ {
448
+ this.setSortItems(sorts);
449
+ this.setState({ show_sort_dialog: false, sorts: sorts ?? [] });
450
+ }}
451
+ />
452
+ }
453
+ {
454
+ this.state.show_reorder_dialog &&
455
+ <NSAReorderDialog
456
+ visibleColumnKeys={this.state.visible_column_keys}
457
+ getColumns={() => this.getColumns()}
458
+ onCancel={() => this.setState({ show_reorder_dialog: false })}
459
+ onApply={orderedKeys =>
460
+ {
461
+ const cs_all = this.getColumns();
462
+ const cs = orderedKeys.map((v: string) => cs_all.find((c: TableColumnInfo) => v === c.table.name + "." + c.name)).filter(Boolean) as TableColumnInfo[];
463
+ this.setVisibleColumns(cs.map(c => ({ table: c.table.name, column: c.name })));
464
+ this.setState({ show_reorder_dialog: false, visible_column_keys: orderedKeys });
465
+ }}
466
+ />
467
+ }
468
+ {
469
+ this.state.show_quick_filter_dialog &&
470
+ <NSAQuickFilterDialog
471
+ configs={this.state.quick_filter_configs}
472
+ getColumns={() => this.getColumns()}
473
+ typeConverter={(type: string) => new ObjectService(type).getEnum(VariableType, VariableType.Any)}
474
+ onSave={configs =>
475
+ {
476
+ NSACacheService.saveQuickFilters(this.props.entity.name, configs);
477
+ this.setState({ quick_filter_configs: configs }, () => this.reloadFromFilters());
478
+ }}
479
+ onConfirm={configs =>
480
+ {
481
+ NSACacheService.saveQuickFilters(this.props.entity.name, configs);
482
+ this.setState({ quick_filter_configs: configs, show_quick_filter_dialog: false }, () => this.reloadFromFilters());
483
+ }}
484
+ onClose={() => this.setState({ show_quick_filter_dialog: false })}
485
+ />
486
+ }
487
+ </>
488
+ );
489
+ }
490
490
  }