@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
@@ -0,0 +1,72 @@
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import { getCronDescription } from '@jsb188/app/utils/cron.ts';
3
+ import { getFullDate } from '@jsb188/app/utils/datetime.ts';
4
+ import type { WorkflowGQL } from '@jsb188/mday/types/workflow.d.ts';
5
+ import { getWorkflowShortLabel, isRecurringReminder, isWorkflowActive } from '@jsb188/mday/utils/workflow.ts';
6
+ import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
7
+ import { getLogActivityGroupIconName } from './log-web.ts';
8
+
9
+ /*
10
+ * Return the icon name used to represent one workflow trigger.
11
+ */
12
+ export function getWorkflowIconName(workflow: WorkflowGQL) {
13
+ const firstLogType = workflow.logTypes?.[0];
14
+
15
+ return firstLogType ? getLogActivityGroupIconName(firstLogType) : COMMON_ICON_NAMES.general_workflow;
16
+ }
17
+
18
+ /*
19
+ * Return the formatted next run date for one workflow, or a table-friendly empty value.
20
+ */
21
+ export function getWorkflowNextRunText(workflow: WorkflowGQL, timeZone: string | null) {
22
+ return workflow.nextAt ? getFullDate(workflow.nextAt, 'NUMERIC_TIME', timeZone) : null;
23
+ }
24
+
25
+ /*
26
+ * Return the schedule description for one reminder (cron text or one-time date).
27
+ */
28
+ export function getReminderScheduleText(reminder: Pick<WorkflowGQL, 'triggerType' | 'schedule' | 'nextAt'>, timeZone: string | null) {
29
+ if (isRecurringReminder(reminder) && reminder.schedule) {
30
+ return getCronDescription(reminder.schedule, true);
31
+ }
32
+
33
+ return reminder.nextAt ? getFullDate(reminder.nextAt, 'NUMERIC_TIME', timeZone) : '-';
34
+ }
35
+
36
+ /*
37
+ * Return the short recipients summary for one reminder (names/addresses).
38
+ */
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);
43
+
44
+ if (!labels.length) {
45
+ return null;
46
+ }
47
+
48
+ if (labels.length <= 2) {
49
+ return labels.join(', ');
50
+ }
51
+
52
+ return `${labels[0]}, ${labels[1]} +${labels.length - 2}`;
53
+ }
54
+
55
+ /*
56
+ * Return the modal header description for one workflow's current scheduling state.
57
+ */
58
+ export function getWorkflowHeaderDescription(workflow: WorkflowGQL, timeZone: string | null, operation?: string | null) {
59
+ if (!isWorkflowActive(workflow)) {
60
+ return i18n.t('workflow.not_active_msg');
61
+ }
62
+
63
+ if (workflow.nextAt) {
64
+ return `${i18n.t('c.next_run')}: ${getWorkflowNextRunText(workflow, timeZone)}`;
65
+ }
66
+
67
+ const logTypeShortLabel = workflow.logTypes?.length ? getWorkflowShortLabel(workflow, operation) : null;
68
+
69
+ return i18n.t('workflow.active_msg', {
70
+ logType: logTypeShortLabel?.toLowerCase(),
71
+ });
72
+ }
@@ -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
+ });
package/tsconfig.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "allowImportingTsExtensions": true,
7
- "jsx": "react-jsx",
8
- "noEmit": true,
9
- "strict": true,
10
- "esModuleInterop": true
11
- },
12
- "include": ["src/**/*"]
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "allowImportingTsExtensions": true,
7
+ "jsx": "react-jsx",
8
+ "noEmit": true,
9
+ "strict": true,
10
+ "esModuleInterop": true
11
+ },
12
+ "include": ["src/**/*"]
13
13
  }
@@ -1,169 +0,0 @@
1
- import i18n from '@jsb188/app/i18n/index.ts';
2
- import type { POListIfaceItem } from '@jsb188/react/types/PopOver.d';
3
- import { type OpenModalPopUpFn } from '@jsb188/react/states';
4
- import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
5
- import { copyTextToClipboard } from '@jsb188/react-web/utils/dom';
6
- import { useEffect } from 'react';
7
- import { getGridContextMenuPopOverId, useGridContextMenu } from './grid-context-menu.ts';
8
-
9
- export const SHEET_CONTEXT_MENU_ID = 'dataTable-context-menu';
10
- export const SHEET_DELETE_ROW_POPUP_PRESET = 'DELETE_SHEET_ROW';
11
-
12
- export const SHEET_CONTEXT_MENU_ACTIONS = {
13
- copyCellValue: 'COPY_CELL_VALUE',
14
- deleteRow: 'DELETE_ROW',
15
- editCell: 'EDIT_CELL',
16
- openCell: 'OPEN_CELL',
17
- } as const;
18
-
19
- export type DataTableArrowNavigationDirection = 'left' | 'right' | 'up' | 'down';
20
- export type DataTableContextMenuAction = typeof SHEET_CONTEXT_MENU_ACTIONS[keyof typeof SHEET_CONTEXT_MENU_ACTIONS];
21
-
22
- export type DataTableContextMenuTarget<Lookup = unknown> = {
23
- canDeleteRow: boolean;
24
- canEdit: boolean;
25
- canOpen: boolean;
26
- cellKey: string;
27
- displayValue: string;
28
- lookup: Lookup;
29
- organizationId: string;
30
- rowId: string;
31
- rowNumber?: number | null;
32
- dataTableId: string;
33
- viewId?: string | null;
34
- };
35
-
36
- type UseDataTableContextMenuParams<Lookup> = {
37
- openModalPopUp: OpenModalPopUpFn;
38
- onEditCell: (target: DataTableContextMenuTarget<Lookup>) => void;
39
- onOpenCell: (target: DataTableContextMenuTarget<Lookup>) => void;
40
- };
41
-
42
- /*
43
- * Copy one dataTable context-menu target's display value to the clipboard.
44
- */
45
-
46
- function copyDataTableContextMenuCellValue(target: DataTableContextMenuTarget) {
47
- void copyTextToClipboard(target.displayValue || '');
48
- }
49
-
50
- /*
51
- * Build the PopOver list options for one dataTable context-menu target.
52
- */
53
-
54
- function getDataTableContextMenuOptions(target: DataTableContextMenuTarget): POListIfaceItem[] {
55
- const options: POListIfaceItem[] = [{
56
- __type: 'LIST_ITEM',
57
- disabled: !target.canEdit,
58
- iconName: COMMON_ICON_NAMES.edit_note,
59
- text: i18n.t('dataTable.context_menu_edit_cell'),
60
- value: SHEET_CONTEXT_MENU_ACTIONS.editCell,
61
- }, {
62
- __type: 'LIST_ITEM',
63
- disabled: !target.canOpen,
64
- iconName: 'external-link',
65
- text: i18n.t('dataTable.context_menu_open_cell'),
66
- value: SHEET_CONTEXT_MENU_ACTIONS.openCell,
67
- }, {
68
- __type: 'LIST_ITEM',
69
- iconName: COMMON_ICON_NAMES.copy,
70
- text: i18n.t('dataTable.context_menu_copy_cell_value'),
71
- value: SHEET_CONTEXT_MENU_ACTIONS.copyCellValue,
72
- }];
73
-
74
- if (target.canDeleteRow) {
75
- options.push({
76
- __type: 'BREAK',
77
- }, {
78
- __type: 'LIST_ITEM',
79
- className: 'cl_err',
80
- iconName: COMMON_ICON_NAMES.delete,
81
- text: i18n.t('dataTable.delete_row'),
82
- value: SHEET_CONTEXT_MENU_ACTIONS.deleteRow,
83
- });
84
- }
85
-
86
- return options;
87
- }
88
-
89
- /*
90
- * Open the delete-row confirmation popup for a menu target.
91
- */
92
-
93
- function openDataTableDeleteRowPopUp<Lookup>(
94
- openModalPopUp: OpenModalPopUpFn,
95
- target: DataTableContextMenuTarget<Lookup>,
96
- ) {
97
- openModalPopUp({
98
- name: SHEET_DELETE_ROW_POPUP_PRESET,
99
- preset: SHEET_DELETE_ROW_POPUP_PRESET,
100
- props: {
101
- allowDelete: target.canDeleteRow,
102
- organizationId: target.organizationId,
103
- rowNumber: target.rowNumber,
104
- dataTableId: target.dataTableId,
105
- dataTableRowId: target.rowId,
106
- viewId: target.viewId || null,
107
- },
108
- });
109
- }
110
-
111
- /*
112
- * Own the DataTable context-menu PopOver actions.
113
- */
114
-
115
- export function useDataTableContextMenu<Lookup>(p: UseDataTableContextMenuParams<Lookup>) {
116
- const {
117
- onEditCell,
118
- onOpenCell,
119
- openModalPopUp,
120
- } = p;
121
- const {
122
- activeTargetRef,
123
- closeContextMenu: closeDataTableContextMenu,
124
- closePopOver,
125
- openContextMenu: openDataTableContextMenu,
126
- popOver,
127
- } = useGridContextMenu<DataTableContextMenuTarget<Lookup>>({
128
- contextMenuId: SHEET_CONTEXT_MENU_ID,
129
- getOptions: getDataTableContextMenuOptions,
130
- });
131
-
132
- useEffect(() => {
133
- const { action, id, value } = popOver?.globalState || {};
134
- const target = activeTargetRef.current;
135
-
136
- if (!target || id !== getGridContextMenuPopOverId(SHEET_CONTEXT_MENU_ID, target) || action !== 'ITEM') {
137
- return;
138
- }
139
-
140
- switch (value as DataTableContextMenuAction) {
141
- case SHEET_CONTEXT_MENU_ACTIONS.copyCellValue:
142
- copyDataTableContextMenuCellValue(target);
143
- closePopOver();
144
- break;
145
- case SHEET_CONTEXT_MENU_ACTIONS.deleteRow:
146
- openDataTableDeleteRowPopUp(openModalPopUp, target);
147
- closePopOver();
148
- break;
149
- case SHEET_CONTEXT_MENU_ACTIONS.editCell:
150
- if (target.canEdit) {
151
- onEditCell(target);
152
- }
153
- closePopOver();
154
- break;
155
- case SHEET_CONTEXT_MENU_ACTIONS.openCell:
156
- if (target.canOpen) {
157
- onOpenCell(target);
158
- }
159
- closePopOver();
160
- break;
161
- default:
162
- }
163
- }, [closePopOver, onEditCell, onOpenCell, openModalPopUp, popOver?.globalState]);
164
-
165
- return {
166
- closeDataTableContextMenu,
167
- openDataTableContextMenu,
168
- };
169
- }