@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.
@@ -2,12 +2,9 @@ import i18n from '@jsb188/app/i18n/index.ts';
2
2
  import { getCronDescription } from '@jsb188/app/utils/cron.ts';
3
3
  import { getFullDate } from '@jsb188/app/utils/datetime.ts';
4
4
  import type { WorkflowGQL } from '@jsb188/mday/types/workflow.d.ts';
5
- import {
6
- getWorkflowShortLabel,
7
- isRecurringReminder,
8
- isWorkflowActive,
9
- } from '@jsb188/mday/utils/workflow.ts';
5
+ import { getWorkflowShortLabel, isRecurringReminder, isWorkflowActive } from '@jsb188/mday/utils/workflow.ts';
10
6
  import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
7
+ import { getLogActivityGroupIconName } from './log-web.ts';
11
8
 
12
9
  /*
13
10
  * Return the icon name used to represent one workflow trigger.
@@ -15,80 +12,59 @@ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
15
12
  export function getWorkflowIconName(workflow: WorkflowGQL) {
16
13
  const firstLogType = workflow.logTypes?.[0];
17
14
 
18
- return firstLogType
19
- ? COMMON_ICON_NAMES[firstLogType] || COMMON_ICON_NAMES.general_workflow
20
- : COMMON_ICON_NAMES.general_workflow;
15
+ return firstLogType ? getLogActivityGroupIconName(firstLogType) : COMMON_ICON_NAMES.general_workflow;
21
16
  }
22
17
 
23
18
  /*
24
19
  * Return the formatted next run date for one workflow, or a table-friendly empty value.
25
20
  */
26
- export function getWorkflowNextRunText(
27
- workflow: WorkflowGQL,
28
- timeZone: string | null,
29
- ) {
30
- return workflow.nextAt
31
- ? getFullDate(workflow.nextAt, 'NUMERIC_TIME', timeZone)
32
- : '-';
21
+ export function getWorkflowNextRunText(workflow: WorkflowGQL, timeZone: string | null) {
22
+ return workflow.nextAt ? getFullDate(workflow.nextAt, 'NUMERIC_TIME', timeZone) : null;
33
23
  }
34
24
 
35
25
  /*
36
26
  * Return the schedule description for one reminder (cron text or one-time date).
37
27
  */
38
- export function getReminderScheduleText(
39
- reminder: Pick<WorkflowGQL, 'triggerType' | 'schedule' | 'nextAt'>,
40
- timeZone: string | null,
41
- ) {
28
+ export function getReminderScheduleText(reminder: Pick<WorkflowGQL, 'triggerType' | 'schedule' | 'nextAt'>, timeZone: string | null) {
42
29
  if (isRecurringReminder(reminder) && reminder.schedule) {
43
30
  return getCronDescription(reminder.schedule, true);
44
31
  }
45
32
 
46
- return reminder.nextAt
47
- ? getFullDate(reminder.nextAt, 'NUMERIC_TIME', timeZone)
48
- : '-';
33
+ return reminder.nextAt ? getFullDate(reminder.nextAt, 'NUMERIC_TIME', timeZone) : '-';
49
34
  }
50
35
 
51
36
  /*
52
37
  * Return the short recipients summary for one reminder (names/addresses).
53
38
  */
54
- export function getReminderRecipientsSummaryText(
55
- reminder: Pick<WorkflowGQL, 'recipients'>,
56
- ) {
57
- const labels = (reminder.recipients || [])
58
- .map(
59
- (recipient) => recipient.name || recipient.phone || recipient.email || '',
60
- )
61
- .filter(Boolean);
39
+ export function getReminderRecipientsSummaryText(reminder: Pick<WorkflowGQL, 'recipients'>) {
40
+ if (!reminder.recipients?.length) return null;
41
+
42
+ const labels = reminder.recipients.map((recipient) => recipient.name || recipient.phone || recipient.email || '').filter(Boolean);
62
43
 
63
44
  if (!labels.length) {
64
- return '-';
45
+ return null;
65
46
  }
66
47
 
67
48
  if (labels.length <= 2) {
68
49
  return labels.join(', ');
69
50
  }
70
51
 
71
- return `${labels.slice(0, 2).join(', ')} +${labels.length - 2}`;
52
+ return `${labels[0]}, ${labels[1]} +${labels.length - 2}`;
72
53
  }
73
54
 
74
55
  /*
75
56
  * Return the modal header description for one workflow's current scheduling state.
76
57
  */
77
- export function getWorkflowHeaderDescription(
78
- workflow: WorkflowGQL,
79
- timeZone: string | null,
80
- ) {
58
+ export function getWorkflowHeaderDescription(workflow: WorkflowGQL, timeZone: string | null, operation?: string | null) {
81
59
  if (!isWorkflowActive(workflow)) {
82
60
  return i18n.t('workflow.not_active_msg');
83
61
  }
84
62
 
85
63
  if (workflow.nextAt) {
86
- return `${i18n.t('form.next_run')}: ${getWorkflowNextRunText(workflow, timeZone)}`;
64
+ return `${i18n.t('c.next_run')}: ${getWorkflowNextRunText(workflow, timeZone)}`;
87
65
  }
88
66
 
89
- const logTypeShortLabel = workflow.logTypes?.length
90
- ? getWorkflowShortLabel(workflow)
91
- : null;
67
+ const logTypeShortLabel = workflow.logTypes?.length ? getWorkflowShortLabel(workflow, operation) : null;
92
68
 
93
69
  return i18n.t('workflow.active_msg', {
94
70
  logType: logTypeShortLabel?.toLowerCase(),
@@ -0,0 +1,134 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { compileIconMatchRules, type IconMatchRule, matchIconName } from '../src/utils/log-web.helpers.ts';
3
+ import { FOOD_MANUFACTURING_ICON_MATCHERS } from '../src/utils/log-web.icons.ts';
4
+ import { getIconNameForArable, getIconNameForFarmersMarket, getIconNameForLog, getIconNameForWord } from '../src/utils/log-web.ts';
5
+
6
+ vi.mock('@jsb188/react-web/svgs/Icon', () => ({
7
+ COMMON_ICON_NAMES: { COOKING_TEMPERATURE: 'thermometer', FOOD_TEMPERATURE: 'thermometer', logs: 'notes-book' },
8
+ }));
9
+
10
+ describe('log icon selection', () => {
11
+ it.each([
12
+ ['canned goods', 'meal-can'],
13
+ ['can', 'meal-can'],
14
+ ['CANS', 'meal-can'],
15
+ ['tinned food', 'meal-can'],
16
+ ['canned ravioli', 'pasta-ravioli'],
17
+ ['salami', 'salami'],
18
+ ['salamis', 'salami'],
19
+ ['spring roll', 'exotic-food-rolls'],
20
+ ['spring rolls', 'exotic-food-rolls'],
21
+ ['Lumpia', 'exotic-food-rolls'],
22
+ ['egg roll', 'exotic-food-rolls'],
23
+ ['egg rolls', 'exotic-food-rolls'],
24
+ ['fried roll', 'exotic-food-rolls'],
25
+ ['fried rolls', 'exotic-food-rolls'],
26
+ ['SPRING-ROLLS', 'exotic-food-rolls'],
27
+ ])('selects the food manufacturing icon for %j', (item, icon) => {
28
+ expect(getIconNameForLog({ item }, false, 'custom', 'FOOD_MANUFACTURING')).toBe(icon);
29
+ expect(getIconNameForWord('FOOD_MANUFACTURING', item)).toBe(icon);
30
+ });
31
+
32
+ it('defaults unmatched food manufacturing text to meal-can instead of activity or group icons', () => {
33
+ const details = { item: 'unknown product', activity: 'COOKING_TEMPERATURE', type: 'FOOD_TEMPERATURE' };
34
+ expect(getIconNameForLog(details, false, undefined, 'FOOD_MANUFACTURING')).toBe('meal-can');
35
+ expect(getIconNameForLog(details, true, undefined, 'FOOD_MANUFACTURING')).toBe('meal-can');
36
+ expect(getIconNameForWord('FOOD_MANUFACTURING', '')).toBe('meal-can');
37
+ expect(getIconNameForWord('FOOD_MANUFACTURING', 'unknown', 'spring rolls')).toBe('exotic-food-rolls');
38
+ expect(matchIconName(FOOD_MANUFACTURING_ICON_MATCHERS, 'candy')).toBeNull();
39
+ });
40
+
41
+ it('uses food manufacturing notes and preserves fallbacks and other operations', () => {
42
+ expect(getIconNameForLog({ item: 'batch', notes: 'Lumpia' }, false, 'custom', 'FOOD_MANUFACTURING')).toBe('exotic-food-rolls');
43
+ expect(getIconNameForLog({ item: 'batch', title: 'Salami' }, true, 'custom', 'FOOD_MANUFACTURING')).toBe('salami');
44
+ expect(getIconNameForLog({ item: 'spring roller' }, false, 'custom', 'FOOD_MANUFACTURING')).toBe('custom');
45
+ expect(getIconNameForLog({ item: 'salami' }, false, 'custom', 'CONSTRUCTION_INSPECTION_AGENCY')).toBe('custom');
46
+ });
47
+
48
+ it.each([
49
+ ['basil and carrots', 'vegetable-basil'],
50
+ ['carrots and basil', 'vegetable-carrot'],
51
+ ['kale and cauliflower', 'vegetable-arugula'],
52
+ ['cauliflower and kale', 'vegetable-broccoli'],
53
+ ['spring onion', 'vegetable-scallion'],
54
+ ['spring onions', 'vegetable-scallion'],
55
+ ['onions and spring onions', 'vegetable-onion'],
56
+ ['sweet peppers', 'vegetable-acornsquash'],
57
+ ['pepper mix with strawberries', 'fruit-strawberry'],
58
+ ['berries and raspberries', 'raspberry'],
59
+ ['gooseberries', 'fruit-billberry-blackberry-blueberry'],
60
+ ['little gem lettuce', 'vegetable-lettuce-top'],
61
+ ['direct seed', 'agriculture-machine-seeder'],
62
+ ['seed direct seed', 'agriculture-machine-seeder'],
63
+ ['direct seeding carrots', 'vegetable-carrot'],
64
+ ['field water testing', 'organic-flask'],
65
+ ['PREPARING_CROPS', 'protein-gluten-wheat'],
66
+ [' SPRING—\t ONIONS ', 'vegetable-scallion'],
67
+ ['JALAPEÑO', 'vegetable-jalapeno'],
68
+ ['jalapen\u0303os', 'vegetable-jalapeno'],
69
+ ['summer savory', 'vegetable-thyme'],
70
+ ['minted', 'seedling'],
71
+ ['fieldwork', 'seedling'],
72
+ ['plumber', 'seedling'],
73
+ ['élettuce', 'seedling'],
74
+ ['', 'seedling'],
75
+ ])('maps %j to %s', (text, icon) => {
76
+ expect(getIconNameForArable(text)).toBe(icon);
77
+ });
78
+
79
+ it('uses notes only when the item has no match, including when the item is a fallback', () => {
80
+ expect(getIconNameForArable('seed', 'basil')).toBe('gardening-seed-bag');
81
+ expect(getIconNameForArable('unknown', 'basil')).toBe('vegetable-basil');
82
+ expect(getIconNameForArable(undefined, 'carrots')).toBe('vegetable-carrot');
83
+ expect(getIconNameForArable('unknown', null, 'custom')).toBe('custom');
84
+ });
85
+
86
+ it('handles repeated hay matches and repeated calls without regex state', () => {
87
+ for (let index = 0; index < 3; index++) {
88
+ expect(getIconNameForFarmersMarket('hay hay')).toBe('farming-hay');
89
+ expect(getIconNameForFarmersMarket('unknown', 'HAY')).toBe('farming-hay');
90
+ expect(getIconNameForFarmersMarket('haystack')).toBe('farmers-market-kiosk');
91
+ expect(getIconNameForFarmersMarket(null, null, 'custom')).toBe('custom');
92
+ }
93
+ });
94
+ });
95
+
96
+ describe('icon rule compilation', () => {
97
+ it('keeps tier, phrase, and tie decisions independent of definition order', () => {
98
+ const rules: IconMatchRule[] = [
99
+ { icon: 'onion', tier: 'specific', words: ['onion'] },
100
+ { icon: 'spring-onion', tier: 'specific', phrases: ['spring onion'] },
101
+ { icon: 'a-pepper', tier: 'specific', words: ['pepper'] },
102
+ { icon: 'z-pepper', tier: 'specific', words: ['pepper'] },
103
+ { icon: 'short', tier: 'specific', words: ['sweet'] },
104
+ { icon: 'long', tier: 'specific', phrases: ['sweet pepper'] },
105
+ { icon: 'seed', tier: 'fallback', words: ['seed'] },
106
+ { icon: 'seeder', tier: 'activity', phrases: ['direct seed'] },
107
+ ];
108
+ for (let index = 0; index < rules.length; index++) {
109
+ const reordered = [...rules.slice(index), ...rules.slice(0, index)].reverse();
110
+ const matchers = compileIconMatchRules(reordered);
111
+ expect(matchIconName(matchers, 'spring onion')).toBe('spring-onion');
112
+ expect(matchIconName(matchers, 'pepper')).toBe('a-pepper');
113
+ expect(matchIconName(matchers, 'sweet pepper')).toBe('long');
114
+ expect(matchIconName(matchers, 'seed direct seed')).toBe('seeder');
115
+ expect(matchIconName(matchers, 'direct seed onion')).toBe('onion');
116
+ }
117
+ });
118
+
119
+ it('escapes literal aliases and retains the longest alternative at the same position', () => {
120
+ const rules: IconMatchRule[] = [
121
+ { icon: 'long', tier: 'specific', phrases: ['red', 'red oak lettuce'], words: ['a+b'], prefixes: ['red'] },
122
+ { icon: 'short', tier: 'specific', phrases: ['red oak'] },
123
+ ];
124
+ for (const phrases of [
125
+ ['red', 'red oak lettuce'],
126
+ ['red oak lettuce', 'red'],
127
+ ]) {
128
+ const matchers = compileIconMatchRules([{ ...rules[0], phrases }, rules[1]]);
129
+ expect(matchIconName(matchers, 'red oak lettuce')).toBe('long');
130
+ expect(matchIconName(matchers, 'a+b')).toBe('long');
131
+ expect(matchIconName(matchers, 'aaab')).toBeNull();
132
+ }
133
+ });
134
+ });
@@ -0,0 +1,17 @@
1
+ import { expect, it, vi } from 'vitest';
2
+ import { getNormalizedSidebarSlug, makeFieldDocFormPath } from '../src/utils/route-helpers.ts';
3
+
4
+ vi.mock('@jsb188/react-web/svgs/Icon', () => ({
5
+ COMMON_ICON_NAMES: new Proxy({}, { get: (_target, key) => String(key) }),
6
+ }));
7
+
8
+ it('links a form to its program page with the submissions page-filter grammar', () => {
9
+ expect(makeFieldDocFormPath('9479047167134723', '5502')).toBe('/app/fd/9479047167134723?filter=fieldDocIds,5502');
10
+ // Values that collide with the grammar are JSON-quoted and URL-encoded by the serializer
11
+ expect(makeFieldDocFormPath('p/1', 'a,b')).toBe('/app/fd/p%2F1?filter=fieldDocIds,%22a,b%22');
12
+ });
13
+
14
+ it('normalizes sidebar slugs without translating retired route prefixes', () => {
15
+ expect(getNormalizedSidebarSlug('/app/fd/6225494309851732/')).toBe('fd/6225494309851732');
16
+ expect(getNormalizedSidebarSlug('r/6225494309851732')).toBe('r/6225494309851732');
17
+ });