@jsb188/mday-web 1.1.8 → 1.1.10
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.
- package/package.json +12 -6
- package/src/modules/DataTable-ContextMenu.tsx +169 -0
- package/src/modules/DataTable-InboundContact.tsx +523 -0
- package/src/modules/DataTable.tsx +5060 -0
- package/src/modules/Sheet-ContextMenu.tsx +161 -0
- package/src/modules/Sheet.tsx +28 -0
- package/src/modules/cell-save-beacon.ts +67 -0
- package/src/modules/dataTable-interaction-state.ts +276 -0
- package/src/modules/dataTable-shortcuts.ts +192 -0
- package/src/modules/dataTable-viewport.ts +89 -0
- package/src/modules/grid-cell-render.ts +72 -0
- package/src/modules/grid-context-menu.ts +112 -0
- package/src/modules/grid-keyboard.ts +267 -0
- package/src/modules/grid-render-store.ts +103 -0
- package/src/modules/grid-runtime.ts +178 -0
- package/src/modules/grid-selection.ts +336 -0
- package/src/modules/grid-viewport.ts +57 -0
- package/src/modules/use-dataTable-states.ts +529 -0
- package/src/modules/use-debounced-cell-save-batch.ts +160 -0
- package/src/types/css.d.ts +1 -0
- package/src/utils/log-web.ts +440 -0
- package/src/utils/org-web.ts +40 -0
- package/src/utils/route-helpers.ts +244 -137
- package/tests/DataTable.test.tsx +4466 -0
- package/tests/dataTable-interaction-state.test.ts +127 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +11 -0
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n';
|
|
1
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import type { OrganizationFeatureEnum, OrganizationOperationEnum, OrganizationSidebarGroupObj, OrganizationSidebarItemObj } from '@jsb188/mday/types/organization.d.ts';
|
|
3
|
+
import type { ReportGroupGQL } from '@jsb188/mday/types/report.d.ts';
|
|
4
|
+
import type { DataTableGQL } from '@jsb188/mday/types/dataTable.d.ts';
|
|
5
|
+
import type { OperationName } from '@jsb188/mday/utils/organization.ts';
|
|
2
6
|
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
-
import type { OrganizationFeatureEnum, OrganizationOperationEnum } from '../types/organization.d';
|
|
4
7
|
|
|
5
8
|
// Use this for report periods, etc
|
|
6
|
-
const CURRENT_YEAR = String(new Date().getFullYear());
|
|
9
|
+
// const CURRENT_YEAR = String(new Date().getFullYear());
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Constants; Re-usable rules
|
|
10
13
|
*/
|
|
11
14
|
|
|
12
|
-
const
|
|
15
|
+
const OP = {
|
|
16
|
+
FARMING: ['ARABLE', 'LIVESTOCK'],
|
|
17
|
+
GROWER_NETWORK: ['GROWER_NETWORK'],
|
|
18
|
+
};
|
|
13
19
|
|
|
14
20
|
const F = {
|
|
15
21
|
normal_logging: ['NORMAL_LOGGING'],
|
|
@@ -23,18 +29,20 @@ const F = {
|
|
|
23
29
|
type ValidRoutePath =
|
|
24
30
|
'/app'
|
|
25
31
|
| '/app/c/'
|
|
26
|
-
| '/app/
|
|
32
|
+
| '/app/workflows-test'
|
|
33
|
+
| '/app/workflows'
|
|
34
|
+
| '/app/sheets'
|
|
35
|
+
| '/app/s/'
|
|
36
|
+
| '/app/emails'
|
|
27
37
|
| '/app/logs'
|
|
38
|
+
| '/app/greenhouse'
|
|
28
39
|
| '/app/seeding'
|
|
29
40
|
| '/app/transplanting'
|
|
30
41
|
| '/app/field-work'
|
|
31
42
|
| '/app/harvested'
|
|
32
43
|
| '/app/post-harvest'
|
|
33
44
|
| '/app/orders'
|
|
34
|
-
| '/app/globalgap/'
|
|
35
|
-
| '/app/cleaning'
|
|
36
45
|
| '/app/purchases'
|
|
37
|
-
| '/app/organic'
|
|
38
46
|
| '/app/hygiene'
|
|
39
47
|
| '/app/sanitation'
|
|
40
48
|
| '/app/materials'
|
|
@@ -43,9 +51,14 @@ type ValidRoutePath =
|
|
|
43
51
|
| '/app/vendors'
|
|
44
52
|
| '/app/markets'
|
|
45
53
|
| '/app/receipts'
|
|
46
|
-
| '/app/livestock'
|
|
47
54
|
| '/app/growers'
|
|
48
|
-
| '/app/foreign-growers'
|
|
55
|
+
| '/app/foreign-growers'
|
|
56
|
+
|
|
57
|
+
// Reports
|
|
58
|
+
| '/app/r/'
|
|
59
|
+
| '/app/d/'
|
|
60
|
+
| '/app/p/';
|
|
61
|
+
// | '/app/r/water-source/';
|
|
49
62
|
|
|
50
63
|
interface RouteDictObj {
|
|
51
64
|
to: ValidRoutePath;
|
|
@@ -54,47 +67,76 @@ interface RouteDictObj {
|
|
|
54
67
|
allowedOperations?: OrganizationOperationEnum[];
|
|
55
68
|
notAllowedOperations?: OrganizationOperationEnum[];
|
|
56
69
|
requiredFeature?: OrganizationFeatureEnum[];
|
|
70
|
+
requiredACL?: OperationName;
|
|
57
71
|
|
|
58
|
-
// These values prevent rendering flickers when calculating TOC/breadcrumbs between page renders
|
|
59
72
|
hasPhysicalToolbar?: 'ALWAYS' | 'NEVER' | ((parts: string[]) => boolean);
|
|
60
|
-
hasAsideNav?: 'ALWAYS' | 'NEVER' | ((parts: string[]) => boolean);
|
|
61
73
|
}
|
|
62
74
|
|
|
75
|
+
type CheckACLClientFn = (opName: OperationName) => boolean;
|
|
76
|
+
|
|
63
77
|
const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
64
78
|
|
|
65
79
|
// Main /app/ routes
|
|
80
|
+
// If route ends with '/', it requires (or optionally accepts) a path segment
|
|
81
|
+
// e.g. "/app/c/" means "/app/c/:chatId" etc
|
|
82
|
+
// e.g. "/app" means exactly "/app", and it never expects a path segment
|
|
66
83
|
|
|
67
84
|
'/app': {
|
|
68
85
|
to: '/app',
|
|
69
86
|
text: 'app.home',
|
|
70
87
|
},
|
|
71
|
-
|
|
72
88
|
'/app/c/': {
|
|
73
89
|
to: '/app/c/',
|
|
74
90
|
text: 'app.route_ai_chat',
|
|
75
91
|
iconName: COMMON_ICON_NAMES.chat,
|
|
76
92
|
|
|
77
93
|
hasPhysicalToolbar: 'ALWAYS',
|
|
78
|
-
hasAsideNav: 'NEVER',
|
|
79
94
|
},
|
|
80
|
-
|
|
81
95
|
// Advanced
|
|
82
96
|
|
|
83
|
-
'/app/
|
|
84
|
-
to: '/app/
|
|
97
|
+
'/app/workflows-test': {
|
|
98
|
+
to: '/app/workflows-test',
|
|
85
99
|
text: 'form.ai_workflows',
|
|
86
100
|
iconName: COMMON_ICON_NAMES.ai_workflow,
|
|
87
101
|
},
|
|
88
|
-
|
|
102
|
+
'/app/workflows': {
|
|
103
|
+
to: '/app/workflows',
|
|
104
|
+
text: 'form.ai_workflows',
|
|
105
|
+
iconName: COMMON_ICON_NAMES.ai_workflow,
|
|
106
|
+
},
|
|
107
|
+
'/app/sheets': {
|
|
108
|
+
to: '/app/sheets',
|
|
109
|
+
text: 'app.sheets',
|
|
110
|
+
iconName: COMMON_ICON_NAMES.sheet,
|
|
111
|
+
},
|
|
112
|
+
'/app/s/': {
|
|
113
|
+
to: '/app/s/',
|
|
114
|
+
text: 'app.sheets',
|
|
115
|
+
iconName: COMMON_ICON_NAMES.sheet,
|
|
116
|
+
},
|
|
117
|
+
'/app/emails': {
|
|
118
|
+
to: '/app/emails',
|
|
119
|
+
text: 'app.ai_inboxes',
|
|
120
|
+
iconName: COMMON_ICON_NAMES.ai_inbox,
|
|
121
|
+
requiredACL: 'ai_inbox_read',
|
|
122
|
+
},
|
|
89
123
|
'/app/logs': {
|
|
90
124
|
to: '/app/logs',
|
|
91
125
|
text: 'log.all_logs',
|
|
92
126
|
iconName: COMMON_ICON_NAMES.logs,
|
|
93
|
-
notAllowedOperations: ['GROWER_NETWORK'], // Temporary for now
|
|
94
127
|
},
|
|
95
128
|
|
|
96
129
|
// Arable
|
|
97
130
|
|
|
131
|
+
'/app/greenhouse': {
|
|
132
|
+
to: '/app/greenhouse',
|
|
133
|
+
text: 'log.greenhouse_seeding',
|
|
134
|
+
iconName: COMMON_ICON_NAMES.GREENHOUSE_SEEDING,
|
|
135
|
+
|
|
136
|
+
allowedOperations: ['ARABLE'],
|
|
137
|
+
requiredFeature: F.normal_logging,
|
|
138
|
+
},
|
|
139
|
+
|
|
98
140
|
'/app/seeding': {
|
|
99
141
|
to: '/app/seeding',
|
|
100
142
|
text: 'log.seeding',
|
|
@@ -140,7 +182,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
140
182
|
text: 'log.purchases',
|
|
141
183
|
iconName: COMMON_ICON_NAMES.invoice,
|
|
142
184
|
|
|
143
|
-
allowedOperations:
|
|
185
|
+
allowedOperations: OP.FARMING,
|
|
144
186
|
requiredFeature: F.normal_logging,
|
|
145
187
|
},
|
|
146
188
|
'/app/orders': {
|
|
@@ -148,44 +190,10 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
148
190
|
text: 'form.sales_orders',
|
|
149
191
|
iconName: COMMON_ICON_NAMES.receipt,
|
|
150
192
|
|
|
151
|
-
allowedOperations:
|
|
193
|
+
allowedOperations: OP.FARMING,
|
|
152
194
|
requiredFeature: F.normal_logging,
|
|
153
195
|
},
|
|
154
196
|
|
|
155
|
-
// Arable; Reports
|
|
156
|
-
|
|
157
|
-
'/app/globalgap/': {
|
|
158
|
-
to: ('/app/globalgap/' + CURRENT_YEAR) as ValidRoutePath,
|
|
159
|
-
text: 'product.report.GLOBAL_GAP',
|
|
160
|
-
iconName: COMMON_ICON_NAMES.generic_report,
|
|
161
|
-
|
|
162
|
-
allowedOperations: OP_FARMING,
|
|
163
|
-
requiredFeature: ['GLOBAL_GAP'],
|
|
164
|
-
|
|
165
|
-
hasPhysicalToolbar: (parts: string[]) => parts.length > 4,
|
|
166
|
-
hasAsideNav: (parts: string[]) => parts.length > 4,
|
|
167
|
-
},
|
|
168
|
-
'/app/cleaning': {
|
|
169
|
-
to: '/app/cleaning',
|
|
170
|
-
text: 'product.report.CLEANING',
|
|
171
|
-
iconName: COMMON_ICON_NAMES.SANITATION,
|
|
172
|
-
|
|
173
|
-
allowedOperations: OP_FARMING,
|
|
174
|
-
requiredFeature: F.food_safety,
|
|
175
|
-
},
|
|
176
|
-
'/app/organic': {
|
|
177
|
-
to: '/app/organic',
|
|
178
|
-
text: 'product.report.ORGANIC_CERTIFICATION',
|
|
179
|
-
iconName: COMMON_ICON_NAMES.generic_report,
|
|
180
|
-
|
|
181
|
-
allowedOperations: OP_FARMING,
|
|
182
|
-
requiredFeature: ['ORGANIC_CERTIFICATION'],
|
|
183
|
-
|
|
184
|
-
// This will need to change later if we're introducing "period" table of contents page selection
|
|
185
|
-
hasPhysicalToolbar: 'ALWAYS',
|
|
186
|
-
hasAsideNav: 'ALWAYS',
|
|
187
|
-
},
|
|
188
|
-
|
|
189
197
|
// Arable; Food Safety
|
|
190
198
|
|
|
191
199
|
'/app/hygiene': {
|
|
@@ -193,7 +201,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
193
201
|
text: 'log.hygiene',
|
|
194
202
|
iconName: COMMON_ICON_NAMES.HYGIENE,
|
|
195
203
|
|
|
196
|
-
allowedOperations:
|
|
204
|
+
allowedOperations: OP.FARMING,
|
|
197
205
|
requiredFeature: F.food_safety,
|
|
198
206
|
},
|
|
199
207
|
'/app/sanitation': {
|
|
@@ -201,7 +209,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
201
209
|
text: 'log.sanitation',
|
|
202
210
|
iconName: COMMON_ICON_NAMES.SANITATION,
|
|
203
211
|
|
|
204
|
-
allowedOperations:
|
|
212
|
+
allowedOperations: OP.FARMING,
|
|
205
213
|
requiredFeature: F.food_safety,
|
|
206
214
|
},
|
|
207
215
|
'/app/materials': {
|
|
@@ -209,7 +217,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
209
217
|
text: 'log.materials',
|
|
210
218
|
iconName: COMMON_ICON_NAMES.MATERIALS,
|
|
211
219
|
|
|
212
|
-
allowedOperations:
|
|
220
|
+
allowedOperations: OP.FARMING,
|
|
213
221
|
requiredFeature: F.food_safety,
|
|
214
222
|
},
|
|
215
223
|
'/app/biosecurity': {
|
|
@@ -217,7 +225,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
217
225
|
text: 'log.biosecurity',
|
|
218
226
|
iconName: COMMON_ICON_NAMES.BIOSECURITY,
|
|
219
227
|
|
|
220
|
-
allowedOperations:
|
|
228
|
+
allowedOperations: OP.FARMING,
|
|
221
229
|
requiredFeature: F.food_safety,
|
|
222
230
|
},
|
|
223
231
|
'/app/employees': {
|
|
@@ -225,7 +233,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
225
233
|
text: 'log.employees',
|
|
226
234
|
iconName: COMMON_ICON_NAMES.EMPLOYEES,
|
|
227
235
|
|
|
228
|
-
allowedOperations:
|
|
236
|
+
allowedOperations: OP.FARMING,
|
|
229
237
|
requiredFeature: F.food_safety,
|
|
230
238
|
},
|
|
231
239
|
|
|
@@ -244,10 +252,9 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
244
252
|
iconName: COMMON_ICON_NAMES.shop_market,
|
|
245
253
|
|
|
246
254
|
allowedOperations: ['FARMERS_MARKET'],
|
|
247
|
-
requiredFeature: ['CAL_EVENTS'],
|
|
248
255
|
},
|
|
249
256
|
'/app/receipts': {
|
|
250
|
-
to: ('/app/receipts
|
|
257
|
+
to: ('/app/receipts') as ValidRoutePath,
|
|
251
258
|
text: 'form.market_receipts',
|
|
252
259
|
iconName: COMMON_ICON_NAMES.market_receipt,
|
|
253
260
|
|
|
@@ -255,30 +262,41 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
255
262
|
requiredFeature: F.normal_logging
|
|
256
263
|
},
|
|
257
264
|
|
|
258
|
-
// Livestock
|
|
259
|
-
'/app/livestock': {
|
|
260
|
-
to: '/app/livestock',
|
|
261
|
-
text: 'form.livestock',
|
|
262
|
-
iconName: COMMON_ICON_NAMES.livestock,
|
|
263
|
-
|
|
264
|
-
allowedOperations: ['LIVESTOCK'],
|
|
265
|
-
requiredFeature: F.normal_logging
|
|
266
|
-
},
|
|
267
|
-
|
|
268
265
|
// Grower Network
|
|
269
266
|
'/app/growers': {
|
|
270
267
|
to: '/app/growers',
|
|
271
268
|
text: 'form.domestic_growers',
|
|
272
269
|
iconName: COMMON_ICON_NAMES.growers,
|
|
273
270
|
|
|
274
|
-
allowedOperations:
|
|
271
|
+
allowedOperations: OP.GROWER_NETWORK,
|
|
275
272
|
},
|
|
276
273
|
'/app/foreign-growers': {
|
|
277
274
|
to: '/app/foreign-growers',
|
|
278
275
|
text: 'form.foreign_growers',
|
|
279
276
|
iconName: COMMON_ICON_NAMES.foreign_growers,
|
|
280
277
|
|
|
281
|
-
allowedOperations:
|
|
278
|
+
allowedOperations: OP.GROWER_NETWORK,
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
// Reports
|
|
282
|
+
|
|
283
|
+
'/app/r/': {
|
|
284
|
+
to: '/app/r/',
|
|
285
|
+
text: 'form.reports',
|
|
286
|
+
iconName: COMMON_ICON_NAMES.generic_report,
|
|
287
|
+
hasPhysicalToolbar: 'NEVER',
|
|
288
|
+
},
|
|
289
|
+
'/app/d/': {
|
|
290
|
+
to: '/app/d/',
|
|
291
|
+
text: 'form.dataTables',
|
|
292
|
+
iconName: COMMON_ICON_NAMES.data_table,
|
|
293
|
+
hasPhysicalToolbar: 'NEVER',
|
|
294
|
+
},
|
|
295
|
+
'/app/p/': {
|
|
296
|
+
to: '/app/p/',
|
|
297
|
+
text: 'form.reports',
|
|
298
|
+
iconName: COMMON_ICON_NAMES.generic_report,
|
|
299
|
+
hasPhysicalToolbar: 'NEVER',
|
|
282
300
|
},
|
|
283
301
|
};
|
|
284
302
|
|
|
@@ -321,18 +339,17 @@ export function isRouteValid(routePath: ValidRoutePath, pathSegment?: string | n
|
|
|
321
339
|
|
|
322
340
|
const ROUTES_DICT_ORDERED = Object.keys(ROUTES_DICT).sort((a, b) => b.length - a.length);
|
|
323
341
|
|
|
324
|
-
interface RouteConfigObj extends Omit<RouteDictObj, 'hasPhysicalToolbar'
|
|
342
|
+
interface RouteConfigObj extends Omit<RouteDictObj, 'hasPhysicalToolbar'> {
|
|
325
343
|
routeName: ValidRoutePath;
|
|
326
|
-
scrollResetKey: string;
|
|
327
344
|
allowed: boolean;
|
|
328
345
|
hasPhysicalToolbar: boolean;
|
|
329
|
-
hasAsideNav: boolean;
|
|
330
346
|
}
|
|
331
347
|
|
|
332
348
|
export function getRouteConfigs(
|
|
333
349
|
pathname: ValidRoutePath | string,
|
|
334
350
|
operation?: OrganizationOperationEnum | null,
|
|
335
351
|
orgFeatures?: OrganizationFeatureEnum[] | null,
|
|
352
|
+
checkACLClient?: CheckACLClientFn | null,
|
|
336
353
|
): RouteConfigObj {
|
|
337
354
|
|
|
338
355
|
for (const routeName of ROUTES_DICT_ORDERED) {
|
|
@@ -345,19 +362,6 @@ export function getRouteConfigs(
|
|
|
345
362
|
const routeDict = ROUTES_DICT[routeName as ValidRoutePath];
|
|
346
363
|
const pathParts = pathname.split('/');
|
|
347
364
|
|
|
348
|
-
let scrollResetKey: string;
|
|
349
|
-
if (pathParts.length >= 3) {
|
|
350
|
-
// scroll reset key here is full path minus last part
|
|
351
|
-
scrollResetKey = pathParts.slice(0, pathParts.length - 1).join('/');
|
|
352
|
-
} else {
|
|
353
|
-
scrollResetKey = pathParts.slice(0, 3).join('/');
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const hasAsideNav = !!routeDict.hasAsideNav && routeDict.hasAsideNav !== 'NEVER' && (
|
|
357
|
-
routeDict.hasAsideNav === 'ALWAYS' ||
|
|
358
|
-
(typeof routeDict.hasAsideNav === 'function' && routeDict.hasAsideNav(pathParts))
|
|
359
|
-
);
|
|
360
|
-
|
|
361
365
|
const hasPhysicalToolbar = !!routeDict.hasPhysicalToolbar && routeDict.hasPhysicalToolbar !== 'NEVER' && (
|
|
362
366
|
routeDict.hasPhysicalToolbar === 'ALWAYS' ||
|
|
363
367
|
(typeof routeDict.hasPhysicalToolbar === 'function' && routeDict.hasPhysicalToolbar(pathParts))
|
|
@@ -367,20 +371,16 @@ export function getRouteConfigs(
|
|
|
367
371
|
...routeDict,
|
|
368
372
|
text: i18n.has(routeDict.text) ? i18n.t(routeDict.text) : routeDict.text,
|
|
369
373
|
routeName: routeName as ValidRoutePath,
|
|
370
|
-
|
|
371
|
-
allowed: isRouteAllowed(pathname, operation, orgFeatures),
|
|
374
|
+
allowed: isRouteAllowed(pathname, operation, orgFeatures, checkACLClient),
|
|
372
375
|
hasPhysicalToolbar,
|
|
373
|
-
hasAsideNav,
|
|
374
376
|
};
|
|
375
377
|
}
|
|
376
378
|
}
|
|
377
379
|
|
|
378
380
|
return {
|
|
379
381
|
routeName: '/__unknown',
|
|
380
|
-
scrollResetKey: '',
|
|
381
382
|
allowed: false,
|
|
382
383
|
hasPhysicalToolbar: false,
|
|
383
|
-
hasAsideNav: false,
|
|
384
384
|
} as any;
|
|
385
385
|
}
|
|
386
386
|
|
|
@@ -395,6 +395,7 @@ export function isRouteAllowed(
|
|
|
395
395
|
pathname: ValidRoutePath | string,
|
|
396
396
|
operation?: OrganizationOperationEnum | null,
|
|
397
397
|
orgFeatures?: OrganizationFeatureEnum[] | null,
|
|
398
|
+
checkACLClient?: CheckACLClientFn | null,
|
|
398
399
|
): boolean {
|
|
399
400
|
|
|
400
401
|
let routeDict = ROUTES_DICT[pathname as ValidRoutePath];
|
|
@@ -420,45 +421,129 @@ export function isRouteAllowed(
|
|
|
420
421
|
(!routeDict.allowedOperations || routeDict.allowedOperations.includes(operation || '')) &&
|
|
421
422
|
(!routeDict.notAllowedOperations || !routeDict.notAllowedOperations.includes(operation || '')) &&
|
|
422
423
|
// If {orgFeature} is null, assume data is not finished loading yet, and allow "benefit of doubt" access
|
|
423
|
-
(!orgFeatures || !routeDict.requiredFeature || routeDict.requiredFeature.some((feature) => orgFeatures.includes(feature)))
|
|
424
|
+
(!orgFeatures || !routeDict.requiredFeature || routeDict.requiredFeature.some((feature) => orgFeatures.includes(feature))) &&
|
|
425
|
+
(!routeDict.requiredACL || !checkACLClient || checkACLClient(routeDict.requiredACL))
|
|
424
426
|
);
|
|
425
427
|
}
|
|
426
428
|
|
|
427
|
-
/**
|
|
428
|
-
* Helper; because i18n isn't registered when this file opens, we gotta do this
|
|
429
|
-
*/
|
|
430
|
-
|
|
431
|
-
function routesDictI18n(routeDictObj: RouteDictObj) {
|
|
432
|
-
return {
|
|
433
|
-
...routeDictObj,
|
|
434
|
-
text: i18n.t(routeDictObj.text),
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
|
|
438
429
|
/**
|
|
439
430
|
* Helper; get static nav list based on organization's operation & features
|
|
440
431
|
*/
|
|
441
432
|
|
|
442
433
|
interface NavListItem {
|
|
443
|
-
break
|
|
434
|
+
break?: never;
|
|
435
|
+
slug?: string;
|
|
444
436
|
to: string;
|
|
445
437
|
text: string;
|
|
446
|
-
iconName
|
|
438
|
+
iconName?: string | null;
|
|
447
439
|
};
|
|
448
440
|
|
|
449
441
|
interface NavBreakItem {
|
|
450
442
|
break: boolean;
|
|
451
|
-
to
|
|
452
|
-
text
|
|
453
|
-
iconName
|
|
443
|
+
to?: never;
|
|
444
|
+
text?: never;
|
|
445
|
+
iconName?: never;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
interface NavGroupItem {
|
|
449
|
+
break?: never;
|
|
450
|
+
to?: never;
|
|
451
|
+
text: string;
|
|
452
|
+
initialExpanded?: boolean;
|
|
453
|
+
navList: (NavListItem | NavBreakItem)[];
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
-
export type NavigationItem = NavListItem | NavBreakItem;
|
|
456
|
+
export type NavigationItem = NavListItem | NavBreakItem | NavGroupItem;
|
|
457
|
+
|
|
458
|
+
/*
|
|
459
|
+
* Return the route dictionary key matching a customized sidebar slug.
|
|
460
|
+
*/
|
|
461
|
+
function getRoutePathFromSidebarSlug(slug: string | null | undefined): ValidRoutePath | null {
|
|
462
|
+
const normalizedSlug = String(slug || '').trim().replace(/^\/?app\/?/, '').replace(/^\/+|\/+$/g, '');
|
|
463
|
+
const routePath = normalizedSlug === 'home' ? '/app' : `/app/${normalizedSlug}`;
|
|
464
|
+
|
|
465
|
+
return ROUTES_DICT[routePath as ValidRoutePath] ? routePath as ValidRoutePath : null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/*
|
|
469
|
+
* Return a stable sidebar slug for a route pathname.
|
|
470
|
+
*/
|
|
471
|
+
function getSidebarSlugFromRoutePath(routePath: string | null | undefined) {
|
|
472
|
+
if (routePath === '/app') {
|
|
473
|
+
return 'home';
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return String(routePath || '').replace(/^\/?app\/?/, '').replace(/^\/+|\/+$/g, '');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/*
|
|
480
|
+
* Resolve a customized sidebar item into a route-backed navigation item.
|
|
481
|
+
*/
|
|
482
|
+
function getNavigationItemFromSidebarItem(
|
|
483
|
+
item: OrganizationSidebarItemObj,
|
|
484
|
+
operation: OrganizationOperationEnum | null,
|
|
485
|
+
orgFeatures?: (OrganizationFeatureEnum | string)[],
|
|
486
|
+
checkACLClient?: CheckACLClientFn | null,
|
|
487
|
+
): NavListItem | null {
|
|
488
|
+
const routePath = getRoutePathFromSidebarSlug(item.slug);
|
|
489
|
+
|
|
490
|
+
if (!routePath || !isRouteAllowed(routePath, operation, orgFeatures, checkACLClient)) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const routeDict = ROUTES_DICT[routePath];
|
|
495
|
+
const fallbackText = routeDict.text && i18n.has(routeDict.text) ? i18n.t(routeDict.text) : routeDict.text;
|
|
496
|
+
|
|
497
|
+
return {
|
|
498
|
+
slug: getSidebarSlugFromRoutePath(routePath),
|
|
499
|
+
to: routePath,
|
|
500
|
+
text: item.label || fallbackText,
|
|
501
|
+
iconName: item.iconName,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/*
|
|
506
|
+
* Build the customized organization sidebar from settings.sidebar groups.
|
|
507
|
+
*/
|
|
508
|
+
function getCustomizedNavigationList(
|
|
509
|
+
sidebar: OrganizationSidebarGroupObj[],
|
|
510
|
+
operation: OrganizationOperationEnum | null,
|
|
511
|
+
orgFeatures?: (OrganizationFeatureEnum | string)[],
|
|
512
|
+
checkACLClient?: CheckACLClientFn | null,
|
|
513
|
+
): NavigationItem[] {
|
|
514
|
+
return sidebar.reduce((acc, group) => {
|
|
515
|
+
const navList = Array.isArray(group?.items)
|
|
516
|
+
? group.items.reduce((items, item) => {
|
|
517
|
+
const navItem = getNavigationItemFromSidebarItem(item, operation, orgFeatures, checkACLClient);
|
|
518
|
+
if (navItem) {
|
|
519
|
+
items.push(navItem);
|
|
520
|
+
}
|
|
521
|
+
return items;
|
|
522
|
+
}, [] as NavListItem[])
|
|
523
|
+
: [];
|
|
524
|
+
|
|
525
|
+
if (navList.length) {
|
|
526
|
+
acc.push({
|
|
527
|
+
text: group?.title || '',
|
|
528
|
+
navList,
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return acc;
|
|
533
|
+
}, [] as NavigationItem[]);
|
|
534
|
+
}
|
|
457
535
|
|
|
458
536
|
export function getNavigationList(
|
|
459
537
|
operation: OrganizationOperationEnum | null,
|
|
460
|
-
orgFeatures?: OrganizationFeatureEnum[],
|
|
538
|
+
orgFeatures?: (OrganizationFeatureEnum | string)[], // This array contains available report groups also
|
|
539
|
+
reportGroups?: ReportGroupGQL[] | null,
|
|
540
|
+
dataTables?: DataTableGQL[] | null,
|
|
541
|
+
checkACLClient?: CheckACLClientFn | null,
|
|
542
|
+
sidebar?: OrganizationSidebarGroupObj[] | null,
|
|
461
543
|
): NavigationItem[] {
|
|
544
|
+
if (Array.isArray(sidebar)) {
|
|
545
|
+
return getCustomizedNavigationList(sidebar, operation, orgFeatures, checkACLClient);
|
|
546
|
+
}
|
|
462
547
|
|
|
463
548
|
const breakItem = {
|
|
464
549
|
break: true,
|
|
@@ -473,27 +558,10 @@ export function getNavigationList(
|
|
|
473
558
|
switch (operation) {
|
|
474
559
|
case 'ARABLE':
|
|
475
560
|
navListArr = [
|
|
476
|
-
{
|
|
477
|
-
text: i18n.t('form.reports'),
|
|
478
|
-
navList: [
|
|
479
|
-
ROUTES_DICT['/app/organic'],
|
|
480
|
-
ROUTES_DICT['/app/globalgap/'],
|
|
481
|
-
]
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
text: i18n.t('log.food_safety'),
|
|
485
|
-
navList: [
|
|
486
|
-
ROUTES_DICT['/app/cleaning'],
|
|
487
|
-
// ROUTES_DICT['/app/hygiene'],
|
|
488
|
-
// ROUTES_DICT['/app/sanitation'],
|
|
489
|
-
// ROUTES_DICT['/app/materials'],
|
|
490
|
-
// ROUTES_DICT['/app/biosecurity'],
|
|
491
|
-
// ROUTES_DICT['/app/employees'],
|
|
492
|
-
]
|
|
493
|
-
},
|
|
494
561
|
{
|
|
495
562
|
text: i18n.t(`org.type_active.${operation}`),
|
|
496
563
|
navList: [
|
|
564
|
+
ROUTES_DICT['/app/greenhouse'],
|
|
497
565
|
ROUTES_DICT['/app/seeding'],
|
|
498
566
|
ROUTES_DICT['/app/transplanting'],
|
|
499
567
|
ROUTES_DICT['/app/field-work'],
|
|
@@ -513,7 +581,6 @@ export function getNavigationList(
|
|
|
513
581
|
{
|
|
514
582
|
text: i18n.t(`org.type_active.${operation}`),
|
|
515
583
|
navList: [
|
|
516
|
-
ROUTES_DICT['/app/livestock'],
|
|
517
584
|
{ ...ROUTES_DICT['/app/purchases'], text: i18n.t('log.supply_purchases') },
|
|
518
585
|
]
|
|
519
586
|
},
|
|
@@ -525,7 +592,7 @@ export function getNavigationList(
|
|
|
525
592
|
text: i18n.t(`org.type_active.${operation}`),
|
|
526
593
|
navList: [
|
|
527
594
|
ROUTES_DICT['/app/vendors'],
|
|
528
|
-
ROUTES_DICT['/app/markets'],
|
|
595
|
+
// ROUTES_DICT['/app/markets'],
|
|
529
596
|
ROUTES_DICT['/app/receipts'],
|
|
530
597
|
]
|
|
531
598
|
},
|
|
@@ -546,6 +613,40 @@ export function getNavigationList(
|
|
|
546
613
|
navListArr = [];
|
|
547
614
|
}
|
|
548
615
|
|
|
616
|
+
// Report sections
|
|
617
|
+
|
|
618
|
+
const reportsSection = {
|
|
619
|
+
text: i18n.t('form.reports'),
|
|
620
|
+
navList: [
|
|
621
|
+
]
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
if (reportGroups) {
|
|
625
|
+
// @ts-ignore
|
|
626
|
+
reportsSection.navList = reportsSection.navList.concat(reportGroups.map((reportGroup) => ({
|
|
627
|
+
to: makePathname('/app/r/', reportGroup.id),
|
|
628
|
+
text: reportGroup.shortName || reportGroup.name,
|
|
629
|
+
iconName: COMMON_ICON_NAMES.generic_report,
|
|
630
|
+
})));
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (reportsSection.navList.length) {
|
|
634
|
+
navListArr.push(reportsSection);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (dataTables) {
|
|
638
|
+
const dataTablesSection = {
|
|
639
|
+
text: i18n.t('form.dataTables'),
|
|
640
|
+
navList: dataTables.map((dataTable) => ({
|
|
641
|
+
to: makePathname('/app/d/', dataTable.id),
|
|
642
|
+
text: dataTable.title || dataTable.name,
|
|
643
|
+
iconName: COMMON_ICON_NAMES.data_table,
|
|
644
|
+
})),
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
navListArr.push(dataTablesSection);
|
|
648
|
+
}
|
|
649
|
+
|
|
549
650
|
// @ts-ignore
|
|
550
651
|
navListArr = [{
|
|
551
652
|
...ROUTES_DICT['/app'],
|
|
@@ -555,9 +656,11 @@ export function getNavigationList(
|
|
|
555
656
|
// @ts-ignore
|
|
556
657
|
].concat(navListArr).concat([{
|
|
557
658
|
text: i18n.t('form.advanced'),
|
|
558
|
-
initialExpanded:
|
|
659
|
+
initialExpanded: true,
|
|
559
660
|
navList: [
|
|
560
|
-
ROUTES_DICT['/app/
|
|
661
|
+
ROUTES_DICT['/app/workflows'],
|
|
662
|
+
// ROUTES_DICT['/app/sheets'],
|
|
663
|
+
// ROUTES_DICT['/app/emails'],
|
|
561
664
|
ROUTES_DICT['/app/logs']
|
|
562
665
|
]
|
|
563
666
|
}] as any);
|
|
@@ -587,10 +690,14 @@ export function getNavigationList(
|
|
|
587
690
|
if (!item.navList.length) {
|
|
588
691
|
return null;
|
|
589
692
|
}
|
|
590
|
-
} else if (item?.to && !isRouteAllowed(item.to, operation, orgFeatures)) {
|
|
693
|
+
} else if (item?.to && !isRouteAllowed(item.to, operation, orgFeatures, checkACLClient)) {
|
|
591
694
|
return null;
|
|
592
695
|
}
|
|
593
696
|
|
|
697
|
+
if (item?.to) {
|
|
698
|
+
item.slug = getSidebarSlugFromRoutePath(item.to);
|
|
699
|
+
}
|
|
700
|
+
|
|
594
701
|
if (item?.text && i18n.has(item.text)) {
|
|
595
702
|
item.text = i18n.t(item.text);
|
|
596
703
|
}
|