namirasoft-account-react 1.5.21 → 1.5.23

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 (143) hide show
  1. package/.env.template +15 -15
  2. package/SKILL.md +514 -514
  3. package/config-overrides.js +72 -72
  4. package/dist/App.d.ts +1 -1
  5. package/dist/Router.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/NSABoxSecret.d.ts +1 -1
  10. package/dist/components/NSABoxSecret.module.css +23 -23
  11. package/dist/components/NSAMasterMenu.d.ts +1 -1
  12. package/dist/components/NSAMasterMenu.module.css +250 -250
  13. package/dist/components/NSAMasterMenuItem.d.ts +1 -1
  14. package/dist/components/NSAMessageListDialog.d.ts +1 -1
  15. package/dist/components/NSAMessageListDialog.module.css +99 -99
  16. package/dist/components/NSANavigationGuard.d.ts +1 -1
  17. package/dist/components/NSAProductListDialog.d.ts +1 -1
  18. package/dist/components/NSAProductListDialog.module.css +44 -44
  19. package/dist/components/NSATaskBar.d.ts +1 -1
  20. package/dist/components/NSATaskBar.module.css +57 -57
  21. package/dist/components/NSAUserDialog.d.ts +1 -1
  22. package/dist/components/NSAUserDialog.module.css +67 -67
  23. package/dist/components/NSAWorkspaceListDialog.d.ts +1 -1
  24. package/dist/components/NSAWorkspaceListDialog.module.css +41 -41
  25. package/dist/components/NSFBoxCategoryScope.d.ts +1 -1
  26. package/dist/components/NSFBoxField.d.ts +1 -1
  27. package/dist/components/NSFBoxSlot.d.ts +1 -1
  28. package/dist/components/NSFBoxWrapper.d.ts +1 -1
  29. package/dist/components/NSLabelSecret.d.ts +1 -1
  30. package/dist/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  31. package/dist/components/quickfilter/NSAQuickFilterBar.d.ts +1 -1
  32. package/dist/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  33. package/dist/components/quickfilter/NSAQuickFilterDialog.d.ts +1 -1
  34. package/dist/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  35. package/dist/layouts/NSALayout.d.ts +1 -1
  36. package/dist/layouts/NSASectionEdit.d.ts +1 -1
  37. package/dist/layouts/NSASectionEditTabPage.d.ts +1 -1
  38. package/dist/layouts/NSASectionEditTabPage.module.css +4 -4
  39. package/dist/layouts/NSASectionList.d.ts +3 -1
  40. package/dist/layouts/NSASectionList.js +14 -6
  41. package/dist/layouts/NSASectionList.js.map +1 -1
  42. package/dist/layouts/NSASectionList.module.css +31 -31
  43. package/dist/layouts/NSASectionView.d.ts +1 -1
  44. package/dist/layouts/NSASectionViewTabMore.d.ts +1 -1
  45. package/dist/layouts/NSASectionViewTabPage.d.ts +1 -1
  46. package/dist/layouts/NSASectionViewTabPage.js +1 -0
  47. package/dist/layouts/NSASectionViewTabPage.js.map +1 -1
  48. package/dist/layouts/NSASectionViewTabPage.module.css +47 -47
  49. package/dist/pages/NSAConsentPage.module.css +26 -26
  50. package/dist/pages/NSAEmailVerificationPage.d.ts +1 -1
  51. package/dist/pages/NSAHomePage.d.ts +1 -1
  52. package/dist/pages/NSAHomePage.module.css +41 -41
  53. package/dist/pages/NSALoginPage.d.ts +1 -1
  54. package/dist/pages/NSALoginPage.module.css +26 -26
  55. package/dist/pages/NSAPhoneVerificationPage.d.ts +1 -1
  56. package/dist/pages/NSAVerificationPage.d.ts +1 -1
  57. package/dist/pages/NSAVerificationPage.module.css +31 -31
  58. package/package.json +95 -95
  59. package/public/index.html +21 -21
  60. package/src/App.tsx +19 -19
  61. package/src/CTFRow.ts +7 -7
  62. package/src/FieldCacheService.tsx +84 -84
  63. package/src/IEntityInfo.ts +33 -33
  64. package/src/NSACacheService.ts +120 -120
  65. package/src/NSAFilterOperators.ts +92 -92
  66. package/src/NSARouterMaker.tsx +140 -140
  67. package/src/NSARouterMakerProps.ts +23 -23
  68. package/src/NSARouterMakerResult.ts +24 -24
  69. package/src/NSFRouterMaker.tsx +35 -35
  70. package/src/NSFRouterProps.ts +7 -7
  71. package/src/NSFRoutes.ts +30 -30
  72. package/src/Router.tsx +48 -48
  73. package/src/UseParams.tsx +17 -17
  74. package/src/components/NSAAccessListDialog.module.css +71 -71
  75. package/src/components/NSAAccessListDialog.tsx +178 -178
  76. package/src/components/NSABoxSecret.module.css +23 -23
  77. package/src/components/NSABoxSecret.tsx +264 -264
  78. package/src/components/NSAMasterMenu.module.css +250 -250
  79. package/src/components/NSAMasterMenu.tsx +169 -169
  80. package/src/components/NSAMasterMenuItem.tsx +250 -250
  81. package/src/components/NSAMessageListDialog.module.css +99 -99
  82. package/src/components/NSAMessageListDialog.tsx +142 -142
  83. package/src/components/NSANavigationGuard.tsx +79 -79
  84. package/src/components/NSAProductListDialog.module.css +44 -44
  85. package/src/components/NSAProductListDialog.tsx +88 -88
  86. package/src/components/NSATable.tsx +494 -494
  87. package/src/components/NSATaskBar.module.css +57 -57
  88. package/src/components/NSATaskBar.tsx +193 -193
  89. package/src/components/NSAUserDialog.module.css +67 -67
  90. package/src/components/NSAUserDialog.tsx +122 -122
  91. package/src/components/NSAWorkspaceListDialog.module.css +41 -41
  92. package/src/components/NSAWorkspaceListDialog.tsx +147 -147
  93. package/src/components/NSFBoxCategoryScope.tsx +52 -52
  94. package/src/components/NSFBoxField.tsx +37 -37
  95. package/src/components/NSFBoxSlot.tsx +71 -71
  96. package/src/components/NSFBoxWrapper.tsx +69 -69
  97. package/src/components/NSLabelSecret.tsx +37 -37
  98. package/src/components/quickfilter/NSAFilterBoxBase.tsx +89 -89
  99. package/src/components/quickfilter/NSAFilterBoxBoolean.tsx +66 -66
  100. package/src/components/quickfilter/NSAFilterBoxDate.tsx +110 -110
  101. package/src/components/quickfilter/NSAFilterBoxDateTime.tsx +110 -110
  102. package/src/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  103. package/src/components/quickfilter/NSAFilterBoxEnum.tsx +79 -79
  104. package/src/components/quickfilter/NSAFilterBoxNumber.tsx +145 -145
  105. package/src/components/quickfilter/NSAFilterBoxString.tsx +83 -83
  106. package/src/components/quickfilter/NSAFilterBoxTime.tsx +106 -106
  107. package/src/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  108. package/src/components/quickfilter/NSAQuickFilterBar.tsx +142 -142
  109. package/src/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  110. package/src/components/quickfilter/NSAQuickFilterDialog.tsx +260 -260
  111. package/src/css.d.ts +13 -13
  112. package/src/formatters/SecretFormatter.tsx +24 -24
  113. package/src/index.tsx +26 -26
  114. package/src/layouts/Actions.ts +146 -146
  115. package/src/layouts/CFTUtil.ts +18 -18
  116. package/src/layouts/NSALayout.tsx +744 -744
  117. package/src/layouts/NSALayout_Field.ts +125 -125
  118. package/src/layouts/NSASectionEdit.tsx +281 -281
  119. package/src/layouts/NSASectionEditTabPage.module.css +4 -4
  120. package/src/layouts/NSASectionEditTabPage.tsx +256 -256
  121. package/src/layouts/NSASectionList.module.css +31 -31
  122. package/src/layouts/NSASectionList.tsx +166 -147
  123. package/src/layouts/NSASectionView.tsx +98 -98
  124. package/src/layouts/NSASectionViewTabMore.tsx +78 -78
  125. package/src/layouts/NSASectionViewTabPage.module.css +47 -47
  126. package/src/layouts/NSASectionViewTabPage.tsx +400 -399
  127. package/src/main.ts +52 -52
  128. package/src/pages/NSAConsentPage.module.css +26 -26
  129. package/src/pages/NSAConsentPage.tsx +120 -120
  130. package/src/pages/NSAEmailVerificationPage.tsx +30 -30
  131. package/src/pages/NSAHomePage.module.css +41 -41
  132. package/src/pages/NSAHomePage.tsx +124 -124
  133. package/src/pages/NSALoginPage.module.css +26 -26
  134. package/src/pages/NSALoginPage.tsx +87 -87
  135. package/src/pages/NSAPhoneVerificationPage.tsx +94 -94
  136. package/src/pages/NSAVerificationPage.module.css +31 -31
  137. package/src/pages/NSAVerificationPage.tsx +185 -185
  138. package/src/pages/NSFCategoryEditPage.tsx +87 -87
  139. package/src/pages/NSFCategoryListPage.tsx +23 -23
  140. package/src/pages/NSFCategoryViewPage.tsx +23 -23
  141. package/src/pages/NSFEntities.ts +58 -58
  142. package/src/pages/PaymentRequired.tsx +80 -80
  143. package/tsconfig.json +43 -43
@@ -1,400 +1,401 @@
1
- import { EnvService, FilterItem, FilterItemOperator, IStorageLocal, NamingConvention } from "namirasoft-core";
2
- import { EntityResolveResponseRow, SlotEntityType, SlotRow } from "namirasoft-field";
3
- import { HistoryRow, NamirasoftHistoryServer } from "namirasoft-history";
4
- import { NamirasoftMap } from "namirasoft-site-map";
5
- import { BaseColumnFormatter, DateTimeFormatter, IBaseComponentProps, IDFormatter, NSInfoProps, NSLabel, NSLoading, NSNoData, NSTable, NSTabPage, NSTabPageTab, StringFormatter, StringFormatterSizeType, TableColumnInfo } from "namirasoft-site-react";
6
- import { Component, createRef, Fragment, ReactNode } from "react";
7
- import { NSFBoxWrapper } from "../components/NSFBoxWrapper";
8
- import { IEntityInfo } from "../IEntityInfo";
9
- import { NSARouterMakerResult } from "../NSARouterMakerResult";
10
- import { CFTUtil } from "./CFTUtil";
11
- import { NSASectionViewTabMore } from "./NSASectionViewTabMore";
12
- import Styles from "./NSASectionViewTabPage.module.css";
13
-
14
- export type TabRenderItem =
15
- | { type: "column"; column: TableColumnInfo }
16
- | { type: "custom"; node: ReactNode };
17
-
18
- export interface NSASectionViewTabPageTabPageTab<RowType> extends IBaseComponentProps
19
- {
20
- isVisible(model: {
21
- id: string | null;
22
- row: RowType | null;
23
- }): boolean;
24
-
25
- title: string;
26
- info?: NSInfoProps;
27
- clicked: boolean;
28
- getContent: (model: {
29
- id: string | null;
30
- row: RowType | null;
31
- }) => React.ReactNode;
32
- }
33
-
34
- export interface NSASectionViewTabPageUIProps<RowType>
35
- {
36
- enabled?: boolean;
37
- tabs?: {
38
- general?: {
39
- enabled?: boolean;
40
- getColumns?: (row: RowType) => TableColumnInfo[];
41
- getValue?: (row: RowType, column: string) => string | undefined;
42
- buildItems?: (row: RowType, tab: string, columns: TableColumnInfo[]) => TabRenderItem[];
43
- }
44
- field?: boolean;
45
- category?: boolean;
46
- tag?: boolean;
47
- history?: boolean;
48
- more?: boolean;
49
- extra?: {
50
- before_general?: NSASectionViewTabPageTabPageTab<RowType>[];
51
- after_general?: NSASectionViewTabPageTabPageTab<RowType>[];
52
- after_field?: NSASectionViewTabPageTabPageTab<RowType>[];
53
- after_category?: NSASectionViewTabPageTabPageTab<RowType>[];
54
- after_tag?: NSASectionViewTabPageTabPageTab<RowType>[];
55
- after_history?: NSASectionViewTabPageTabPageTab<RowType>[];
56
- after_more?: NSASectionViewTabPageTabPageTab<RowType>[];
57
- };
58
- };
59
- }
60
-
61
- export interface NSASectionViewTabPageCutomProps<RowType>
62
- {
63
- ui?: NSASectionViewTabPageUIProps<RowType>;
64
- onRowLoaded?: (row: RowType) => void;
65
- }
66
-
67
- export interface NSASectionViewTabPageProps<RowType extends { id: string }, RowTypeInput = RowType> extends NSARouterMakerResult, NSASectionViewTabPageCutomProps<RowType>
68
- {
69
- entity: IEntityInfo<RowType, RowTypeInput>;
70
- ctf: {
71
- enabled: boolean;
72
- rows: EntityResolveResponseRow | null;
73
- };
74
- model: {
75
- id: string | null;
76
- row: RowType | null;
77
- };
78
- }
79
-
80
- interface NSASectionViewTabPageState<RowType>
81
- {
82
- row: RowType | null;
83
- }
84
-
85
- export class NSASectionViewTabPage<RowType extends { id: string }, RowTypeInput = RowType> extends Component<NSASectionViewTabPageProps<RowType, RowTypeInput>, NSASectionViewTabPageState<RowType>>
86
- {
87
- NSTabPage_Ref = createRef<NSTabPage>();
88
-
89
- constructor(props: NSASectionViewTabPageProps<RowType, RowTypeInput>)
90
- {
91
- super(props);
92
-
93
- this.state = { row: this.props.model.row };
94
-
95
- this.reload = this.reload.bind(this);
96
- this.getRow = this.getRow.bind(this);
97
- }
98
- reload()
99
- {
100
- this.setState(prev => ({ ...prev, row: null }));
101
- if (this.props.model.id)
102
- if (this.props.entity.server.get)
103
- this.props.entity.server.get(this.props.model.id).then(row =>
104
- {
105
- this.setState(prev => ({ ...prev, row }), () =>
106
- {
107
- this.props.onRowLoaded?.(row);
108
- });
109
- }).catch(() => { });
110
- }
111
- getRow()
112
- {
113
- return this.state.row;
114
- }
115
- override componentDidMount()
116
- {
117
- if (this.props.model.id)
118
- if (!this.props.model.row || this.props.model.row.id !== this.props.model.id)
119
- this.reload();
120
- }
121
- override render()
122
- {
123
- const tabs: NSTabPageTab[] = [];
124
- let namirasoft = new NamirasoftMap(this.props.account.token_manager, this.props.notifier.onError);
125
-
126
- let rows = (this.props.model.id && this.props.ctf.enabled) ? this.props.ctf.rows : null;
127
- let slots = rows?.slots ?? [];
128
-
129
- let renderSlot = (slot: SlotRow): ReactNode =>
130
- {
131
- if (!this.state.row || !rows)
132
- return null;
133
- let ctf = CFTUtil.get(this.props.entity.name, this.state.row);
134
- let value = "";
135
- if (slot.entity_type === SlotEntityType.Field)
136
- value = ctf.fields.filter(x => x.field_id === slot.entity_id).map(x => x.value).join(", ");
137
- else if (slot.entity_type === SlotEntityType.CategoryScope)
138
- {
139
- let ids = ctf.categories.map(x => x.category_id);
140
- value = rows.categories
141
- .filter(category => category.category_scope_id === slot.entity_id && ids.includes(category.id))
142
- .map(category => category.name)
143
- .join(", ");
144
- }
145
- return <NSLabel
146
- key={`NSASectionViewTabPage_NSLabel_Slot_${slot.id}`}
147
- title={slot.name + ":"}
148
- classList={[Styles.nsa_section_tab_page_item]}
149
- >
150
- <div>{value}</div>
151
- </NSLabel>;
152
- };
153
-
154
- let pushTabs = (ts?: NSASectionViewTabPageTabPageTab<RowType>[]) =>
155
- {
156
- if (ts)
157
- for (let i = 0; i < ts.length; i++)
158
- {
159
- const tab = ts[i];
160
- if (tab.isVisible(this.props.model))
161
- tabs.push({
162
- ...tab,
163
- getContent: () =>
164
- {
165
- return tab.getContent(this.props.model);
166
- }
167
- });
168
- }
169
- };
170
-
171
- pushTabs(this.props.ui?.tabs?.extra?.before_general);
172
- if (this.props.ui?.tabs?.general?.enabled ?? true)
173
- if (this.props.model.id)
174
- if (this.props.entity.server.get)
175
- {
176
- let getColumns = (): TableColumnInfo[] =>
177
- {
178
- let columns: TableColumnInfo[] = [];
179
- if (this.state.row)
180
- if (this.props.ui?.tabs?.general?.getColumns)
181
- columns = this.props.ui?.tabs?.general?.getColumns(this.state.row);
182
- if (columns.length === 0)
183
- columns = this.props.entity.client.getColumns();
184
- return columns;
185
- };
186
- let getValue = (column: string): string =>
187
- {
188
- if (this.state.row)
189
- if (this.props.ui?.tabs?.general?.getValue)
190
- {
191
- let ans = this.props.ui?.tabs?.general?.getValue(this.state.row, column);
192
- if (ans !== undefined)
193
- return ans;
194
- }
195
- return (this.state.row as any)[column];
196
- };
197
- let renderColumn = (column: TableColumnInfo, tab: string, index: number): ReactNode =>
198
- {
199
- let title = column.text;
200
- if (title.startsWith(tab))
201
- title = title.substring(tab.length + 1);
202
-
203
- let value = getValue(column.name);
204
- let formatted = column.formatter.format(value, column, { index: 0, value: this.state.row }, false);
205
-
206
- return (
207
- <NSLabel
208
- key={`NSASectionViewTabPage_NSLabel_${tab}_${index}`}
209
- title={title + ":"}
210
- classList={[Styles.nsa_section_tab_page_item]}
211
- >
212
- <div>{formatted}</div>
213
- </NSLabel>
214
- );
215
- }
216
-
217
- let TAB_GENERAL = "General";
218
- let columns = getColumns();
219
- columns.filter(c => !c.group).forEach(c => { c.group = TAB_GENERAL });
220
- let tab_names: string[] = columns.map(tab => tab.group) as string[];
221
- tab_names = [...new Set(tab_names)];
222
- tab_names = tab_names.filter(t => t !== TAB_GENERAL);
223
- tab_names = [TAB_GENERAL, ...tab_names];
224
-
225
- tab_names.forEach(tab =>
226
- {
227
- tabs.push({
228
- title: tab,
229
- clicked: false,
230
- getContent: () =>
231
- {
232
- if (!this.state.row)
233
- return <NSLoading />;
234
-
235
- let tab_columns = columns.filter(c => c.group === tab);
236
- let render_items = this.props.ui?.tabs?.general?.buildItems?.(this.state.row, tab, tab_columns);
237
-
238
- if (!render_items)
239
- return (
240
- <div className={Styles.nsa_section_tab_page_parent}>
241
- <NSFBoxWrapper slots={slots.filter(x => x.tab === tab)} renderSlot={renderSlot}>
242
- {tab_columns.map((col, index) => renderColumn(col, tab, index))}
243
- </NSFBoxWrapper>
244
- </div>
245
- )
246
-
247
- return (
248
- <div className={Styles.nsa_section_tab_page_parent}>
249
- <NSFBoxWrapper slots={slots.filter(x => x.tab === tab)} renderSlot={renderSlot}>
250
- {
251
- render_items.map((render_item, index) =>
252
- {
253
- if (render_item.type === "column")
254
- return renderColumn(render_item.column, tab, index);
255
-
256
- return (
257
- <Fragment key={`NSASectionViewTabPage_Custom_${tab}_${index}`}>
258
- {render_item.node}
259
- </Fragment>
260
- );
261
- })
262
- }
263
- </NSFBoxWrapper>
264
- </div>
265
- );
266
- }
267
- });
268
- });
269
- }
270
- pushTabs(this.props.ui?.tabs?.extra?.after_general);
271
-
272
- if (this.props.ui?.tabs?.history ?? true)
273
- if (this.props.model.id)
274
- tabs.push({
275
- title: 'History',
276
- clicked: false,
277
- getContent: () =>
278
- {
279
- return <NSTable<HistoryRow>
280
- name="History"
281
- checkbox={false}
282
- columns={[
283
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.id, new IDFormatter(namirasoft, null)),
284
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.user_id, new IDFormatter(namirasoft, new IStorageLocal())),
285
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.session_id, new IDFormatter(namirasoft, null)),
286
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.entity_name, new StringFormatter(StringFormatterSizeType.TwoWords, NamingConvention.Pascal_Case_Space)),
287
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.entity_id, new IDFormatter(namirasoft, new IStorageLocal())),
288
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.action, new StringFormatter(StringFormatterSizeType.Word)),
289
- BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.created_at, new DateTimeFormatter()),
290
- ]}
291
- getRows={async () =>
292
- {
293
- if (this.props.model.id)
294
- {
295
- let REACT_APP_BASE_URL_HISTORY = new EnvService("REACT_APP_BASE_URL_HISTORY", true).getString();
296
- let server = new NamirasoftHistoryServer(REACT_APP_BASE_URL_HISTORY, this.props.account.token_manager, this.props.notifier.onError);
297
- let filters = [new FilterItem(namirasoft.history.tables.history, namirasoft.history.tables.history.columns.entity_id, false, FilterItemOperator.all.equals, this.props.model.id)]
298
- return await server.history.List(filters, null, null, [], null);
299
- }
300
- return { rows: [], count: 0 };
301
- }}
302
- getRowKey={row => row.value.id}
303
- style={{ width: "100%" }}
304
- ></NSTable>;
305
- }
306
- });
307
- pushTabs(this.props.ui?.tabs?.extra?.after_history);
308
-
309
- if (this.props.ui?.tabs?.field ?? true)
310
- if (this.props.model.id)
311
- if (this.props.ctf.enabled)
312
- {
313
- let known = new Set(tabs.map(tab => tab.title));
314
- let slot_tabs = Array.from(new Set(slots.map(x => x.tab))).filter(tab => !known.has(tab));
315
- slot_tabs.forEach(tab =>
316
- {
317
- tabs.push({
318
- title: tab,
319
- clicked: false,
320
- getContent: () =>
321
- {
322
- if (this.state.row == null)
323
- return <NSLoading></NSLoading>;
324
- return <div className={Styles.nsa_section_tab_page_parent}>
325
- <NSFBoxWrapper slots={slots.filter(x => x.tab === tab)} renderSlot={renderSlot} />
326
- </div>;
327
- }
328
- });
329
- });
330
- }
331
- pushTabs(this.props.ui?.tabs?.extra?.after_field);
332
- pushTabs(this.props.ui?.tabs?.extra?.after_category);
333
-
334
- if (this.props.ui?.tabs?.tag ?? true)
335
- if (this.props.model.id)
336
- if (this.props.ctf.enabled)
337
- tabs.push({
338
- title: 'Tag',
339
- clicked: false,
340
- getContent: () =>
341
- {
342
- if (this.state.row == null)
343
- return <NSLoading></NSLoading>;
344
- let ctf = CFTUtil.get(this.props.entity.name, this.state.row);
345
- if (ctf.tags.length === 0)
346
- return <NSNoData lable="No tag found" />
347
- return <div className={Styles.nsa_section_tab_page_parent}>
348
- {
349
- ctf.tags?.map((tag, index) =>
350
- {
351
- return <NSLabel
352
- key={`NSASectionViewTabPage_NSLabel_Tag_${index}`}
353
- title={tag.name + ":"}
354
- classList={[Styles.nsa_section_tab_page_item]}
355
- >
356
- <div>{tag.value}</div>
357
- </NSLabel>
358
- })
359
- }
360
- </div>;
361
- }
362
- });
363
- pushTabs(this.props.ui?.tabs?.extra?.after_tag);
364
- //todo
365
- // tabs.push({title: 'Log', getContent: todo });
366
- // tabs.push({title: 'Monitor', getContent: todo });
367
-
368
- if (this.props.ui?.tabs?.more ?? true)
369
- if (this.props.model.id)
370
- if (this.props.entity.server.get)
371
- if (this.props.ctf.enabled)
372
- tabs.push({
373
- title: "More",
374
- clicked: true,
375
- getContent: () => <NSASectionViewTabMore
376
- {...this.props}
377
- />
378
- });
379
- pushTabs(this.props.ui?.tabs?.extra?.after_more);
380
-
381
- //todo
382
- // tabs.push({title: 'How It Works', getContent: todo });
383
- // tabs.push({title: 'API', getContent: todo });
384
- // tabs.push({title: 'Sample Code', getContent: todo });
385
- //todo
386
- // tabs.push({title: 'Category', getContent: todo });
387
- // tabs.push({title: 'Field', getContent: todo });
388
-
389
- if (!(this.props.ui?.enabled ?? true))
390
- return <></>;
391
- return (
392
- <>
393
- {
394
- tabs.length > 0 &&
395
- <NSTabPage ref={this.NSTabPage_Ref} tabs={tabs} />
396
- }
397
- </>
398
- );
399
- }
1
+ import { EnvService, FilterItem, FilterItemOperator, IStorageLocal, NamingConvention } from "namirasoft-core";
2
+ import { EntityResolveResponseRow, SlotEntityType, SlotRow } from "namirasoft-field";
3
+ import { HistoryRow, NamirasoftHistoryServer } from "namirasoft-history";
4
+ import { NamirasoftMap } from "namirasoft-site-map";
5
+ import { BaseColumnFormatter, DateTimeFormatter, IBaseComponentProps, IDFormatter, NSInfoProps, NSLabel, NSLoading, NSNoData, NSTable, NSTabPage, NSTabPageTab, StringFormatter, StringFormatterSizeType, TableColumnInfo } from "namirasoft-site-react";
6
+ import { Component, createRef, Fragment, ReactNode } from "react";
7
+ import { NSFBoxWrapper } from "../components/NSFBoxWrapper";
8
+ import { IEntityInfo } from "../IEntityInfo";
9
+ import { NSARouterMakerResult } from "../NSARouterMakerResult";
10
+ import { CFTUtil } from "./CFTUtil";
11
+ import { NSASectionViewTabMore } from "./NSASectionViewTabMore";
12
+ import Styles from "./NSASectionViewTabPage.module.css";
13
+
14
+ export type TabRenderItem =
15
+ | { type: "column"; column: TableColumnInfo }
16
+ | { type: "custom"; node: ReactNode };
17
+
18
+ export interface NSASectionViewTabPageTabPageTab<RowType> extends IBaseComponentProps
19
+ {
20
+ isVisible(model: {
21
+ id: string | null;
22
+ row: RowType | null;
23
+ }): boolean;
24
+
25
+ title: string;
26
+ info?: NSInfoProps;
27
+ clicked: boolean;
28
+ getContent: (model: {
29
+ id: string | null;
30
+ row: RowType | null;
31
+ }) => React.ReactNode;
32
+ }
33
+
34
+ export interface NSASectionViewTabPageUIProps<RowType>
35
+ {
36
+ enabled?: boolean;
37
+ tabs?: {
38
+ general?: {
39
+ enabled?: boolean;
40
+ getColumns?: (row: RowType) => TableColumnInfo[];
41
+ getValue?: (row: RowType, column: string) => string | undefined;
42
+ buildItems?: (row: RowType, tab: string, columns: TableColumnInfo[]) => TabRenderItem[];
43
+ }
44
+ field?: boolean;
45
+ category?: boolean;
46
+ tag?: boolean;
47
+ history?: boolean;
48
+ more?: boolean;
49
+ extra?: {
50
+ before_general?: NSASectionViewTabPageTabPageTab<RowType>[];
51
+ after_general?: NSASectionViewTabPageTabPageTab<RowType>[];
52
+ after_field?: NSASectionViewTabPageTabPageTab<RowType>[];
53
+ after_category?: NSASectionViewTabPageTabPageTab<RowType>[];
54
+ after_tag?: NSASectionViewTabPageTabPageTab<RowType>[];
55
+ after_history?: NSASectionViewTabPageTabPageTab<RowType>[];
56
+ after_more?: NSASectionViewTabPageTabPageTab<RowType>[];
57
+ };
58
+ };
59
+ }
60
+
61
+ export interface NSASectionViewTabPageCutomProps<RowType>
62
+ {
63
+ ui?: NSASectionViewTabPageUIProps<RowType>;
64
+ onRowLoaded?: (row: RowType) => void;
65
+ }
66
+
67
+ export interface NSASectionViewTabPageProps<RowType extends { id: string }, RowTypeInput = RowType> extends NSARouterMakerResult, NSASectionViewTabPageCutomProps<RowType>
68
+ {
69
+ entity: IEntityInfo<RowType, RowTypeInput>;
70
+ ctf: {
71
+ enabled: boolean;
72
+ rows: EntityResolveResponseRow | null;
73
+ };
74
+ model: {
75
+ id: string | null;
76
+ row: RowType | null;
77
+ };
78
+ }
79
+
80
+ interface NSASectionViewTabPageState<RowType>
81
+ {
82
+ row: RowType | null;
83
+ }
84
+
85
+ export class NSASectionViewTabPage<RowType extends { id: string }, RowTypeInput = RowType> extends Component<NSASectionViewTabPageProps<RowType, RowTypeInput>, NSASectionViewTabPageState<RowType>>
86
+ {
87
+ NSTabPage_Ref = createRef<NSTabPage>();
88
+
89
+ constructor(props: NSASectionViewTabPageProps<RowType, RowTypeInput>)
90
+ {
91
+ super(props);
92
+
93
+ this.state = { row: this.props.model.row };
94
+
95
+ this.reload = this.reload.bind(this);
96
+ this.getRow = this.getRow.bind(this);
97
+ }
98
+ reload()
99
+ {
100
+ this.setState(prev => ({ ...prev, row: null }));
101
+ if (this.props.model.id)
102
+ if (this.props.entity.server.get)
103
+ this.props.entity.server.get(this.props.model.id).then(row =>
104
+ {
105
+ this.setState(prev => ({ ...prev, row }), () =>
106
+ {
107
+ this.props.onRowLoaded?.(row);
108
+ });
109
+ }).catch(() => { });
110
+ }
111
+ getRow()
112
+ {
113
+ return this.state.row;
114
+ }
115
+ override componentDidMount()
116
+ {
117
+ if (this.props.model.id)
118
+ if (!this.props.model.row || this.props.model.row.id !== this.props.model.id)
119
+ this.reload();
120
+ }
121
+ override render()
122
+ {
123
+ const tabs: NSTabPageTab[] = [];
124
+ let namirasoft = new NamirasoftMap(this.props.account.token_manager, this.props.notifier.onError);
125
+
126
+ let rows = (this.props.model.id && this.props.ctf.enabled) ? this.props.ctf.rows : null;
127
+ let slots = rows?.slots ?? [];
128
+
129
+ let renderSlot = (slot: SlotRow): ReactNode =>
130
+ {
131
+ if (!this.state.row || !rows)
132
+ return null;
133
+ let ctf = CFTUtil.get(this.props.entity.name, this.state.row);
134
+ let value = "";
135
+ if (slot.entity_type === SlotEntityType.Field)
136
+ value = ctf.fields.filter(x => x.field_id === slot.entity_id).map(x => x.value).join(", ");
137
+ else if (slot.entity_type === SlotEntityType.CategoryScope)
138
+ {
139
+ let ids = ctf.categories.map(x => x.category_id);
140
+ value = rows.categories
141
+ .filter(category => category.category_scope_id === slot.entity_id && ids.includes(category.id))
142
+ .map(category => category.name)
143
+ .join(", ");
144
+ }
145
+ return <NSLabel
146
+ key={`NSASectionViewTabPage_NSLabel_Slot_${slot.id}`}
147
+ title={slot.name + ":"}
148
+ classList={[Styles.nsa_section_tab_page_item]}
149
+ >
150
+ <div>{value}</div>
151
+ </NSLabel>;
152
+ };
153
+
154
+ let pushTabs = (ts?: NSASectionViewTabPageTabPageTab<RowType>[]) =>
155
+ {
156
+ if (ts)
157
+ for (let i = 0; i < ts.length; i++)
158
+ {
159
+ const tab = ts[i];
160
+ if (tab.isVisible(this.props.model))
161
+ tabs.push({
162
+ ...tab,
163
+ getContent: () =>
164
+ {
165
+ return tab.getContent(this.props.model);
166
+ }
167
+ });
168
+ }
169
+ };
170
+
171
+ pushTabs(this.props.ui?.tabs?.extra?.before_general);
172
+ if (this.props.ui?.tabs?.general?.enabled ?? true)
173
+ if (this.props.model.id)
174
+ if (this.props.entity.server.get)
175
+ {
176
+ let getColumns = (): TableColumnInfo[] =>
177
+ {
178
+ let columns: TableColumnInfo[] = [];
179
+ if (this.state.row)
180
+ if (this.props.ui?.tabs?.general?.getColumns)
181
+ columns = this.props.ui?.tabs?.general?.getColumns(this.state.row);
182
+ if (columns.length === 0)
183
+ columns = this.props.entity.client.getColumns();
184
+ return columns;
185
+ };
186
+ let getValue = (column: string): string =>
187
+ {
188
+ if (this.state.row)
189
+ if (this.props.ui?.tabs?.general?.getValue)
190
+ {
191
+ let ans = this.props.ui?.tabs?.general?.getValue(this.state.row, column);
192
+ if (ans !== undefined)
193
+ return ans;
194
+ }
195
+ return (this.state.row as any)[column];
196
+ };
197
+ let renderColumn = (column: TableColumnInfo, tab: string, index: number): ReactNode =>
198
+ {
199
+ let title = column.text;
200
+ if (title.startsWith(tab))
201
+ title = title.substring(tab.length + 1);
202
+
203
+ let value = getValue(column.name);
204
+ let formatted = column.formatter.format(value, column, { index: 0, value: this.state.row }, false);
205
+
206
+ return (
207
+ <NSLabel
208
+ key={`NSASectionViewTabPage_NSLabel_${tab}_${index}`}
209
+ title={title + ":"}
210
+ classList={[Styles.nsa_section_tab_page_item]}
211
+ >
212
+ <div>{formatted}</div>
213
+ </NSLabel>
214
+ );
215
+ }
216
+
217
+ let TAB_GENERAL = "General";
218
+ let columns = getColumns();
219
+ columns.filter(c => !c.group).forEach(c => { c.group = TAB_GENERAL });
220
+ let tab_names: string[] = columns.map(tab => tab.group) as string[];
221
+ tab_names = [...new Set(tab_names)];
222
+ tab_names = tab_names.filter(t => t !== TAB_GENERAL);
223
+ tab_names = [TAB_GENERAL, ...tab_names];
224
+
225
+ tab_names.forEach(tab =>
226
+ {
227
+ tabs.push({
228
+ title: tab,
229
+ clicked: false,
230
+ getContent: () =>
231
+ {
232
+ if (!this.state.row)
233
+ return <NSLoading />;
234
+
235
+ let tab_columns = columns.filter(c => c.group === tab);
236
+ let render_items = this.props.ui?.tabs?.general?.buildItems?.(this.state.row, tab, tab_columns);
237
+
238
+ if (!render_items)
239
+ return (
240
+ <div className={Styles.nsa_section_tab_page_parent}>
241
+ <NSFBoxWrapper slots={slots.filter(x => x.tab === tab)} renderSlot={renderSlot}>
242
+ {tab_columns.map((col, index) => renderColumn(col, tab, index))}
243
+ </NSFBoxWrapper>
244
+ </div>
245
+ )
246
+
247
+ return (
248
+ <div className={Styles.nsa_section_tab_page_parent}>
249
+ <NSFBoxWrapper slots={slots.filter(x => x.tab === tab)} renderSlot={renderSlot}>
250
+ {
251
+ render_items.map((render_item, index) =>
252
+ {
253
+ if (render_item.type === "column")
254
+ return renderColumn(render_item.column, tab, index);
255
+
256
+ return (
257
+ <Fragment key={`NSASectionViewTabPage_Custom_${tab}_${index}`}>
258
+ {render_item.node}
259
+ </Fragment>
260
+ );
261
+ })
262
+ }
263
+ </NSFBoxWrapper>
264
+ </div>
265
+ );
266
+ }
267
+ });
268
+ });
269
+ }
270
+ pushTabs(this.props.ui?.tabs?.extra?.after_general);
271
+
272
+ if (this.props.ui?.tabs?.history ?? true)
273
+ if (this.props.model.id)
274
+ tabs.push({
275
+ title: 'History',
276
+ clicked: false,
277
+ getContent: () =>
278
+ {
279
+ return <NSTable<HistoryRow>
280
+ name="History"
281
+ checkbox={false}
282
+ columns={[
283
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.id, new IDFormatter(namirasoft, null)),
284
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.owner_id, new IDFormatter(namirasoft, new IStorageLocal())),
285
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.user_id, new IDFormatter(namirasoft, new IStorageLocal())),
286
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.session_id, new IDFormatter(namirasoft, null)),
287
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.entity_name, new StringFormatter(StringFormatterSizeType.TwoWords, NamingConvention.Pascal_Case_Space)),
288
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.entity_id, new IDFormatter(namirasoft, new IStorageLocal())),
289
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.action, new StringFormatter(StringFormatterSizeType.Word)),
290
+ BaseColumnFormatter.getColumn(namirasoft.history.tables.history.columns.created_at, new DateTimeFormatter()),
291
+ ]}
292
+ getRows={async () =>
293
+ {
294
+ if (this.props.model.id)
295
+ {
296
+ let REACT_APP_BASE_URL_HISTORY = new EnvService("REACT_APP_BASE_URL_HISTORY", true).getString();
297
+ let server = new NamirasoftHistoryServer(REACT_APP_BASE_URL_HISTORY, this.props.account.token_manager, this.props.notifier.onError);
298
+ let filters = [new FilterItem(namirasoft.history.tables.history, namirasoft.history.tables.history.columns.entity_id, false, FilterItemOperator.all.equals, this.props.model.id)]
299
+ return await server.history.List(filters, null, null, [], null);
300
+ }
301
+ return { rows: [], count: 0 };
302
+ }}
303
+ getRowKey={row => row.value.id}
304
+ style={{ width: "100%" }}
305
+ ></NSTable>;
306
+ }
307
+ });
308
+ pushTabs(this.props.ui?.tabs?.extra?.after_history);
309
+
310
+ if (this.props.ui?.tabs?.field ?? true)
311
+ if (this.props.model.id)
312
+ if (this.props.ctf.enabled)
313
+ {
314
+ let known = new Set(tabs.map(tab => tab.title));
315
+ let slot_tabs = Array.from(new Set(slots.map(x => x.tab))).filter(tab => !known.has(tab));
316
+ slot_tabs.forEach(tab =>
317
+ {
318
+ tabs.push({
319
+ title: tab,
320
+ clicked: false,
321
+ getContent: () =>
322
+ {
323
+ if (this.state.row == null)
324
+ return <NSLoading></NSLoading>;
325
+ return <div className={Styles.nsa_section_tab_page_parent}>
326
+ <NSFBoxWrapper slots={slots.filter(x => x.tab === tab)} renderSlot={renderSlot} />
327
+ </div>;
328
+ }
329
+ });
330
+ });
331
+ }
332
+ pushTabs(this.props.ui?.tabs?.extra?.after_field);
333
+ pushTabs(this.props.ui?.tabs?.extra?.after_category);
334
+
335
+ if (this.props.ui?.tabs?.tag ?? true)
336
+ if (this.props.model.id)
337
+ if (this.props.ctf.enabled)
338
+ tabs.push({
339
+ title: 'Tag',
340
+ clicked: false,
341
+ getContent: () =>
342
+ {
343
+ if (this.state.row == null)
344
+ return <NSLoading></NSLoading>;
345
+ let ctf = CFTUtil.get(this.props.entity.name, this.state.row);
346
+ if (ctf.tags.length === 0)
347
+ return <NSNoData lable="No tag found" />
348
+ return <div className={Styles.nsa_section_tab_page_parent}>
349
+ {
350
+ ctf.tags?.map((tag, index) =>
351
+ {
352
+ return <NSLabel
353
+ key={`NSASectionViewTabPage_NSLabel_Tag_${index}`}
354
+ title={tag.name + ":"}
355
+ classList={[Styles.nsa_section_tab_page_item]}
356
+ >
357
+ <div>{tag.value}</div>
358
+ </NSLabel>
359
+ })
360
+ }
361
+ </div>;
362
+ }
363
+ });
364
+ pushTabs(this.props.ui?.tabs?.extra?.after_tag);
365
+ //todo
366
+ // tabs.push({title: 'Log', getContent: todo });
367
+ // tabs.push({title: 'Monitor', getContent: todo });
368
+
369
+ if (this.props.ui?.tabs?.more ?? true)
370
+ if (this.props.model.id)
371
+ if (this.props.entity.server.get)
372
+ if (this.props.ctf.enabled)
373
+ tabs.push({
374
+ title: "More",
375
+ clicked: true,
376
+ getContent: () => <NSASectionViewTabMore
377
+ {...this.props}
378
+ />
379
+ });
380
+ pushTabs(this.props.ui?.tabs?.extra?.after_more);
381
+
382
+ //todo
383
+ // tabs.push({title: 'How It Works', getContent: todo });
384
+ // tabs.push({title: 'API', getContent: todo });
385
+ // tabs.push({title: 'Sample Code', getContent: todo });
386
+ //todo
387
+ // tabs.push({title: 'Category', getContent: todo });
388
+ // tabs.push({title: 'Field', getContent: todo });
389
+
390
+ if (!(this.props.ui?.enabled ?? true))
391
+ return <></>;
392
+ return (
393
+ <>
394
+ {
395
+ tabs.length > 0 &&
396
+ <NSTabPage ref={this.NSTabPage_Ref} tabs={tabs} />
397
+ }
398
+ </>
399
+ );
400
+ }
400
401
  }