@jsb188/mday 1.1.8 → 1.1.11

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 (123) hide show
  1. package/package.json +105 -35
  2. package/src/constants/agentDoc.ts +12 -0
  3. package/src/constants/agentMemory.ts +154 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/campaign.ts +127 -0
  6. package/src/constants/dataTable.ts +48 -0
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +44 -0
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/inboundContact.ts +8 -0
  13. package/src/constants/integration.ts +13 -0
  14. package/src/constants/log.ts +7 -366
  15. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  16. package/src/constants/logTaxonomy.generated.ts +1103 -0
  17. package/src/constants/noteDoc.ts +77 -0
  18. package/src/constants/organization.ts +18 -11
  19. package/src/constants/pageRoute.ts +23 -0
  20. package/src/constants/schedule.ts +220 -0
  21. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  22. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  23. package/src/constants/sheet.ts +168 -0
  24. package/src/constants/sheetRegionSources.generated.ts +578 -0
  25. package/src/constants/square.ts +16 -0
  26. package/src/constants/storage.ts +61 -0
  27. package/src/constants/usage.ts +79 -0
  28. package/src/schemas/editLogEntry.ts +1017 -738
  29. package/src/schemas/fieldDocsQuery.ts +12 -0
  30. package/src/schemas/inboundContact.ts +77 -0
  31. package/src/schemas/logsQuery.ts +57 -316
  32. package/src/schemas/organization.ts +53 -213
  33. package/src/types/account.d.ts +81 -0
  34. package/src/types/agentDoc.d.ts +64 -0
  35. package/src/types/agentMemory.d.ts +74 -0
  36. package/src/types/campaign.d.ts +683 -0
  37. package/src/types/dataTable.d.ts +366 -0
  38. package/src/types/docAccess.d.ts +96 -0
  39. package/src/types/email.d.ts +142 -0
  40. package/src/types/fieldDoc.d.ts +273 -0
  41. package/src/types/inboundContact.d.ts +57 -0
  42. package/src/types/integration.d.ts +42 -0
  43. package/src/types/log.d.ts +169 -190
  44. package/src/types/noteDoc.d.ts +86 -0
  45. package/src/types/organization.d.ts +175 -76
  46. package/src/types/pageRoute.d.ts +48 -0
  47. package/src/types/schedule.d.ts +391 -0
  48. package/src/types/sheet.d.ts +1130 -0
  49. package/src/types/storage.d.ts +242 -0
  50. package/src/types/usage.d.ts +106 -0
  51. package/src/types/workflow.d.ts +305 -0
  52. package/src/utils/agentDoc.ts +109 -0
  53. package/src/utils/aiChat.ts +26 -0
  54. package/src/utils/campaign.ts +741 -0
  55. package/src/utils/campaignFormEditor.ts +871 -0
  56. package/src/utils/dataTable.ts +849 -0
  57. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  58. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  59. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  60. package/src/utils/dataTableRowDocument.ts +508 -0
  61. package/src/utils/dataTableSource.ts +230 -0
  62. package/src/utils/docAccess.ts +383 -0
  63. package/src/utils/documentName.ts +53 -0
  64. package/src/utils/email.ts +172 -0
  65. package/src/utils/fieldDoc.ts +113 -0
  66. package/src/utils/log.ts +173 -778
  67. package/src/utils/logRegistryValue.ts +90 -0
  68. package/src/utils/logStoreRead.ts +266 -0
  69. package/src/utils/logTaxonomy.ts +76 -0
  70. package/src/utils/logTaxonomyDisplay.ts +439 -0
  71. package/src/utils/noteDoc.ts +827 -0
  72. package/src/utils/organization.ts +683 -81
  73. package/src/utils/pageRoute.ts +71 -0
  74. package/src/utils/schedule.ts +799 -0
  75. package/src/utils/scheduleEvaluation.ts +1994 -0
  76. package/src/utils/scheduleICS.ts +246 -0
  77. package/src/utils/scheduleRuleTemplates.ts +188 -0
  78. package/src/utils/sheet.ts +4973 -0
  79. package/src/utils/sheetAxisMove.ts +830 -0
  80. package/src/utils/sheetBootstrap.ts +1769 -0
  81. package/src/utils/sheetCommand.ts +423 -0
  82. package/src/utils/sheetExport.ts +238 -0
  83. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  84. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  85. package/src/utils/sheetJournal.ts +78 -0
  86. package/src/utils/sheetNumberFormat.ts +1211 -0
  87. package/src/utils/sheetRegion.ts +374 -0
  88. package/src/utils/sheetRegionFilter.ts +1259 -0
  89. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  90. package/src/utils/sheetSequence.ts +148 -0
  91. package/src/utils/sheetSnapshot.ts +992 -0
  92. package/src/utils/sheetStructureEdit.ts +1284 -0
  93. package/src/utils/square.ts +32 -0
  94. package/src/utils/storage.ts +152 -0
  95. package/src/utils/table-route.ts +262 -0
  96. package/src/utils/workflow.ts +380 -0
  97. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  98. package/tests/docAccess.test.ts +525 -0
  99. package/tests/editLogEntry.test.ts +112 -0
  100. package/tests/noteDoc.test.ts +669 -0
  101. package/tests/schedule.test.ts +693 -0
  102. package/tests/scheduleEvaluation.test.ts +1970 -0
  103. package/tests/scheduleICS.test.ts +208 -0
  104. package/tests/scheduleRuleTemplates.test.ts +176 -0
  105. package/tests/scheduleSweepInvariants.test.ts +428 -0
  106. package/tests/sheetAxisMove.test.ts +343 -0
  107. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  108. package/tests/sheetRegionFilter.test.ts +1135 -0
  109. package/tests/sheetSequence.test.ts +41 -0
  110. package/tests/sheetStructureEdit.test.ts +82 -0
  111. package/tsconfig.json +12 -0
  112. package/vitest.config.ts +8 -0
  113. package/src/constants/log-activityTexts.ts +0 -209
  114. package/src/constants/product.ts +0 -66
  115. package/src/constants/report.ts +0 -25
  116. package/src/schemas/childOrganizationsQuery.ts +0 -44
  117. package/src/schemas/productsQuery.ts +0 -145
  118. package/src/schemas/reportsQuery.ts +0 -107
  119. package/src/types/action.d.ts +0 -42
  120. package/src/types/product.d.ts +0 -173
  121. package/src/types/report.d.ts +0 -203
  122. package/src/utils/product-calEvent.ts +0 -508
  123. package/src/utils/route-helpers.ts +0 -583
package/src/utils/log.ts CHANGED
@@ -1,30 +1,104 @@
1
- import i18n from '@jsb188/app/i18n';
2
- import type { OrganizationOperationEnum } from '../types/organization.d';
3
- import { formatCurrency, formatDecimal } from '@jsb188/app/utils/number';
4
- import { formatReferenceNumber, joinReadable, textWithBrackets, ucFirst } from '@jsb188/app/utils/string';
5
- import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
1
+ import i18n from '@jsb188/app/i18n/index.ts';
2
+ import { formatCurrency, formatDecimal } from '@jsb188/app/utils/number.ts';
6
3
  import {
7
- ARABLE_ACTIVITIES_GROUPED,
8
- FARMERS_MARKET_ACTIVITIES_GROUPED,
9
- LIVESTOCK_ACTIVITIES_GROUPED,
10
- LOG_TYPES_BY_OPERATION
11
- } from '../constants/log';
12
- import type { LogEntryData, LogTypeEnum, LogContentName } from '../types/log.d';
4
+ joinReadable,
5
+ textWithBrackets,
6
+ ucFirst,
7
+ } from '@jsb188/app/utils/string.ts';
8
+ import {
9
+ LOG_ACTIVITIES_BY_OPERATION,
10
+ LOG_TYPES_BY_OPERATION,
11
+ PURCHASE_ACTIVITIES,
12
+ SALE_ACTIVITIES,
13
+ } from '../constants/log.ts';
14
+ import { LOG_ACTIVITY_GROUP_COLORS } from '../constants/logActivityGroupColors.generated.ts';
15
+ import type {
16
+ LogContentName,
17
+ LogEntryData,
18
+ LogTypeEnum,
19
+ } from '../types/log.d.ts';
20
+ import type { OrganizationOperationEnum } from '../types/organization.d.ts';
21
+ import type { SheetCustomRegionSourceColumnFormulaValueSourceEnum } from '../types/sheet.d.ts';
22
+ import {
23
+ getLogEntryDetailsFieldUnitByKey,
24
+ getLogEntryDetailsFieldValueByKey,
25
+ humanizeRegistryKey,
26
+ } from './logTaxonomyDisplay.ts';
27
+
28
+ const FILE_CONSTANTS = {
29
+ accountingActivities: new Set([
30
+ ...PURCHASE_ACTIVITIES,
31
+ ...SALE_ACTIVITIES,
32
+ ] as string[]),
33
+ };
34
+
35
+ type LogRegionSourceFormulaValueSource = {
36
+ accountId?: string | number | bigint | null;
37
+ childOrgId?: string | number | bigint | null;
38
+ id?: string | number | bigint | null;
39
+ inboundContactId?: string | number | bigint | null;
40
+ fieldDocId?: string | number | bigint | null;
41
+ fieldDocSubmissionId?: string | number | bigint | null;
42
+ siteId?: string | number | bigint | null;
43
+ };
44
+
45
+ /*
46
+ * Return the related record id backing one Logs custom source display column.
47
+ */
48
+ export function getLogRegionSourceCellRelatedId(
49
+ log: LogRegionSourceFormulaValueSource | null | undefined,
50
+ formulaValueSource?:
51
+ | SheetCustomRegionSourceColumnFormulaValueSourceEnum
52
+ | string
53
+ | null,
54
+ ): string | number | bigint | null {
55
+ const relatedId = {
56
+ LOG_ACCOUNT_ID: log?.accountId,
57
+ LOG_CHILD_ORGANIZATION_ID: log?.childOrgId,
58
+ LOG_ID: log?.id,
59
+ LOG_INBOUND_CONTACT_ID: log?.inboundContactId,
60
+ LOG_REPORT_ID: log?.fieldDocId,
61
+ LOG_REPORT_SUBMISSION_ID: log?.fieldDocSubmissionId,
62
+ LOG_SITE_ID: log?.siteId,
63
+ }[String(formulaValueSource || '')];
64
+
65
+ return relatedId !== null && relatedId !== undefined ? relatedId : null;
66
+ }
67
+
68
+ /*
69
+ * Return the formula comparison value backing one Logs custom source display column.
70
+ */
71
+ export function getLogRegionSourceCellFormulaValue(
72
+ log: LogRegionSourceFormulaValueSource | null | undefined,
73
+ formulaValueSource?:
74
+ | SheetCustomRegionSourceColumnFormulaValueSourceEnum
75
+ | string
76
+ | null,
77
+ ): string | null {
78
+ const formulaValue = getLogRegionSourceCellRelatedId(log, formulaValueSource);
79
+
80
+ return formulaValue !== null && formulaValue !== undefined
81
+ ? String(formulaValue)
82
+ : null;
83
+ }
84
+
85
+ /*
86
+ * Return whether one log activity uses the shared accounting metadata fields.
87
+ */
88
+ export function isAccountingLogActivity(activity?: string | null) {
89
+ return FILE_CONSTANTS.accountingActivities.has(activity || '');
90
+ }
13
91
 
14
92
  /**
15
93
  * Get content type for log by activity
16
94
  */
17
95
 
18
96
  export function getLogContentName(activity: string): LogContentName {
19
- const value = {
20
- 'SALE_PRODUCE_ORDER': 'invoice',
21
- 'OTHER_SALE_ORDER': 'invoice',
22
- 'FEED_PURCHASE': 'invoice',
23
- 'OTHER_SUPPLY_PURCHASE_ACTIVITY': 'invoice',
24
- 'MARKET_CREDIT_RECEIPT': 'receipt',
25
- }[activity as string] || 'log';
97
+ if (activity === 'MARKET_CREDIT_RECEIPT') {
98
+ return 'receipt';
99
+ }
26
100
 
27
- return value as LogContentName;
101
+ return isAccountingLogActivity(activity) ? 'invoice' : 'log';
28
102
  }
29
103
 
30
104
  /**
@@ -33,57 +107,14 @@ export function getLogContentName(activity: string): LogContentName {
33
107
  * @returns The color associated with the journal type
34
108
  */
35
109
 
36
- export function getLogCategoryColor(type: LogTypeEnum) {
37
- // Do switch operation here
38
- // switch (operation) {
39
- // case 'ARABLE':
40
- // case 'LogArable':
41
- // // ..
42
- // break;
43
- // case 'LIVESTOCK':
44
- // case 'LogLivestock':
45
- // // ..
46
- // break;
47
- // default:
48
- // }
49
-
50
- const logTypeToColor = {
51
- // #### ARABLE
52
- SEED: 'brown',
53
- PLANTING: 'amber',
54
- FIELD: 'lime',
55
- HARVEST: 'emerald',
56
- POST_HARVEST: 'cyan',
57
- SALES: 'blue',
58
- WATER: 'violet',
59
- DELETED: 'medium',
60
-
61
- // #### ARABLE - Food Safety
62
- HYGIENE: 'teal',
63
- SANITATION: 'sky',
64
- EQUIPMENTS: 'indigo',
65
- BIOSECURITY: 'green',
66
- EMPLOYEES: 'yellow',
67
-
68
- // #### FARMERS_MARKET
69
- MARKET_RECEIPTS: 'blue',
70
- MARKET_OPERATIONS: 'rose',
71
-
72
- // #### LIVESTOCK
73
- SUPPLY_PURCHASE: 'brown',
74
- LIVESTOCK_LIFE_CYCLE: 'amber',
75
- LIVESTOCK_TRACKING: 'lime',
76
- PASTURE_LAND_MANAGEMENT: 'green',
77
- LIVESTOCK_HEALTHCARE: 'teal',
78
- LIVESTOCK_SALE: 'blue',
79
-
80
- // #### Merged into every operation
81
- AI_TASK: 'slate',
82
- } as Record<LogTypeEnum, string>;
110
+ export function getLogCategoryColor(
111
+ type: LogTypeEnum | 'DELETED' | string | null | undefined,
112
+ ) {
113
+ if (type === 'DELETED') {
114
+ return 'medium';
115
+ }
83
116
 
84
- // Default to zinc if type is not found
85
- const color = logTypeToColor[type] || 'zinc';
86
- return color;
117
+ return type ? LOG_ACTIVITY_GROUP_COLORS[type] || 'zinc' : 'zinc';
87
118
  }
88
119
 
89
120
  /**
@@ -92,12 +123,11 @@ export function getLogCategoryColor(type: LogTypeEnum) {
92
123
  * @returns Array of log types for the operation
93
124
  */
94
125
 
95
- export function getLogTypesForOperation(operation: OrganizationOperationEnum, includeAITask: boolean): LogTypeEnum[] {
126
+ export function getLogTypesForOperation(
127
+ operation: OrganizationOperationEnum,
128
+ ): LogTypeEnum[] {
96
129
  const logTypes = (LOG_TYPES_BY_OPERATION[operation] || []) as LogTypeEnum[];
97
- if (includeAITask) {
98
- return logTypes;
99
- }
100
- return logTypes.filter((type) => type !== 'AI_TASK');
130
+ return logTypes;
101
131
  }
102
132
 
103
133
  /**
@@ -107,27 +137,15 @@ export function getLogTypesForOperation(operation: OrganizationOperationEnum, in
107
137
  * @returns The log type or null if not found
108
138
  */
109
139
 
110
- export function getLogTypeFromActivity(operation: OrganizationOperationEnum | string, activity: any): LogTypeEnum | null {
111
- let logGroup;
112
- switch (operation) {
113
- case 'ARABLE':
114
- case 'LogArable':
115
- logGroup = ARABLE_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
116
- break;
117
- case 'LIVESTOCK':
118
- case 'LogLivestock':
119
- logGroup = LIVESTOCK_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
120
- break;
121
- case 'FARMERS_MARKET':
122
- case 'LogFarmersMarket':
123
- logGroup = FARMERS_MARKET_ACTIVITIES_GROUPED.find((group: any) => group[1].includes(activity));
124
- break;
125
- default:
126
- console.warn('(!1) Cannot get log type from unknown operation type:', operation);
127
- return null;
128
- }
140
+ export function getLogTypeFromActivity(
141
+ operation: OrganizationOperationEnum | string,
142
+ activity: any,
143
+ ): LogTypeEnum | null {
144
+ const logGroup = (LOG_ACTIVITIES_BY_OPERATION[operation] || []).find(
145
+ (group: any) => group[1].includes(activity),
146
+ );
129
147
 
130
- return logGroup?.[0] as LogTypeEnum || null;
148
+ return (logGroup?.[0] as LogTypeEnum) || null;
131
149
  }
132
150
 
133
151
  /**
@@ -140,109 +158,95 @@ export function getActivityText(activity: any, tryShortForm?: boolean): string {
140
158
  if (tryShortForm && i18n.has(`log.activity_short.${activity}`)) {
141
159
  return i18n.t(`log.activity_short.${activity}`);
142
160
  }
143
- return i18n.t(`log.activity.${activity}`);
161
+ return i18n.has(`log.activity.${activity}`)
162
+ ? i18n.t(`log.activity.${activity}`)
163
+ : humanizeRegistryKey(activity);
144
164
  }
145
165
 
146
166
  /**
147
- * Get the title for log entry for each Union interface
148
- * @param details - The details Union interface for log entry
167
+ * Get the title for a generic log entry.
168
+ * @param details - The generic details interface for the log entry
149
169
  * @param isServer - True if used in server
150
- * @param logType - Use this param if this function is used in server; {d.type} will be undefined unless manually set
170
+ * @param logType - Optional group-key override for partial or form details
151
171
  * @param iface - In unique cases (such as client-side form), you can use this for interface name
152
172
  * @return The title for the log entry
153
173
  */
154
174
 
155
- export function getLogEntryTitle(d: any, isServer?: boolean, logType_?: string, iface?: string): string {
156
- const { __typename, __table, type } = d;
157
- const logType = logType_ || type;
158
- const md = isServer ? (d.metadata || {}) : d;
175
+ export function getLogEntryTitle(
176
+ d: any,
177
+ isServer?: boolean,
178
+ logType_?: string | null,
179
+ iface?: string,
180
+ ): string {
181
+ const { __typename, __table, type, logType: storedLogType } = d;
182
+ const logType = logType_ || type || storedLogType;
183
+ const md = isServer ? d.metadata || {} : d;
159
184
 
160
185
  switch (iface || __typename || __table) {
161
- case 'ARABLE':
162
- case 'logs_arable':
163
- case 'LogArable': {
164
- const quantityText = joinReadable([formatDecimal(md.quantity, true, true), md.unit], ' ', ' ');
186
+ case 'log_entry_details':
187
+ case 'LogEntryDetails': {
188
+ const quantityText = joinReadable(
189
+ [formatDecimal(md.quantity, true, true), md.unit],
190
+ ' ',
191
+ ' ',
192
+ );
165
193
 
166
194
  let titleItem = ucFirst(md.item);
167
195
  let logSpecificText = '';
168
196
 
169
197
  if (logType === 'WATER') {
170
- logSpecificText = joinReadable([md.concentration, md.concentration && md.concentrationUnit], ' ', ' ');
198
+ const concentration = getLogEntryDetailsFieldValueByKey(
199
+ md,
200
+ 'concentration',
201
+ );
202
+ logSpecificText = joinReadable(
203
+ [
204
+ concentration === null ? null : String(concentration),
205
+ concentration === null
206
+ ? null
207
+ : getLogEntryDetailsFieldUnitByKey(md, 'concentration'),
208
+ ],
209
+ ' ',
210
+ ' ',
211
+ );
171
212
  } else if (['SEED', 'SALES'].includes(logType)) {
172
213
  if (!titleItem) {
173
214
  titleItem = i18n.t('log.unknown_crop');
174
215
  }
175
- const totalPrice = (md?.values || []).reduce((sum: number, item: any) => sum + Number(item.value || 0), 0);
216
+ const totalPrice = (md?.values || []).reduce(
217
+ (sum: number, item: any) => sum + Number(item.value || 0),
218
+ 0,
219
+ );
176
220
  logSpecificText = formatCurrency(totalPrice, false);
177
221
  }
178
222
 
179
223
  // console.log(md);
180
224
  // console.log('titleItem', titleItem);
181
225
 
182
- return textWithBrackets(
183
- titleItem,
184
- [
185
- logSpecificText + (logSpecificText && quantityText ? ',' : ''),
186
- quantityText,
187
- ],
188
- );
189
- }
190
- case 'FARMERS_MARKET':
191
- case 'logs_farmers_market':
192
- case 'LogFarmersMarket': {
193
- let creditsText = '';
194
- if (Array.isArray(md.values) && md.values.length) {
195
- creditsText = md.values.map((item: any) => {
196
- return `${formatCurrency(item.value, false)} ${item.label}`;
197
- }).join(', ');
198
-
199
- const totalAmount = md.values.reduce((sum: number, item: any) => sum + Number(item.value || 0), 0);
200
- creditsText += ` = ${i18n.t('form.total')}: ${formatCurrency(totalAmount, false)}`;
201
- }
202
-
203
- const voidText = isServer && md.voided ? i18n.t('form.void').toUpperCase() : '';
204
- return `${creditsText && voidText ? '(' + voidText + ')' : voidText} ${creditsText}`.trim();
205
- }
206
- case 'LIVESTOCK':
207
- case 'logs_livestock':
208
- case 'LogLivestock': {
209
- if (['SUPPLY_PURCHASE', 'LIVESTOCK_SALE'].includes(logType)) {
210
- return joinReadable(
211
- [
212
- formatReferenceNumber(md?.referenceNumber),
213
- formatCurrency((md?.values || []).reduce((sum: number, item: any) => sum + Number(item.value || 0), 0), false),
214
- ],
215
- ' - ',
216
- ' - ',
226
+ const priceText = md.price ? formatCurrency(md.price, false) : '';
227
+ if (
228
+ logType === 'MARKET_RECEIPT' &&
229
+ Array.isArray(md.values) &&
230
+ md.values.length
231
+ ) {
232
+ const creditsText = md.values
233
+ .map(
234
+ (item: any) => `${formatCurrency(item.value, false)} ${item.label}`,
235
+ )
236
+ .join(', ');
237
+ const totalAmount = md.values.reduce(
238
+ (sum: number, item: any) => sum + Number(item.value || 0),
239
+ 0,
217
240
  );
241
+ const voidText =
242
+ isServer && md.voided ? i18n.t('form.void').toUpperCase() : '';
243
+ return `${voidText ? `(${voidText}) ` : ''}${creditsText} = ${i18n.t('form.total')}: ${formatCurrency(totalAmount, false)}`;
218
244
  }
219
245
 
220
- if (isServer) {
221
- let livestockText = '';
222
- if (md.livestock) {
223
- livestockText += 'Species: ' + ucFirst(md.livestock) + '\n';
224
- }
225
- if (d.livestockGroup) {
226
- livestockText += 'Group: ' + d.livestockGroup + '\n';
227
- }
228
- if (Array.isArray(d.livestockIdentifiers) && d.livestockIdentifiers.length) {
229
- livestockText += 'Animal ID(s): ' + d.livestockIdentifiers.join(', ') + '\n';
230
- }
231
- if (d.damIdentifier) {
232
- livestockText += 'Dam ID: ' + d.damIdentifier + '\n';
233
- }
234
- return livestockText.trim();
235
- }
236
-
237
- return textWithBrackets(
238
- ucFirst(md.livestock),
239
- (d.livestockGroup ? [d.livestockGroup] : []).concat(
240
- (d.livestockIdentifiers || []).map((id: string) => `#${id}`),
241
- ).join(', ') + (
242
- d.damIdentifier ? ` (Dam: #${d.damIdentifier})` : ''
243
- ),
244
- [' - ', ''],
245
- );
246
+ return textWithBrackets(titleItem, [
247
+ logSpecificText || priceText + (priceText && quantityText ? ',' : ''),
248
+ quantityText,
249
+ ]);
246
250
  }
247
251
  default:
248
252
  }
@@ -260,612 +264,3 @@ export function getTextFormatLog(log: LogEntryData) {
260
264
  const title = getLogEntryTitle(log.details || {}, true);
261
265
  return (title + '\n\n' + (notes + '')).trim();
262
266
  }
263
-
264
- const PRODUCE_WORDS = [
265
- 'little gem',
266
- 'lil gem',
267
- 'romaine',
268
- 'cauliflow',
269
- 'broccoli',
270
- 'piracicab',
271
- 'mesclun',
272
- 'spinach',
273
- 'mustard green',
274
- 'arugula',
275
- 'kale',
276
- 'kohlrab',
277
- 'cabbag',
278
- 'parsley',
279
- 'beoc raab',
280
- 'wasabina',
281
- 'chervil',
282
- 'basil',
283
- 'artichoke',
284
- 'romanesco',
285
- 'zucchini',
286
- 'zuchini',
287
- 'potato',
288
- 'eggplant',
289
- 'jalapeno',
290
- 'jalapeño',
291
- 'carrot',
292
- 'midnight light',
293
- 'cilantro',
294
- 'bennings green',
295
- 'lettuce',
296
- 'escarol',
297
- 'raddish',
298
- 'radish',
299
- 'bean',
300
- 'stringbean',
301
- 'stinging kettle',
302
- 'radicchio',
303
- 'braci ardenti',
304
- 'braci adenti',
305
- 'chicory',
306
- 'puntarelle',
307
- 'chioggia',
308
- 'beet',
309
- 'thaddeus',
310
- 'sunshine kabocha',
311
- 'yellow star patty',
312
- 'butternut squash',
313
- 'butternutsquash',
314
- 'asparagus',
315
- 'acorn squash',
316
- 'acornsquash',
317
- 'delicata squash',
318
- 'hubbard squash',
319
- 'hubbard',
320
- 'red kuri',
321
- 'squash',
322
- 'cargo pump',
323
- 'pumpkin',
324
- 'cucumber',
325
- 'shiso',
326
- 'shinto',
327
- 'thyme',
328
- 'rosemary',
329
- 'di lusia',
330
- 'di lusio',
331
- 'treviso',
332
- 'scallion',
333
- 'scalion',
334
- 'spring onion',
335
- 'springonion',
336
- 'onion',
337
- 'shallot',
338
- 'wasabi',
339
- 'lavendar',
340
- 'lavender',
341
- 'anise hyssop',
342
- 'alyssum',
343
- 'marjoram',
344
- 'mint',
345
- 'sorrel',
346
- 'tomato',
347
- 'grapes',
348
- 'apricot',
349
- 'peach',
350
- 'plum',
351
- 'blueberr',
352
- 'billberr',
353
- 'blackberr',
354
- 'raspberr',
355
- 'cloudberr',
356
- 'cloud berr',
357
- 'sweet pepper',
358
- 'bell pepper',
359
- 'strawberr',
360
- 'berry',
361
-
362
- // Leave at end for backup
363
- 'marciano',
364
- 'spretnak',
365
- 'newham',
366
- 'red butter',
367
- 'frisee',
368
- 'cresta',
369
- 'cardoon',
370
- 'cynara cardunculus',
371
- 'cardunculus',
372
- 'butternut',
373
- 'green gem',
374
- 'red gem',
375
- 'starry night',
376
- 'benning',
377
- 'summar savor',
378
- 'summer savor',
379
- 'summery savor',
380
- 'summary savor',
381
- 'delicata',
382
- 'matador',
383
- 'green curl',
384
- 'red oak',
385
- 'flower',
386
- 'yellow tooth',
387
- 'sage\\b',
388
- 'sages\\b',
389
- 'okra',
390
- 'flor\\b',
391
- 'gems\\b',
392
- 'pump\\b',
393
- 'cruced\\b',
394
- 'star\\b',
395
- 'stars\\b',
396
- 'seed',
397
- 'pepper',
398
- 'chilli',
399
- 'mix\\b',
400
- 'chard',
401
- 'nettle',
402
- 'savory',
403
- 'dino',
404
-
405
- // log activities
406
- // NOTE: If i18n words change, these have to change too
407
- 'soil',
408
- 'irrigation',
409
- 'fertilization',
410
- 'crop protection',
411
- 'crop monitoring',
412
- 'direct seed',
413
- 'pruning',
414
- 'trellising',
415
- 'preparing crops',
416
- 'crops',
417
- 'estimating yield',
418
- 'other harvest',
419
- 'grading produce',
420
- 'moving produce',
421
- 'cold storage temperature',
422
- 'post harvest',
423
- 'sale',
424
- 'water testing',
425
- 'chlorine level',
426
- 'field',
427
- ];
428
-
429
- /**
430
- * Get the icon name from crop name by using regex
431
- * @param crop - The name of the crop
432
- * @param note - Additional note that may contain crop type
433
- * @param defaultIcon - The default icon to return if no match is found
434
- * @returns The icon name or a default icon if no match is found
435
- */
436
-
437
- export function getIconNameForArable(crop?: string | undefined, note?: string | null, defaultIcon?: string): string {
438
- if (crop) {
439
- const regex = new RegExp(`\\b(${PRODUCE_WORDS.join('|')})`, 'gi');
440
- const match = crop.replace('-', ' ').match(regex);
441
- if (match) {
442
- let matchedWord;
443
- if (match.length === 1) {
444
- matchedWord = match[0].toLowerCase();
445
- } else {
446
- // If multiple matches, choose the first match from produce words
447
- const lcMatch = match.map((m) => m.toLowerCase());
448
- matchedWord = PRODUCE_WORDS.find((word) => lcMatch.includes(word));
449
- }
450
-
451
- switch (matchedWord) {
452
- case 'little gem':
453
- case 'lil gem':
454
- case 'marciano':
455
- case 'red butter':
456
- case 'green gem':
457
- case 'red gem':
458
- case 'gems':
459
- case 'spretnak':
460
- case 'newham':
461
- return 'vegetable-lettuce-top';
462
- case 'lettuce':
463
- case 'red oak':
464
- case 'romaine':
465
- case 'escarol':
466
- case 'radicchio':
467
- case 'braci ardenti':
468
- case 'braci adenti':
469
- case 'di lusia':
470
- case 'di lusio':
471
- case 'treviso':
472
- case 'thaddeus':
473
- case 'cruced':
474
- return 'vegetable-lettuce';
475
- case 'lavendar':
476
- case 'lavender':
477
- case 'anise hyssop':
478
- case 'alyssum':
479
- return 'vegetable-lavender';
480
- case 'basil':
481
- return 'vegetable-basil';
482
- case 'chioggia':
483
- case 'beet':
484
- case 'yellow tooth':
485
- return 'vegetable-beet';
486
- case 'cauliflow':
487
- case 'broccoli':
488
- case 'piracicab':
489
- return 'vegetable-broccoli';
490
- case 'pumpkin':
491
- case 'pump':
492
- case 'cargo pump':
493
- case 'bennings green':
494
- case 'benning':
495
- return 'vegetable-pumpkin';
496
- case 'mesclun':
497
- case 'spinach':
498
- case 'chard':
499
- case 'mustard green':
500
- case 'mix':
501
- return 'vegetable-spinach';
502
- case 'tomato':
503
- return 'vegetable-tomato';
504
- case 'grapes':
505
- return 'fruit-grapes';
506
- case 'apricot':
507
- case 'peach':
508
- case 'plum':
509
- return 'fruit-apricot';
510
- case 'raspberr':
511
- return 'raspberry';
512
- case 'blackberr':
513
- case 'cloudberr':
514
- case 'cloud berr':
515
- return 'fruit-cloud-berry';
516
- case 'blueberr':
517
- case 'billberr':
518
- case 'berry':
519
- return 'fruit-billberry-blackberry-blueberry';
520
- case 'asparagus':
521
- return 'vegetable-asparagus';
522
- case 'sunshine kabocha':
523
- case 'acorn squash':
524
- case 'acornsquash':
525
- case 'yellow star patty':
526
- case 'sweet pepper':
527
- case 'bell pepper':
528
- return 'vegetable-acornsquash';
529
- case 'strawberr':
530
- return 'fruit-strawberry';
531
- case 'pepper':
532
- case 'chilli':
533
- return 'seasoning-chilli';
534
- case 'delicata':
535
- case 'delicata squash':
536
- return 'vegetable-delicata-squash';
537
- case 'hubbard squash':
538
- case 'hubbard':
539
- case 'red kuri':
540
- return 'vegetable-hubbard-squash';
541
- case 'shinto':
542
- case 'cucumber':
543
- return 'vegetable-cucumber';
544
- case 'butternut squash':
545
- case 'butternutsquash':
546
- case 'butternut':
547
- case 'squash':
548
- case 'starry night':
549
- return 'vegetable-butternutsquash';
550
- case 'summar savor':
551
- case 'summer savor':
552
- case 'summery savor':
553
- case 'summary savor':
554
- case 'thyme':
555
- case 'rosemary':
556
- case 'savory':
557
- return 'vegetable-thyme';
558
- case 'arugula':
559
- case 'chicory':
560
- case 'puntarelle':
561
- case 'frisee':
562
- case 'kale':
563
- case 'dino':
564
- case 'green curl':
565
- return 'vegetable-arugula';
566
- case 'parsley':
567
- case 'beoc raab':
568
- case 'wasabina':
569
- case 'chervil':
570
- return 'vegetable-parsley';
571
- case 'carrot':
572
- return 'vegetable-carrot';
573
- case 'artichoke':
574
- case 'romanesco':
575
- case 'star':
576
- case 'stars':
577
- return 'vegetable-artichoke';
578
- case 'cabbag':
579
- return 'vegetable-cabbage';
580
- case 'kohlrab':
581
- return 'vegetable-kohlrabi';
582
- case 'zucchini':
583
- case 'zuchini':
584
- case 'midnight light':
585
- return 'vegetable-zucchini';
586
- case 'potato':
587
- return 'vegetable-potato';
588
- case 'eggplant':
589
- return 'vegetable-eggplant';
590
- case 'jalapeno':
591
- case 'jalapeño':
592
- return 'vegetable-jalapeno';
593
- case 'stinging kettle':
594
- case 'nettle':
595
- case 'cardoon':
596
- case 'cynara cardunculus':
597
- case 'cardunculus':
598
- case 'cresta':
599
- case 'shiso':
600
- return 'vegetable-stinging-kettle';
601
- case 'okra':
602
- return 'vegetable-okra';
603
- case 'sage':
604
- case 'marjoram':
605
- case 'sorrel':
606
- case 'mint':
607
- return 'plant-1';
608
- case 'scallion':
609
- case 'scalion':
610
- case 'spring onion':
611
- case 'springonion':
612
- return 'vegetable-scallion';
613
- case 'seed':
614
- return 'gardening-seed-bag';
615
- case 'onion':
616
- case 'shallot':
617
- case 'matador':
618
- return 'vegetable-onion';
619
- case 'bean':
620
- case 'stringbean':
621
- return 'vegetable-stringbean-1';
622
- case 'cilantro':
623
- case 'flor':
624
- return 'vegetable-cilantro';
625
- case 'raddish':
626
- case 'radish':
627
- return 'vegetable-radish';
628
- case 'wasabi':
629
- return 'vegetable-wasabi';
630
- case 'flower':
631
- return 'flower';
632
- case 'soil':
633
- return 'product-growth-tree-box';
634
- case 'irrigation':
635
- return 'gardening-sprinkler';
636
- case 'direct seed':
637
- return 'agriculture-machine-seeder';
638
- case 'fertilization':
639
- return 'organic-bag-leaf';
640
- case 'crop protection':
641
- return 'gardening-tools-1';
642
- case 'crop monitoring':
643
- case 'field':
644
- return 'farming-barn-sun';
645
- case 'pruning':
646
- return 'gardening-scissors';
647
- case 'trellising':
648
- return 'barbed-wire-fence';
649
- case 'preparing crops':
650
- return 'protein-gluten-wheat';
651
- case 'crops':
652
- return 'harvest-product';
653
- case 'estimating yield':
654
- case 'other harvest':
655
- return 'crop-info-biotech-1';
656
- case 'grading produce':
657
- case 'moving produce':
658
- return 'harvest-product';
659
- case 'post harvest':
660
- return 'warehouse-storage';
661
- case 'cold storage temperature':
662
- return 'temperature-control-warehouse-1';
663
- case 'sale':
664
- return 'receipt-dollar';
665
- case 'water testing':
666
- case 'chlorine level':
667
- return 'organic-flask';
668
- default:
669
- console.log('Missing switchcase for crop:', crop);
670
- }
671
- }
672
-
673
- // console.log('No match found for crop:', crop);
674
- }
675
-
676
- if (note) {
677
- return getIconNameForArable(note, null, defaultIcon);
678
- }
679
-
680
- return defaultIcon || 'seedling';
681
- }
682
-
683
- /**
684
- * Get the icon name for livestock using regex
685
- * @param purchasedItem - The name of the purchased item
686
- * @param note - Additional note that may contain livestock type
687
- * @param defaultIcon - The default icon to return if no match is found
688
- * @returns The icon name or a default icon if no match is found
689
- */
690
-
691
- export function getIconNameForLivestock(
692
- purchasedItem?: string | null,
693
- note?: string | null,
694
- defaultIcon?: string,
695
- ): string {
696
- if (purchasedItem) {
697
- // return 'seedling';
698
- const LIVESTOCK_WORDS = [
699
- 'hay\\b',
700
- 'cow',
701
- 'calf',
702
- 'cattle',
703
- 'bull',
704
- 'sheep',
705
- ];
706
-
707
- const regex = new RegExp(`\\b(${LIVESTOCK_WORDS.join('|')})`, 'gi');
708
- const match = purchasedItem.replace('-', ' ').match(regex);
709
- if (match) {
710
- let matchedWord;
711
- if (match.length === 1) {
712
- matchedWord = match[0].toLowerCase();
713
- } else {
714
- // If multiple matches, choose the first match from produce words
715
- const lcMatch = match.map((m) => m.toLowerCase());
716
- matchedWord = LIVESTOCK_WORDS.find((word) => lcMatch.includes(word));
717
- }
718
-
719
- switch (matchedWord) {
720
- case 'hay':
721
- return 'farming-hay';
722
- case 'cow':
723
- case 'calf':
724
- case 'cattle':
725
- case 'bull':
726
- return 'livestock-cow-body';
727
- default:
728
- console.log('Missing switchcase for crop:', purchasedItem);
729
- }
730
- }
731
-
732
- console.log('No match found for crop:', purchasedItem);
733
- }
734
-
735
- if (note) {
736
- return getIconNameForLivestock(note, null, defaultIcon);
737
- }
738
-
739
- return defaultIcon || 'oat-2';
740
- }
741
-
742
- /**
743
- * Get the icon name for farmers market using regex
744
- * @param purchasedItem - The name of the purchased item
745
- * @param note - Additional note that may contain livestock type
746
- * @param defaultIcon - The default icon to return if no match is found
747
- * @returns The icon name or a default icon if no match is found
748
- */
749
-
750
- export function getIconNameForFarmersMarket(
751
- purchasedItem?: string | null,
752
- note?: string | null,
753
- defaultIcon?: string,
754
- ): string {
755
- if (purchasedItem) {
756
- // return 'seedling';
757
- const FARMERS_MARKET_WORDS = [
758
- 'hay\\b',
759
- 'cow',
760
- 'calf',
761
- 'cattle',
762
- 'bull',
763
- 'sheep',
764
- ];
765
-
766
- const regex = new RegExp(`\\b(${FARMERS_MARKET_WORDS.join('|')})`, 'gi');
767
- const match = purchasedItem.replace('-', ' ').match(regex);
768
- if (match) {
769
- let matchedWord;
770
- if (match.length === 1) {
771
- matchedWord = match[0].toLowerCase();
772
- } else {
773
- // If multiple matches, choose the first match from produce words
774
- const lcMatch = match.map((m) => m.toLowerCase());
775
- matchedWord = FARMERS_MARKET_WORDS.find((word) => lcMatch.includes(word));
776
- }
777
-
778
- switch (matchedWord) {
779
- case 'hay':
780
- return 'farming-hay';
781
- case 'cow':
782
- case 'calf':
783
- case 'cattle':
784
- case 'bull':
785
- return 'livestock-cow-body';
786
- default:
787
- console.log('Missing switchcase for crop:', purchasedItem);
788
- }
789
- }
790
-
791
- // console.log('No match found for farmers market:', purchasedItem);
792
- }
793
-
794
- if (note) {
795
- return getIconNameForFarmersMarket(note, null, defaultIcon);
796
- }
797
-
798
- return defaultIcon || 'farmers-market-kiosk';
799
- }
800
-
801
- /**
802
- * Get any icon name for any word
803
- */
804
-
805
- export function getIconNameForWord(
806
- decidingWord: any,
807
- text1: string,
808
- text2?: string | null,
809
- defaultIcon?: string,
810
- ) {
811
- switch (decidingWord) {
812
- case 'ARABLE':
813
- case 'LogArable':
814
- return getIconNameForArable(text1, text2, defaultIcon);
815
- case 'LIVESTOCK':
816
- case 'LogLivestock':
817
- return getIconNameForLivestock(text1, text2, defaultIcon);
818
- case 'FARMERS_MARKET':
819
- case 'LogFarmersMarket':
820
- return getIconNameForFarmersMarket(text1, text2, defaultIcon);
821
- default:
822
- // titleIconName = COMMON_ICON_NAMES.document;
823
- }
824
- return 'circle';
825
- }
826
-
827
- /**
828
- * Get icon name for any operation using regex
829
- * @param details - GraphQL log details object
830
- * @param defaultIcon - The default icon to return if no match is found
831
- * @returns The icon name or a default icon if no match is found
832
- */
833
-
834
- export function getIconNameForLog(
835
- details: any,
836
- preferActivityText?: boolean,
837
- defaultIcon_?: string,
838
- ) {
839
- // "crop" is deprecation support -- it should be "item" going forward
840
- const text1 = preferActivityText ? details.activity : details.item;
841
- const text2 = preferActivityText ? (details.title + ' ' + details.notes) : details.notes;
842
- // @ts-ignore - allow dynamic key access
843
- const defaultIcon = (preferActivityText && COMMON_ICON_NAMES[details.activity]) || defaultIcon_;
844
-
845
- // console.log('defaultIcon', preferActivityText, details.activity, defaultIcon);
846
-
847
- return getIconNameForWord(details.__typename, text1, text2, defaultIcon);
848
- }
849
-
850
- /**
851
- * Get title for log
852
- */
853
-
854
- export function getTitleForLog(details: any): string {
855
- switch (details.__typename) {
856
- case 'LogFarmersMarket':
857
- {
858
- // Check if text from values is short, else rely on the AI summary
859
- const valuesText = (details.values || []).map((item: any) => {
860
- return `${item.label} ${item.value ? formatCurrency(item.value, false) : ''}`.trim();
861
- }).join(', ');
862
-
863
- if (valuesText.length <= 40) {
864
- return valuesText;
865
- }
866
- }
867
- break;
868
- default:
869
- }
870
- return details.item;
871
- }