@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,457 +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
- [
6
- 'vegetable-lettuce-top',
7
- [
8
- 'little gem',
9
- 'lil gem',
10
- 'marciano',
11
- 'red butter',
12
- 'green gem',
13
- 'red gem',
14
- 'gems\\b',
15
- 'spretnak',
16
- 'newham',
17
- 'bokchoy',
18
- 'bok choy',
19
- ],
20
- ],
21
- [
22
- 'vegetable-lettuce',
23
- [
24
- 'lettuce',
25
- 'red oak',
26
- 'romaine',
27
- 'escarol',
28
- 'radicchio',
29
- 'braci ardenti',
30
- 'braci adenti',
31
- 'di lusia',
32
- 'di lusio',
33
- 'treviso',
34
- 'thaddeus',
35
- 'cruced\\b',
36
- ],
37
- ],
38
- ['vegetable-lavender', ['lavendar', 'lavender', 'anise hyssop', 'alyssum']],
39
- ['vegetable-basil', ['basil']],
40
- ['vegetable-beet', ['chioggia', 'beet', 'yellow tooth']],
41
- ['vegetable-broccoli', ['cauliflow', 'broccoli', 'piracicab']],
42
- [
43
- 'vegetable-pumpkin',
44
- ['pumpkin', 'pump\\b', 'cargo pump', 'bennings green', 'benning'],
45
- ],
46
- [
47
- 'vegetable-spinach',
48
- ['mesclun', 'spinach', 'chard', 'mustard green', 'mix\\b'],
49
- ],
50
- ['vegetable-tomato', ['tomato']],
51
- ['fruit-grapes', ['grapes']],
52
- ['fruit-apricot', ['apricot', 'peach', 'plum']],
53
- ['raspberry', ['raspberr']],
54
- ['fruit-cloud-berry', ['blackberr', 'cloudberr', 'cloud berr']],
55
- [
56
- 'fruit-billberry-blackberry-blueberry',
57
- ['blueberr', 'billberr', 'berry', '\\w*berr(?:y|ies)\\b'],
58
- ],
59
- ['vegetable-asparagus', ['asparagus']],
60
- [
61
- 'vegetable-acornsquash',
62
- [
63
- 'sunshine kabocha',
64
- 'acorn squash',
65
- 'acornsquash',
66
- 'yellow star patty',
67
- 'sweet pepper',
68
- 'bell pepper',
69
- ],
70
- ],
71
- ['fruit-strawberry', ['strawberr']], // commented now for testing
72
- ['seasoning-chilli', ['pepper', 'chilli']],
73
- ['vegetable-delicata-squash', ['delicata', 'delicata squash']],
74
- ['vegetable-hubbard-squash', ['hubbard squash', 'hubbard', 'red kuri']],
75
- ['vegetable-cucumber', ['shinto', 'cucumber', 'pickle']],
76
- [
77
- 'vegetable-butternutsquash',
78
- [
79
- 'butternut squash',
80
- 'butternutsquash',
81
- 'butternut',
82
- 'squash',
83
- 'starry night',
84
- ],
85
- ],
86
- [
87
- 'vegetable-thyme',
88
- [
89
- 'summar savor',
90
- 'summer savor',
91
- 'summery savor',
92
- 'summary savor',
93
- 'thyme',
94
- 'rosemary',
95
- 'savory',
96
- ],
97
- ],
98
- [
99
- 'vegetable-arugula',
100
- [
101
- 'arugula',
102
- 'chicory',
103
- 'puntarelle',
104
- 'frisee',
105
- 'kale',
106
- 'dino',
107
- 'green curl',
108
- ],
109
- ],
110
- ['vegetable-parsley', ['parsley', 'beoc raab', 'wasabina', 'chervil']],
111
- ['vegetable-carrot', ['carrot']],
112
- ['vegetable-artichoke', ['artichoke', 'romanesco', 'star\\b', 'stars\\b']],
113
- ['vegetable-cabbage', ['cabbag']],
114
- ['vegetable-kohlrabi', ['kohlrab']],
115
- ['vegetable-zucchini', ['zucchini', 'zuchini', 'midnight light']],
116
- ['vegetable-potato', ['potato']],
117
- ['vegetable-eggplant', ['eggplant']],
118
- ['vegetable-jalapeno', ['jalapeno', 'jalapeño']],
119
- [
120
- 'vegetable-stinging-kettle',
121
- [
122
- 'stinging kettle',
123
- 'nettle',
124
- 'cardoon',
125
- 'cynara cardunculus',
126
- 'cardunculus',
127
- 'cresta',
128
- 'shiso',
129
- ],
130
- ],
131
- ['vegetable-okra', ['okra']],
132
- ['plant-1', ['sage\\b', 'sages\\b', 'marjoram', 'sorrel', 'mint']],
133
- [
134
- 'vegetable-scallion',
135
- ['scallion', 'scalion', 'spring onion', 'springonion'],
136
- ],
137
- ['gardening-seed-bag', ['seed']],
138
- ['vegetable-onion', ['onion', 'shallot', 'matador']],
139
- ['vegetable-black-bean', ['oliv']],
140
- ['vegetable-stringbean-1', ['bean', 'stringbean']],
141
- ['vegetable-cilantro', ['cilantro', 'flor\\b']],
142
- ['vegetable-radish', ['raddish', 'radish']],
143
- ['vegetable-wasabi', ['wasabi']],
144
- ['flower', ['flower']],
145
- ['product-growth-tree-box', ['soil']],
146
- ['gardening-sprinkler', ['irrigation']],
147
- ['agriculture-machine-seeder', ['direct seed']],
148
- ['organic-bag-leaf', ['fertilization']],
149
- ['gardening-tools-1', ['crop protection']],
150
- ['farming-barn-sun', ['crop monitoring', 'field']],
151
- ['gardening-scissors', ['pruning']],
152
- ['barbed-wire-fence', ['trellising']],
153
- ['protein-gluten-wheat', ['preparing crops']],
154
- ['harvest-product', ['crops', 'grading produce', 'moving produce']],
155
- ['crop-info-biotech-1', ['estimating yield', 'other harvest']],
156
- ['warehouse-storage', ['post harvest']],
157
- ['temperature-control-warehouse-1', ['cold storage temperature']],
158
- ['receipt-dollar', ['sale']],
159
- ['organic-flask', ['water testing', 'chlorine level']],
160
- ];
161
-
162
- const ARABLE_ICON_PRIORITY_WORDS = [
163
- 'little gem',
164
- 'lil gem',
165
- 'romaine',
166
- 'cauliflow',
167
- 'broccoli',
168
- 'piracicab',
169
- 'mesclun',
170
- 'spinach',
171
- 'mustard green',
172
- 'arugula',
173
- 'kale',
174
- 'kohlrab',
175
- 'cabbag',
176
- 'parsley',
177
- 'beoc raab',
178
- 'wasabina',
179
- 'chervil',
180
- 'basil',
181
- 'artichoke',
182
- 'romanesco',
183
- 'zucchini',
184
- 'zuchini',
185
- 'potato',
186
- 'eggplant',
187
- 'jalapeno',
188
- 'jalapeño',
189
- 'carrot',
190
- 'midnight light',
191
- 'cilantro',
192
- 'bennings green',
193
- 'lettuce',
194
- 'escarol',
195
- 'raddish',
196
- 'radish',
197
- 'bean',
198
- 'stringbean',
199
- 'oliv',
200
- 'stinging kettle',
201
- 'radicchio',
202
- 'braci ardenti',
203
- 'braci adenti',
204
- 'chicory',
205
- 'puntarelle',
206
- 'chioggia',
207
- 'beet',
208
- 'thaddeus',
209
- 'sunshine kabocha',
210
- 'yellow star patty',
211
- 'butternut squash',
212
- 'butternutsquash',
213
- 'asparagus',
214
- 'acorn squash',
215
- 'acornsquash',
216
- 'delicata squash',
217
- 'hubbard squash',
218
- 'hubbard',
219
- 'red kuri',
220
- 'squash',
221
- 'cargo pump',
222
- 'pumpkin',
223
- 'cucumber',
224
- 'pickle',
225
- 'shiso',
226
- 'shinto',
227
- 'thyme',
228
- 'rosemary',
229
- 'di lusia',
230
- 'di lusio',
231
- 'treviso',
232
- 'scallion',
233
- 'scalion',
234
- 'spring onion',
235
- 'springonion',
236
- 'onion',
237
- 'shallot',
238
- 'wasabi',
239
- 'lavendar',
240
- 'lavender',
241
- 'anise hyssop',
242
- 'alyssum',
243
- 'marjoram',
244
- 'mint',
245
- 'sorrel',
246
- 'tomato',
247
- 'grapes',
248
- 'apricot',
249
- 'peach',
250
- 'plum',
251
- 'blueberr',
252
- 'billberr',
253
- 'blackberr',
254
- 'raspberr',
255
- 'cloudberr',
256
- 'cloud berr',
257
- 'sweet pepper',
258
- 'bell pepper',
259
- 'strawberr',
260
- '\\w*berr(?:y|ies)\\b',
261
- 'berry',
262
-
263
- // Leave at end for backup
264
- 'marciano',
265
- 'spretnak',
266
- 'newham',
267
- 'bokchoy',
268
- 'bok choy',
269
- 'red butter',
270
- 'frisee',
271
- 'cresta',
272
- 'cardoon',
273
- 'cynara cardunculus',
274
- 'cardunculus',
275
- 'butternut',
276
- 'green gem',
277
- 'red gem',
278
- 'starry night',
279
- 'benning',
280
- 'summar savor',
281
- 'summer savor',
282
- 'summery savor',
283
- 'summary savor',
284
- 'delicata',
285
- 'matador',
286
- 'green curl',
287
- 'red oak',
288
- 'flower',
289
- 'yellow tooth',
290
- 'sage\\b',
291
- 'sages\\b',
292
- 'okra',
293
- 'flor\\b',
294
- 'gems\\b',
295
- 'pump\\b',
296
- 'cruced\\b',
297
- 'star\\b',
298
- 'stars\\b',
299
- 'seed',
300
- 'pepper',
301
- 'chilli',
302
- 'mix\\b',
303
- 'chard',
304
- 'nettle',
305
- 'savory',
306
- 'dino',
307
-
308
- // log activities
309
- // NOTE: If i18n words change, these have to change too
310
- 'soil',
311
- 'irrigation',
312
- 'fertilization',
313
- 'crop protection',
314
- 'crop monitoring',
315
- 'direct seed',
316
- 'pruning',
317
- 'trellising',
318
- 'preparing crops',
319
- 'crops',
320
- 'estimating yield',
321
- 'other harvest',
322
- 'grading produce',
323
- 'moving produce',
324
- 'cold storage temperature',
325
- 'post harvest',
326
- 'sale',
327
- 'water testing',
328
- 'chlorine level',
329
- 'field',
330
- ];
331
- const ARABLE_ICON_BY_WORD = new Map(
332
- ARABLE_ICON_WORD_GROUPS.flatMap(([iconName, words]) =>
333
- words.map((word) => [normalizeIconMatchWord(word), iconName]),
334
- ),
335
- );
336
- const ARABLE_WORD_REGEX = new RegExp(
337
- `\\b(${ARABLE_ICON_PRIORITY_WORDS.join('|')})`,
338
- 'gi',
339
- );
340
- const ARABLE_ICON_PRIORITY_MATCHERS = ARABLE_ICON_PRIORITY_WORDS.map(
341
- (word) => [word, new RegExp(`^${word}$`, 'i')] as const,
342
- );
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';
343
12
 
344
13
  /*
345
- * 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.
346
15
  */
347
- function normalizeIconMatchWord(word: string): string {
348
- 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';
349
18
  }
350
19
 
351
20
  /*
352
- * Pick the highest-priority arable icon word from a list of regex matches.
21
+ * Select a market item icon using the same matching rules and item-before-notes fallback as crops.
353
22
  */
354
- function getPreferredArableIconWord(matches: string[]): string {
355
- if (matches.length === 1) {
356
- const matchedPriorityWord = ARABLE_ICON_PRIORITY_MATCHERS.find(
357
- ([, regex]) => regex.test(matches[0]),
358
- )?.[0];
359
-
360
- return normalizeIconMatchWord(matchedPriorityWord || matches[0]);
361
- }
362
-
363
- const preferredWord = ARABLE_ICON_PRIORITY_MATCHERS.find(([, regex]) =>
364
- matches.some((match) => regex.test(match)),
365
- )?.[0];
366
-
367
- return preferredWord
368
- ? normalizeIconMatchWord(preferredWord)
369
- : normalizeIconMatchWord(matches[0]);
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
+ );
370
30
  }
371
31
 
372
- /**
373
- * Get the icon name from crop name by using regex
374
- * @param crop - The name of the crop
375
- * @param note - Additional note that may contain crop type
376
- * @param defaultIcon - The default icon to return if no match is found
377
- * @returns The icon name or a default icon if no match is found
378
- */
379
-
380
- export function getIconNameForArable(
381
- crop?: string | undefined,
382
- note?: string | null,
383
- defaultIcon?: string,
384
- ): string {
385
- if (crop) {
386
- const match = crop.replace(/-/g, ' ').match(ARABLE_WORD_REGEX);
387
- if (match) {
388
- const matchedWord = getPreferredArableIconWord(match);
389
- const iconName = ARABLE_ICON_BY_WORD.get(matchedWord);
390
-
391
- if (iconName) {
392
- return iconName;
393
- }
394
-
395
- console.log('Missing icon lookup for crop:', crop);
396
- }
397
-
398
- // console.log('No match found for crop:', crop);
399
- }
400
-
401
- if (note) {
402
- return getIconNameForArable(note, null, defaultIcon);
403
- }
404
-
405
- return defaultIcon || 'seedling';
406
- }
407
-
408
- /**
409
- * Get the icon name for farmers market using regex
410
- * @param purchasedItem - The name of the purchased item
411
- * @param note - Additional note that may contain a market item type
412
- * @param defaultIcon - The default icon to return if no match is found
413
- * @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.
414
34
  */
415
-
416
- export function getIconNameForFarmersMarket(
417
- purchasedItem?: string | null,
418
- note?: string | null,
419
- defaultIcon?: string,
420
- ): string {
421
- if (purchasedItem) {
422
- // return 'seedling';
423
- const FARMERS_MARKET_WORDS = ['hay\\b'];
424
-
425
- const regex = new RegExp(`\\b(${FARMERS_MARKET_WORDS.join('|')})`, 'gi');
426
- const match = purchasedItem.replace('-', ' ').match(regex);
427
- if (match) {
428
- let matchedWord: string | undefined;
429
- if (match.length === 1) {
430
- matchedWord = match[0].toLowerCase();
431
- } else {
432
- // If multiple matches, choose the first match from produce words
433
- const lcMatch = match.map((m) => m.toLowerCase());
434
- matchedWord = FARMERS_MARKET_WORDS.find((word) =>
435
- lcMatch.includes(word),
436
- );
437
- }
438
-
439
- switch (matchedWord) {
440
- case 'hay':
441
- return 'farming-hay';
442
- default:
443
- console.log('Missing switchcase for crop:', purchasedItem);
444
- }
445
- }
446
-
447
- // console.log('No match found for farmers market:', purchasedItem);
448
- }
449
-
450
- if (note) {
451
- return getIconNameForFarmersMarket(note, null, defaultIcon);
452
- }
453
-
454
- 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
+ );
455
42
  }
456
43
 
457
44
  /**
@@ -462,11 +49,7 @@ export function getIconNameForFarmersMarket(
462
49
  * @returns The icon name or a default icon if no match is found
463
50
  */
464
51
 
465
- export function getIconNameForGrowerNetwork(
466
- _item?: string | null,
467
- _note?: string | null,
468
- _defaultIcon?: string,
469
- ): string {
52
+ export function getIconNameForGrowerNetwork(_item?: string | null, _note?: string | null, _defaultIcon?: string): string {
470
53
  return 'circle';
471
54
  }
472
55
 
@@ -474,17 +57,14 @@ export function getIconNameForGrowerNetwork(
474
57
  * Get any icon name for any word
475
58
  */
476
59
 
477
- export function getIconNameForWord(
478
- decidingWord: any,
479
- text1: string,
480
- text2?: string | null,
481
- defaultIcon?: string,
482
- ) {
60
+ export function getIconNameForWord(decidingWord: any, text1: string, text2?: string | null, defaultIcon?: string) {
483
61
  switch (decidingWord) {
484
62
  case 'ARABLE':
485
63
  return getIconNameForArable(text1, text2, defaultIcon);
486
64
  case 'FARMERS_MARKET':
487
65
  return getIconNameForFarmersMarket(text1, text2, defaultIcon);
66
+ case 'FOOD_MANUFACTURING':
67
+ return getIconNameForFoodManufacturing(text1, text2, defaultIcon);
488
68
  case 'GROWER_NETWORK':
489
69
  return getIconNameForGrowerNetwork(text1, text2, defaultIcon);
490
70
  default:
@@ -493,9 +73,18 @@ export function getIconNameForWord(
493
73
  }
494
74
 
495
75
  /**
496
- * 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.
497
85
  * @param details - GraphQL log details object
498
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)
499
88
  * @returns The icon name or a default icon if no match is found
500
89
  */
501
90
 
@@ -503,15 +92,26 @@ export function getIconNameForLog(
503
92
  details: any,
504
93
  preferActivityText?: boolean,
505
94
  defaultIcon_?: string,
95
+ orgOperation?: OrganizationOperationEnum | null,
506
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
+
507
110
  // "crop" is deprecation support -- it should be "item" going forward
508
111
  const text1 = preferActivityText ? details.activity : details.item;
509
- const text2 = preferActivityText
510
- ? details.title + ' ' + details.notes
511
- : details.notes;
112
+ const text2 = preferActivityText ? details.title + ' ' + details.notes : details.notes;
512
113
  // @ts-ignore - allow dynamic key access
513
- const defaultIcon =
514
- (preferActivityText && COMMON_ICON_NAMES[details.activity]) || defaultIcon_;
114
+ const defaultIcon = (preferActivityText && COMMON_ICON_NAMES[details.activity]) || defaultIcon_;
515
115
 
516
116
  // console.log('defaultIcon', preferActivityText, details.activity, defaultIcon);
517
117