@jsb188/mday-web 1.1.12 → 1.1.13

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,154 +0,0 @@
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
- }
@@ -1,134 +0,0 @@
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
- });
@@ -1,17 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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/**/*"]
13
- }
package/vitest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- esbuild: {
5
- jsx: 'automatic',
6
- },
7
- test: {
8
- environment: 'node',
9
- include: ['tests/**/*.test.ts?(x)'],
10
- },
11
- });