@jsb188/mday 1.1.8 → 1.1.11
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 +105 -35
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +48 -0
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +44 -0
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +7 -366
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -11
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +168 -0
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +61 -0
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1017 -738
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +57 -316
- package/src/schemas/organization.ts +53 -213
- package/src/types/account.d.ts +81 -0
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +366 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +142 -0
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +57 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +169 -190
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +175 -76
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +1130 -0
- package/src/types/storage.d.ts +242 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +305 -0
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +849 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +172 -0
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +173 -778
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +683 -81
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4973 -0
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/workflow.ts +380 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -209
- package/src/constants/product.ts +0 -66
- package/src/constants/report.ts +0 -25
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -145
- package/src/schemas/reportsQuery.ts +0 -107
- package/src/types/action.d.ts +0 -42
- package/src/types/product.d.ts +0 -173
- package/src/types/report.d.ts +0 -203
- package/src/utils/product-calEvent.ts +0 -508
- package/src/utils/route-helpers.ts +0 -583
|
@@ -1,583 +0,0 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n';
|
|
2
|
-
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
3
|
-
import type { OrganizationFeatureEnum, OrganizationOperationEnum } from '../types/organization.d';
|
|
4
|
-
|
|
5
|
-
// Use this for report periods, etc
|
|
6
|
-
const CURRENT_YEAR = String(new Date().getFullYear());
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Constants; Re-usable rules
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const OP_FARMING = ['ARABLE', 'LIVESTOCK'];
|
|
13
|
-
|
|
14
|
-
const F = {
|
|
15
|
-
normal_logging: ['NORMAL_LOGGING'],
|
|
16
|
-
food_safety: ['FOOD_SAFETY', 'GLOBAL_GAP'],
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Rules
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
type ValidRoutePath =
|
|
24
|
-
'/app'
|
|
25
|
-
| '/app/c/'
|
|
26
|
-
| '/app/ai-workflows'
|
|
27
|
-
| '/app/logs'
|
|
28
|
-
| '/app/seeding'
|
|
29
|
-
| '/app/transplanting'
|
|
30
|
-
| '/app/field-work'
|
|
31
|
-
| '/app/harvested'
|
|
32
|
-
| '/app/post-harvest'
|
|
33
|
-
| '/app/orders'
|
|
34
|
-
| '/app/globalgap/'
|
|
35
|
-
| '/app/cleaning'
|
|
36
|
-
| '/app/purchases'
|
|
37
|
-
| '/app/organic'
|
|
38
|
-
| '/app/hygiene'
|
|
39
|
-
| '/app/sanitation'
|
|
40
|
-
| '/app/materials'
|
|
41
|
-
| '/app/biosecurity'
|
|
42
|
-
| '/app/employees'
|
|
43
|
-
| '/app/vendors'
|
|
44
|
-
| '/app/markets'
|
|
45
|
-
| '/app/receipts'
|
|
46
|
-
| '/app/livestock'
|
|
47
|
-
| '/app/growers'
|
|
48
|
-
| '/app/foreign-growers';
|
|
49
|
-
|
|
50
|
-
interface RouteDictObj {
|
|
51
|
-
to: ValidRoutePath;
|
|
52
|
-
text: string;
|
|
53
|
-
iconName?: string;
|
|
54
|
-
allowedOperations?: OrganizationOperationEnum[];
|
|
55
|
-
notAllowedOperations?: OrganizationOperationEnum[];
|
|
56
|
-
requiredFeature?: OrganizationFeatureEnum[];
|
|
57
|
-
|
|
58
|
-
// These values prevent rendering flickers when calculating TOC/breadcrumbs between page renders
|
|
59
|
-
hasPhysicalToolbar?: 'ALWAYS' | 'NEVER' | ((parts: string[]) => boolean);
|
|
60
|
-
hasAsideNav?: 'ALWAYS' | 'NEVER' | ((parts: string[]) => boolean);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
64
|
-
|
|
65
|
-
// Main /app/ routes
|
|
66
|
-
|
|
67
|
-
'/app': {
|
|
68
|
-
to: '/app',
|
|
69
|
-
text: i18n.t('app.home'),
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
'/app/c/': {
|
|
73
|
-
to: '/app/c/',
|
|
74
|
-
text: i18n.t('app.route_ai_chat'),
|
|
75
|
-
iconName: COMMON_ICON_NAMES.chat,
|
|
76
|
-
|
|
77
|
-
hasPhysicalToolbar: 'ALWAYS',
|
|
78
|
-
hasAsideNav: 'NEVER',
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
// Advanced
|
|
82
|
-
|
|
83
|
-
'/app/ai-workflows': {
|
|
84
|
-
to: '/app/ai-workflows',
|
|
85
|
-
text: i18n.t('form.ai_workflows'),
|
|
86
|
-
iconName: COMMON_ICON_NAMES.ai_workflow,
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
'/app/logs': {
|
|
90
|
-
to: '/app/logs',
|
|
91
|
-
text: i18n.t('log.all_logs'),
|
|
92
|
-
iconName: COMMON_ICON_NAMES.logs,
|
|
93
|
-
notAllowedOperations: ['GROWER_NETWORK'], // Temporary for now
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
// Arable
|
|
97
|
-
|
|
98
|
-
'/app/seeding': {
|
|
99
|
-
to: '/app/seeding',
|
|
100
|
-
text: i18n.t('log.seeding'),
|
|
101
|
-
iconName: COMMON_ICON_NAMES.seeding,
|
|
102
|
-
|
|
103
|
-
allowedOperations: ['ARABLE'],
|
|
104
|
-
requiredFeature: F.normal_logging,
|
|
105
|
-
},
|
|
106
|
-
'/app/transplanting': {
|
|
107
|
-
to: '/app/transplanting',
|
|
108
|
-
text: i18n.t('log.transplanting'),
|
|
109
|
-
iconName: COMMON_ICON_NAMES.transplanting,
|
|
110
|
-
|
|
111
|
-
allowedOperations: ['ARABLE'],
|
|
112
|
-
requiredFeature: F.normal_logging,
|
|
113
|
-
},
|
|
114
|
-
'/app/field-work': {
|
|
115
|
-
to: '/app/field-work',
|
|
116
|
-
text: i18n.t('log.field_work'),
|
|
117
|
-
iconName: COMMON_ICON_NAMES.field_work,
|
|
118
|
-
|
|
119
|
-
allowedOperations: ['ARABLE'],
|
|
120
|
-
requiredFeature: F.normal_logging,
|
|
121
|
-
},
|
|
122
|
-
'/app/harvested': {
|
|
123
|
-
to: '/app/harvested',
|
|
124
|
-
text: i18n.t('log.harvested'),
|
|
125
|
-
iconName: COMMON_ICON_NAMES.harvest,
|
|
126
|
-
|
|
127
|
-
allowedOperations: ['ARABLE'],
|
|
128
|
-
requiredFeature: F.normal_logging,
|
|
129
|
-
},
|
|
130
|
-
'/app/post-harvest': {
|
|
131
|
-
to: '/app/post-harvest',
|
|
132
|
-
text: i18n.t('log.post_harvest'),
|
|
133
|
-
iconName: COMMON_ICON_NAMES.post_harvest,
|
|
134
|
-
|
|
135
|
-
allowedOperations: ['ARABLE'],
|
|
136
|
-
requiredFeature: F.normal_logging,
|
|
137
|
-
},
|
|
138
|
-
'/app/purchases': {
|
|
139
|
-
to: '/app/purchases',
|
|
140
|
-
text: i18n.t('log.purchases'),
|
|
141
|
-
iconName: COMMON_ICON_NAMES.invoice,
|
|
142
|
-
|
|
143
|
-
allowedOperations: OP_FARMING,
|
|
144
|
-
requiredFeature: F.normal_logging,
|
|
145
|
-
},
|
|
146
|
-
'/app/orders': {
|
|
147
|
-
to: '/app/orders',
|
|
148
|
-
text: i18n.t('form.sales_orders'),
|
|
149
|
-
iconName: COMMON_ICON_NAMES.receipt,
|
|
150
|
-
|
|
151
|
-
allowedOperations: OP_FARMING,
|
|
152
|
-
requiredFeature: F.normal_logging,
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
// Arable; Reports
|
|
156
|
-
|
|
157
|
-
'/app/globalgap/': {
|
|
158
|
-
to: ('/app/globalgap/' + CURRENT_YEAR) as ValidRoutePath,
|
|
159
|
-
text: i18n.t('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: i18n.t('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: i18n.t('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
|
-
// Arable; Food Safety
|
|
190
|
-
|
|
191
|
-
'/app/hygiene': {
|
|
192
|
-
to: '/app/hygiene',
|
|
193
|
-
text: i18n.t('log.hygiene'),
|
|
194
|
-
iconName: COMMON_ICON_NAMES.HYGIENE,
|
|
195
|
-
|
|
196
|
-
allowedOperations: OP_FARMING,
|
|
197
|
-
requiredFeature: F.food_safety,
|
|
198
|
-
},
|
|
199
|
-
'/app/sanitation': {
|
|
200
|
-
to: '/app/sanitation',
|
|
201
|
-
text: i18n.t('log.sanitation'),
|
|
202
|
-
iconName: COMMON_ICON_NAMES.SANITATION,
|
|
203
|
-
|
|
204
|
-
allowedOperations: OP_FARMING,
|
|
205
|
-
requiredFeature: F.food_safety,
|
|
206
|
-
},
|
|
207
|
-
'/app/materials': {
|
|
208
|
-
to: '/app/materials',
|
|
209
|
-
text: i18n.t('log.materials'),
|
|
210
|
-
iconName: COMMON_ICON_NAMES.MATERIALS,
|
|
211
|
-
|
|
212
|
-
allowedOperations: OP_FARMING,
|
|
213
|
-
requiredFeature: F.food_safety,
|
|
214
|
-
},
|
|
215
|
-
'/app/biosecurity': {
|
|
216
|
-
to: '/app/biosecurity',
|
|
217
|
-
text: i18n.t('log.biosecurity'),
|
|
218
|
-
iconName: COMMON_ICON_NAMES.BIOSECURITY,
|
|
219
|
-
|
|
220
|
-
allowedOperations: OP_FARMING,
|
|
221
|
-
requiredFeature: F.food_safety,
|
|
222
|
-
},
|
|
223
|
-
'/app/employees': {
|
|
224
|
-
to: '/app/employees',
|
|
225
|
-
text: i18n.t('log.employees'),
|
|
226
|
-
iconName: COMMON_ICON_NAMES.EMPLOYEES,
|
|
227
|
-
|
|
228
|
-
allowedOperations: OP_FARMING,
|
|
229
|
-
requiredFeature: F.food_safety,
|
|
230
|
-
},
|
|
231
|
-
|
|
232
|
-
// Farmers Market
|
|
233
|
-
'/app/vendors': {
|
|
234
|
-
to: '/app/vendors',
|
|
235
|
-
text: i18n.t('form.vendors'),
|
|
236
|
-
iconName: COMMON_ICON_NAMES.shop_vendor,
|
|
237
|
-
|
|
238
|
-
allowedOperations: ['FARMERS_MARKET'],
|
|
239
|
-
requiredFeature: F.normal_logging
|
|
240
|
-
},
|
|
241
|
-
'/app/markets': {
|
|
242
|
-
to: '/app/markets',
|
|
243
|
-
text: i18n.t('form.markets'),
|
|
244
|
-
iconName: COMMON_ICON_NAMES.shop_market,
|
|
245
|
-
|
|
246
|
-
allowedOperations: ['FARMERS_MARKET'],
|
|
247
|
-
requiredFeature: ['CAL_EVENTS'],
|
|
248
|
-
},
|
|
249
|
-
'/app/receipts': {
|
|
250
|
-
to: ('/app/receipts?s=1') as ValidRoutePath,
|
|
251
|
-
text: i18n.t('form.market_receipts'),
|
|
252
|
-
iconName: COMMON_ICON_NAMES.market_receipt,
|
|
253
|
-
|
|
254
|
-
allowedOperations: ['FARMERS_MARKET'],
|
|
255
|
-
requiredFeature: F.normal_logging
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
// Livestock
|
|
259
|
-
'/app/livestock': {
|
|
260
|
-
to: '/app/livestock',
|
|
261
|
-
text: i18n.t('form.livestock'),
|
|
262
|
-
iconName: COMMON_ICON_NAMES.livestock,
|
|
263
|
-
|
|
264
|
-
allowedOperations: ['LIVESTOCK'],
|
|
265
|
-
requiredFeature: F.normal_logging
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
// Grower Network
|
|
269
|
-
'/app/growers': {
|
|
270
|
-
to: '/app/growers',
|
|
271
|
-
text: i18n.t('form.domestic_growers'),
|
|
272
|
-
iconName: COMMON_ICON_NAMES.growers,
|
|
273
|
-
|
|
274
|
-
allowedOperations: ['GROWER_NETWORK'],
|
|
275
|
-
},
|
|
276
|
-
'/app/foreign-growers': {
|
|
277
|
-
to: '/app/foreign-growers',
|
|
278
|
-
text: i18n.t('form.foreign_growers'),
|
|
279
|
-
iconName: COMMON_ICON_NAMES.foreign_growers,
|
|
280
|
-
|
|
281
|
-
allowedOperations: ['GROWER_NETWORK'],
|
|
282
|
-
},
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Make pathname to a route in Marketday app.
|
|
287
|
-
* @param routeName - The name of the route.
|
|
288
|
-
* @param pathSegment - Optional additional path segment to append.
|
|
289
|
-
* @returns The full pathname for the route.
|
|
290
|
-
*/
|
|
291
|
-
|
|
292
|
-
export function makePathname(routePath: ValidRoutePath, pathSegment?: string | null): ValidRoutePath {
|
|
293
|
-
const pathExists = !!ROUTES_DICT[routePath];
|
|
294
|
-
if (pathExists && routePath.endsWith('/')) {
|
|
295
|
-
return (pathSegment ? `${routePath}${pathSegment}` : routePath.substring(0, routePath.length - 1)) as ValidRoutePath;
|
|
296
|
-
}
|
|
297
|
-
return pathExists ? routePath : '/app';
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Check if route is valid.
|
|
302
|
-
* @param routeName - The name of the route.
|
|
303
|
-
* @param pathSegment - Optional additional path segment to append.
|
|
304
|
-
* @returns The full pathname for the route.
|
|
305
|
-
*/
|
|
306
|
-
|
|
307
|
-
export function isRouteValid(routePath: ValidRoutePath, pathSegment?: string | null): boolean {
|
|
308
|
-
const routeDict = !!ROUTES_DICT[routePath];
|
|
309
|
-
return (
|
|
310
|
-
!!routeDict &&
|
|
311
|
-
(!routePath.endsWith('/') || !!pathSegment)
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Get route config from pathname.
|
|
317
|
-
* NOTE: This is the best way to prevent page flickers due to breadcrumbs/TOC calculations/resets/etc.
|
|
318
|
-
* @param pathname - The pathname to check.
|
|
319
|
-
* @returns The route name if found.
|
|
320
|
-
*/
|
|
321
|
-
|
|
322
|
-
const ROUTES_DICT_ORDERED = Object.keys(ROUTES_DICT).sort((a, b) => b.length - a.length);
|
|
323
|
-
|
|
324
|
-
interface RouteConfigObj extends Omit<RouteDictObj, 'hasPhysicalToolbar' | 'hasAsideNav'> {
|
|
325
|
-
routeName: ValidRoutePath;
|
|
326
|
-
scrollResetKey: string;
|
|
327
|
-
allowed: boolean;
|
|
328
|
-
hasPhysicalToolbar: boolean;
|
|
329
|
-
hasAsideNav: boolean;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export function getRouteConfigs(
|
|
333
|
-
pathname: ValidRoutePath | string,
|
|
334
|
-
operation?: OrganizationOperationEnum | null,
|
|
335
|
-
orgFeatures?: OrganizationFeatureEnum[] | null,
|
|
336
|
-
): RouteConfigObj {
|
|
337
|
-
|
|
338
|
-
for (const routeName of ROUTES_DICT_ORDERED) {
|
|
339
|
-
if (pathname.startsWith(routeName)) {
|
|
340
|
-
|
|
341
|
-
// Scroll position fix + breadcrumb / TOC cleanup on unmount
|
|
342
|
-
// This will retain scroll position for deeper links,
|
|
343
|
-
// ie. "/app/globalgap/2023/.." will be retained
|
|
344
|
-
|
|
345
|
-
const routeDict = ROUTES_DICT[routeName as ValidRoutePath];
|
|
346
|
-
const pathParts = pathname.split('/');
|
|
347
|
-
|
|
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
|
-
const hasPhysicalToolbar = !!routeDict.hasPhysicalToolbar && routeDict.hasPhysicalToolbar !== 'NEVER' && (
|
|
362
|
-
routeDict.hasPhysicalToolbar === 'ALWAYS' ||
|
|
363
|
-
(typeof routeDict.hasPhysicalToolbar === 'function' && routeDict.hasPhysicalToolbar(pathParts))
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
return {
|
|
367
|
-
...routeDict,
|
|
368
|
-
routeName: routeName as ValidRoutePath,
|
|
369
|
-
scrollResetKey,
|
|
370
|
-
allowed: isRouteAllowed(pathname, operation, orgFeatures),
|
|
371
|
-
hasPhysicalToolbar,
|
|
372
|
-
hasAsideNav,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return {
|
|
378
|
-
routeName: '/__unknown',
|
|
379
|
-
scrollResetKey: '',
|
|
380
|
-
allowed: false,
|
|
381
|
-
hasPhysicalToolbar: false,
|
|
382
|
-
hasAsideNav: false,
|
|
383
|
-
} as any;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Check if this organization's operation allows access to this route path
|
|
388
|
-
* @param pathname - pathname to check.
|
|
389
|
-
* @param operation - Organization operation.
|
|
390
|
-
* @param orgFeatures - Enabled features for organization.
|
|
391
|
-
*/
|
|
392
|
-
|
|
393
|
-
export function isRouteAllowed(
|
|
394
|
-
pathname: ValidRoutePath | string,
|
|
395
|
-
operation?: OrganizationOperationEnum | null,
|
|
396
|
-
orgFeatures?: OrganizationFeatureEnum[] | null,
|
|
397
|
-
): boolean {
|
|
398
|
-
|
|
399
|
-
let routeDict = ROUTES_DICT[pathname as ValidRoutePath];
|
|
400
|
-
if (!routeDict) {
|
|
401
|
-
const parts = pathname.split('/');
|
|
402
|
-
for (let i = parts.length; i > 0; i--) {
|
|
403
|
-
const subPath = parts.slice(0, i).join('/');
|
|
404
|
-
|
|
405
|
-
// @ts-ignore - sub paths may not be valid route paths
|
|
406
|
-
routeDict = ROUTES_DICT[subPath] || ROUTES_DICT[subPath + '/'];
|
|
407
|
-
if (routeDict || i <= 3) {
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (!routeDict) {
|
|
414
|
-
// Assume true if there are no rules set
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return (
|
|
419
|
-
(!routeDict.allowedOperations || routeDict.allowedOperations.includes(operation || '')) &&
|
|
420
|
-
(!routeDict.notAllowedOperations || !routeDict.notAllowedOperations.includes(operation || '')) &&
|
|
421
|
-
// If {orgFeature} is null, assume data is not finished loading yet, and allow "benefit of doubt" access
|
|
422
|
-
(!orgFeatures || !routeDict.requiredFeature || routeDict.requiredFeature.some((feature) => orgFeatures.includes(feature)))
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Helper; get static nav list based on organization's operation & features
|
|
428
|
-
*/
|
|
429
|
-
|
|
430
|
-
interface NavListItem {
|
|
431
|
-
break: never;
|
|
432
|
-
to: string;
|
|
433
|
-
text: string;
|
|
434
|
-
iconName: string;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
interface NavBreakItem {
|
|
438
|
-
break: boolean;
|
|
439
|
-
to: never;
|
|
440
|
-
text: never;
|
|
441
|
-
iconName: never;
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
export type NavigationItem = NavListItem | NavBreakItem;
|
|
445
|
-
|
|
446
|
-
export function getNavigationList(
|
|
447
|
-
operation: OrganizationOperationEnum | null,
|
|
448
|
-
orgFeatures?: OrganizationFeatureEnum[],
|
|
449
|
-
): NavigationItem[] {
|
|
450
|
-
|
|
451
|
-
const breakItem = {
|
|
452
|
-
break: true,
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
let navListArr: {
|
|
456
|
-
text: string;
|
|
457
|
-
initialExpanded?: boolean;
|
|
458
|
-
navList: (RouteDictObj | { break: boolean })[];
|
|
459
|
-
}[] = [];
|
|
460
|
-
|
|
461
|
-
switch (operation) {
|
|
462
|
-
case 'ARABLE':
|
|
463
|
-
navListArr = [
|
|
464
|
-
{
|
|
465
|
-
text: i18n.t('form.reports'),
|
|
466
|
-
navList: [
|
|
467
|
-
ROUTES_DICT['/app/organic'],
|
|
468
|
-
ROUTES_DICT['/app/globalgap/'],
|
|
469
|
-
]
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
text: i18n.t('log.food_safety'),
|
|
473
|
-
navList: [
|
|
474
|
-
ROUTES_DICT['/app/cleaning'],
|
|
475
|
-
// ROUTES_DICT['/app/hygiene'],
|
|
476
|
-
// ROUTES_DICT['/app/sanitation'],
|
|
477
|
-
// ROUTES_DICT['/app/materials'],
|
|
478
|
-
// ROUTES_DICT['/app/biosecurity'],
|
|
479
|
-
// ROUTES_DICT['/app/employees'],
|
|
480
|
-
]
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
text: i18n.t(`org.type_active.${operation}`),
|
|
484
|
-
navList: [
|
|
485
|
-
ROUTES_DICT['/app/seeding'],
|
|
486
|
-
ROUTES_DICT['/app/transplanting'],
|
|
487
|
-
ROUTES_DICT['/app/field-work'],
|
|
488
|
-
ROUTES_DICT['/app/harvested'],
|
|
489
|
-
ROUTES_DICT['/app/post-harvest'],
|
|
490
|
-
|
|
491
|
-
breakItem,
|
|
492
|
-
|
|
493
|
-
ROUTES_DICT['/app/purchases'],
|
|
494
|
-
ROUTES_DICT['/app/orders'],
|
|
495
|
-
]
|
|
496
|
-
},
|
|
497
|
-
];
|
|
498
|
-
break;
|
|
499
|
-
case 'LIVESTOCK':
|
|
500
|
-
navListArr = [
|
|
501
|
-
{
|
|
502
|
-
text: i18n.t(`org.type_active.${operation}`),
|
|
503
|
-
navList: [
|
|
504
|
-
ROUTES_DICT['/app/livestock'],
|
|
505
|
-
{ ...ROUTES_DICT['/app/purchases'], text: i18n.t('log.supply_purchases') },
|
|
506
|
-
]
|
|
507
|
-
},
|
|
508
|
-
];
|
|
509
|
-
break;
|
|
510
|
-
case 'FARMERS_MARKET':
|
|
511
|
-
navListArr = [
|
|
512
|
-
{
|
|
513
|
-
text: i18n.t(`org.type_active.${operation}`),
|
|
514
|
-
navList: [
|
|
515
|
-
ROUTES_DICT['/app/vendors'],
|
|
516
|
-
ROUTES_DICT['/app/markets'],
|
|
517
|
-
ROUTES_DICT['/app/receipts'],
|
|
518
|
-
]
|
|
519
|
-
},
|
|
520
|
-
];
|
|
521
|
-
break;
|
|
522
|
-
case 'GROWER_NETWORK':
|
|
523
|
-
navListArr = [
|
|
524
|
-
{
|
|
525
|
-
text: i18n.t(`org.type_active.${operation}`),
|
|
526
|
-
navList: [
|
|
527
|
-
ROUTES_DICT['/app/growers'],
|
|
528
|
-
ROUTES_DICT['/app/foreign-growers'],
|
|
529
|
-
]
|
|
530
|
-
}
|
|
531
|
-
];
|
|
532
|
-
break;
|
|
533
|
-
default:
|
|
534
|
-
navListArr = [];
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// @ts-ignore
|
|
538
|
-
navListArr = [{
|
|
539
|
-
...ROUTES_DICT['/app'],
|
|
540
|
-
iconName: COMMON_ICON_NAMES[operation!] || 'home',
|
|
541
|
-
},
|
|
542
|
-
breakItem,
|
|
543
|
-
// @ts-ignore
|
|
544
|
-
].concat(navListArr).concat([{
|
|
545
|
-
text: i18n.t('form.advanced'),
|
|
546
|
-
initialExpanded: false,
|
|
547
|
-
navList: [
|
|
548
|
-
ROUTES_DICT['/app/ai-workflows'],
|
|
549
|
-
ROUTES_DICT['/app/logs']
|
|
550
|
-
]
|
|
551
|
-
}] as any);
|
|
552
|
-
|
|
553
|
-
const mapNavItems = (item: any) => {
|
|
554
|
-
if (Array.isArray(item)) {
|
|
555
|
-
const [navItem, ...requiredFeatures] = item;
|
|
556
|
-
if (requiredFeatures.some(feature => orgFeatures?.includes?.(feature))) {
|
|
557
|
-
return navItem;
|
|
558
|
-
}
|
|
559
|
-
return null;
|
|
560
|
-
} else if (item?.navList) {
|
|
561
|
-
item.navList = item.navList.reduce((acc: any[], x: any, i: number) => {
|
|
562
|
-
const mappedItem = mapNavItems(x);
|
|
563
|
-
if (
|
|
564
|
-
mappedItem &&
|
|
565
|
-
(mappedItem.to || (acc.length && i !== (item.navList.length - 1)))
|
|
566
|
-
) {
|
|
567
|
-
acc.push(mappedItem);
|
|
568
|
-
}
|
|
569
|
-
return acc;
|
|
570
|
-
}, []);
|
|
571
|
-
|
|
572
|
-
if (!item.navList.length) {
|
|
573
|
-
return null;
|
|
574
|
-
}
|
|
575
|
-
} else if (item?.to && !isRouteAllowed(item.to, operation, orgFeatures)) {
|
|
576
|
-
return null;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
return item;
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
return navListArr.map(mapNavItems).filter(Boolean);
|
|
583
|
-
}
|