namirasoft-account-react 1.5.38 → 1.5.39

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