namirasoft-account-react 1.4.19 → 1.4.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 (76) hide show
  1. package/.env.template +10 -10
  2. package/config-overrides.js +72 -72
  3. package/dist/IEntityInfo.d.ts +11 -11
  4. package/dist/Messages.js.map +1 -1
  5. package/dist/NSARouterMaker.d.ts +0 -1
  6. package/dist/NSARouterMaker.js.map +1 -1
  7. package/dist/Router.d.ts +0 -1
  8. package/dist/components/NSAAccessListDialog.js.map +1 -1
  9. package/dist/components/NSAAccessListDialog.module.css +87 -0
  10. package/dist/components/NSABoxOTP.js.map +1 -1
  11. package/dist/components/NSABoxOTP.module.css +11 -0
  12. package/dist/components/NSAMessageListDialog.js.map +1 -1
  13. package/dist/components/NSAMessageListDialog.module.css +98 -0
  14. package/dist/components/NSAProductListDialog.js.map +1 -1
  15. package/dist/components/NSAProductListDialog.module.css +45 -0
  16. package/dist/components/NSAWorkspaceListDialog.js.map +1 -1
  17. package/dist/components/NSAWorkspaceListDialog.module.css +43 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/layouts/Actions.d.ts +2 -1
  20. package/dist/layouts/Actions.js +38 -17
  21. package/dist/layouts/Actions.js.map +1 -1
  22. package/dist/layouts/NSALayout.d.ts +2 -1
  23. package/dist/layouts/NSALayout.js +58 -37
  24. package/dist/layouts/NSALayout.js.map +1 -1
  25. package/dist/layouts/NSASectionEdit.d.ts +0 -1
  26. package/dist/layouts/NSASectionEdit.js +12 -8
  27. package/dist/layouts/NSASectionEdit.js.map +1 -1
  28. package/dist/layouts/NSASectionList.js +6 -4
  29. package/dist/layouts/NSASectionList.js.map +1 -1
  30. package/dist/layouts/NSASectionTabs.d.ts +0 -1
  31. package/dist/layouts/NSASectionTabs.js +4 -7
  32. package/dist/layouts/NSASectionTabs.js.map +1 -1
  33. package/dist/layouts/NSASectionView.js +4 -3
  34. package/dist/layouts/NSASectionView.js.map +1 -1
  35. package/dist/pages/NSAHomePage.module.css +23 -0
  36. package/dist/pages/NSALoginPage.module.css +20 -0
  37. package/dist/pages/NSAVerificationPage.module.css +23 -0
  38. package/package.json +70 -70
  39. package/public/index.html +21 -21
  40. package/src/App.css +31 -31
  41. package/src/App.tsx +18 -18
  42. package/src/IEntityInfo.ts +31 -31
  43. package/src/INSARouterMaker.ts +7 -7
  44. package/src/INSARouterProps.ts +17 -17
  45. package/src/INSARouterState.ts +5 -5
  46. package/src/Info.ts +20 -20
  47. package/src/Message.ts +6 -6
  48. package/src/Messages.ts +33 -33
  49. package/src/NSARouterMaker.tsx +142 -142
  50. package/src/Router.tsx +39 -39
  51. package/src/components/NSAAccessListDialog.module.css +86 -86
  52. package/src/components/NSAAccessListDialog.tsx +160 -160
  53. package/src/components/NSABoxOTP.module.css +10 -10
  54. package/src/components/NSABoxOTP.tsx +63 -63
  55. package/src/components/NSAMessageListDialog.module.css +97 -97
  56. package/src/components/NSAMessageListDialog.tsx +116 -116
  57. package/src/components/NSAProductListDialog.module.css +44 -44
  58. package/src/components/NSAProductListDialog.tsx +100 -100
  59. package/src/components/NSAWorkspaceListDialog.module.css +42 -42
  60. package/src/components/NSAWorkspaceListDialog.tsx +73 -73
  61. package/src/index.tsx +24 -24
  62. package/src/layouts/Actions.ts +147 -119
  63. package/src/layouts/Menus.ts +15 -15
  64. package/src/layouts/NSALayout.tsx +417 -387
  65. package/src/layouts/NSASectionEdit.tsx +144 -140
  66. package/src/layouts/NSASectionList.tsx +161 -158
  67. package/src/layouts/NSASectionTabs.tsx +152 -156
  68. package/src/layouts/NSASectionView.tsx +61 -60
  69. package/src/main.ts +19 -19
  70. package/src/pages/NSAHomePage.module.css +22 -22
  71. package/src/pages/NSAHomePage.tsx +27 -27
  72. package/src/pages/NSALoginPage.module.css +19 -19
  73. package/src/pages/NSALoginPage.tsx +65 -65
  74. package/src/pages/NSAVerificationPage.module.css +22 -22
  75. package/src/pages/NSAVerificationPage.tsx +59 -59
  76. package/tsconfig.json +43 -43
@@ -1,141 +1,145 @@
1
- import { IBaseComponentProps } from "namirasoft-site-react";
2
- import { NSSection, NSPanel, NSButtonBlue, NSLine, NSSpace, NSSpaceSizeType } from 'namirasoft-site-react';
3
- import { INSARouterProps } from "../INSARouterProps";
4
- import { forwardRef, ReactNode, useEffect, useImperativeHandle, useRef } from "react";
5
- import { useParams } from "react-router-dom";
6
- import { IEntityInfo } from "../IEntityInfo";
7
- import { NamingConvention } from "namirasoft-core";
8
- import { NSASectionTabs, NSASectionTabsRef } from "./NSASectionTabs";
9
-
10
- export interface NSASectionEditProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
11
- {
12
- isEdit: boolean;
13
- ui: {
14
- getEntity: (entity: EntityType | null) => EntityTypeInput;
15
- setEntity: (entity: EntityType) => void;
16
- action?: {
17
- menus: {
18
- apply?: boolean,
19
- }
20
- },
21
- tabs?: boolean;
22
- panel?: boolean;
23
- }
24
- }
25
-
26
- export interface NSASectionEditRef
27
- {
28
- NSASectionTabs: NSASectionTabsRef | null;
29
- onApply: () => void;
30
- }
31
-
32
- export function onApply<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput>, entity: IEntityInfo<EntityType, EntityTypeInput>, id: string | undefined): void
33
- {
34
- try
35
- {
36
- let Name_Pascal_Space = NamingConvention.lower_case_underscore.convert(entity.name, NamingConvention.Pascal_Case_Space);
37
-
38
- let onSuccess = (new_entity: EntityType, message: string) =>
39
- {
40
- props.notifier.onSuccess(message);
41
- if (entity.client.onSuccess)
42
- entity.client.onSuccess(new_entity);
43
- else
44
- {
45
- let url = entity.client.getViewURL(new_entity.id);
46
- if (!url)
47
- url = entity.client.getListURL();
48
- props.url.redirect(url, {});
49
- }
50
- };
51
- let old_entity: EntityType | null = null;
52
- let cur_entity = props.ui.getEntity(old_entity);
53
- if (props.isEdit)
54
- {
55
- if (id)
56
- {
57
- if (entity.client.onUpdate)
58
- entity.client.onUpdate(id, cur_entity).then(new_entity =>
59
- {
60
- if (new_entity)
61
- onSuccess(new_entity, Name_Pascal_Space + " has been updated successfully");
62
- }).catch(() => { });
63
- else
64
- entity.server.update(id, cur_entity).then((new_entity) =>
65
- {
66
- onSuccess(new_entity, Name_Pascal_Space + " has been updated successfully");
67
- }).catch(() => { });
68
- }
69
- else
70
- throw new Error("ID was not provided.");
71
- }
72
- else
73
- {
74
- if (entity.client.onCreate)
75
- entity.client.onCreate(cur_entity).then(new_entity =>
76
- {
77
- if (new_entity)
78
- onSuccess(new_entity, Name_Pascal_Space + " has been created successfully");
79
- }).catch(() => { });
80
- else
81
- entity.server.create(cur_entity).then((new_entity) =>
82
- {
83
- onSuccess(new_entity, Name_Pascal_Space + " has been created successfully");
84
- }).catch(() => { });
85
- }
86
- } catch (error: any)
87
- {
88
- props.notifier.onError(error);
89
- }
90
- }
91
-
92
- export const NSASectionEdit = forwardRef<any, any>(<EntityType extends { id: string }, EntityTypeInput = EntityType>(
93
- props: Omit<NSASectionEditProps<EntityType, EntityTypeInput> & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode; } & INSARouterProps, "ref">,
94
- ref: React.Ref<NSASectionEditRef>
95
- ) =>
96
- {
97
- let { id } = useParams();
98
- let NSASectionTabs_Ref = useRef<NSASectionTabsRef>(null);
99
-
100
- useEffect(() =>
101
- {
102
- if (id)
103
- props.entity.server.get(id).then((entity) =>
104
- {
105
- props.ui.setEntity(entity);
106
- }).catch(() => { });
107
-
108
- }, [id]); // eslint-disable-line react-hooks/exhaustive-deps
109
-
110
- useImperativeHandle(ref, () => ({
111
- NSASectionTabs: NSASectionTabs_Ref.current,
112
- onApply: () =>
113
- {
114
- onApply(props, props.entity, id);
115
- }
116
- }));
117
-
118
- let panel = props.ui.panel;
119
- if (panel !== false)
120
- panel = true;
121
-
122
- return (
123
- <NSSection
124
- id={props.id}
125
- classList={[`${props.classList?.join(" ")}`]}
126
- center_items={true}
127
- >
128
- {
129
- panel ? <NSPanel grid={false}>
130
- {props.children}
131
- </NSPanel> : props.children
132
- }
133
- <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
134
- <NSButtonBlue title="Apply" onClick={() => { onApply(props, props.entity, id); }} />
135
- <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
136
- {props.isEdit && <NSLine />}
137
- {props.isEdit && <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>}
138
- {props.isEdit && (props.ui.tabs ?? true) && <NSASectionTabs ref={NSASectionTabs_Ref} id={id ?? ""} {...props} />}
139
- </NSSection>
140
- );
1
+ import { IBaseComponentProps } from "namirasoft-site-react";
2
+ import { NSSection, NSPanel, NSButtonBlue, NSLine, NSSpace, NSSpaceSizeType } from 'namirasoft-site-react';
3
+ import { INSARouterProps } from "../INSARouterProps";
4
+ import { forwardRef, ReactNode, useEffect, useImperativeHandle, useRef } from "react";
5
+ import { useParams } from "react-router-dom";
6
+ import { IEntityInfo } from "../IEntityInfo";
7
+ import { NamingConvention } from "namirasoft-core";
8
+ import { NSASectionTabs, NSASectionTabsRef } from "./NSASectionTabs";
9
+
10
+ export interface NSASectionEditProps<EntityType extends { id: string }, EntityTypeInput = EntityType> extends IBaseComponentProps, INSARouterProps
11
+ {
12
+ isEdit: boolean;
13
+ ui: {
14
+ getEntity: (entity: EntityType | null) => EntityTypeInput;
15
+ setEntity: (entity: EntityType) => void;
16
+ action?: {
17
+ menus: {
18
+ apply?: boolean,
19
+ }
20
+ },
21
+ tabs?: boolean;
22
+ panel?: boolean;
23
+ }
24
+ }
25
+
26
+ export interface NSASectionEditRef
27
+ {
28
+ NSASectionTabs: NSASectionTabsRef | null;
29
+ onApply: () => void;
30
+ }
31
+
32
+ export function onApply<EntityType extends { id: string }, EntityTypeInput = EntityType>(props: NSASectionEditProps<EntityType, EntityTypeInput>, entity: IEntityInfo<EntityType, EntityTypeInput>, id: string | undefined): void
33
+ {
34
+ try
35
+ {
36
+ let Name_Pascal_Space = NamingConvention.lower_case_underscore.convert(entity.name, NamingConvention.Pascal_Case_Space);
37
+
38
+ let onSuccess = (new_entity: EntityType, message: string) =>
39
+ {
40
+ props.notifier.onSuccess(message);
41
+ if (entity.client.onSuccess)
42
+ entity.client.onSuccess(new_entity);
43
+ else
44
+ {
45
+ let url = null;
46
+ if (entity.client.getViewURL)
47
+ url = entity.client.getViewURL(new_entity.id);
48
+ else if (entity.client.getListURL)
49
+ url = entity.client.getListURL();
50
+ if (url)
51
+ props.url.redirect(url, {});
52
+ }
53
+ };
54
+ let old_entity: EntityType | null = null;
55
+ let cur_entity = props.ui.getEntity(old_entity);
56
+ if (props.isEdit)
57
+ {
58
+ if (id)
59
+ {
60
+ if (entity.client.onUpdate)
61
+ entity.client.onUpdate(id, cur_entity).then(new_entity =>
62
+ {
63
+ if (new_entity)
64
+ onSuccess(new_entity, Name_Pascal_Space + " has been updated successfully");
65
+ }).catch(() => { });
66
+ else if (entity.server.update)
67
+ entity.server.update(id, cur_entity).then((new_entity) =>
68
+ {
69
+ onSuccess(new_entity, Name_Pascal_Space + " has been updated successfully");
70
+ }).catch(() => { });
71
+ }
72
+ else
73
+ throw new Error("ID was not provided.");
74
+ }
75
+ else
76
+ {
77
+ if (entity.client.onCreate)
78
+ entity.client.onCreate(cur_entity).then(new_entity =>
79
+ {
80
+ if (new_entity)
81
+ onSuccess(new_entity, Name_Pascal_Space + " has been created successfully");
82
+ }).catch(() => { });
83
+ else if (entity.server.create)
84
+ entity.server.create(cur_entity).then((new_entity) =>
85
+ {
86
+ onSuccess(new_entity, Name_Pascal_Space + " has been created successfully");
87
+ }).catch(() => { });
88
+ }
89
+ } catch (error: any)
90
+ {
91
+ props.notifier.onError(error);
92
+ }
93
+ }
94
+
95
+ export const NSASectionEdit = forwardRef<any, any>(<EntityType extends { id: string }, EntityTypeInput = EntityType>(
96
+ props: Omit<NSASectionEditProps<EntityType, EntityTypeInput> & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode; } & INSARouterProps, "ref">,
97
+ ref: React.Ref<NSASectionEditRef>
98
+ ) =>
99
+ {
100
+ let { id } = useParams();
101
+ let NSASectionTabs_Ref = useRef<NSASectionTabsRef>(null);
102
+
103
+ useEffect(() =>
104
+ {
105
+ if (id)
106
+ if (props.entity.server.get)
107
+ props.entity.server.get(id).then((entity) =>
108
+ {
109
+ props.ui.setEntity(entity);
110
+ }).catch(() => { });
111
+
112
+ }, [id]); // eslint-disable-line react-hooks/exhaustive-deps
113
+
114
+ useImperativeHandle(ref, () => ({
115
+ NSASectionTabs: NSASectionTabs_Ref.current,
116
+ onApply: () =>
117
+ {
118
+ onApply(props, props.entity, id);
119
+ }
120
+ }));
121
+
122
+ let panel = props.ui.panel;
123
+ if (panel !== false)
124
+ panel = true;
125
+
126
+ return (
127
+ <NSSection
128
+ id={props.id}
129
+ classList={[`${props.classList?.join(" ")}`]}
130
+ center_items={true}
131
+ >
132
+ {
133
+ panel ? <NSPanel grid={false}>
134
+ {props.children}
135
+ </NSPanel> : props.children
136
+ }
137
+ <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
138
+ <NSButtonBlue title="Apply" onClick={() => { onApply(props, props.entity, id); }} />
139
+ <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
140
+ {props.isEdit && <NSLine />}
141
+ {props.isEdit && <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>}
142
+ {props.isEdit && (props.ui.tabs ?? true) && <NSASectionTabs ref={NSASectionTabs_Ref} id={id ?? ""} {...props} />}
143
+ </NSSection>
144
+ );
141
145
  });
@@ -1,159 +1,162 @@
1
- import { Component, ReactNode, createRef } from "react";
2
- import { EnvService, FilterItem, FilterItemColumnType, FilterItemOperator, ObjectService } from "namirasoft-core";
3
- import { NSLine, NSSection, NSSpace, NSSpaceSizeType, NSTable, NSFilterBox, INSFilterBoxProps_Table, INSFilterBoxProps_Column, TableColumnInfo, TableRowInfo } from "namirasoft-site-react";
4
- import { MetaDatabase, NamirasoftFieldServer } from "namirasoft-field";
5
- import { IEntityInfo } from "../IEntityInfo";
6
- import { INSARouterProps } from "../INSARouterProps";
7
- import { NSASectionTabs } from "./NSASectionTabs";
8
-
9
- export interface NSASectionListProps<EntityType extends { id: string }>
10
- {
11
- ui: {
12
- getColumnAttributes?: () => { [key: string]: string };
13
- getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<EntityType>) => any;
14
- tabs?: boolean;
15
- }
16
- }
17
-
18
- export interface NSASectionListState
19
- {
20
- }
21
-
22
- export class NSASectionList<EntityType extends { id: string }, EntityTypeInput = EntityType> extends Component<NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput> } & INSARouterProps, NSASectionListState>
23
- {
24
- public NSFilterBox_Top = createRef<NSFilterBox>();
25
- public NSTable_Main = createRef<NSTable<EntityType>>();
26
- constructor(props: NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode })
27
- {
28
- super(props);
29
- this.state = { totalItems: 0 };
30
- }
31
- getSelectedIDs(): string[]
32
- {
33
- return this.NSTable_Main.current?.getSelectedIDs() ?? [];
34
- }
35
- override componentDidMount()
36
- {
37
- let filters;
38
- try
39
- {
40
- let encoded = this.props.url.getQuery("filters");
41
- filters = FilterItem.decode(encoded);
42
- } catch (error)
43
- {
44
- }
45
- if (filters)
46
- this.NSFilterBox_Top.current?.setFilterItems(filters);
47
- else
48
- this.NSTable_Main.current?.reload(null, null);
49
- }
50
- override render()
51
- {
52
- const getColumns = (): TableColumnInfo[] =>
53
- {
54
- return this.props.entity.client.getColumns();
55
- };
56
- const getRowKey = (row: TableRowInfo<EntityType>): string =>
57
- {
58
- return row.value.id.toString();
59
- };
60
- let ids = this.getSelectedIDs();
61
- let id = "";
62
- if (ids.length === 1)
63
- id = ids[0];
64
-
65
- return (
66
- <NSSection center_items={false}>
67
- <NSFilterBox ref={this.NSFilterBox_Top}
68
- getTables={() =>
69
- {
70
- return this.props.entity.tables.map(table =>
71
- {
72
- let columns = table.table.getColumns().map(c => { return { ...c, type: new ObjectService(c.type).getEnum(FilterItemColumnType, FilterItemColumnType.Any) }; });
73
- return { table: { name: table.table.name, text: table.table.text, columns }, required: table.required };
74
- })
75
- }}
76
- getMoreTables={async () =>
77
- {
78
- let REACT_APP_BASE_URL_FIELD = new EnvService("REACT_APP_BASE_URL_FIELD", true).getString();
79
- let server = new NamirasoftFieldServer(REACT_APP_BASE_URL_FIELD, this.props.account.token_manager, this.props.notifier.onError);
80
- let f_items = [
81
- new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
82
- new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
83
- ];
84
- let c_items = [
85
- new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
86
- new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
87
- ];
88
- let ans: { table: INSFilterBoxProps_Table, required: boolean }[] = [];
89
- try
90
- {
91
- let f = server.field.List(f_items, null, null);
92
- let c = server.category.List(c_items, null, null);
93
- let r = await Promise.all([f, c]);
94
-
95
- if (r[0].rows.length > 0)
96
- ans.push({
97
- table: {
98
- name: "fields",
99
- text: "Fields",
100
- columns: r[0].rows.map(f => { return { name: f.name, text: f.name, type: new ObjectService(f.type).getEnum(FilterItemColumnType, FilterItemColumnType.Number) } })
101
- },
102
- required: false
103
- });
104
- if (r[1].rows.length > 0)
105
- ans.push({
106
- table: {
107
- name: "categories",
108
- text: "Categories",
109
- columns: r[1].rows.map(c => { return { name: c.name, text: c.name, type: FilterItemColumnType.Number } })
110
- },
111
- required: false
112
- });
113
-
114
- } catch (error)
115
- {
116
- }
117
- // todo add tags
118
- return ans;
119
- }}
120
- getData={async (table: INSFilterBoxProps_Table, column: INSFilterBoxProps_Column) =>
121
- {
122
- return await this.props.entity.server.value_list(table.name, column.name);
123
- }}
124
- onChanged={() =>
125
- {
126
- this.NSTable_Main.current?.setSelectedIDs([]);
127
- this.NSTable_Main.current?.reload(null, null);
128
- }} />
129
- <NSTable<EntityType>
130
- ref={this.NSTable_Main}
131
- checkbox={true}
132
- columns={getColumns()}
133
- getRows={async () =>
134
- {
135
- if (this.NSTable_Main.current)
136
- {
137
- let items = this.NSFilterBox_Top.current?.getFilterItems() ?? [];
138
- let NSPagination = this.NSTable_Main.current.NSPagination.current;
139
- if (NSPagination)
140
- {
141
- let res = await this.props.entity.server.list(items, NSPagination.getCurrentPage(), NSPagination.getPageSize());
142
- return res;
143
- }
144
- }
145
- return { rows: [], count: 0 };
146
- }}
147
- getRowKey={getRowKey}
148
- getColumnAttributes={this.props.ui.getColumnAttributes}
149
- getCellFormattedValue={this.props.ui.getCellFormattedValue}
150
- onSelectedIDsChanged={() => this.setState({})}
151
- />
152
- <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
153
- <NSLine></NSLine>
154
- <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
155
- {(this.props.ui.tabs ?? true) && <NSASectionTabs id={id} {...this.props} />}
156
- </NSSection>
157
- );
158
- }
1
+ import { Component, ReactNode, createRef } from "react";
2
+ import { EnvService, FilterItem, FilterItemColumnType, FilterItemOperator, ObjectService } from "namirasoft-core";
3
+ import { NSLine, NSSection, NSSpace, NSSpaceSizeType, NSTable, NSFilterBox, INSFilterBoxProps_Table, INSFilterBoxProps_Column, TableColumnInfo, TableRowInfo } from "namirasoft-site-react";
4
+ import { MetaDatabase, NamirasoftFieldServer } from "namirasoft-field";
5
+ import { IEntityInfo } from "../IEntityInfo";
6
+ import { INSARouterProps } from "../INSARouterProps";
7
+ import { NSASectionTabs } from "./NSASectionTabs";
8
+
9
+ export interface NSASectionListProps<EntityType extends { id: string }>
10
+ {
11
+ ui: {
12
+ getColumnAttributes?: () => { [key: string]: string };
13
+ getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<EntityType>) => any;
14
+ tabs?: boolean;
15
+ }
16
+ }
17
+
18
+ export interface NSASectionListState
19
+ {
20
+ }
21
+
22
+ export class NSASectionList<EntityType extends { id: string }, EntityTypeInput = EntityType> extends Component<NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput> } & INSARouterProps, NSASectionListState>
23
+ {
24
+ public NSFilterBox_Top = createRef<NSFilterBox>();
25
+ public NSTable_Main = createRef<NSTable<EntityType>>();
26
+ constructor(props: NSASectionListProps<EntityType> & INSARouterProps & { entity: IEntityInfo<EntityType, EntityTypeInput>, children: ReactNode })
27
+ {
28
+ super(props);
29
+ this.state = { totalItems: 0 };
30
+ }
31
+ getSelectedIDs(): string[]
32
+ {
33
+ return this.NSTable_Main.current?.getSelectedIDs() ?? [];
34
+ }
35
+ override componentDidMount()
36
+ {
37
+ let filters;
38
+ try
39
+ {
40
+ let encoded = this.props.url.getQuery("filters");
41
+ filters = FilterItem.decode(encoded);
42
+ } catch (error)
43
+ {
44
+ }
45
+ if (filters)
46
+ this.NSFilterBox_Top.current?.setFilterItems(filters);
47
+ else
48
+ this.NSTable_Main.current?.reload(null, null);
49
+ }
50
+ override render()
51
+ {
52
+ const getColumns = (): TableColumnInfo[] =>
53
+ {
54
+ return this.props.entity.client.getColumns();
55
+ };
56
+ const getRowKey = (row: TableRowInfo<EntityType>): string =>
57
+ {
58
+ return row.value.id.toString();
59
+ };
60
+ let ids = this.getSelectedIDs();
61
+ let id = "";
62
+ if (ids.length === 1)
63
+ id = ids[0];
64
+
65
+ return (
66
+ <NSSection center_items={false}>
67
+ <NSFilterBox ref={this.NSFilterBox_Top}
68
+ getTables={() =>
69
+ {
70
+ return this.props.entity.tables.map(table =>
71
+ {
72
+ let columns = table.table.getColumns().map(c => { return { ...c, type: new ObjectService(c.type).getEnum(FilterItemColumnType, FilterItemColumnType.Any) }; });
73
+ return { table: { name: table.table.name, text: table.table.text, columns }, required: table.required };
74
+ })
75
+ }}
76
+ getMoreTables={async () =>
77
+ {
78
+ let REACT_APP_BASE_URL_FIELD = new EnvService("REACT_APP_BASE_URL_FIELD", true).getString();
79
+ let server = new NamirasoftFieldServer(REACT_APP_BASE_URL_FIELD, this.props.account.token_manager, this.props.notifier.onError);
80
+ let f_items = [
81
+ new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
82
+ new FilterItem(MetaDatabase.main.field, MetaDatabase.main.field.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
83
+ ];
84
+ let c_items = [
85
+ new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.product_id, false, FilterItemOperator.all.equals, this.props.entity.product_id),
86
+ new FilterItem(MetaDatabase.main.category, MetaDatabase.main.category.columns.entity, false, FilterItemOperator.all.equals, this.props.entity.name)
87
+ ];
88
+ let ans: { table: INSFilterBoxProps_Table, required: boolean }[] = [];
89
+ try
90
+ {
91
+ let f = server.field.List(f_items, null, null);
92
+ let c = server.category.List(c_items, null, null);
93
+ let r = await Promise.all([f, c]);
94
+
95
+ if (r[0].rows.length > 0)
96
+ ans.push({
97
+ table: {
98
+ name: "fields",
99
+ text: "Fields",
100
+ columns: r[0].rows.map(f => { return { name: f.name, text: f.name, type: new ObjectService(f.type).getEnum(FilterItemColumnType, FilterItemColumnType.Number) } })
101
+ },
102
+ required: false
103
+ });
104
+ if (r[1].rows.length > 0)
105
+ ans.push({
106
+ table: {
107
+ name: "categories",
108
+ text: "Categories",
109
+ columns: r[1].rows.map(c => { return { name: c.name, text: c.name, type: FilterItemColumnType.Number } })
110
+ },
111
+ required: false
112
+ });
113
+
114
+ } catch (error)
115
+ {
116
+ }
117
+ // todo add tags
118
+ return ans;
119
+ }}
120
+ getData={async (table: INSFilterBoxProps_Table, column: INSFilterBoxProps_Column) =>
121
+ {
122
+ return await this.props.entity.server.value_list(table.name, column.name);
123
+ }}
124
+ onChanged={() =>
125
+ {
126
+ this.NSTable_Main.current?.setSelectedIDs([]);
127
+ this.NSTable_Main.current?.reload(null, null);
128
+ }} />
129
+ <NSTable<EntityType>
130
+ ref={this.NSTable_Main}
131
+ checkbox={true}
132
+ columns={getColumns()}
133
+ getRows={async () =>
134
+ {
135
+ if (this.NSTable_Main.current)
136
+ {
137
+ let items = this.NSFilterBox_Top.current?.getFilterItems() ?? [];
138
+ let NSPagination = this.NSTable_Main.current.NSPagination.current;
139
+ if (NSPagination)
140
+ {
141
+ if (this.props.entity.server.list)
142
+ {
143
+ let res = await this.props.entity.server.list(items, NSPagination.getCurrentPage(), NSPagination.getPageSize());
144
+ return res;
145
+ }
146
+ }
147
+ }
148
+ return { rows: [], count: 0 };
149
+ }}
150
+ getRowKey={getRowKey}
151
+ getColumnAttributes={this.props.ui.getColumnAttributes}
152
+ getCellFormattedValue={this.props.ui.getCellFormattedValue}
153
+ onSelectedIDsChanged={() => this.setState({})}
154
+ />
155
+ <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
156
+ <NSLine></NSLine>
157
+ <NSSpace size={NSSpaceSizeType.NORMAL}></NSSpace>
158
+ {(this.props.ui.tabs ?? true) && <NSASectionTabs id={id} {...this.props} />}
159
+ </NSSection>
160
+ );
161
+ }
159
162
  }