@jsb188/mday-web 1.1.11 → 1.1.13
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/LICENSE +21 -0
- package/package.json +25 -17
- package/src/modules/Grids.filters.ts +9 -0
- package/src/modules/Grids.tsx +62 -650
- package/src/modules/RouteShell.tsx +9 -19
- package/src/schemas/organization.ts +154 -0
- package/src/utils/email.ts +122 -0
- package/src/utils/linkedEntity.ts +110 -0
- package/src/utils/log-web.helpers.ts +99 -0
- package/src/utils/log-web.icons.ts +184 -0
- package/src/utils/log-web.ts +58 -458
- package/src/utils/route-helpers.ts +207 -296
- package/src/utils/workflow-web.ts +11 -62
- package/src/modules/AgentDocs.tsx +0 -800
- package/src/modules/DocAccessSettings.tsx +0 -963
- package/src/utils/account-web.ts +0 -64
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -11
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
// Schedule and projects are not ready.
|
|
2
|
+
// import { SCHEDULING_TYPE_BY_OPERATION } from '@jsb188/mday/constants/logTaxonomy.generated.ts';
|
|
1
3
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
-
import type {
|
|
3
|
-
OrganizationOperationEnum,
|
|
4
|
-
OrganizationSidebarItemObj,
|
|
5
|
-
} from '@jsb188/mday/types/organization.d.ts';
|
|
4
|
+
import type { OrganizationOperationEnum, OrganizationSidebarItemObj } from '@jsb188/mday/types/organization.d.ts';
|
|
6
5
|
import type { OperationName } from '@jsb188/mday/utils/organization.ts';
|
|
6
|
+
import { definePageFilterSchema, serializePageFilters, stringifyPageSearchParams } from '@jsb188/react/libs/page-filters';
|
|
7
7
|
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
8
8
|
|
|
9
9
|
// Use this for fieldDoc periods, etc
|
|
@@ -13,22 +13,13 @@ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
|
13
13
|
* Constants; Re-usable rules
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
const OP = {
|
|
17
|
-
FARMING: ['ARABLE'],
|
|
18
|
-
GROWER_NETWORK: ['GROWER_NETWORK'],
|
|
19
|
-
};
|
|
20
|
-
|
|
21
16
|
const LOGIN_CHANGED_ERROR_CODES = new Set(['20080', '20081']);
|
|
22
17
|
const AUTH_RETURN_TO_BASE_URL = 'https://marketday.invalid';
|
|
23
|
-
const AUTH_RETURN_TO_PUBLIC_FORM_PATH_PATTERN = /^\/form\/[^/]+$/;
|
|
24
18
|
|
|
25
19
|
/**
|
|
26
20
|
* Build the translated title and description metadata for a Marketday route.
|
|
27
21
|
*/
|
|
28
|
-
export function getMarketdayRouteMeta(
|
|
29
|
-
titleKey: string,
|
|
30
|
-
descriptionKey: string,
|
|
31
|
-
) {
|
|
22
|
+
export function getMarketdayRouteMeta(titleKey: string, descriptionKey: string) {
|
|
32
23
|
return [
|
|
33
24
|
{
|
|
34
25
|
title: i18n.t('app.route_', { text: i18n.t(titleKey) }),
|
|
@@ -44,42 +35,31 @@ export function getMarketdayRouteMeta(
|
|
|
44
35
|
* Rules
|
|
45
36
|
*/
|
|
46
37
|
|
|
47
|
-
type
|
|
38
|
+
type StaticRoutePath =
|
|
48
39
|
| '/app'
|
|
49
40
|
| '/app/c/'
|
|
41
|
+
| '/app/library'
|
|
42
|
+
| '/app/library/'
|
|
43
|
+
| '/app/y/'
|
|
50
44
|
| '/app/calendar'
|
|
51
|
-
| '/app/
|
|
52
|
-
| '/app/grids'
|
|
45
|
+
| '/app/projects'
|
|
53
46
|
| '/app/workspace'
|
|
54
47
|
| '/app/s/'
|
|
55
|
-
| '/app/emails'
|
|
56
|
-
| '/app/outbound/forms'
|
|
57
|
-
| '/app/outbound/emails'
|
|
58
|
-
| '/app/downloads'
|
|
59
|
-
| '/app/logs'
|
|
60
|
-
| '/app/greenhouse'
|
|
61
|
-
| '/app/seeding'
|
|
62
|
-
| '/app/transplanting'
|
|
63
|
-
| '/app/field-work'
|
|
64
|
-
| '/app/harvested'
|
|
65
|
-
| '/app/post-harvest'
|
|
66
|
-
| '/app/orders'
|
|
67
|
-
| '/app/purchases'
|
|
68
|
-
| '/app/vendors'
|
|
69
|
-
| '/app/receipts'
|
|
70
|
-
| '/app/growers'
|
|
71
48
|
|
|
72
49
|
// FieldDocs
|
|
73
50
|
| '/app/fd/'
|
|
51
|
+
| '/app/programs/'
|
|
74
52
|
| '/app/d/'
|
|
75
53
|
| '/app/p/';
|
|
76
|
-
|
|
54
|
+
|
|
55
|
+
type TablePageRoutePath = `/app/${string}`;
|
|
56
|
+
type ValidRoutePath = StaticRoutePath | TablePageRoutePath;
|
|
77
57
|
|
|
78
58
|
interface RouteDictObj {
|
|
79
59
|
to: ValidRoutePath;
|
|
80
60
|
text: string;
|
|
81
61
|
iconName?: string;
|
|
82
|
-
allowedOperations?: OrganizationOperationEnum[];
|
|
62
|
+
allowedOperations?: readonly OrganizationOperationEnum[];
|
|
83
63
|
notAllowedOperations?: OrganizationOperationEnum[];
|
|
84
64
|
requiredACL?: OperationName;
|
|
85
65
|
|
|
@@ -89,8 +69,7 @@ interface RouteDictObj {
|
|
|
89
69
|
type CheckACLClientFn = (opName: OperationName) => boolean;
|
|
90
70
|
|
|
91
71
|
/*
|
|
92
|
-
* Return a same-origin auth destination only when it targets
|
|
93
|
-
* an authenticated app route.
|
|
72
|
+
* Return a same-origin auth destination only when it targets an authenticated app route.
|
|
94
73
|
*/
|
|
95
74
|
export function getSafeAuthReturnToPath(returnTo?: string | null) {
|
|
96
75
|
if (!returnTo?.startsWith('/') || returnTo.startsWith('//')) {
|
|
@@ -99,16 +78,9 @@ export function getSafeAuthReturnToPath(returnTo?: string | null) {
|
|
|
99
78
|
|
|
100
79
|
try {
|
|
101
80
|
const url = new URL(returnTo, AUTH_RETURN_TO_BASE_URL);
|
|
102
|
-
const
|
|
103
|
-
url.pathname,
|
|
104
|
-
);
|
|
105
|
-
const isAppPath =
|
|
106
|
-
url.pathname === '/app' || url.pathname.startsWith('/app/');
|
|
81
|
+
const isAppPath = url.pathname === '/app' || url.pathname.startsWith('/app/');
|
|
107
82
|
|
|
108
|
-
if (
|
|
109
|
-
url.origin !== AUTH_RETURN_TO_BASE_URL ||
|
|
110
|
-
(!isPublicFormPath && !isAppPath)
|
|
111
|
-
) {
|
|
83
|
+
if (url.origin !== AUTH_RETURN_TO_BASE_URL || !isAppPath) {
|
|
112
84
|
return null;
|
|
113
85
|
}
|
|
114
86
|
|
|
@@ -138,15 +110,12 @@ const STABLE_OUTLET_ROUTES = ['/app/runs'];
|
|
|
138
110
|
*/
|
|
139
111
|
|
|
140
112
|
export function getOutletPathnameKey(pathname: string): string {
|
|
141
|
-
const stableRoute = STABLE_OUTLET_ROUTES.find(
|
|
142
|
-
(routePrefix) =>
|
|
143
|
-
pathname === routePrefix || pathname.startsWith(`${routePrefix}/`),
|
|
144
|
-
);
|
|
113
|
+
const stableRoute = STABLE_OUTLET_ROUTES.find((routePrefix) => pathname === routePrefix || pathname.startsWith(`${routePrefix}/`));
|
|
145
114
|
|
|
146
115
|
return stableRoute || pathname;
|
|
147
116
|
}
|
|
148
117
|
|
|
149
|
-
const
|
|
118
|
+
const STATIC_ROUTES_DICT: Record<StaticRoutePath, RouteDictObj> = {
|
|
150
119
|
// Main /app/ routes
|
|
151
120
|
// If route ends with '/', it requires (or optionally accepts) a path segment
|
|
152
121
|
// e.g. "/app/c/" means "/app/c/:chatId" etc
|
|
@@ -156,11 +125,6 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
156
125
|
to: '/app',
|
|
157
126
|
text: 'app.home',
|
|
158
127
|
},
|
|
159
|
-
'/app/grids': {
|
|
160
|
-
to: '/app/grids',
|
|
161
|
-
text: 'app.grids',
|
|
162
|
-
iconName: COMMON_ICON_NAMES.grids,
|
|
163
|
-
},
|
|
164
128
|
'/app/workspace': {
|
|
165
129
|
to: '/app/workspace',
|
|
166
130
|
text: 'app.workspace',
|
|
@@ -174,6 +138,13 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
174
138
|
// surfaces do; it renders its own toolbar row
|
|
175
139
|
hasPhysicalToolbar: 'NEVER',
|
|
176
140
|
},
|
|
141
|
+
'/app/projects': {
|
|
142
|
+
to: '/app/projects',
|
|
143
|
+
text: 'app.route_projects',
|
|
144
|
+
iconName: COMMON_ICON_NAMES.progress,
|
|
145
|
+
// The project pages render their own toolbar row, like the calendar
|
|
146
|
+
hasPhysicalToolbar: 'NEVER',
|
|
147
|
+
},
|
|
177
148
|
'/app/c/': {
|
|
178
149
|
to: '/app/c/',
|
|
179
150
|
text: 'app.route_ai_chat',
|
|
@@ -181,152 +152,99 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
181
152
|
|
|
182
153
|
hasPhysicalToolbar: 'ALWAYS',
|
|
183
154
|
},
|
|
155
|
+
'/app/library': {
|
|
156
|
+
to: '/app/library',
|
|
157
|
+
text: 'app.route_library',
|
|
158
|
+
iconName: COMMON_ICON_NAMES.library,
|
|
159
|
+
hasPhysicalToolbar: 'ALWAYS',
|
|
160
|
+
},
|
|
161
|
+
'/app/library/': {
|
|
162
|
+
to: '/app/library/',
|
|
163
|
+
text: 'app.route_library',
|
|
164
|
+
iconName: COMMON_ICON_NAMES.library,
|
|
165
|
+
hasPhysicalToolbar: 'ALWAYS',
|
|
166
|
+
},
|
|
167
|
+
'/app/y/': {
|
|
168
|
+
to: '/app/y/',
|
|
169
|
+
text: 'c.document',
|
|
170
|
+
hasPhysicalToolbar: 'ALWAYS',
|
|
171
|
+
},
|
|
184
172
|
// Advanced
|
|
185
173
|
|
|
186
|
-
'/app/workflows': {
|
|
187
|
-
to: '/app/workflows',
|
|
188
|
-
text: 'form.ai_workflows',
|
|
189
|
-
iconName: COMMON_ICON_NAMES.ai_workflow,
|
|
190
|
-
},
|
|
191
174
|
'/app/s/': {
|
|
192
175
|
to: '/app/s/',
|
|
193
176
|
text: 'sheet.sheets',
|
|
194
177
|
iconName: COMMON_ICON_NAMES.sheet,
|
|
195
178
|
},
|
|
196
|
-
'/app/emails': {
|
|
197
|
-
to: '/app/emails',
|
|
198
|
-
text: 'app.ai_inboxes',
|
|
199
|
-
iconName: COMMON_ICON_NAMES.ai_inbox,
|
|
200
|
-
requiredACL: 'ai_inbox_read',
|
|
201
|
-
},
|
|
202
|
-
'/app/outbound/forms': {
|
|
203
|
-
to: '/app/outbound/forms',
|
|
204
|
-
text: 'campaign.published_forms',
|
|
205
|
-
iconName: COMMON_ICON_NAMES.public_form,
|
|
206
|
-
},
|
|
207
|
-
'/app/outbound/emails': {
|
|
208
|
-
to: '/app/outbound/emails',
|
|
209
|
-
text: 'campaign.email_campaigns',
|
|
210
|
-
iconName: COMMON_ICON_NAMES.email_campaign,
|
|
211
|
-
},
|
|
212
|
-
'/app/downloads': {
|
|
213
|
-
to: '/app/downloads',
|
|
214
|
-
text: 'form.downloads',
|
|
215
|
-
iconName: 'download',
|
|
216
|
-
},
|
|
217
|
-
'/app/logs': {
|
|
218
|
-
to: '/app/logs',
|
|
219
|
-
text: 'log.all_logs',
|
|
220
|
-
iconName: COMMON_ICON_NAMES.logs,
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
// Arable
|
|
224
|
-
|
|
225
|
-
'/app/greenhouse': {
|
|
226
|
-
to: '/app/greenhouse',
|
|
227
|
-
text: 'log.greenhouse_seeding',
|
|
228
|
-
iconName: COMMON_ICON_NAMES.GREENHOUSE_SEEDING,
|
|
229
|
-
|
|
230
|
-
allowedOperations: ['ARABLE'],
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
'/app/seeding': {
|
|
234
|
-
to: '/app/seeding',
|
|
235
|
-
text: 'log.seeding',
|
|
236
|
-
iconName: COMMON_ICON_NAMES.seeding,
|
|
237
|
-
|
|
238
|
-
allowedOperations: ['ARABLE'],
|
|
239
|
-
},
|
|
240
|
-
'/app/transplanting': {
|
|
241
|
-
to: '/app/transplanting',
|
|
242
|
-
text: 'log.transplanting',
|
|
243
|
-
iconName: COMMON_ICON_NAMES.transplanting,
|
|
244
|
-
|
|
245
|
-
allowedOperations: ['ARABLE'],
|
|
246
|
-
},
|
|
247
|
-
'/app/field-work': {
|
|
248
|
-
to: '/app/field-work',
|
|
249
|
-
text: 'log.field_work',
|
|
250
|
-
iconName: COMMON_ICON_NAMES.field_work,
|
|
251
|
-
|
|
252
|
-
allowedOperations: ['ARABLE'],
|
|
253
|
-
},
|
|
254
|
-
'/app/harvested': {
|
|
255
|
-
to: '/app/harvested',
|
|
256
|
-
text: 'log.harvested',
|
|
257
|
-
iconName: COMMON_ICON_NAMES.harvest,
|
|
258
|
-
|
|
259
|
-
allowedOperations: ['ARABLE'],
|
|
260
|
-
},
|
|
261
|
-
'/app/post-harvest': {
|
|
262
|
-
to: '/app/post-harvest',
|
|
263
|
-
text: 'log.post_harvest',
|
|
264
|
-
iconName: COMMON_ICON_NAMES.post_harvest,
|
|
265
|
-
|
|
266
|
-
allowedOperations: ['ARABLE'],
|
|
267
|
-
},
|
|
268
|
-
'/app/purchases': {
|
|
269
|
-
to: '/app/purchases',
|
|
270
|
-
text: 'log.purchases',
|
|
271
|
-
iconName: COMMON_ICON_NAMES.invoice,
|
|
272
|
-
|
|
273
|
-
allowedOperations: OP.FARMING,
|
|
274
|
-
},
|
|
275
|
-
'/app/orders': {
|
|
276
|
-
to: '/app/orders',
|
|
277
|
-
text: 'form.sales_orders',
|
|
278
|
-
iconName: COMMON_ICON_NAMES.receipt,
|
|
279
|
-
|
|
280
|
-
allowedOperations: OP.FARMING,
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
// Farmers Market
|
|
284
|
-
'/app/vendors': {
|
|
285
|
-
to: '/app/vendors',
|
|
286
|
-
text: 'form.vendors',
|
|
287
|
-
iconName: COMMON_ICON_NAMES.shop_vendor,
|
|
288
|
-
|
|
289
|
-
allowedOperations: ['FARMERS_MARKET'],
|
|
290
|
-
},
|
|
291
|
-
'/app/receipts': {
|
|
292
|
-
to: '/app/receipts' as ValidRoutePath,
|
|
293
|
-
text: 'form.market_receipts',
|
|
294
|
-
iconName: COMMON_ICON_NAMES.market_receipt,
|
|
295
|
-
|
|
296
|
-
allowedOperations: ['FARMERS_MARKET'],
|
|
297
|
-
},
|
|
298
|
-
|
|
299
|
-
// Grower Network
|
|
300
|
-
'/app/growers': {
|
|
301
|
-
to: '/app/growers',
|
|
302
|
-
text: 'org.growers',
|
|
303
|
-
iconName: COMMON_ICON_NAMES.growers,
|
|
304
|
-
|
|
305
|
-
allowedOperations: OP.GROWER_NETWORK,
|
|
306
|
-
},
|
|
307
179
|
|
|
308
180
|
// FieldDocs
|
|
309
181
|
|
|
182
|
+
'/app/programs/': {
|
|
183
|
+
to: '/app/programs/',
|
|
184
|
+
text: 'field_docs.program_overview',
|
|
185
|
+
iconName: COMMON_ICON_NAMES.field_document_group,
|
|
186
|
+
hasPhysicalToolbar: 'NEVER',
|
|
187
|
+
},
|
|
310
188
|
'/app/fd/': {
|
|
311
189
|
to: '/app/fd/',
|
|
312
|
-
text: '
|
|
313
|
-
iconName: COMMON_ICON_NAMES.
|
|
190
|
+
text: 'c.field_docs',
|
|
191
|
+
iconName: COMMON_ICON_NAMES.program,
|
|
314
192
|
hasPhysicalToolbar: 'NEVER',
|
|
315
193
|
},
|
|
316
194
|
'/app/d/': {
|
|
317
195
|
to: '/app/d/',
|
|
318
|
-
text: '
|
|
196
|
+
text: 'c.data_tables',
|
|
319
197
|
iconName: COMMON_ICON_NAMES.data_table,
|
|
320
198
|
hasPhysicalToolbar: 'NEVER',
|
|
321
199
|
},
|
|
322
200
|
'/app/p/': {
|
|
323
201
|
to: '/app/p/',
|
|
324
|
-
text: '
|
|
325
|
-
iconName: COMMON_ICON_NAMES.
|
|
202
|
+
text: 'c.field_docs',
|
|
203
|
+
iconName: COMMON_ICON_NAMES.program,
|
|
326
204
|
hasPhysicalToolbar: 'NEVER',
|
|
327
205
|
},
|
|
328
206
|
};
|
|
329
207
|
|
|
208
|
+
export interface TablePageRouteMetadata {
|
|
209
|
+
path: TablePageRoutePath;
|
|
210
|
+
navigationTitleKey: string;
|
|
211
|
+
iconName: string;
|
|
212
|
+
allowedOperations?: readonly OrganizationOperationEnum[];
|
|
213
|
+
requiredACL?: OperationName;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = { ...STATIC_ROUTES_DICT };
|
|
217
|
+
|
|
218
|
+
/*
|
|
219
|
+
* Register app-owned table navigation and access metadata on client and server startup.
|
|
220
|
+
*/
|
|
221
|
+
export function configureTablePageRoutes(pages: readonly TablePageRouteMetadata[]) {
|
|
222
|
+
ROUTES_DICT = {
|
|
223
|
+
...Object.fromEntries(
|
|
224
|
+
pages.map((page) => [
|
|
225
|
+
page.path,
|
|
226
|
+
{
|
|
227
|
+
to: page.path,
|
|
228
|
+
text: page.navigationTitleKey,
|
|
229
|
+
iconName: page.iconName,
|
|
230
|
+
allowedOperations: page.allowedOperations,
|
|
231
|
+
requiredACL: page.requiredACL,
|
|
232
|
+
},
|
|
233
|
+
]),
|
|
234
|
+
),
|
|
235
|
+
...STATIC_ROUTES_DICT,
|
|
236
|
+
};
|
|
237
|
+
ROUTES_DICT_ORDERED = Object.keys(ROUTES_DICT).sort((a, b) => b.length - a.length);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/*
|
|
241
|
+
* Normalize trailing slashes only for registered table paths, without inheriting their rules for deeper URLs.
|
|
242
|
+
*/
|
|
243
|
+
function getTablePageRoutePath(pathname: string): TablePageRoutePath | null {
|
|
244
|
+
const path = pathname.replace(/\/+$/, '') as TablePageRoutePath;
|
|
245
|
+
return Object.hasOwn(ROUTES_DICT, path) && !Object.hasOwn(STATIC_ROUTES_DICT, path) ? path : null;
|
|
246
|
+
}
|
|
247
|
+
|
|
330
248
|
/**
|
|
331
249
|
* Make pathname to a route in Marketday app.
|
|
332
250
|
* @param routeName - The name of the route.
|
|
@@ -334,21 +252,26 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
|
|
|
334
252
|
* @returns The full pathname for the route.
|
|
335
253
|
*/
|
|
336
254
|
|
|
337
|
-
export function makePathname(
|
|
338
|
-
routePath: ValidRoutePath,
|
|
339
|
-
pathSegment?: string | null,
|
|
340
|
-
): ValidRoutePath {
|
|
255
|
+
export function makePathname(routePath: ValidRoutePath, pathSegment?: string | null): ValidRoutePath {
|
|
341
256
|
const pathExists = !!ROUTES_DICT[routePath];
|
|
342
257
|
if (pathExists && routePath.endsWith('/')) {
|
|
343
|
-
return (
|
|
344
|
-
pathSegment
|
|
345
|
-
? `${routePath}${pathSegment}`
|
|
346
|
-
: routePath.substring(0, routePath.length - 1)
|
|
347
|
-
) as ValidRoutePath;
|
|
258
|
+
return (pathSegment ? `${routePath}${pathSegment}` : routePath.substring(0, routePath.length - 1)) as ValidRoutePath;
|
|
348
259
|
}
|
|
349
260
|
return pathExists ? routePath : '/app';
|
|
350
261
|
}
|
|
351
262
|
|
|
263
|
+
/*
|
|
264
|
+
* Build the program page link that lists one form's submissions, written in the submissions table's page-filter grammar.
|
|
265
|
+
*/
|
|
266
|
+
export function makeFieldDocFormPath(fieldDocProgramId: string, fieldDocId: string): string {
|
|
267
|
+
const schema = definePageFilterSchema({ filter: { fieldDocIds: { type: 'array', items: { type: 'string' } } } });
|
|
268
|
+
const search = stringifyPageSearchParams(
|
|
269
|
+
new URLSearchParams({ filter: serializePageFilters(schema, { fieldDocIds: [fieldDocId] }) }),
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
return `${makePathname('/app/fd/', encodeURIComponent(fieldDocProgramId))}?${search}`;
|
|
273
|
+
}
|
|
274
|
+
|
|
352
275
|
/**
|
|
353
276
|
* Check if route is valid.
|
|
354
277
|
* @param routeName - The name of the route.
|
|
@@ -356,10 +279,7 @@ export function makePathname(
|
|
|
356
279
|
* @returns The full pathname for the route.
|
|
357
280
|
*/
|
|
358
281
|
|
|
359
|
-
export function isRouteValid(
|
|
360
|
-
routePath: ValidRoutePath,
|
|
361
|
-
pathSegment?: string | null,
|
|
362
|
-
): boolean {
|
|
282
|
+
export function isRouteValid(routePath: ValidRoutePath, pathSegment?: string | null): boolean {
|
|
363
283
|
const routeDict = !!ROUTES_DICT[routePath];
|
|
364
284
|
return !!routeDict && (!routePath.endsWith('/') || !!pathSegment);
|
|
365
285
|
}
|
|
@@ -371,9 +291,7 @@ export function isRouteValid(
|
|
|
371
291
|
* @returns The route name if found.
|
|
372
292
|
*/
|
|
373
293
|
|
|
374
|
-
|
|
375
|
-
(a, b) => b.length - a.length,
|
|
376
|
-
);
|
|
294
|
+
let ROUTES_DICT_ORDERED = Object.keys(ROUTES_DICT).sort((a, b) => b.length - a.length);
|
|
377
295
|
|
|
378
296
|
interface RouteConfigObj extends Omit<RouteDictObj, 'hasPhysicalToolbar'> {
|
|
379
297
|
routeName: ValidRoutePath;
|
|
@@ -386,8 +304,14 @@ export function getRouteConfigs(
|
|
|
386
304
|
operation?: OrganizationOperationEnum | null,
|
|
387
305
|
checkACLClient?: CheckACLClientFn | null,
|
|
388
306
|
): RouteConfigObj {
|
|
307
|
+
const tablePageRoutePath = getTablePageRoutePath(pathname);
|
|
308
|
+
|
|
389
309
|
for (const routeName of ROUTES_DICT_ORDERED) {
|
|
390
|
-
if (
|
|
310
|
+
if (
|
|
311
|
+
pathname === routeName ||
|
|
312
|
+
tablePageRoutePath === routeName ||
|
|
313
|
+
(Object.hasOwn(STATIC_ROUTES_DICT, routeName) && pathname.startsWith(routeName.endsWith('/') ? routeName : routeName + '/'))
|
|
314
|
+
) {
|
|
391
315
|
// Scroll position fix + breadcrumb / TOC cleanup on unmount
|
|
392
316
|
// This will retain scroll position for deeper links,
|
|
393
317
|
// ie. "/app/globalgap/2023/.." will be retained
|
|
@@ -399,14 +323,11 @@ export function getRouteConfigs(
|
|
|
399
323
|
!!routeDict.hasPhysicalToolbar &&
|
|
400
324
|
routeDict.hasPhysicalToolbar !== 'NEVER' &&
|
|
401
325
|
(routeDict.hasPhysicalToolbar === 'ALWAYS' ||
|
|
402
|
-
(typeof routeDict.hasPhysicalToolbar === 'function' &&
|
|
403
|
-
routeDict.hasPhysicalToolbar(pathParts)));
|
|
326
|
+
(typeof routeDict.hasPhysicalToolbar === 'function' && routeDict.hasPhysicalToolbar(pathParts)));
|
|
404
327
|
|
|
405
328
|
return {
|
|
406
329
|
...routeDict,
|
|
407
|
-
text: i18n.has(routeDict.text)
|
|
408
|
-
? i18n.t(routeDict.text)
|
|
409
|
-
: routeDict.text,
|
|
330
|
+
text: i18n.has(routeDict.text) ? i18n.t(routeDict.text) : routeDict.text,
|
|
410
331
|
routeName: routeName as ValidRoutePath,
|
|
411
332
|
allowed: isRouteAllowed(pathname, operation, checkACLClient),
|
|
412
333
|
hasPhysicalToolbar,
|
|
@@ -432,14 +353,14 @@ export function isRouteAllowed(
|
|
|
432
353
|
operation?: OrganizationOperationEnum | null,
|
|
433
354
|
checkACLClient?: CheckACLClientFn | null,
|
|
434
355
|
): boolean {
|
|
435
|
-
let routeDict = ROUTES_DICT[pathname as ValidRoutePath];
|
|
356
|
+
let routeDict = ROUTES_DICT[(getTablePageRoutePath(pathname) || pathname) as ValidRoutePath];
|
|
436
357
|
if (!routeDict) {
|
|
437
358
|
const parts = pathname.split('/');
|
|
438
359
|
for (let i = parts.length; i > 0; i--) {
|
|
439
360
|
const subPath = parts.slice(0, i).join('/');
|
|
440
361
|
|
|
441
|
-
//
|
|
442
|
-
routeDict =
|
|
362
|
+
// Table pages match only their exact path; only explicit routes inherit rules for deeper links.
|
|
363
|
+
routeDict = STATIC_ROUTES_DICT[subPath as StaticRoutePath] || STATIC_ROUTES_DICT[`${subPath}/` as StaticRoutePath];
|
|
443
364
|
if (routeDict || i <= 3) {
|
|
444
365
|
break;
|
|
445
366
|
}
|
|
@@ -452,13 +373,9 @@ export function isRouteAllowed(
|
|
|
452
373
|
}
|
|
453
374
|
|
|
454
375
|
return (
|
|
455
|
-
(!routeDict.allowedOperations ||
|
|
456
|
-
|
|
457
|
-
(!routeDict.
|
|
458
|
-
!routeDict.notAllowedOperations.includes(operation || '')) &&
|
|
459
|
-
(!routeDict.requiredACL ||
|
|
460
|
-
!checkACLClient ||
|
|
461
|
-
checkACLClient(routeDict.requiredACL))
|
|
376
|
+
(!routeDict.allowedOperations || routeDict.allowedOperations.includes(operation || '')) &&
|
|
377
|
+
(!routeDict.notAllowedOperations || !routeDict.notAllowedOperations.includes(operation || '')) &&
|
|
378
|
+
(!routeDict.requiredACL || !checkACLClient || checkACLClient(routeDict.requiredACL))
|
|
462
379
|
);
|
|
463
380
|
}
|
|
464
381
|
|
|
@@ -514,31 +431,18 @@ export interface ClientRouteManifestItem {
|
|
|
514
431
|
/*
|
|
515
432
|
* Return a normalized sidebar slug without the optional app prefix.
|
|
516
433
|
*/
|
|
517
|
-
function getNormalizedSidebarSlug(slug: string | null | undefined) {
|
|
434
|
+
export function getNormalizedSidebarSlug(slug: string | null | undefined) {
|
|
518
435
|
return String(slug || '')
|
|
519
436
|
.trim()
|
|
520
437
|
.replace(/^\/?app\/?/, '')
|
|
521
438
|
.replace(/^\/+|\/+$/g, '');
|
|
522
439
|
}
|
|
523
440
|
|
|
524
|
-
/*
|
|
525
|
-
* Return the current sidebar slug while translating legacy route prefixes.
|
|
526
|
-
*/
|
|
527
|
-
export function normalizeSidebarRouteSlug(slug: string | null | undefined) {
|
|
528
|
-
const normalizedSlug = getNormalizedSidebarSlug(slug);
|
|
529
|
-
|
|
530
|
-
return normalizedSlug.startsWith('r/')
|
|
531
|
-
? `fd/${normalizedSlug.slice(2)}`
|
|
532
|
-
: normalizedSlug;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
441
|
/*
|
|
536
442
|
* Return route metadata and renderable path for a customized sidebar slug.
|
|
537
443
|
*/
|
|
538
|
-
function getSidebarRouteFromSlug(
|
|
539
|
-
|
|
540
|
-
): SidebarRouteFromSlugObj | null {
|
|
541
|
-
const normalizedSlug = normalizeSidebarRouteSlug(slug);
|
|
444
|
+
function getSidebarRouteFromSlug(slug: string | null | undefined): SidebarRouteFromSlugObj | null {
|
|
445
|
+
const normalizedSlug = getNormalizedSidebarSlug(slug);
|
|
542
446
|
|
|
543
447
|
if (!normalizedSlug) {
|
|
544
448
|
return null;
|
|
@@ -605,19 +509,12 @@ function doesClientRoutePatternMatchPath(routePattern: string, path: string) {
|
|
|
605
509
|
}
|
|
606
510
|
|
|
607
511
|
const optional = patternSegment.endsWith('?');
|
|
608
|
-
const requiredPatternSegment = optional
|
|
609
|
-
? patternSegment.slice(0, -1)
|
|
610
|
-
: patternSegment;
|
|
512
|
+
const requiredPatternSegment = optional ? patternSegment.slice(0, -1) : patternSegment;
|
|
611
513
|
const dynamic = requiredPatternSegment.startsWith(':');
|
|
612
|
-
const pathSegmentMatches =
|
|
613
|
-
pathIndex < pathSegments.length &&
|
|
614
|
-
(dynamic || requiredPatternSegment === pathSegments[pathIndex]);
|
|
514
|
+
const pathSegmentMatches = pathIndex < pathSegments.length && (dynamic || requiredPatternSegment === pathSegments[pathIndex]);
|
|
615
515
|
|
|
616
516
|
if (optional) {
|
|
617
|
-
return (
|
|
618
|
-
matchSegments(patternIndex + 1, pathIndex) ||
|
|
619
|
-
(pathSegmentMatches && matchSegments(patternIndex + 1, pathIndex + 1))
|
|
620
|
-
);
|
|
517
|
+
return matchSegments(patternIndex + 1, pathIndex) || (pathSegmentMatches && matchSegments(patternIndex + 1, pathIndex + 1));
|
|
621
518
|
}
|
|
622
519
|
|
|
623
520
|
return pathSegmentMatches && matchSegments(patternIndex + 1, pathIndex + 1);
|
|
@@ -641,42 +538,29 @@ export function assertRouteHelperRouteExists(
|
|
|
641
538
|
const pendingRoutes = Object.entries(routeManifest);
|
|
642
539
|
let previousPendingRouteCount = -1;
|
|
643
540
|
|
|
644
|
-
while (
|
|
645
|
-
pendingRoutes.length &&
|
|
646
|
-
pendingRoutes.length !== previousPendingRouteCount
|
|
647
|
-
) {
|
|
541
|
+
while (pendingRoutes.length && pendingRoutes.length !== previousPendingRouteCount) {
|
|
648
542
|
previousPendingRouteCount = pendingRoutes.length;
|
|
649
543
|
|
|
650
544
|
for (let index = pendingRoutes.length - 1; index >= 0; index -= 1) {
|
|
651
545
|
const [routeId, route] = pendingRoutes[index];
|
|
652
|
-
const parentPath = route.parentId
|
|
653
|
-
? routePathsById.get(route.parentId)
|
|
654
|
-
: '';
|
|
546
|
+
const parentPath = route.parentId ? routePathsById.get(route.parentId) : '';
|
|
655
547
|
|
|
656
548
|
if (route.parentId && parentPath === undefined) {
|
|
657
549
|
continue;
|
|
658
550
|
}
|
|
659
551
|
|
|
660
|
-
const routePath = route.path?.startsWith('/')
|
|
661
|
-
? route.path
|
|
662
|
-
: [parentPath, route.path].filter(Boolean).join('/');
|
|
552
|
+
const routePath = route.path?.startsWith('/') ? route.path : [parentPath, route.path].filter(Boolean).join('/');
|
|
663
553
|
routePathsById.set(routeId, `/${routePath}`.replace(/\/+/g, '/'));
|
|
664
554
|
pendingRoutes.splice(index, 1);
|
|
665
555
|
}
|
|
666
556
|
}
|
|
667
557
|
|
|
668
558
|
const clientRoutePatterns = Array.from(new Set(routePathsById.values()));
|
|
669
|
-
const samplePath = routePath.endsWith('/')
|
|
670
|
-
|
|
671
|
-
: routePath;
|
|
672
|
-
const routeExists = clientRoutePatterns.some((routePattern) =>
|
|
673
|
-
doesClientRoutePatternMatchPath(routePattern, samplePath),
|
|
674
|
-
);
|
|
559
|
+
const samplePath = routePath.endsWith('/') ? `${routePath}__route_helper_validation__` : routePath;
|
|
560
|
+
const routeExists = clientRoutePatterns.some((routePattern) => doesClientRoutePatternMatchPath(routePattern, samplePath));
|
|
675
561
|
|
|
676
562
|
if (!routeExists) {
|
|
677
|
-
throw new Error(
|
|
678
|
-
`Route registered in ROUTES_DICT is missing from the client app: ${routePath}`,
|
|
679
|
-
);
|
|
563
|
+
throw new Error(`Route registered in ROUTES_DICT is missing from the client app: ${routePath}`);
|
|
680
564
|
}
|
|
681
565
|
}
|
|
682
566
|
|
|
@@ -688,7 +572,7 @@ function getSidebarSlugFromRoutePath(routePath: string | null | undefined) {
|
|
|
688
572
|
return 'home';
|
|
689
573
|
}
|
|
690
574
|
|
|
691
|
-
return
|
|
575
|
+
return getNormalizedSidebarSlug(routePath);
|
|
692
576
|
}
|
|
693
577
|
|
|
694
578
|
/*
|
|
@@ -710,10 +594,7 @@ function getNavigationItemFromSidebarItem(
|
|
|
710
594
|
}
|
|
711
595
|
|
|
712
596
|
const routeDict = ROUTES_DICT[route.routePath];
|
|
713
|
-
const fallbackText =
|
|
714
|
-
routeDict.text && i18n.has(routeDict.text)
|
|
715
|
-
? i18n.t(routeDict.text)
|
|
716
|
-
: routeDict.text;
|
|
597
|
+
const fallbackText = routeDict.text && i18n.has(routeDict.text) ? i18n.t(routeDict.text) : routeDict.text;
|
|
717
598
|
|
|
718
599
|
return {
|
|
719
600
|
slug: route.slug,
|
|
@@ -726,9 +607,7 @@ function getNavigationItemFromSidebarItem(
|
|
|
726
607
|
/*
|
|
727
608
|
* Return whether a navigation item is a visual break.
|
|
728
609
|
*/
|
|
729
|
-
function isNavigationBreakItem(
|
|
730
|
-
item: NavigationItem | null,
|
|
731
|
-
): item is NavBreakItem {
|
|
610
|
+
function isNavigationBreakItem(item: NavigationItem | null): item is NavBreakItem {
|
|
732
611
|
return !!item && 'break' in item && !!item.break;
|
|
733
612
|
}
|
|
734
613
|
|
|
@@ -768,11 +647,7 @@ function getNavigationGroupFromSidebarItem(
|
|
|
768
647
|
return null;
|
|
769
648
|
}
|
|
770
649
|
|
|
771
|
-
const navList = getCustomizedNestedNavigationList(
|
|
772
|
-
item.items,
|
|
773
|
-
operation,
|
|
774
|
-
checkACLClient,
|
|
775
|
-
);
|
|
650
|
+
const navList = getCustomizedNestedNavigationList(item.items, operation, checkACLClient);
|
|
776
651
|
|
|
777
652
|
return {
|
|
778
653
|
text: item.label || '',
|
|
@@ -815,14 +690,7 @@ function getCustomizedNestedNavigationList(
|
|
|
815
690
|
|
|
816
691
|
const navList = sidebar.reduce(
|
|
817
692
|
(acc, item) => {
|
|
818
|
-
const navItem =
|
|
819
|
-
item.kind === 'GROUP'
|
|
820
|
-
? null
|
|
821
|
-
: getNavigationItemFromCustomSidebarItem(
|
|
822
|
-
item,
|
|
823
|
-
operation,
|
|
824
|
-
checkACLClient,
|
|
825
|
-
);
|
|
693
|
+
const navItem = item.kind === 'GROUP' ? null : getNavigationItemFromCustomSidebarItem(item, operation, checkACLClient);
|
|
826
694
|
|
|
827
695
|
if (navItem && !('navList' in navItem)) {
|
|
828
696
|
acc.push(navItem);
|
|
@@ -845,11 +713,7 @@ function getCustomizedNavigationList(
|
|
|
845
713
|
checkACLClient?: CheckACLClientFn | null,
|
|
846
714
|
): NavigationItem[] {
|
|
847
715
|
const navList = sidebar.reduce((acc, item) => {
|
|
848
|
-
const navItem = getNavigationItemFromCustomSidebarItem(
|
|
849
|
-
item,
|
|
850
|
-
operation,
|
|
851
|
-
checkACLClient,
|
|
852
|
-
);
|
|
716
|
+
const navItem = getNavigationItemFromCustomSidebarItem(item, operation, checkACLClient);
|
|
853
717
|
|
|
854
718
|
if (navItem) {
|
|
855
719
|
acc.push(navItem);
|
|
@@ -876,10 +740,7 @@ function mapNavigationList(
|
|
|
876
740
|
if (item?.navList) {
|
|
877
741
|
item.navList = item.navList.reduce((acc: any[], x: any, i: number) => {
|
|
878
742
|
const mappedItem = mapNavItems(x);
|
|
879
|
-
if (
|
|
880
|
-
mappedItem &&
|
|
881
|
-
(mappedItem.to || (acc.length && i !== item.navList.length - 1))
|
|
882
|
-
) {
|
|
743
|
+
if (mappedItem && (mappedItem.to || (acc.length && i !== item.navList.length - 1))) {
|
|
883
744
|
if (mappedItem.text && i18n.has(mappedItem.text)) {
|
|
884
745
|
mappedItem.text = i18n.t(mappedItem.text);
|
|
885
746
|
}
|
|
@@ -891,10 +752,7 @@ function mapNavigationList(
|
|
|
891
752
|
if (!item.navList.length) {
|
|
892
753
|
return null;
|
|
893
754
|
}
|
|
894
|
-
} else if (
|
|
895
|
-
item?.to &&
|
|
896
|
-
!isRouteAllowed(item.to, operation, checkACLClient)
|
|
897
|
-
) {
|
|
755
|
+
} else if (item?.to && !isRouteAllowed(item.to, operation, checkACLClient)) {
|
|
898
756
|
return null;
|
|
899
757
|
}
|
|
900
758
|
|
|
@@ -912,6 +770,16 @@ function mapNavigationList(
|
|
|
912
770
|
return navListArr.map(mapNavItems).filter(Boolean);
|
|
913
771
|
}
|
|
914
772
|
|
|
773
|
+
/*
|
|
774
|
+
* Return optional links available in Workspace and sidebar customization, outside the default sidebar.
|
|
775
|
+
*/
|
|
776
|
+
export function getOptionalNavigationItems(
|
|
777
|
+
operation: OrganizationOperationEnum | null,
|
|
778
|
+
checkACLClient?: CheckACLClientFn | null,
|
|
779
|
+
): NavigationItem[] {
|
|
780
|
+
return mapNavigationList([{ ...ROUTES_DICT['/app/workflows'] }, { ...ROUTES_DICT['/app/qrcodes'] }], operation, checkACLClient);
|
|
781
|
+
}
|
|
782
|
+
|
|
915
783
|
/*
|
|
916
784
|
* Return the default operation-specific sidebar list without pinned Home or Workspace links.
|
|
917
785
|
*/
|
|
@@ -946,6 +814,14 @@ export function getDefaultNav(
|
|
|
946
814
|
},
|
|
947
815
|
];
|
|
948
816
|
break;
|
|
817
|
+
case 'FOOD_MANUFACTURING':
|
|
818
|
+
navListArr = [
|
|
819
|
+
{
|
|
820
|
+
text: i18n.t(`org.type_active.${operation}`),
|
|
821
|
+
navList: [ROUTES_DICT['/app/temperature'], ROUTES_DICT['/app/inspections']],
|
|
822
|
+
},
|
|
823
|
+
];
|
|
824
|
+
break;
|
|
949
825
|
case 'FARMERS_MARKET':
|
|
950
826
|
navListArr = [
|
|
951
827
|
{
|
|
@@ -967,17 +843,28 @@ export function getDefaultNav(
|
|
|
967
843
|
}
|
|
968
844
|
|
|
969
845
|
navListArr = navListArr.concat([
|
|
846
|
+
// Schedule and projects are not ready.
|
|
847
|
+
// {
|
|
848
|
+
// text: i18n.t('schedule.title'),
|
|
849
|
+
// initialExpanded: true,
|
|
850
|
+
// navList:
|
|
851
|
+
// operation && SCHEDULING_TYPE_BY_OPERATION[operation] === 'PROJECT_MANAGEMENT'
|
|
852
|
+
// ? [ROUTES_DICT['/app/projects'], ROUTES_DICT['/app/calendar']]
|
|
853
|
+
// : [ROUTES_DICT['/app/calendar'], ROUTES_DICT['/app/projects']],
|
|
854
|
+
// },
|
|
970
855
|
{
|
|
971
|
-
text: i18n.t('
|
|
856
|
+
text: i18n.t('campaign.outbound'),
|
|
857
|
+
initialExpanded: true,
|
|
858
|
+
navList: [ROUTES_DICT['/app/outreach']],
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
text: i18n.t('c.advanced'),
|
|
972
862
|
initialExpanded: true,
|
|
973
863
|
navList: [
|
|
974
864
|
// ROUTES_DICT['/app/calendar'],
|
|
975
|
-
ROUTES_DICT['/app/workflows'],
|
|
976
|
-
// ROUTES_DICT['/app/emails'],
|
|
977
|
-
// ROUTES_DICT['/app/downloads'],
|
|
978
|
-
// ROUTES_DICT['/app/outbound/forms'],
|
|
979
|
-
// ROUTES_DICT['/app/outbound/emails'],
|
|
980
865
|
ROUTES_DICT['/app/logs'],
|
|
866
|
+
ROUTES_DICT['/app/emails'],
|
|
867
|
+
// ROUTES_DICT['/app/downloads'],
|
|
981
868
|
],
|
|
982
869
|
},
|
|
983
870
|
]);
|
|
@@ -1011,5 +898,29 @@ export function getNavigationList(
|
|
|
1011
898
|
? getCustomizedNavigationList(sidebar, operation, checkACLClient)
|
|
1012
899
|
: getDefaultNav(operation, checkACLClient);
|
|
1013
900
|
|
|
1014
|
-
|
|
1015
|
-
|
|
901
|
+
const result = pinnedNavList.concat(remainingNavList);
|
|
902
|
+
// Schedule and projects are not ready.
|
|
903
|
+
// const missingSchedule = [
|
|
904
|
+
// ROUTES_DICT['/app/calendar'],
|
|
905
|
+
// ROUTES_DICT['/app/projects'],
|
|
906
|
+
// ].filter((route) => !hasNavigationDestination(result, route.to!));
|
|
907
|
+
// return result.concat(
|
|
908
|
+
// mapNavigationList(missingSchedule, operation, checkACLClient),
|
|
909
|
+
// );
|
|
910
|
+
return result;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// Schedule and projects are not ready.
|
|
914
|
+
// /* Find a schedule destination in customized groups before appending required navigation. */
|
|
915
|
+
// function hasNavigationDestination(
|
|
916
|
+
// items: NavigationItem[],
|
|
917
|
+
// destination: string,
|
|
918
|
+
// ): boolean {
|
|
919
|
+
// return items.some(
|
|
920
|
+
// (item) =>
|
|
921
|
+
// item.to === destination ||
|
|
922
|
+
// ('navList' in item && item.navList
|
|
923
|
+
// ? hasNavigationDestination(item.navList, destination)
|
|
924
|
+
// : false),
|
|
925
|
+
// );
|
|
926
|
+
// }
|