namirasoft-account-react 1.5.20 → 1.5.21

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 (139) 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 +1 -1
  40. package/dist/layouts/NSASectionList.module.css +31 -31
  41. package/dist/layouts/NSASectionView.d.ts +1 -1
  42. package/dist/layouts/NSASectionViewTabMore.d.ts +1 -1
  43. package/dist/layouts/NSASectionViewTabPage.d.ts +1 -1
  44. package/dist/layouts/NSASectionViewTabPage.module.css +47 -47
  45. package/dist/pages/NSAConsentPage.module.css +26 -26
  46. package/dist/pages/NSAEmailVerificationPage.d.ts +1 -1
  47. package/dist/pages/NSAHomePage.d.ts +1 -1
  48. package/dist/pages/NSAHomePage.module.css +41 -41
  49. package/dist/pages/NSALoginPage.d.ts +1 -1
  50. package/dist/pages/NSALoginPage.module.css +26 -26
  51. package/dist/pages/NSAPhoneVerificationPage.d.ts +1 -1
  52. package/dist/pages/NSAVerificationPage.d.ts +1 -1
  53. package/dist/pages/NSAVerificationPage.module.css +31 -31
  54. package/package.json +95 -95
  55. package/public/index.html +21 -21
  56. package/src/App.tsx +19 -19
  57. package/src/CTFRow.ts +7 -7
  58. package/src/FieldCacheService.tsx +84 -84
  59. package/src/IEntityInfo.ts +33 -33
  60. package/src/NSACacheService.ts +120 -120
  61. package/src/NSAFilterOperators.ts +92 -92
  62. package/src/NSARouterMaker.tsx +140 -140
  63. package/src/NSARouterMakerProps.ts +23 -23
  64. package/src/NSARouterMakerResult.ts +24 -24
  65. package/src/NSFRouterMaker.tsx +35 -35
  66. package/src/NSFRouterProps.ts +7 -7
  67. package/src/NSFRoutes.ts +30 -30
  68. package/src/Router.tsx +48 -48
  69. package/src/UseParams.tsx +17 -17
  70. package/src/components/NSAAccessListDialog.module.css +71 -71
  71. package/src/components/NSAAccessListDialog.tsx +178 -178
  72. package/src/components/NSABoxSecret.module.css +23 -23
  73. package/src/components/NSABoxSecret.tsx +264 -264
  74. package/src/components/NSAMasterMenu.module.css +250 -250
  75. package/src/components/NSAMasterMenu.tsx +169 -169
  76. package/src/components/NSAMasterMenuItem.tsx +250 -250
  77. package/src/components/NSAMessageListDialog.module.css +99 -99
  78. package/src/components/NSAMessageListDialog.tsx +142 -142
  79. package/src/components/NSANavigationGuard.tsx +79 -79
  80. package/src/components/NSAProductListDialog.module.css +44 -44
  81. package/src/components/NSAProductListDialog.tsx +88 -88
  82. package/src/components/NSATable.tsx +494 -494
  83. package/src/components/NSATaskBar.module.css +57 -57
  84. package/src/components/NSATaskBar.tsx +193 -193
  85. package/src/components/NSAUserDialog.module.css +67 -67
  86. package/src/components/NSAUserDialog.tsx +122 -122
  87. package/src/components/NSAWorkspaceListDialog.module.css +41 -41
  88. package/src/components/NSAWorkspaceListDialog.tsx +147 -147
  89. package/src/components/NSFBoxCategoryScope.tsx +52 -52
  90. package/src/components/NSFBoxField.tsx +37 -37
  91. package/src/components/NSFBoxSlot.tsx +71 -71
  92. package/src/components/NSFBoxWrapper.tsx +69 -69
  93. package/src/components/NSLabelSecret.tsx +37 -37
  94. package/src/components/quickfilter/NSAFilterBoxBase.tsx +89 -89
  95. package/src/components/quickfilter/NSAFilterBoxBoolean.tsx +66 -66
  96. package/src/components/quickfilter/NSAFilterBoxDate.tsx +110 -110
  97. package/src/components/quickfilter/NSAFilterBoxDateTime.tsx +110 -110
  98. package/src/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  99. package/src/components/quickfilter/NSAFilterBoxEnum.tsx +79 -79
  100. package/src/components/quickfilter/NSAFilterBoxNumber.tsx +145 -145
  101. package/src/components/quickfilter/NSAFilterBoxString.tsx +83 -83
  102. package/src/components/quickfilter/NSAFilterBoxTime.tsx +106 -106
  103. package/src/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  104. package/src/components/quickfilter/NSAQuickFilterBar.tsx +142 -142
  105. package/src/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  106. package/src/components/quickfilter/NSAQuickFilterDialog.tsx +260 -260
  107. package/src/css.d.ts +13 -13
  108. package/src/formatters/SecretFormatter.tsx +24 -24
  109. package/src/index.tsx +26 -26
  110. package/src/layouts/Actions.ts +146 -146
  111. package/src/layouts/CFTUtil.ts +18 -18
  112. package/src/layouts/NSALayout.tsx +744 -744
  113. package/src/layouts/NSALayout_Field.ts +125 -125
  114. package/src/layouts/NSASectionEdit.tsx +281 -281
  115. package/src/layouts/NSASectionEditTabPage.module.css +4 -4
  116. package/src/layouts/NSASectionEditTabPage.tsx +256 -256
  117. package/src/layouts/NSASectionList.module.css +31 -31
  118. package/src/layouts/NSASectionList.tsx +147 -147
  119. package/src/layouts/NSASectionView.tsx +98 -98
  120. package/src/layouts/NSASectionViewTabMore.tsx +78 -78
  121. package/src/layouts/NSASectionViewTabPage.module.css +47 -47
  122. package/src/layouts/NSASectionViewTabPage.tsx +399 -399
  123. package/src/main.ts +52 -52
  124. package/src/pages/NSAConsentPage.module.css +26 -26
  125. package/src/pages/NSAConsentPage.tsx +120 -120
  126. package/src/pages/NSAEmailVerificationPage.tsx +30 -30
  127. package/src/pages/NSAHomePage.module.css +41 -41
  128. package/src/pages/NSAHomePage.tsx +124 -124
  129. package/src/pages/NSALoginPage.module.css +26 -26
  130. package/src/pages/NSALoginPage.tsx +87 -87
  131. package/src/pages/NSAPhoneVerificationPage.tsx +94 -94
  132. package/src/pages/NSAVerificationPage.module.css +31 -31
  133. package/src/pages/NSAVerificationPage.tsx +185 -185
  134. package/src/pages/NSFCategoryEditPage.tsx +87 -87
  135. package/src/pages/NSFCategoryListPage.tsx +23 -23
  136. package/src/pages/NSFCategoryViewPage.tsx +23 -23
  137. package/src/pages/NSFEntities.ts +58 -58
  138. package/src/pages/PaymentRequired.tsx +80 -80
  139. package/tsconfig.json +43 -43
@@ -1,400 +1,400 @@
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.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
+ }
400
400
  }