namirasoft-account-react 1.5.43 → 1.5.45

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