@jsb188/mday-web 1.1.10 → 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.
Files changed (38) hide show
  1. package/package.json +36 -24
  2. package/src/libs/route-metadata.server.ts +67 -0
  3. package/src/modules/Grids.filters.ts +36 -0
  4. package/src/modules/Grids.tsx +610 -0
  5. package/src/modules/RouteShell.tsx +76 -0
  6. package/src/schemas/organization.ts +128 -0
  7. package/src/utils/email.ts +117 -0
  8. package/src/utils/list-web.ts +17 -0
  9. package/src/utils/log-web.helpers.ts +99 -0
  10. package/src/utils/log-web.icons.ts +184 -0
  11. package/src/utils/log-web.ts +74 -364
  12. package/src/utils/operation-pages.ts +154 -0
  13. package/src/utils/org-web.ts +35 -8
  14. package/src/utils/route-helpers.ts +837 -596
  15. package/src/utils/workflow-web.ts +72 -0
  16. package/tests/log-web.test.ts +134 -0
  17. package/tests/route-helpers.test.ts +17 -0
  18. package/tsconfig.json +11 -11
  19. package/src/modules/DataTable-ContextMenu.tsx +0 -169
  20. package/src/modules/DataTable-InboundContact.tsx +0 -523
  21. package/src/modules/DataTable.tsx +0 -5060
  22. package/src/modules/Sheet-ContextMenu.tsx +0 -161
  23. package/src/modules/Sheet.tsx +0 -28
  24. package/src/modules/cell-save-beacon.ts +0 -67
  25. package/src/modules/dataTable-interaction-state.ts +0 -276
  26. package/src/modules/dataTable-shortcuts.ts +0 -192
  27. package/src/modules/dataTable-viewport.ts +0 -89
  28. package/src/modules/grid-cell-render.ts +0 -72
  29. package/src/modules/grid-context-menu.ts +0 -112
  30. package/src/modules/grid-keyboard.ts +0 -267
  31. package/src/modules/grid-render-store.ts +0 -103
  32. package/src/modules/grid-runtime.ts +0 -178
  33. package/src/modules/grid-selection.ts +0 -336
  34. package/src/modules/grid-viewport.ts +0 -57
  35. package/src/modules/use-dataTable-states.ts +0 -529
  36. package/src/modules/use-debounced-cell-save-batch.ts +0 -160
  37. package/tests/DataTable.test.tsx +0 -4466
  38. package/tests/dataTable-interaction-state.test.ts +0 -127
@@ -1,355 +1,44 @@
1
1
  import { formatCurrency } from '@jsb188/app/utils/number.ts';
2
+ import type { OrganizationOperationEnum } from '@jsb188/mday/types/organization.d.ts';
2
3
  import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
3
4
 
4
- const ARABLE_ICON_WORD_GROUPS: [string, string[]][] = [
5
- ['vegetable-lettuce-top', ['little gem', 'lil gem', 'marciano', 'red butter', 'green gem', 'red gem', 'gems\\b', 'spretnak', 'newham', 'bokchoy', 'bok choy']],
6
- ['vegetable-lettuce', ['lettuce', 'red oak', 'romaine', 'escarol', 'radicchio', 'braci ardenti', 'braci adenti', 'di lusia', 'di lusio', 'treviso', 'thaddeus', 'cruced\\b']],
7
- ['vegetable-lavender', ['lavendar', 'lavender', 'anise hyssop', 'alyssum']],
8
- ['vegetable-basil', ['basil']],
9
- ['vegetable-beet', ['chioggia', 'beet', 'yellow tooth']],
10
- ['vegetable-broccoli', ['cauliflow', 'broccoli', 'piracicab']],
11
- ['vegetable-pumpkin', ['pumpkin', 'pump\\b', 'cargo pump', 'bennings green', 'benning']],
12
- ['vegetable-spinach', ['mesclun', 'spinach', 'chard', 'mustard green', 'mix\\b']],
13
- ['vegetable-tomato', ['tomato']],
14
- ['fruit-grapes', ['grapes']],
15
- ['fruit-apricot', ['apricot', 'peach', 'plum']],
16
- ['raspberry', ['raspberr']],
17
- ['fruit-cloud-berry', ['blackberr', 'cloudberr', 'cloud berr']],
18
- ['fruit-billberry-blackberry-blueberry', ['blueberr', 'billberr', 'berry', '\\w*berr(?:y|ies)\\b']],
19
- ['vegetable-asparagus', ['asparagus']],
20
- ['vegetable-acornsquash', ['sunshine kabocha', 'acorn squash', 'acornsquash', 'yellow star patty', 'sweet pepper', 'bell pepper']],
21
- ['fruit-strawberry', ['strawberr']], // commented now for testing
22
- ['seasoning-chilli', ['pepper', 'chilli']],
23
- ['vegetable-delicata-squash', ['delicata', 'delicata squash']],
24
- ['vegetable-hubbard-squash', ['hubbard squash', 'hubbard', 'red kuri']],
25
- ['vegetable-cucumber', ['shinto', 'cucumber', 'pickle']],
26
- ['vegetable-butternutsquash', ['butternut squash', 'butternutsquash', 'butternut', 'squash', 'starry night']],
27
- ['vegetable-thyme', ['summar savor', 'summer savor', 'summery savor', 'summary savor', 'thyme', 'rosemary', 'savory']],
28
- ['vegetable-arugula', ['arugula', 'chicory', 'puntarelle', 'frisee', 'kale', 'dino', 'green curl']],
29
- ['vegetable-parsley', ['parsley', 'beoc raab', 'wasabina', 'chervil']],
30
- ['vegetable-carrot', ['carrot']],
31
- ['vegetable-artichoke', ['artichoke', 'romanesco', 'star\\b', 'stars\\b']],
32
- ['vegetable-cabbage', ['cabbag']],
33
- ['vegetable-kohlrabi', ['kohlrab']],
34
- ['vegetable-zucchini', ['zucchini', 'zuchini', 'midnight light']],
35
- ['vegetable-potato', ['potato']],
36
- ['vegetable-eggplant', ['eggplant']],
37
- ['vegetable-jalapeno', ['jalapeno', 'jalapeño']],
38
- ['vegetable-stinging-kettle', ['stinging kettle', 'nettle', 'cardoon', 'cynara cardunculus', 'cardunculus', 'cresta', 'shiso']],
39
- ['vegetable-okra', ['okra']],
40
- ['plant-1', ['sage\\b', 'sages\\b', 'marjoram', 'sorrel', 'mint']],
41
- ['vegetable-scallion', ['scallion', 'scalion', 'spring onion', 'springonion']],
42
- ['gardening-seed-bag', ['seed']],
43
- ['vegetable-onion', ['onion', 'shallot', 'matador']],
44
- ['vegetable-black-bean', ['oliv']],
45
- ['vegetable-stringbean-1', ['bean', 'stringbean']],
46
- ['vegetable-cilantro', ['cilantro', 'flor\\b']],
47
- ['vegetable-radish', ['raddish', 'radish']],
48
- ['vegetable-wasabi', ['wasabi']],
49
- ['flower', ['flower']],
50
- ['product-growth-tree-box', ['soil']],
51
- ['gardening-sprinkler', ['irrigation']],
52
- ['agriculture-machine-seeder', ['direct seed']],
53
- ['organic-bag-leaf', ['fertilization']],
54
- ['gardening-tools-1', ['crop protection']],
55
- ['farming-barn-sun', ['crop monitoring', 'field']],
56
- ['gardening-scissors', ['pruning']],
57
- ['barbed-wire-fence', ['trellising']],
58
- ['protein-gluten-wheat', ['preparing crops']],
59
- ['harvest-product', ['crops', 'grading produce', 'moving produce']],
60
- ['crop-info-biotech-1', ['estimating yield', 'other harvest']],
61
- ['warehouse-storage', ['post harvest']],
62
- ['temperature-control-warehouse-1', ['cold storage temperature']],
63
- ['receipt-dollar', ['sale']],
64
- ['organic-flask', ['water testing', 'chlorine level']],
65
- ];
66
-
67
- const ARABLE_ICON_PRIORITY_WORDS = [
68
- 'little gem',
69
- 'lil gem',
70
- 'romaine',
71
- 'cauliflow',
72
- 'broccoli',
73
- 'piracicab',
74
- 'mesclun',
75
- 'spinach',
76
- 'mustard green',
77
- 'arugula',
78
- 'kale',
79
- 'kohlrab',
80
- 'cabbag',
81
- 'parsley',
82
- 'beoc raab',
83
- 'wasabina',
84
- 'chervil',
85
- 'basil',
86
- 'artichoke',
87
- 'romanesco',
88
- 'zucchini',
89
- 'zuchini',
90
- 'potato',
91
- 'eggplant',
92
- 'jalapeno',
93
- 'jalapeño',
94
- 'carrot',
95
- 'midnight light',
96
- 'cilantro',
97
- 'bennings green',
98
- 'lettuce',
99
- 'escarol',
100
- 'raddish',
101
- 'radish',
102
- 'bean',
103
- 'stringbean',
104
- 'oliv',
105
- 'stinging kettle',
106
- 'radicchio',
107
- 'braci ardenti',
108
- 'braci adenti',
109
- 'chicory',
110
- 'puntarelle',
111
- 'chioggia',
112
- 'beet',
113
- 'thaddeus',
114
- 'sunshine kabocha',
115
- 'yellow star patty',
116
- 'butternut squash',
117
- 'butternutsquash',
118
- 'asparagus',
119
- 'acorn squash',
120
- 'acornsquash',
121
- 'delicata squash',
122
- 'hubbard squash',
123
- 'hubbard',
124
- 'red kuri',
125
- 'squash',
126
- 'cargo pump',
127
- 'pumpkin',
128
- 'cucumber',
129
- 'pickle',
130
- 'shiso',
131
- 'shinto',
132
- 'thyme',
133
- 'rosemary',
134
- 'di lusia',
135
- 'di lusio',
136
- 'treviso',
137
- 'scallion',
138
- 'scalion',
139
- 'spring onion',
140
- 'springonion',
141
- 'onion',
142
- 'shallot',
143
- 'wasabi',
144
- 'lavendar',
145
- 'lavender',
146
- 'anise hyssop',
147
- 'alyssum',
148
- 'marjoram',
149
- 'mint',
150
- 'sorrel',
151
- 'tomato',
152
- 'grapes',
153
- 'apricot',
154
- 'peach',
155
- 'plum',
156
- 'blueberr',
157
- 'billberr',
158
- 'blackberr',
159
- 'raspberr',
160
- 'cloudberr',
161
- 'cloud berr',
162
- 'sweet pepper',
163
- 'bell pepper',
164
- 'strawberr',
165
- '\\w*berr(?:y|ies)\\b',
166
- 'berry',
167
-
168
- // Leave at end for backup
169
- 'marciano',
170
- 'spretnak',
171
- 'newham',
172
- 'bokchoy',
173
- 'bok choy',
174
- 'red butter',
175
- 'frisee',
176
- 'cresta',
177
- 'cardoon',
178
- 'cynara cardunculus',
179
- 'cardunculus',
180
- 'butternut',
181
- 'green gem',
182
- 'red gem',
183
- 'starry night',
184
- 'benning',
185
- 'summar savor',
186
- 'summer savor',
187
- 'summery savor',
188
- 'summary savor',
189
- 'delicata',
190
- 'matador',
191
- 'green curl',
192
- 'red oak',
193
- 'flower',
194
- 'yellow tooth',
195
- 'sage\\b',
196
- 'sages\\b',
197
- 'okra',
198
- 'flor\\b',
199
- 'gems\\b',
200
- 'pump\\b',
201
- 'cruced\\b',
202
- 'star\\b',
203
- 'stars\\b',
204
- 'seed',
205
- 'pepper',
206
- 'chilli',
207
- 'mix\\b',
208
- 'chard',
209
- 'nettle',
210
- 'savory',
211
- 'dino',
212
-
213
- // log activities
214
- // NOTE: If i18n words change, these have to change too
215
- 'soil',
216
- 'irrigation',
217
- 'fertilization',
218
- 'crop protection',
219
- 'crop monitoring',
220
- 'direct seed',
221
- 'pruning',
222
- 'trellising',
223
- 'preparing crops',
224
- 'crops',
225
- 'estimating yield',
226
- 'other harvest',
227
- 'grading produce',
228
- 'moving produce',
229
- 'cold storage temperature',
230
- 'post harvest',
231
- 'sale',
232
- 'water testing',
233
- 'chlorine level',
234
- 'field',
235
- ];
236
- const ARABLE_ICON_BY_WORD = new Map(
237
- ARABLE_ICON_WORD_GROUPS.flatMap(([iconName, words]) => words.map((word) => [normalizeIconMatchWord(word), iconName])),
238
- );
239
- const ARABLE_WORD_REGEX = new RegExp(`\\b(${ARABLE_ICON_PRIORITY_WORDS.join('|')})`, 'gi');
240
- const ARABLE_ICON_PRIORITY_MATCHERS = ARABLE_ICON_PRIORITY_WORDS.map((word) => [word, new RegExp(`^${word}$`, 'i')] as const);
5
+ import { matchIconName } from './log-web.helpers.ts';
6
+ import {
7
+ ARABLE_ICON_MATCHERS,
8
+ FARMERS_MARKET_ICON_MATCHERS,
9
+ FOOD_MANUFACTURING_DEFAULT_ICON,
10
+ FOOD_MANUFACTURING_ICON_MATCHERS,
11
+ } from './log-web.icons.ts';
241
12
 
242
13
  /*
243
- * Normalize a matched icon word so regex-only word boundary markers do not affect map lookups.
14
+ * Select a crop icon by tier and specificity, falling back to notes only when the crop has no match.
244
15
  */
245
- function normalizeIconMatchWord(word: string): string {
246
- return word.replace(/\\b/g, '').toLowerCase();
16
+ export function getIconNameForArable(crop?: string | undefined, note?: string | null, defaultIcon?: string): string {
17
+ return matchIconName(ARABLE_ICON_MATCHERS, crop) || matchIconName(ARABLE_ICON_MATCHERS, note) || defaultIcon || 'seedling';
247
18
  }
248
19
 
249
20
  /*
250
- * Pick the highest-priority arable icon word from a list of regex matches.
251
- */
252
- function getPreferredArableIconWord(matches: string[]): string {
253
- if (matches.length === 1) {
254
- const matchedPriorityWord = ARABLE_ICON_PRIORITY_MATCHERS.find(([, regex]) => regex.test(matches[0]))?.[0];
255
-
256
- return normalizeIconMatchWord(matchedPriorityWord || matches[0]);
257
- }
258
-
259
- const preferredWord = ARABLE_ICON_PRIORITY_MATCHERS.find(([, regex]) => matches.some((match) => regex.test(match)))?.[0];
260
-
261
- return preferredWord ? normalizeIconMatchWord(preferredWord) : normalizeIconMatchWord(matches[0]);
262
- }
263
-
264
- /**
265
- * Get the icon name from crop name by using regex
266
- * @param crop - The name of the crop
267
- * @param note - Additional note that may contain crop type
268
- * @param defaultIcon - The default icon to return if no match is found
269
- * @returns The icon name or a default icon if no match is found
21
+ * Select a market item icon using the same matching rules and item-before-notes fallback as crops.
270
22
  */
271
-
272
- export function getIconNameForArable(crop?: string | undefined, note?: string | null, defaultIcon?: string): string {
273
- if (crop) {
274
- const match = crop.replace(/-/g, ' ').match(ARABLE_WORD_REGEX);
275
- if (match) {
276
- const matchedWord = getPreferredArableIconWord(match);
277
- const iconName = ARABLE_ICON_BY_WORD.get(matchedWord);
278
-
279
- if (iconName) {
280
- return iconName;
281
- }
282
-
283
- console.log('Missing icon lookup for crop:', crop);
284
- }
285
-
286
- // console.log('No match found for crop:', crop);
287
- }
288
-
289
- if (note) {
290
- return getIconNameForArable(note, null, defaultIcon);
291
- }
292
-
293
- return defaultIcon || 'seedling';
23
+ export function getIconNameForFarmersMarket(purchasedItem?: string | null, note?: string | null, defaultIcon?: string): string {
24
+ return (
25
+ matchIconName(FARMERS_MARKET_ICON_MATCHERS, purchasedItem) ||
26
+ matchIconName(FARMERS_MARKET_ICON_MATCHERS, note) ||
27
+ defaultIcon ||
28
+ 'farmers-market-kiosk'
29
+ );
294
30
  }
295
31
 
296
- /**
297
- * Get the icon name for farmers market using regex
298
- * @param purchasedItem - The name of the purchased item
299
- * @param note - Additional note that may contain livestock type
300
- * @param defaultIcon - The default icon to return if no match is found
301
- * @returns The icon name or a default icon if no match is found
32
+ /*
33
+ * Select a food manufacturing icon from the item, then notes, defaulting to meal-can unless the caller supplies a fallback.
302
34
  */
303
-
304
- export function getIconNameForFarmersMarket(
305
- purchasedItem?: string | null,
306
- note?: string | null,
307
- defaultIcon?: string,
308
- ): string {
309
- if (purchasedItem) {
310
- // return 'seedling';
311
- const FARMERS_MARKET_WORDS = [
312
- 'hay\\b',
313
- 'cow',
314
- 'calf',
315
- 'cattle',
316
- 'bull',
317
- 'sheep',
318
- ];
319
-
320
- const regex = new RegExp(`\\b(${FARMERS_MARKET_WORDS.join('|')})`, 'gi');
321
- const match = purchasedItem.replace('-', ' ').match(regex);
322
- if (match) {
323
- let matchedWord;
324
- if (match.length === 1) {
325
- matchedWord = match[0].toLowerCase();
326
- } else {
327
- // If multiple matches, choose the first match from produce words
328
- const lcMatch = match.map((m) => m.toLowerCase());
329
- matchedWord = FARMERS_MARKET_WORDS.find((word) => lcMatch.includes(word));
330
- }
331
-
332
- switch (matchedWord) {
333
- case 'hay':
334
- return 'farming-hay';
335
- case 'cow':
336
- case 'calf':
337
- case 'cattle':
338
- case 'bull':
339
- return 'livestock-cow-body';
340
- default:
341
- console.log('Missing switchcase for crop:', purchasedItem);
342
- }
343
- }
344
-
345
- // console.log('No match found for farmers market:', purchasedItem);
346
- }
347
-
348
- if (note) {
349
- return getIconNameForFarmersMarket(note, null, defaultIcon);
350
- }
351
-
352
- return defaultIcon || 'farmers-market-kiosk';
35
+ export function getIconNameForFoodManufacturing(item?: string | null, note?: string | null, defaultIcon?: string): string {
36
+ return (
37
+ matchIconName(FOOD_MANUFACTURING_ICON_MATCHERS, item) ||
38
+ matchIconName(FOOD_MANUFACTURING_ICON_MATCHERS, note) ||
39
+ defaultIcon ||
40
+ FOOD_MANUFACTURING_DEFAULT_ICON
41
+ );
353
42
  }
354
43
 
355
44
  /**
@@ -360,11 +49,7 @@ export function getIconNameForFarmersMarket(
360
49
  * @returns The icon name or a default icon if no match is found
361
50
  */
362
51
 
363
- export function getIconNameForGrowerNetwork(
364
- _item?: string | null,
365
- _note?: string | null,
366
- _defaultIcon?: string,
367
- ): string {
52
+ export function getIconNameForGrowerNetwork(_item?: string | null, _note?: string | null, _defaultIcon?: string): string {
368
53
  return 'circle';
369
54
  }
370
55
 
@@ -372,21 +57,15 @@ export function getIconNameForGrowerNetwork(
372
57
  * Get any icon name for any word
373
58
  */
374
59
 
375
- export function getIconNameForWord(
376
- decidingWord: any,
377
- text1: string,
378
- text2?: string | null,
379
- defaultIcon?: string,
380
- ) {
381
- switch (decidingWord) {
382
- case 'ARABLE':
383
- case 'LogArable':
60
+ export function getIconNameForWord(decidingWord: any, text1: string, text2?: string | null, defaultIcon?: string) {
61
+ switch (decidingWord) {
62
+ case 'ARABLE':
384
63
  return getIconNameForArable(text1, text2, defaultIcon);
385
- case 'FARMERS_MARKET':
386
- case 'LogFarmersMarket':
64
+ case 'FARMERS_MARKET':
387
65
  return getIconNameForFarmersMarket(text1, text2, defaultIcon);
66
+ case 'FOOD_MANUFACTURING':
67
+ return getIconNameForFoodManufacturing(text1, text2, defaultIcon);
388
68
  case 'GROWER_NETWORK':
389
- case 'LogGrowerNetwork':
390
69
  return getIconNameForGrowerNetwork(text1, text2, defaultIcon);
391
70
  default:
392
71
  }
@@ -394,9 +73,18 @@ export function getIconNameForWord(
394
73
  }
395
74
 
396
75
  /**
397
- * Get icon name for any operation using regex
76
+ * Return the shared icon for one log activity-group key.
77
+ */
78
+ export function getLogActivityGroupIconName(activityGroup?: string | null) {
79
+ return COMMON_ICON_NAMES[activityGroup || 'UNKNOWN'] || COMMON_ICON_NAMES.UNKNOWN;
80
+ }
81
+
82
+ /**
83
+ * Get an operation's text-matched icon. Food manufacturing defaults to meal-can for unmatched text;
84
+ * other non-legacy operations use activity, group, or caller-provided fallback icons.
398
85
  * @param details - GraphQL log details object
399
86
  * @param defaultIcon - The default icon to return if no match is found
87
+ * @param orgOperation - The organization's operation; when omitted, the operation is inferred from the log type (legacy behavior)
400
88
  * @returns The icon name or a default icon if no match is found
401
89
  */
402
90
 
@@ -404,16 +92,36 @@ export function getIconNameForLog(
404
92
  details: any,
405
93
  preferActivityText?: boolean,
406
94
  defaultIcon_?: string,
95
+ orgOperation?: OrganizationOperationEnum | null,
407
96
  ) {
97
+ if (orgOperation === 'FOOD_MANUFACTURING') {
98
+ return getIconNameForFoodManufacturing(
99
+ preferActivityText ? details.activity : details.item,
100
+ preferActivityText ? `${details.title || ''} ${details.notes || ''}` : details.notes,
101
+ defaultIcon_,
102
+ );
103
+ }
104
+
105
+ // Non-legacy operations can share group keys with legacy operations (e.g. OPERATION), so only the org's operation can tell them apart
106
+ if (orgOperation && !['ARABLE', 'FARMERS_MARKET', 'GROWER_NETWORK'].includes(orgOperation)) {
107
+ return COMMON_ICON_NAMES[details.activity] || COMMON_ICON_NAMES[details.type] || defaultIcon_ || COMMON_ICON_NAMES.logs;
108
+ }
109
+
408
110
  // "crop" is deprecation support -- it should be "item" going forward
409
111
  const text1 = preferActivityText ? details.activity : details.item;
410
- const text2 = preferActivityText ? (details.title + ' ' + details.notes) : details.notes;
112
+ const text2 = preferActivityText ? details.title + ' ' + details.notes : details.notes;
411
113
  // @ts-ignore - allow dynamic key access
412
114
  const defaultIcon = (preferActivityText && COMMON_ICON_NAMES[details.activity]) || defaultIcon_;
413
115
 
414
116
  // console.log('defaultIcon', preferActivityText, details.activity, defaultIcon);
415
117
 
416
- return getIconNameForWord(details.__typename, text1, text2, defaultIcon);
118
+ const operation = String(details.type || '').startsWith('MARKET_')
119
+ ? 'FARMERS_MARKET'
120
+ : ['WORKER_PRACTICE', 'PRODUCTION_INPUT'].includes(details.type)
121
+ ? 'GROWER_NETWORK'
122
+ : 'ARABLE';
123
+
124
+ return getIconNameForWord(operation, text1, text2, defaultIcon);
417
125
  }
418
126
 
419
127
  /**
@@ -421,13 +129,15 @@ export function getIconNameForLog(
421
129
  */
422
130
 
423
131
  export function getTitleForLog(details: any): string {
424
- switch (details.__typename) {
425
- case 'LogFarmersMarket':
132
+ switch (details.type) {
133
+ case 'MARKET_RECEIPT':
426
134
  {
427
135
  // Check if text from values is short, else rely on the AI summary
428
- const valuesText = (details.values || []).map((item: any) => {
429
- return `${item.label} ${item.value ? formatCurrency(item.value, false) : ''}`.trim();
430
- }).join(', ');
136
+ const valuesText = (details.values || [])
137
+ .map((item: any) => {
138
+ return `${item.label} ${item.value ? formatCurrency(item.value, false) : ''}`.trim();
139
+ })
140
+ .join(', ');
431
141
 
432
142
  if (valuesText.length <= 40) {
433
143
  return valuesText;
@@ -0,0 +1,154 @@
1
+ import type { OrganizationOperationEnum } from '@jsb188/mday/types/organization.d.ts';
2
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
3
+
4
+ interface OperationPageDefinition {
5
+ slug: string;
6
+ titleKey: string;
7
+ metaTitleKey: string;
8
+ descriptionKey: string;
9
+ navigationTitleKey: string;
10
+ iconName: string;
11
+ allowedOperations: readonly OrganizationOperationEnum[];
12
+ }
13
+
14
+ export const OPERATION_PAGES = {
15
+ greenhouse: {
16
+ slug: 'greenhouse',
17
+ titleKey: 'log.greenhouse_seeding',
18
+ metaTitleKey: 'log.greenhouse_seeding',
19
+ descriptionKey: 'app.meta_greenhouse_desc',
20
+ navigationTitleKey: 'log.greenhouse_seeding',
21
+ iconName: COMMON_ICON_NAMES.GREENHOUSE_SEEDING,
22
+ allowedOperations: ['ARABLE'],
23
+ },
24
+ seeding: {
25
+ slug: 'seeding',
26
+ titleKey: 'log.seeding',
27
+ metaTitleKey: 'log.seeding',
28
+ descriptionKey: 'app.meta_seeding_desc',
29
+ navigationTitleKey: 'log.seeding',
30
+ iconName: COMMON_ICON_NAMES.seeding,
31
+ allowedOperations: ['ARABLE'],
32
+ },
33
+ transplanting: {
34
+ slug: 'transplanting',
35
+ titleKey: 'log.transplanting',
36
+ metaTitleKey: 'log.transplanting',
37
+ descriptionKey: 'app.meta_transplanting_desc',
38
+ navigationTitleKey: 'log.transplanting',
39
+ iconName: COMMON_ICON_NAMES.transplanting,
40
+ allowedOperations: ['ARABLE'],
41
+ },
42
+ 'field-work': {
43
+ slug: 'field-work',
44
+ titleKey: 'log.field_work',
45
+ metaTitleKey: 'log.field_work',
46
+ descriptionKey: 'app.meta_field_work_desc',
47
+ navigationTitleKey: 'log.field_work',
48
+ iconName: COMMON_ICON_NAMES.field_work,
49
+ allowedOperations: ['ARABLE'],
50
+ },
51
+ harvested: {
52
+ slug: 'harvested',
53
+ titleKey: 'log.harvested',
54
+ metaTitleKey: 'log.harvested',
55
+ descriptionKey: 'app.meta_harvested_desc',
56
+ navigationTitleKey: 'log.harvested',
57
+ iconName: COMMON_ICON_NAMES.harvest,
58
+ allowedOperations: ['ARABLE'],
59
+ },
60
+ 'post-harvest': {
61
+ slug: 'post-harvest',
62
+ titleKey: 'log.post_harvest',
63
+ metaTitleKey: 'log.post_harvest',
64
+ descriptionKey: 'app.meta_post_harvest_desc',
65
+ navigationTitleKey: 'log.post_harvest',
66
+ iconName: COMMON_ICON_NAMES.post_harvest,
67
+ allowedOperations: ['ARABLE'],
68
+ },
69
+ purchases: {
70
+ slug: 'purchases',
71
+ titleKey: 'log.purchases',
72
+ metaTitleKey: 'log.purchases',
73
+ descriptionKey: 'app.meta_purchases_desc',
74
+ navigationTitleKey: 'log.purchases',
75
+ iconName: COMMON_ICON_NAMES.invoice,
76
+ allowedOperations: ['ARABLE'],
77
+ },
78
+ orders: {
79
+ slug: 'orders',
80
+ titleKey: 'c.sales_orders',
81
+ metaTitleKey: 'c.sales_orders',
82
+ descriptionKey: 'app.meta_orders_desc',
83
+ navigationTitleKey: 'c.sales_orders',
84
+ iconName: COMMON_ICON_NAMES.receipt,
85
+ allowedOperations: ['ARABLE'],
86
+ },
87
+ temperature: {
88
+ slug: 'temperature',
89
+ titleKey: 'log.temperature',
90
+ metaTitleKey: 'log.temperature',
91
+ descriptionKey: 'app.meta_temperature_desc',
92
+ navigationTitleKey: 'log.temperature',
93
+ iconName: COMMON_ICON_NAMES.temperature,
94
+ allowedOperations: ['FOOD_MANUFACTURING'],
95
+ },
96
+ inspections: {
97
+ slug: 'inspections',
98
+ titleKey: 'log.inspections',
99
+ metaTitleKey: 'log.inspections',
100
+ descriptionKey: 'app.meta_inspections_desc',
101
+ navigationTitleKey: 'log.inspections',
102
+ iconName: COMMON_ICON_NAMES.SITE_INSPECTION,
103
+ allowedOperations: ['FOOD_MANUFACTURING'],
104
+ },
105
+ receipts: {
106
+ slug: 'receipts',
107
+ titleKey: 'c.receipts',
108
+ metaTitleKey: 'c.market_receipts',
109
+ descriptionKey: 'app.meta_receipts_desc',
110
+ navigationTitleKey: 'c.market_receipts',
111
+ iconName: COMMON_ICON_NAMES.market_receipt,
112
+ allowedOperations: ['FARMERS_MARKET'],
113
+ },
114
+ vendors: {
115
+ slug: 'vendors',
116
+ titleKey: 'c.vendors',
117
+ metaTitleKey: 'c.vendors',
118
+ descriptionKey: 'app.meta_vendors_desc',
119
+ navigationTitleKey: 'c.vendors',
120
+ iconName: COMMON_ICON_NAMES.shop_vendor,
121
+ allowedOperations: ['FARMERS_MARKET'],
122
+ },
123
+ growers: {
124
+ slug: 'growers',
125
+ titleKey: 'org.growers',
126
+ metaTitleKey: 'org.growers',
127
+ descriptionKey: 'app.meta_growers_desc',
128
+ navigationTitleKey: 'org.growers',
129
+ iconName: COMMON_ICON_NAMES.growers,
130
+ allowedOperations: ['GROWER_NETWORK'],
131
+ },
132
+ } as const satisfies Record<string, OperationPageDefinition>;
133
+
134
+ export type OperationPageSlug = keyof typeof OPERATION_PAGES;
135
+ export type OperationPageMetadata = (typeof OPERATION_PAGES)[OperationPageSlug];
136
+
137
+ /*
138
+ * Return operation-page metadata only for an exact registered slug.
139
+ */
140
+ export function getOperationPageMetadata(page: string | null | undefined): OperationPageMetadata | null {
141
+ return page && Object.hasOwn(OPERATION_PAGES, page) ? OPERATION_PAGES[page as OperationPageSlug] : null;
142
+ }
143
+
144
+ /*
145
+ * Resolve an exact page slug only when it supports the organization's operation.
146
+ */
147
+ export function resolveOperationPage(
148
+ page: string | null | undefined,
149
+ operation: OrganizationOperationEnum | null | undefined,
150
+ ): OperationPageMetadata | null {
151
+ const metadata = getOperationPageMetadata(page);
152
+
153
+ return metadata?.allowedOperations.some((allowedOperation) => allowedOperation === operation) ? metadata : null;
154
+ }