@jsb188/mday-web 1.1.11 → 1.1.12

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.
@@ -1,10 +1,11 @@
1
+ // Schedule and projects are not ready.
2
+ // import { getScheduleDefaultSurface } from '@jsb188/schedule/utils/defaults.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
+ import { getOperationPageMetadata, OPERATION_PAGES, type OperationPageSlug } from './operation-pages.ts';
8
9
 
9
10
  // Use this for fieldDoc periods, etc
10
11
  // const CURRENT_YEAR = String(new Date().getFullYear());
@@ -13,11 +14,6 @@ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
13
14
  * Constants; Re-usable rules
14
15
  */
15
16
 
16
- const OP = {
17
- FARMING: ['ARABLE'],
18
- GROWER_NETWORK: ['GROWER_NETWORK'],
19
- };
20
-
21
17
  const LOGIN_CHANGED_ERROR_CODES = new Set(['20080', '20081']);
22
18
  const AUTH_RETURN_TO_BASE_URL = 'https://marketday.invalid';
23
19
  const AUTH_RETURN_TO_PUBLIC_FORM_PATH_PATTERN = /^\/form\/[^/]+$/;
@@ -25,10 +21,7 @@ const AUTH_RETURN_TO_PUBLIC_FORM_PATH_PATTERN = /^\/form\/[^/]+$/;
25
21
  /**
26
22
  * Build the translated title and description metadata for a Marketday route.
27
23
  */
28
- export function getMarketdayRouteMeta(
29
- titleKey: string,
30
- descriptionKey: string,
31
- ) {
24
+ export function getMarketdayRouteMeta(titleKey: string, descriptionKey: string) {
32
25
  return [
33
26
  {
34
27
  title: i18n.t('app.route_', { text: i18n.t(titleKey) }),
@@ -44,10 +37,11 @@ export function getMarketdayRouteMeta(
44
37
  * Rules
45
38
  */
46
39
 
47
- type ValidRoutePath =
40
+ type StaticRoutePath =
48
41
  | '/app'
49
42
  | '/app/c/'
50
43
  | '/app/calendar'
44
+ | '/app/projects'
51
45
  | '/app/workflows'
52
46
  | '/app/grids'
53
47
  | '/app/workspace'
@@ -56,30 +50,23 @@ type ValidRoutePath =
56
50
  | '/app/outbound/forms'
57
51
  | '/app/outbound/emails'
58
52
  | '/app/downloads'
53
+ | '/app/qrcodes'
59
54
  | '/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
55
 
72
56
  // FieldDocs
73
57
  | '/app/fd/'
58
+ | '/app/programs/'
74
59
  | '/app/d/'
75
60
  | '/app/p/';
76
- // | '/app/fd/water-source/';
61
+
62
+ type OperationPageRoutePath = `/app/${OperationPageSlug}`;
63
+ type ValidRoutePath = StaticRoutePath | OperationPageRoutePath;
77
64
 
78
65
  interface RouteDictObj {
79
66
  to: ValidRoutePath;
80
67
  text: string;
81
68
  iconName?: string;
82
- allowedOperations?: OrganizationOperationEnum[];
69
+ allowedOperations?: readonly OrganizationOperationEnum[];
83
70
  notAllowedOperations?: OrganizationOperationEnum[];
84
71
  requiredACL?: OperationName;
85
72
 
@@ -99,16 +86,10 @@ export function getSafeAuthReturnToPath(returnTo?: string | null) {
99
86
 
100
87
  try {
101
88
  const url = new URL(returnTo, AUTH_RETURN_TO_BASE_URL);
102
- const isPublicFormPath = AUTH_RETURN_TO_PUBLIC_FORM_PATH_PATTERN.test(
103
- url.pathname,
104
- );
105
- const isAppPath =
106
- url.pathname === '/app' || url.pathname.startsWith('/app/');
89
+ const isPublicFormPath = AUTH_RETURN_TO_PUBLIC_FORM_PATH_PATTERN.test(url.pathname);
90
+ const isAppPath = url.pathname === '/app' || url.pathname.startsWith('/app/');
107
91
 
108
- if (
109
- url.origin !== AUTH_RETURN_TO_BASE_URL ||
110
- (!isPublicFormPath && !isAppPath)
111
- ) {
92
+ if (url.origin !== AUTH_RETURN_TO_BASE_URL || (!isPublicFormPath && !isAppPath)) {
112
93
  return null;
113
94
  }
114
95
 
@@ -138,15 +119,12 @@ const STABLE_OUTLET_ROUTES = ['/app/runs'];
138
119
  */
139
120
 
140
121
  export function getOutletPathnameKey(pathname: string): string {
141
- const stableRoute = STABLE_OUTLET_ROUTES.find(
142
- (routePrefix) =>
143
- pathname === routePrefix || pathname.startsWith(`${routePrefix}/`),
144
- );
122
+ const stableRoute = STABLE_OUTLET_ROUTES.find((routePrefix) => pathname === routePrefix || pathname.startsWith(`${routePrefix}/`));
145
123
 
146
124
  return stableRoute || pathname;
147
125
  }
148
126
 
149
- const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
127
+ const STATIC_ROUTES_DICT: Record<StaticRoutePath, RouteDictObj> = {
150
128
  // Main /app/ routes
151
129
  // If route ends with '/', it requires (or optionally accepts) a path segment
152
130
  // e.g. "/app/c/" means "/app/c/:chatId" etc
@@ -174,6 +152,13 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
174
152
  // surfaces do; it renders its own toolbar row
175
153
  hasPhysicalToolbar: 'NEVER',
176
154
  },
155
+ '/app/projects': {
156
+ to: '/app/projects',
157
+ text: 'app.route_projects',
158
+ iconName: COMMON_ICON_NAMES.progress,
159
+ // The project pages render their own toolbar row, like the calendar
160
+ hasPhysicalToolbar: 'NEVER',
161
+ },
177
162
  '/app/c/': {
178
163
  to: '/app/c/',
179
164
  text: 'app.route_ai_chat',
@@ -185,7 +170,7 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
185
170
 
186
171
  '/app/workflows': {
187
172
  to: '/app/workflows',
188
- text: 'form.ai_workflows',
173
+ text: 'c.ai_workflows',
189
174
  iconName: COMMON_ICON_NAMES.ai_workflow,
190
175
  },
191
176
  '/app/s/': {
@@ -195,13 +180,13 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
195
180
  },
196
181
  '/app/emails': {
197
182
  to: '/app/emails',
198
- text: 'app.ai_inboxes',
199
- iconName: COMMON_ICON_NAMES.ai_inbox,
183
+ text: 'app.emails',
184
+ iconName: COMMON_ICON_NAMES.email_history,
200
185
  requiredACL: 'ai_inbox_read',
201
186
  },
202
187
  '/app/outbound/forms': {
203
188
  to: '/app/outbound/forms',
204
- text: 'campaign.published_forms',
189
+ text: 'campaign.web_forms',
205
190
  iconName: COMMON_ICON_NAMES.public_form,
206
191
  },
207
192
  '/app/outbound/emails': {
@@ -211,122 +196,77 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
211
196
  },
212
197
  '/app/downloads': {
213
198
  to: '/app/downloads',
214
- text: 'form.downloads',
199
+ text: 'c.downloads',
215
200
  iconName: 'download',
216
201
  },
202
+ '/app/qrcodes': {
203
+ to: '/app/qrcodes',
204
+ text: 'c.qr_codes',
205
+ iconName: COMMON_ICON_NAMES.qr_code,
206
+ requiredACL: 'general_read',
207
+ },
217
208
  '/app/logs': {
218
209
  to: '/app/logs',
219
- text: 'log.all_logs',
210
+ text: 'log.logs',
220
211
  iconName: COMMON_ICON_NAMES.logs,
221
212
  },
222
213
 
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
-
308
214
  // FieldDocs
309
215
 
216
+ '/app/programs/': {
217
+ to: '/app/programs/',
218
+ text: 'field_docs.program_overview',
219
+ iconName: COMMON_ICON_NAMES.field_document_group,
220
+ hasPhysicalToolbar: 'NEVER',
221
+ },
310
222
  '/app/fd/': {
311
223
  to: '/app/fd/',
312
- text: 'form.field_docs',
313
- iconName: COMMON_ICON_NAMES.generic_field_doc,
224
+ text: 'c.field_docs',
225
+ iconName: COMMON_ICON_NAMES.program,
314
226
  hasPhysicalToolbar: 'NEVER',
315
227
  },
316
228
  '/app/d/': {
317
229
  to: '/app/d/',
318
- text: 'form.data_tables',
230
+ text: 'c.data_tables',
319
231
  iconName: COMMON_ICON_NAMES.data_table,
320
232
  hasPhysicalToolbar: 'NEVER',
321
233
  },
322
234
  '/app/p/': {
323
235
  to: '/app/p/',
324
- text: 'form.field_docs',
325
- iconName: COMMON_ICON_NAMES.generic_field_doc,
236
+ text: 'c.field_docs',
237
+ iconName: COMMON_ICON_NAMES.program,
326
238
  hasPhysicalToolbar: 'NEVER',
327
239
  },
328
240
  };
329
241
 
242
+ /*
243
+ * Build route-helper entries from shared operation-page navigation metadata.
244
+ */
245
+ function getOperationPageRoutes(): Record<OperationPageRoutePath, RouteDictObj> {
246
+ return Object.fromEntries(
247
+ Object.values(OPERATION_PAGES).map((page): [OperationPageRoutePath, RouteDictObj] => {
248
+ const to: OperationPageRoutePath = `/app/${page.slug}`;
249
+
250
+ return [to, { to, text: page.navigationTitleKey, iconName: page.iconName, allowedOperations: page.allowedOperations }];
251
+ }),
252
+ ) as Record<OperationPageRoutePath, RouteDictObj>;
253
+ }
254
+
255
+ // Explicit routes own their metadata when their path also names an operation page.
256
+ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
257
+ ...getOperationPageRoutes(),
258
+ ...STATIC_ROUTES_DICT,
259
+ };
260
+
261
+ /*
262
+ * Normalize trailing slashes only for exact operation-page paths, matching the client router.
263
+ */
264
+ function getOperationPageRoutePath(pathname: string): OperationPageRoutePath | null {
265
+ const page = pathname.startsWith('/app/') ? getOperationPageMetadata(pathname.slice(5).replace(/\/+$/, '')) : null;
266
+
267
+ return page ? `/app/${page.slug}` : null;
268
+ }
269
+
330
270
  /**
331
271
  * Make pathname to a route in Marketday app.
332
272
  * @param routeName - The name of the route.
@@ -334,21 +274,26 @@ const ROUTES_DICT: Record<ValidRoutePath, RouteDictObj> = {
334
274
  * @returns The full pathname for the route.
335
275
  */
336
276
 
337
- export function makePathname(
338
- routePath: ValidRoutePath,
339
- pathSegment?: string | null,
340
- ): ValidRoutePath {
277
+ export function makePathname(routePath: ValidRoutePath, pathSegment?: string | null): ValidRoutePath {
341
278
  const pathExists = !!ROUTES_DICT[routePath];
342
279
  if (pathExists && routePath.endsWith('/')) {
343
- return (
344
- pathSegment
345
- ? `${routePath}${pathSegment}`
346
- : routePath.substring(0, routePath.length - 1)
347
- ) as ValidRoutePath;
280
+ return (pathSegment ? `${routePath}${pathSegment}` : routePath.substring(0, routePath.length - 1)) as ValidRoutePath;
348
281
  }
349
282
  return pathExists ? routePath : '/app';
350
283
  }
351
284
 
285
+ /*
286
+ * Build the program page link that lists one form's submissions, written in the submissions table's page-filter grammar.
287
+ */
288
+ export function makeFieldDocFormPath(fieldDocProgramId: string, fieldDocId: string): string {
289
+ const schema = definePageFilterSchema({ filter: { fieldDocIds: { type: 'array', items: { type: 'string' } } } });
290
+ const search = stringifyPageSearchParams(
291
+ new URLSearchParams({ filter: serializePageFilters(schema, { fieldDocIds: [fieldDocId] }) }),
292
+ );
293
+
294
+ return `${makePathname('/app/fd/', encodeURIComponent(fieldDocProgramId))}?${search}`;
295
+ }
296
+
352
297
  /**
353
298
  * Check if route is valid.
354
299
  * @param routeName - The name of the route.
@@ -356,10 +301,7 @@ export function makePathname(
356
301
  * @returns The full pathname for the route.
357
302
  */
358
303
 
359
- export function isRouteValid(
360
- routePath: ValidRoutePath,
361
- pathSegment?: string | null,
362
- ): boolean {
304
+ export function isRouteValid(routePath: ValidRoutePath, pathSegment?: string | null): boolean {
363
305
  const routeDict = !!ROUTES_DICT[routePath];
364
306
  return !!routeDict && (!routePath.endsWith('/') || !!pathSegment);
365
307
  }
@@ -371,9 +313,7 @@ export function isRouteValid(
371
313
  * @returns The route name if found.
372
314
  */
373
315
 
374
- const ROUTES_DICT_ORDERED = Object.keys(ROUTES_DICT).sort(
375
- (a, b) => b.length - a.length,
376
- );
316
+ const ROUTES_DICT_ORDERED = Object.keys(ROUTES_DICT).sort((a, b) => b.length - a.length);
377
317
 
378
318
  interface RouteConfigObj extends Omit<RouteDictObj, 'hasPhysicalToolbar'> {
379
319
  routeName: ValidRoutePath;
@@ -386,8 +326,14 @@ export function getRouteConfigs(
386
326
  operation?: OrganizationOperationEnum | null,
387
327
  checkACLClient?: CheckACLClientFn | null,
388
328
  ): RouteConfigObj {
329
+ const operationPageRoutePath = getOperationPageRoutePath(pathname);
330
+
389
331
  for (const routeName of ROUTES_DICT_ORDERED) {
390
- if (pathname.startsWith(routeName)) {
332
+ if (
333
+ pathname === routeName ||
334
+ operationPageRoutePath === routeName ||
335
+ (Object.hasOwn(STATIC_ROUTES_DICT, routeName) && pathname.startsWith(routeName))
336
+ ) {
391
337
  // Scroll position fix + breadcrumb / TOC cleanup on unmount
392
338
  // This will retain scroll position for deeper links,
393
339
  // ie. "/app/globalgap/2023/.." will be retained
@@ -399,14 +345,11 @@ export function getRouteConfigs(
399
345
  !!routeDict.hasPhysicalToolbar &&
400
346
  routeDict.hasPhysicalToolbar !== 'NEVER' &&
401
347
  (routeDict.hasPhysicalToolbar === 'ALWAYS' ||
402
- (typeof routeDict.hasPhysicalToolbar === 'function' &&
403
- routeDict.hasPhysicalToolbar(pathParts)));
348
+ (typeof routeDict.hasPhysicalToolbar === 'function' && routeDict.hasPhysicalToolbar(pathParts)));
404
349
 
405
350
  return {
406
351
  ...routeDict,
407
- text: i18n.has(routeDict.text)
408
- ? i18n.t(routeDict.text)
409
- : routeDict.text,
352
+ text: i18n.has(routeDict.text) ? i18n.t(routeDict.text) : routeDict.text,
410
353
  routeName: routeName as ValidRoutePath,
411
354
  allowed: isRouteAllowed(pathname, operation, checkACLClient),
412
355
  hasPhysicalToolbar,
@@ -432,14 +375,14 @@ export function isRouteAllowed(
432
375
  operation?: OrganizationOperationEnum | null,
433
376
  checkACLClient?: CheckACLClientFn | null,
434
377
  ): boolean {
435
- let routeDict = ROUTES_DICT[pathname as ValidRoutePath];
378
+ let routeDict = ROUTES_DICT[(getOperationPageRoutePath(pathname) || pathname) as ValidRoutePath];
436
379
  if (!routeDict) {
437
380
  const parts = pathname.split('/');
438
381
  for (let i = parts.length; i > 0; i--) {
439
382
  const subPath = parts.slice(0, i).join('/');
440
383
 
441
- // @ts-ignore - sub paths may not be valid route paths
442
- routeDict = ROUTES_DICT[subPath] || ROUTES_DICT[subPath + '/'];
384
+ // Operation pages match only their exact path; only explicit routes inherit rules for deeper links.
385
+ routeDict = STATIC_ROUTES_DICT[subPath as StaticRoutePath] || STATIC_ROUTES_DICT[`${subPath}/` as StaticRoutePath];
443
386
  if (routeDict || i <= 3) {
444
387
  break;
445
388
  }
@@ -452,13 +395,9 @@ export function isRouteAllowed(
452
395
  }
453
396
 
454
397
  return (
455
- (!routeDict.allowedOperations ||
456
- routeDict.allowedOperations.includes(operation || '')) &&
457
- (!routeDict.notAllowedOperations ||
458
- !routeDict.notAllowedOperations.includes(operation || '')) &&
459
- (!routeDict.requiredACL ||
460
- !checkACLClient ||
461
- checkACLClient(routeDict.requiredACL))
398
+ (!routeDict.allowedOperations || routeDict.allowedOperations.includes(operation || '')) &&
399
+ (!routeDict.notAllowedOperations || !routeDict.notAllowedOperations.includes(operation || '')) &&
400
+ (!routeDict.requiredACL || !checkACLClient || checkACLClient(routeDict.requiredACL))
462
401
  );
463
402
  }
464
403
 
@@ -514,31 +453,18 @@ export interface ClientRouteManifestItem {
514
453
  /*
515
454
  * Return a normalized sidebar slug without the optional app prefix.
516
455
  */
517
- function getNormalizedSidebarSlug(slug: string | null | undefined) {
456
+ export function getNormalizedSidebarSlug(slug: string | null | undefined) {
518
457
  return String(slug || '')
519
458
  .trim()
520
459
  .replace(/^\/?app\/?/, '')
521
460
  .replace(/^\/+|\/+$/g, '');
522
461
  }
523
462
 
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
463
  /*
536
464
  * Return route metadata and renderable path for a customized sidebar slug.
537
465
  */
538
- function getSidebarRouteFromSlug(
539
- slug: string | null | undefined,
540
- ): SidebarRouteFromSlugObj | null {
541
- const normalizedSlug = normalizeSidebarRouteSlug(slug);
466
+ function getSidebarRouteFromSlug(slug: string | null | undefined): SidebarRouteFromSlugObj | null {
467
+ const normalizedSlug = getNormalizedSidebarSlug(slug);
542
468
 
543
469
  if (!normalizedSlug) {
544
470
  return null;
@@ -605,19 +531,12 @@ function doesClientRoutePatternMatchPath(routePattern: string, path: string) {
605
531
  }
606
532
 
607
533
  const optional = patternSegment.endsWith('?');
608
- const requiredPatternSegment = optional
609
- ? patternSegment.slice(0, -1)
610
- : patternSegment;
534
+ const requiredPatternSegment = optional ? patternSegment.slice(0, -1) : patternSegment;
611
535
  const dynamic = requiredPatternSegment.startsWith(':');
612
- const pathSegmentMatches =
613
- pathIndex < pathSegments.length &&
614
- (dynamic || requiredPatternSegment === pathSegments[pathIndex]);
536
+ const pathSegmentMatches = pathIndex < pathSegments.length && (dynamic || requiredPatternSegment === pathSegments[pathIndex]);
615
537
 
616
538
  if (optional) {
617
- return (
618
- matchSegments(patternIndex + 1, pathIndex) ||
619
- (pathSegmentMatches && matchSegments(patternIndex + 1, pathIndex + 1))
620
- );
539
+ return matchSegments(patternIndex + 1, pathIndex) || (pathSegmentMatches && matchSegments(patternIndex + 1, pathIndex + 1));
621
540
  }
622
541
 
623
542
  return pathSegmentMatches && matchSegments(patternIndex + 1, pathIndex + 1);
@@ -641,42 +560,29 @@ export function assertRouteHelperRouteExists(
641
560
  const pendingRoutes = Object.entries(routeManifest);
642
561
  let previousPendingRouteCount = -1;
643
562
 
644
- while (
645
- pendingRoutes.length &&
646
- pendingRoutes.length !== previousPendingRouteCount
647
- ) {
563
+ while (pendingRoutes.length && pendingRoutes.length !== previousPendingRouteCount) {
648
564
  previousPendingRouteCount = pendingRoutes.length;
649
565
 
650
566
  for (let index = pendingRoutes.length - 1; index >= 0; index -= 1) {
651
567
  const [routeId, route] = pendingRoutes[index];
652
- const parentPath = route.parentId
653
- ? routePathsById.get(route.parentId)
654
- : '';
568
+ const parentPath = route.parentId ? routePathsById.get(route.parentId) : '';
655
569
 
656
570
  if (route.parentId && parentPath === undefined) {
657
571
  continue;
658
572
  }
659
573
 
660
- const routePath = route.path?.startsWith('/')
661
- ? route.path
662
- : [parentPath, route.path].filter(Boolean).join('/');
574
+ const routePath = route.path?.startsWith('/') ? route.path : [parentPath, route.path].filter(Boolean).join('/');
663
575
  routePathsById.set(routeId, `/${routePath}`.replace(/\/+/g, '/'));
664
576
  pendingRoutes.splice(index, 1);
665
577
  }
666
578
  }
667
579
 
668
580
  const clientRoutePatterns = Array.from(new Set(routePathsById.values()));
669
- const samplePath = routePath.endsWith('/')
670
- ? `${routePath}__route_helper_validation__`
671
- : routePath;
672
- const routeExists = clientRoutePatterns.some((routePattern) =>
673
- doesClientRoutePatternMatchPath(routePattern, samplePath),
674
- );
581
+ const samplePath = routePath.endsWith('/') ? `${routePath}__route_helper_validation__` : routePath;
582
+ const routeExists = clientRoutePatterns.some((routePattern) => doesClientRoutePatternMatchPath(routePattern, samplePath));
675
583
 
676
584
  if (!routeExists) {
677
- throw new Error(
678
- `Route registered in ROUTES_DICT is missing from the client app: ${routePath}`,
679
- );
585
+ throw new Error(`Route registered in ROUTES_DICT is missing from the client app: ${routePath}`);
680
586
  }
681
587
  }
682
588
 
@@ -688,7 +594,7 @@ function getSidebarSlugFromRoutePath(routePath: string | null | undefined) {
688
594
  return 'home';
689
595
  }
690
596
 
691
- return normalizeSidebarRouteSlug(routePath);
597
+ return getNormalizedSidebarSlug(routePath);
692
598
  }
693
599
 
694
600
  /*
@@ -710,10 +616,7 @@ function getNavigationItemFromSidebarItem(
710
616
  }
711
617
 
712
618
  const routeDict = ROUTES_DICT[route.routePath];
713
- const fallbackText =
714
- routeDict.text && i18n.has(routeDict.text)
715
- ? i18n.t(routeDict.text)
716
- : routeDict.text;
619
+ const fallbackText = routeDict.text && i18n.has(routeDict.text) ? i18n.t(routeDict.text) : routeDict.text;
717
620
 
718
621
  return {
719
622
  slug: route.slug,
@@ -726,9 +629,7 @@ function getNavigationItemFromSidebarItem(
726
629
  /*
727
630
  * Return whether a navigation item is a visual break.
728
631
  */
729
- function isNavigationBreakItem(
730
- item: NavigationItem | null,
731
- ): item is NavBreakItem {
632
+ function isNavigationBreakItem(item: NavigationItem | null): item is NavBreakItem {
732
633
  return !!item && 'break' in item && !!item.break;
733
634
  }
734
635
 
@@ -768,11 +669,7 @@ function getNavigationGroupFromSidebarItem(
768
669
  return null;
769
670
  }
770
671
 
771
- const navList = getCustomizedNestedNavigationList(
772
- item.items,
773
- operation,
774
- checkACLClient,
775
- );
672
+ const navList = getCustomizedNestedNavigationList(item.items, operation, checkACLClient);
776
673
 
777
674
  return {
778
675
  text: item.label || '',
@@ -815,14 +712,7 @@ function getCustomizedNestedNavigationList(
815
712
 
816
713
  const navList = sidebar.reduce(
817
714
  (acc, item) => {
818
- const navItem =
819
- item.kind === 'GROUP'
820
- ? null
821
- : getNavigationItemFromCustomSidebarItem(
822
- item,
823
- operation,
824
- checkACLClient,
825
- );
715
+ const navItem = item.kind === 'GROUP' ? null : getNavigationItemFromCustomSidebarItem(item, operation, checkACLClient);
826
716
 
827
717
  if (navItem && !('navList' in navItem)) {
828
718
  acc.push(navItem);
@@ -845,11 +735,7 @@ function getCustomizedNavigationList(
845
735
  checkACLClient?: CheckACLClientFn | null,
846
736
  ): NavigationItem[] {
847
737
  const navList = sidebar.reduce((acc, item) => {
848
- const navItem = getNavigationItemFromCustomSidebarItem(
849
- item,
850
- operation,
851
- checkACLClient,
852
- );
738
+ const navItem = getNavigationItemFromCustomSidebarItem(item, operation, checkACLClient);
853
739
 
854
740
  if (navItem) {
855
741
  acc.push(navItem);
@@ -876,10 +762,7 @@ function mapNavigationList(
876
762
  if (item?.navList) {
877
763
  item.navList = item.navList.reduce((acc: any[], x: any, i: number) => {
878
764
  const mappedItem = mapNavItems(x);
879
- if (
880
- mappedItem &&
881
- (mappedItem.to || (acc.length && i !== item.navList.length - 1))
882
- ) {
765
+ if (mappedItem && (mappedItem.to || (acc.length && i !== item.navList.length - 1))) {
883
766
  if (mappedItem.text && i18n.has(mappedItem.text)) {
884
767
  mappedItem.text = i18n.t(mappedItem.text);
885
768
  }
@@ -891,10 +774,7 @@ function mapNavigationList(
891
774
  if (!item.navList.length) {
892
775
  return null;
893
776
  }
894
- } else if (
895
- item?.to &&
896
- !isRouteAllowed(item.to, operation, checkACLClient)
897
- ) {
777
+ } else if (item?.to && !isRouteAllowed(item.to, operation, checkACLClient)) {
898
778
  return null;
899
779
  }
900
780
 
@@ -912,12 +792,23 @@ function mapNavigationList(
912
792
  return navListArr.map(mapNavItems).filter(Boolean);
913
793
  }
914
794
 
795
+ /*
796
+ * Return optional links available in Workspace and sidebar customization, outside the default sidebar.
797
+ */
798
+ export function getOptionalNavigationItems(
799
+ operation: OrganizationOperationEnum | null,
800
+ checkACLClient?: CheckACLClientFn | null,
801
+ ): NavigationItem[] {
802
+ return mapNavigationList([{ ...ROUTES_DICT['/app/workflows'] }, { ...ROUTES_DICT['/app/qrcodes'] }], operation, checkACLClient);
803
+ }
804
+
915
805
  /*
916
806
  * Return the default operation-specific sidebar list without pinned Home or Workspace links.
917
807
  */
918
808
  export function getDefaultNav(
919
809
  operation: OrganizationOperationEnum | null,
920
810
  checkACLClient?: CheckACLClientFn | null,
811
+ _defaultSurface?: 'PROJECT' | 'COVERAGE' | null,
921
812
  ): NavigationItem[] {
922
813
  const breakItem = {
923
814
  break: true,
@@ -946,6 +837,14 @@ export function getDefaultNav(
946
837
  },
947
838
  ];
948
839
  break;
840
+ case 'FOOD_MANUFACTURING':
841
+ navListArr = [
842
+ {
843
+ text: i18n.t(`org.type_active.${operation}`),
844
+ navList: [ROUTES_DICT['/app/temperature'], ROUTES_DICT['/app/inspections']],
845
+ },
846
+ ];
847
+ break;
949
848
  case 'FARMERS_MARKET':
950
849
  navListArr = [
951
850
  {
@@ -967,17 +866,28 @@ export function getDefaultNav(
967
866
  }
968
867
 
969
868
  navListArr = navListArr.concat([
869
+ // Schedule and projects are not ready.
870
+ // {
871
+ // text: i18n.t('schedule.title'),
872
+ // initialExpanded: true,
873
+ // navList:
874
+ // (_defaultSurface || getScheduleDefaultSurface(operation)) === 'PROJECT'
875
+ // ? [ROUTES_DICT['/app/projects'], ROUTES_DICT['/app/calendar']]
876
+ // : [ROUTES_DICT['/app/calendar'], ROUTES_DICT['/app/projects']],
877
+ // },
970
878
  {
971
- text: i18n.t('form.advanced'),
879
+ text: i18n.t('campaign.outbound'),
880
+ initialExpanded: true,
881
+ navList: [ROUTES_DICT['/app/outbound/forms'], ROUTES_DICT['/app/outbound/emails']],
882
+ },
883
+ {
884
+ text: i18n.t('c.advanced'),
972
885
  initialExpanded: true,
973
886
  navList: [
974
887
  // 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
888
  ROUTES_DICT['/app/logs'],
889
+ ROUTES_DICT['/app/emails'],
890
+ // ROUTES_DICT['/app/downloads'],
981
891
  ],
982
892
  },
983
893
  ]);
@@ -992,6 +902,7 @@ export function getNavigationList(
992
902
  operation: OrganizationOperationEnum | null,
993
903
  checkACLClient?: CheckACLClientFn | null,
994
904
  sidebar?: OrganizationSidebarItemObj[] | null,
905
+ defaultSurface?: 'PROJECT' | 'COVERAGE' | null,
995
906
  ): NavigationItem[] {
996
907
  const breakItem = { break: true };
997
908
  const pinnedNavList = mapNavigationList(
@@ -1009,7 +920,31 @@ export function getNavigationList(
1009
920
 
1010
921
  const remainingNavList = Array.isArray(sidebar)
1011
922
  ? getCustomizedNavigationList(sidebar, operation, checkACLClient)
1012
- : getDefaultNav(operation, checkACLClient);
1013
-
1014
- return pinnedNavList.concat(remainingNavList);
1015
- }
923
+ : getDefaultNav(operation, checkACLClient, defaultSurface);
924
+
925
+ const result = pinnedNavList.concat(remainingNavList);
926
+ // Schedule and projects are not ready.
927
+ // const missingSchedule = [
928
+ // ROUTES_DICT['/app/calendar'],
929
+ // ROUTES_DICT['/app/projects'],
930
+ // ].filter((route) => !hasNavigationDestination(result, route.to!));
931
+ // return result.concat(
932
+ // mapNavigationList(missingSchedule, operation, checkACLClient),
933
+ // );
934
+ return result;
935
+ }
936
+
937
+ // Schedule and projects are not ready.
938
+ // /* Find a schedule destination in customized groups before appending required navigation. */
939
+ // function hasNavigationDestination(
940
+ // items: NavigationItem[],
941
+ // destination: string,
942
+ // ): boolean {
943
+ // return items.some(
944
+ // (item) =>
945
+ // item.to === destination ||
946
+ // ('navList' in item && item.navList
947
+ // ? hasNavigationDestination(item.navList, destination)
948
+ // : false),
949
+ // );
950
+ // }