@jsb188/mday 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 (210) hide show
  1. package/package.json +140 -54
  2. package/src/constants/agentMemory.ts +123 -0
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +10 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +236 -0
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +21 -21
  10. package/src/constants/dataTableFieldTypes.generated.ts +59 -0
  11. package/src/constants/docAccess.ts +33 -0
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +125 -7
  14. package/src/constants/fieldDoc.ts +104 -0
  15. package/src/constants/graphqlReactivity.ts +196 -0
  16. package/src/constants/integration.ts +8 -9
  17. package/src/constants/log.ts +14 -408
  18. package/src/constants/logDisplay/README.md +88 -0
  19. package/src/constants/logDisplay/defaults.ts +39 -0
  20. package/src/constants/logDisplay/index.ts +27 -0
  21. package/src/constants/logDisplay/operations/arable.ts +16 -0
  22. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  23. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  24. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  25. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  26. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  27. package/src/constants/logTaxonomy.generated.ts +2207 -0
  28. package/src/constants/noteDoc.ts +77 -0
  29. package/src/constants/organization.ts +18 -21
  30. package/src/constants/pageRoute.ts +23 -0
  31. package/src/constants/qrCode.ts +30 -0
  32. package/src/constants/sheet.ts +126 -14
  33. package/src/constants/sms.ts +18 -0
  34. package/src/constants/square.ts +6 -6
  35. package/src/constants/storage.ts +80 -7
  36. package/src/constants/usage.ts +82 -0
  37. package/src/constants/workflowSteps.ts +60 -0
  38. package/src/schemas/editLogEntry.ts +836 -780
  39. package/src/schemas/inboundContact.ts +60 -55
  40. package/src/schemas/logsQuery.ts +55 -49
  41. package/src/types/account.d.ts +4 -1
  42. package/src/types/agentMemory.d.ts +98 -0
  43. package/src/types/agentNote.d.ts +443 -0
  44. package/src/types/billing.d.ts +537 -0
  45. package/src/types/campaign.d.ts +1533 -0
  46. package/src/types/contact.d.ts +15 -0
  47. package/src/types/csvExport.d.ts +213 -0
  48. package/src/types/dataAnalysis.d.ts +44 -0
  49. package/src/types/dataTable.d.ts +115 -403
  50. package/src/types/definitionElement.d.ts +35 -0
  51. package/src/types/docAccess.d.ts +96 -0
  52. package/src/types/dt.d.ts +257 -0
  53. package/src/types/email.d.ts +184 -24
  54. package/src/types/emailReplyReport.d.ts +76 -0
  55. package/src/types/fieldDoc.d.ts +702 -0
  56. package/src/types/fieldDocContract.d.ts +90 -0
  57. package/src/types/inboundContact.d.ts +10 -1
  58. package/src/types/log.d.ts +254 -295
  59. package/src/types/logDisplay.types.ts +85 -0
  60. package/src/types/organization.d.ts +91 -43
  61. package/src/types/pageRoute.d.ts +48 -0
  62. package/src/types/qrCode.d.ts +96 -0
  63. package/src/types/richText.d.ts +81 -0
  64. package/src/types/sheet.d.ts +678 -129
  65. package/src/types/sms.d.ts +38 -0
  66. package/src/types/storage.d.ts +449 -129
  67. package/src/types/usage.d.ts +106 -0
  68. package/src/types/workflow.d.ts +315 -54
  69. package/src/utils/agentMemory.ts +15 -0
  70. package/src/utils/agentNote.ts +850 -0
  71. package/src/utils/aiChat.ts +43 -0
  72. package/src/utils/aiChatWork.ts +64 -0
  73. package/src/utils/billing.ts +37 -0
  74. package/src/utils/campaign.ts +1174 -0
  75. package/src/utils/campaignAI.ts +72 -0
  76. package/src/utils/campaignAccess.ts +239 -0
  77. package/src/utils/campaignEmail.ts +601 -0
  78. package/src/utils/campaignEmailCompiler.ts +372 -0
  79. package/src/utils/campaignEmailImages.ts +60 -0
  80. package/src/utils/campaignEmailStyles.ts +544 -0
  81. package/src/utils/campaignLifecycle.ts +104 -0
  82. package/src/utils/campaignPreview.ts +285 -0
  83. package/src/utils/contact.ts +50 -0
  84. package/src/utils/csvExport.ts +19 -0
  85. package/src/utils/dataTable.ts +95 -618
  86. package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
  87. package/src/utils/dataTableRelativeDate.ts +447 -0
  88. package/src/utils/definitionElement.ts +84 -0
  89. package/src/utils/docAccess.ts +383 -0
  90. package/src/utils/documentName.ts +53 -0
  91. package/src/utils/email.ts +317 -51
  92. package/src/utils/emailReplyReport.test.ts +187 -0
  93. package/src/utils/emailReplyReport.ts +143 -0
  94. package/src/utils/fieldDoc.ts +157 -0
  95. package/src/utils/fieldDocAnswers.ts +128 -0
  96. package/src/utils/fieldDocDefaults.ts +36 -0
  97. package/src/utils/fieldDocProgram.ts +36 -0
  98. package/src/utils/fieldDocSummary.ts +30 -0
  99. package/src/utils/log.ts +276 -192
  100. package/src/utils/logDisplay.helpers.ts +177 -0
  101. package/src/utils/logDisplay.ts +87 -0
  102. package/src/utils/logRegistryValue.ts +90 -0
  103. package/src/utils/logStoreRead.ts +262 -0
  104. package/src/utils/logTaxonomy.helpers.ts +17 -0
  105. package/src/utils/logTaxonomy.ts +76 -0
  106. package/src/utils/logTaxonomyDisplay.ts +395 -0
  107. package/src/utils/noteDoc.ts +609 -0
  108. package/src/utils/organization.ts +337 -84
  109. package/src/utils/pageRoute.ts +71 -0
  110. package/src/utils/qrCode.helpers.ts +189 -0
  111. package/src/utils/qrCode.test.ts +519 -0
  112. package/src/utils/qrCode.ts +273 -0
  113. package/src/utils/richTextHTML.ts +385 -0
  114. package/src/utils/sheet.ts +199 -107
  115. package/src/utils/sheetAxisMove.ts +616 -0
  116. package/src/utils/sheetBootstrap.ts +1402 -0
  117. package/src/utils/sheetCellLiteral.ts +101 -0
  118. package/src/utils/sheetCommand.ts +358 -0
  119. package/src/utils/sheetDesign.ts +705 -0
  120. package/src/utils/sheetExport.ts +186 -0
  121. package/src/utils/sheetFeatureReference.ts +183 -0
  122. package/src/utils/sheetFormulaArgs.ts +168 -0
  123. package/src/utils/sheetFormulaCompile.ts +475 -0
  124. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  125. package/src/utils/sheetFormulaCriteria.ts +656 -0
  126. package/src/utils/sheetFormulaDate.ts +444 -0
  127. package/src/utils/sheetFormulaEvaluation.ts +899 -0
  128. package/src/utils/sheetFormulaEvaluator.ts +997 -0
  129. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  130. package/src/utils/sheetFormulaLogical.ts +116 -0
  131. package/src/utils/sheetFormulaLookup.ts +488 -0
  132. package/src/utils/sheetFormulaMath.ts +48 -0
  133. package/src/utils/sheetFormulaParser.ts +729 -0
  134. package/src/utils/sheetFormulaRange.ts +330 -0
  135. package/src/utils/sheetFormulaReference.ts +703 -0
  136. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  137. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  138. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  139. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  140. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  141. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  142. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  143. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  144. package/src/utils/sheetFormulaText.ts +430 -0
  145. package/src/utils/sheetJournal.ts +200 -0
  146. package/src/utils/sheetNumberFormat.ts +1012 -0
  147. package/src/utils/sheetPreview.ts +68 -0
  148. package/src/utils/sheetSequence.ts +118 -0
  149. package/src/utils/sheetSnapshot.ts +739 -0
  150. package/src/utils/sheetStructureEdit.ts +914 -0
  151. package/src/utils/sheetStructureReferences.ts +389 -0
  152. package/src/utils/square.ts +22 -12
  153. package/src/utils/storage.ts +198 -0
  154. package/src/utils/table-route.ts +127 -11
  155. package/src/utils/time.ts +12 -0
  156. package/src/utils/workflow.ts +334 -40
  157. package/src/utils/workflowLogFingerprint.ts +302 -0
  158. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  159. package/src/utils/workflowProgress.ts +280 -0
  160. package/src/utils/workflowTriggers.ts +61 -0
  161. package/tests/agentNote.test.ts +395 -0
  162. package/tests/campaignAI.test.ts +119 -0
  163. package/tests/campaignAccess.test.ts +239 -0
  164. package/tests/campaignEmail.test.ts +441 -0
  165. package/tests/campaignLifecycle.test.ts +134 -0
  166. package/tests/campaignPublication.test.ts +309 -0
  167. package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
  168. package/tests/dataTableRelativeDate.test.ts +412 -0
  169. package/tests/docAccess.test.ts +525 -0
  170. package/tests/editLogEntry.test.ts +112 -0
  171. package/tests/email.test.ts +39 -0
  172. package/tests/fieldDocProgram.test.ts +114 -0
  173. package/tests/logDisplay.fixtures.ts +67 -0
  174. package/tests/logDisplay.test.ts +227 -0
  175. package/tests/noteDoc.test.ts +514 -0
  176. package/tests/richTextHTML.test.ts +185 -0
  177. package/tests/sheetAxisMove.test.ts +352 -0
  178. package/tests/sheetBootstrap.test.ts +1967 -0
  179. package/tests/sheetFeatureReference.test.ts +22 -0
  180. package/tests/sheetFormulaCriteria.test.ts +269 -0
  181. package/tests/sheetFormulaEvaluator.test.ts +468 -0
  182. package/tests/sheetFormulaFunctions.test.ts +538 -0
  183. package/tests/sheetFormulaLanguage.test.ts +361 -0
  184. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  185. package/tests/sheetFormulaParity.test.ts +188 -0
  186. package/tests/sheetFormulaRange.test.ts +167 -0
  187. package/tests/sheetFormulaReference.test.ts +78 -0
  188. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  189. package/tests/sheetFormulaTextDate.test.ts +512 -0
  190. package/tests/sheetSequence.test.ts +22 -0
  191. package/tests/sheetSnapshot.test.ts +134 -0
  192. package/tests/sheetStructureEdit.test.ts +537 -0
  193. package/tests/sheetStructureReferences.test.ts +589 -0
  194. package/tests/workflowLifecycleStatus.test.ts +60 -0
  195. package/tests/workflowLogFingerprint.test.ts +203 -0
  196. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  197. package/tests/workflowProgress.test.ts +180 -0
  198. package/tests/workflowTriggers.test.ts +29 -0
  199. package/tsconfig.json +10 -10
  200. package/vitest.config.ts +8 -0
  201. package/src/constants/log-activityTexts.ts +0 -235
  202. package/src/constants/product.ts +0 -42
  203. package/src/constants/report.ts +0 -44
  204. package/src/schemas/organization.ts +0 -65
  205. package/src/schemas/productsQuery.ts +0 -53
  206. package/src/schemas/reportsQuery.ts +0 -20
  207. package/src/types/product.d.ts +0 -84
  208. package/src/types/report.d.ts +0 -290
  209. package/src/utils/product-calEvent.ts +0 -455
  210. package/src/utils/report.ts +0 -158
@@ -1,660 +1,776 @@
1
+ import { LOG_UNIT_INPUT_MAX_LENGTH } from '../constants/log.ts';
1
2
  import i18n from '@jsb188/app/i18n/index.ts';
2
3
  import { getCalDate } from '@jsb188/app/utils/datetime.ts';
3
4
  import { formatCurrency } from '@jsb188/app/utils/number.ts';
4
- import { getObject } from '@jsb188/app/utils/object.ts';
5
5
  import { textWithBrackets } from '@jsb188/app/utils/string.ts';
6
6
  import { getTimeZoneCode } from '@jsb188/app/utils/timeZone.ts';
7
+ import type { LogEntryDetailsFieldInput, LogEntryDetailsGQL, LogEntryGQL, LogTaxonomyGQL } from '../types/log.d.ts';
8
+ import { isAccountingLogActivity } from '../utils/log.ts';
7
9
  import {
8
- ARABLE_ACTIVITIES_GROUPED,
9
- FARMERS_MARKET_ACTIVITIES_GROUPED,
10
- GROWER_NETWORK_ACTIVITIES_GROUPED,
11
- LIVESTOCK_ACTIVITIES_GROUPED
12
- } from '../constants/log.ts';
13
- import type {
14
- LogArableDetailsGQL,
15
- LogEntryGQL,
16
- LogFarmersMarketDetailsGQL,
17
- LogGrowerNetworkDetailsGQL,
18
- LogLivestockDetailsGQL,
19
- LogTypeEnum
20
- } from '../types/log.d.ts';
21
- import { getLogCategoryColor, getLogTypeFromActivity } from '../utils/log.ts';
10
+ formatLogTaxonomyFieldLabel,
11
+ getLogEntryDetailsEnvelopeFieldLabel,
12
+ getLogEntryDetailsFieldLabel,
13
+ getLogEntryDetailsFieldValue,
14
+ getTaxonomyActivitiesGrouped,
15
+ getTaxonomyActivityLabel,
16
+ getTaxonomyFieldDefsForActivity,
17
+ getTaxonomyFieldRequirement,
18
+ getTaxonomyGroupKey,
19
+ getTaxonomyGroupLabel,
20
+ normalizeLogEntryDetailsDateTimeValue,
21
+ normalizeLogEntryDetailsDateValue,
22
+ } from '../utils/logTaxonomyDisplay.ts';
22
23
 
23
24
  /**
24
25
  * Get editable values based on activity & type (which is also used to display UI)
25
26
  */
26
27
 
27
- export const LOG_TYPENAME_TO_DETAILS_INPUT_NAME = {
28
- LogArable: 'arableDetails',
29
- LogFarmersMarket: 'farmersMarketDetails',
30
- LogGrowerNetwork: 'growerNetworkDetails',
31
- LogLivestock: 'livestockDetails',
28
+ export const LOG_DETAILS_INPUT_NAME_BY_TYPENAME = {
29
+ LogEntryDetails: 'details',
32
30
  };
33
31
 
34
32
  /**
35
33
  * Convert GQL data to GQL mutation input format
36
34
  */
37
35
 
38
- export function makeFormValuesFromData(logEntry: LogEntryGQL) {
39
- const formValues = {
40
- logEntryId: logEntry.id,
41
- organizationId: logEntry.organizationId,
42
- accountId: logEntry.accountId,
43
- date: logEntry.date,
44
- } as Record<string, any>;
45
-
46
- switch (logEntry.details?.__typename) {
47
- case 'LogArable': {
48
- const details = logEntry.details as LogArableDetailsGQL;
49
- formValues.arableDetails = {
50
- activity: details.activity,
51
- quantity: details.quantity,
52
- item: details.item,
53
- unit: details.unit,
54
- concentration: details.concentration,
55
- concentrationUnit: details.concentrationUnit,
56
- location: logEntry.location,
57
- referenceNumber: details.referenceNumber,
58
- otherParty: details.otherParty,
59
- values: details.values,
60
- voided: details.voided,
61
- notes: details.notes,
62
- };
63
- } break;
64
- case 'LogFarmersMarket': {
65
- const details = logEntry.details as LogFarmersMarketDetailsGQL;
66
- formValues.farmersMarketDetails = {
67
- activity: details.activity,
68
- referenceNumber: details.referenceNumber,
69
- voided: details.voided,
70
- values: details.values,
71
- notes: details.notes,
72
- };
73
- } break;
74
- case 'LogGrowerNetwork': {
75
- const details = logEntry.details as LogGrowerNetworkDetailsGQL;
76
- formValues.growerNetworkDetails = {
77
- activity: details.activity,
78
- childOrgId: logEntry.childOrgId,
79
- otherParty: details.otherParty,
80
- item: details.item,
81
- location: logEntry.location,
82
- notes: details.notes,
83
- };
84
- } break;
85
- case 'LogLivestock': {
86
- const details = logEntry.details as LogLivestockDetailsGQL;
87
- formValues.livestockDetails = {
88
- activity: details.activity,
89
- livestock: details.livestock,
90
- livestockIdentifiers: details.livestockIdentifiers,
91
- livestockGroup: details.livestockGroup,
92
- referenceNumber: details.referenceNumber,
93
- otherParty: details.otherParty,
94
- values: details.values,
95
- item: details.item,
96
- quantity: details.quantity,
97
- unit: details.unit,
98
- location: logEntry.location,
99
- price: details.price,
100
- tax: details.tax,
101
- notes: details.notes,
102
- };
103
- } break;
104
- default:
105
- // @ts-expect-error
106
- console.log(`${logEntry.details?.__typename} is not done yet.`);
107
- }
108
-
109
- // input LogArableInput {
110
- // activity: LogArableActivity
111
- // voided: Boolean
112
- // item: String
113
- // quantity: Float
114
- // unit: String
115
- // concentration: Float
116
- // concentrationUnit: String
117
- // price: Float
118
- // notes: String
119
- // }
120
-
121
- // input LogFarmersMarketInput {
122
- // activity: LogFarmersMarketActivity
123
- // childOrgId: GenericID
124
- // voided: Boolean
125
- // values: [LabelAndValueInput]
126
- // notes: String
127
- // }
128
-
129
- // input LogLivestockInput {
130
- // activity: LogLivestockType
131
- // livestock: String
132
- // livestockIdentifiers: [String]
133
- // item: String
134
- // quantity: Float
135
- // unit: String
136
- // price: Float
137
- // notes: String
138
- // }
139
-
140
-
141
- return formValues;
36
+ export function makeFormValuesFromData(logEntry: LogEntryGQL, taxonomy?: LogTaxonomyGQL | null, timeZone?: string | null) {
37
+ const formValues = {
38
+ logEntryId: logEntry.id,
39
+ organizationId: logEntry.organizationId,
40
+ accountId: logEntry.accountId,
41
+ date: logEntry.date,
42
+ } as Record<string, any>;
43
+
44
+ if (logEntry.details?.__typename === 'LogEntryDetails') {
45
+ // Registry-driven operations (Phase 8b): typed field-def values ride a
46
+ // flat map keyed by field-def key; every taxonomy def key is
47
+ // initialized so popover-driven inputs pass the form's hasObject guard
48
+ const details = logEntry.details as LogEntryDetailsGQL;
49
+ const fields: Record<string, any> = {};
50
+ const fieldUnits: Record<string, string | null> = {};
51
+ for (const def of taxonomy?.fieldDefs || []) {
52
+ fields[def.key] = null;
53
+ fieldUnits[def.key] = null;
54
+ }
55
+ for (const field of details.fields || []) {
56
+ fields[field.key] = getLogEntryDetailsFieldValue(field, timeZone);
57
+ fieldUnits[field.key] = field.unit;
58
+ }
59
+
60
+ formValues.details = {
61
+ activity: details.activity,
62
+ __groupKey: details.type,
63
+ __originalFields: { ...fields },
64
+ __originalFieldUnits: { ...fieldUnits },
65
+ item: details.item,
66
+ quantity: details.quantity,
67
+ unit: details.unit,
68
+ price: details.price,
69
+ values: details.values,
70
+ otherParty: details.otherParty,
71
+ referenceNumber: details.referenceNumber,
72
+ voided: details.voided,
73
+ fieldLocation: details.fieldLocation,
74
+ notes: details.notes,
75
+ fields,
76
+ fieldUnits,
77
+ };
78
+ }
79
+
80
+ return formValues;
142
81
  }
143
82
 
144
- /**
145
- * Convert HTML input values to GQL mutation input types
83
+ /*
84
+ * Clone the top-level mutation variables and each details envelope so
85
+ * normalization never mutates the React form state object.
146
86
  */
147
87
 
148
- export function formatFormValuesForMutation(formValues: Record<string, any>) {
149
- for (const key in formValues) {
150
- if (formValues[key] && typeof formValues[key] === 'object') {
88
+ function cloneFormValuesForMutation(formValues: Record<string, any>) {
89
+ return Object.fromEntries(
90
+ Object.entries(formValues).map(([key, value]) => {
91
+ if (!value || typeof value !== 'object' || Array.isArray(value) || value instanceof Date) {
92
+ return [key, value];
93
+ }
94
+
95
+ return [key, { ...value }];
96
+ }),
97
+ );
98
+ }
99
+
100
+ /*
101
+ * Return a finite form number, using null for an empty or invalid input so a
102
+ * GraphQL Float never receives NaN.
103
+ */
151
104
 
152
- for (const subKey in formValues[key]) {
153
- if (['quantity','price','tax','concentration'].includes(subKey)) {
154
- formValues[key][subKey] = parseFloat(formValues[key][subKey]);
155
- }
156
- }
157
- }
158
- }
105
+ function getFormNumberValue(value: unknown): number | null {
106
+ if (value === '' || value === null || value === undefined) {
107
+ return null;
108
+ }
159
109
 
160
- return formValues;
110
+ const numberValue = Number(value);
111
+ return Number.isFinite(numberValue) ? numberValue : null;
161
112
  }
162
113
 
163
- /**
164
- * Arable log metadata schema
114
+ /*
115
+ * Render numeric form values as strings so a valid zero is not replaced by the shared input's empty fallback.
116
+ */
117
+
118
+ function getLogEntryDetailsNumericInputValue(value: unknown): string {
119
+ return value === null || value === undefined || value === '' ? '' : String(value);
120
+ }
121
+
122
+ /*
123
+ * Return whether one generic form scalar represents an intentionally empty
124
+ * optional field.
125
+ */
126
+
127
+ function isEmptyLogEntryDetailsFieldValue(value: unknown): boolean {
128
+ return value === undefined || value === null || (typeof value === 'string' && !value.trim());
129
+ }
130
+
131
+ /*
132
+ * Return whether a generic field value or quantity unit changed from the form's original snapshot.
133
+ */
134
+
135
+ function logEntryDetailsFieldValueChanged(
136
+ key: string,
137
+ fields: Record<string, any>,
138
+ fieldUnits: Record<string, any>,
139
+ originalFields: Record<string, any> | null,
140
+ originalFieldUnits: Record<string, any> | null,
141
+ ): boolean {
142
+ if (!originalFields || !originalFieldUnits) {
143
+ return true;
144
+ }
145
+ return !Object.is(fields[key], originalFields[key]) || !Object.is(fieldUnits[key], originalFieldUnits[key]);
146
+ }
147
+
148
+ /*
149
+ * Convert one applicable field-def form value to the typed mutation shape.
150
+ * Optional empty fields become explicit clear operations.
165
151
  */
166
152
 
167
- export type ValidMetadataFieldName =
168
- | 'break'
169
- | 'activity'
170
- | 'childOrgName'
171
- | 'childOrgName*fill'
172
- | 'location'
173
- | 'location*fill'
174
- | 'fieldLocation'
175
-
176
- // ARABLE
177
- | 'water_testing'
178
- | 'concentration_unit'
179
- | 'water_quantity'
180
- | 'quantity'
181
- | 'water_unit'
182
- | 'unit'
183
- | 'price'
184
- | 'crop'
185
- | 'purchased_item'
186
- | 'location_water'
187
- | 'location_arable'
188
-
189
- // FARMERS_MARKET
190
- | 'receiptNumber'
191
- // | 'childOrgId' // Not editable
192
- | 'void'
193
- | 'marketCredits'
194
-
195
- // LIVESTOCK
196
- | 'livestock'
197
- | 'livestockIdentifiers'
198
- | 'livestockGroup'
199
- | 'otherParty'
200
- | 'invoiceNumber'
201
- | 'invoiceItems'
202
- | 'tax'
203
- | 'item_used'
204
- | 'location_livestock'
205
- | null; // Need this for eslint satisfcation, but null will never happen (because of a filter())
206
-
207
- function makeMetadataSchema(
208
- namespace: string,
209
- formValues: Record<string, any>,
210
- metadataParams: MakeMetadataSchemaParams,
211
- basePopOverProps: Record<string, any>,
212
- schemaFields: ValidMetadataFieldName[]
153
+ function makeLogEntryDetailsFieldMutationInput(
154
+ def: LogTaxonomyGQL['fieldDefs'][number],
155
+ rawValue: unknown,
156
+ rawUnit: unknown,
157
+ timeZone?: string | null,
158
+ ): LogEntryDetailsFieldInput | null {
159
+ if (isEmptyLogEntryDetailsFieldValue(rawValue)) {
160
+ // The server rejects clears for required defs after merging against the
161
+ // locked current row; omitting the key would silently preserve it.
162
+ return { key: def.key, clear: true };
163
+ }
164
+
165
+ if (def.fieldType === 'BOOLEAN') {
166
+ return {
167
+ key: def.key,
168
+ booleanValue: rawValue === true || rawValue === 'true',
169
+ };
170
+ }
171
+
172
+ if (['NUMBER', 'MONEY'].includes(def.fieldType)) {
173
+ const numberValue = getFormNumberValue(rawValue);
174
+ return numberValue === null ? null : { key: def.key, numberValue };
175
+ }
176
+
177
+ if (def.fieldType === 'QUANTITY') {
178
+ const numberValue = getFormNumberValue(rawValue);
179
+ if (numberValue === null) {
180
+ return null;
181
+ }
182
+
183
+ return {
184
+ key: def.key,
185
+ numberValue,
186
+ unit: String(rawUnit || '').trim() || null,
187
+ };
188
+ }
189
+
190
+ if (def.fieldType === 'DATE') {
191
+ const dateValue = normalizeLogEntryDetailsDateValue(String(rawValue));
192
+ return dateValue ? { key: def.key, dateValue } : null;
193
+ }
194
+
195
+ if (def.fieldType === 'DATETIME') {
196
+ const datetimeValue = normalizeLogEntryDetailsDateTimeValue(String(rawValue), timeZone);
197
+ return datetimeValue ? { key: def.key, datetimeValue } : null;
198
+ }
199
+
200
+ return { key: def.key, textValue: String(rawValue) };
201
+ }
202
+
203
+ /*
204
+ * Build mutation variables without mutating the React form state object.
205
+ */
206
+
207
+ export function formatFormValuesForMutation(
208
+ formValues: Record<string, any>,
209
+ taxonomy?: LogTaxonomyGQL | null,
210
+ timeZone?: string | null,
211
+ ) {
212
+ const mutationValues = cloneFormValuesForMutation(formValues);
213
+
214
+ for (const key in mutationValues) {
215
+ const details = mutationValues[key];
216
+ if (details && typeof details === 'object' && !Array.isArray(details)) {
217
+ for (const subKey in details) {
218
+ if (['quantity', 'price', 'tax', 'concentration'].includes(subKey)) {
219
+ details[subKey] = getFormNumberValue(details[subKey]);
220
+ }
221
+ }
222
+ }
223
+ }
224
+
225
+ // Only fields applicable to the saved activity are sent. The server owns
226
+ // authoritative cleanup of stale fields from the previous activity scope.
227
+ const details = mutationValues.details;
228
+ if (details && typeof details === 'object') {
229
+ const { fields = {}, fieldUnits = {}, __groupKey, __originalFields = null, __originalFieldUnits = null, ...envelope } = details;
230
+ const applicableDefs = getTaxonomyFieldDefsForActivity(taxonomy, envelope.activity, __groupKey);
231
+ const fieldInputs = applicableDefs
232
+ .filter((def) =>
233
+ logEntryDetailsFieldValueChanged(
234
+ def.key,
235
+ fields as Record<string, any>,
236
+ fieldUnits as Record<string, any>,
237
+ __originalFields as Record<string, any> | null,
238
+ __originalFieldUnits as Record<string, any> | null,
239
+ )
240
+ )
241
+ .map((def) =>
242
+ makeLogEntryDetailsFieldMutationInput(
243
+ def,
244
+ (fields as Record<string, any>)[def.key],
245
+ (fieldUnits as Record<string, any>)[def.key],
246
+ timeZone,
247
+ )
248
+ )
249
+ .filter(Boolean) as LogEntryDetailsFieldInput[];
250
+
251
+ mutationValues.details = { ...envelope, fields: fieldInputs };
252
+ }
253
+
254
+ return mutationValues;
255
+ }
256
+
257
+ /*
258
+ * Build the companion unit editor for a QUANTITY field def. Registry enum
259
+ * units use a picker; defs without an enum keep the existing free-text input.
260
+ */
261
+
262
+ function makeLogEntryDetailsQuantityUnitSchemaItem(
263
+ def: LogTaxonomyGQL['fieldDefs'][number],
264
+ fieldUnitName: string,
265
+ currentUnit: string | null | undefined,
266
+ formId: string,
267
+ focusedName: string,
268
+ basePopOverProps: Record<string, any>,
213
269
  ) {
214
- const { scrollAreaDOMId, formId, timeZone, focusedName, isCreateNew } = metadataParams;
215
- const schemaItems = schemaFields.map((field: ValidMetadataFieldName) => {
216
- switch (field) {
217
- case 'activity':
218
- return {
219
- __type: 'input_click',
220
- forceClickId: `input_click_${namespace}.activity`,
221
- label: i18n.t('form.activity'),
222
- item: {
223
- // editable: false,
224
- // locked: () => true, // Conditional lock is possible
225
- focused: focusedName === (formId + '_activity'),
226
- name: `${namespace}.activity`,
227
- placeholder: isCreateNew ? i18n.t(`form.activity_ph`) : '',
228
- getter: (value: string) => value ? i18n.t(`log.activity.${value}`) : '',
229
- },
230
- };
231
- case 'water_testing':
232
- return {
233
- __type: 'input',
234
- label: i18n.t('form.concentration'),
235
- item: {
236
- name: `${namespace}.concentration`,
237
- type: 'number',
238
- step: 0.1,
239
- min: 0.1,
240
- max: 99999999.99, // database max is numeric(10, 2)
241
- placeholder: isCreateNew ? i18n.t('form.concentration_ph') : '',
242
- }
243
- };
244
- case 'concentration_unit':
245
- return {
246
- __type: 'input',
247
- label: i18n.t('form.concentration_unit'),
248
- item: {
249
- name: `${namespace}.concentrationUnit`,
250
- maxLength: 40,
251
- placeholder: isCreateNew ? i18n.t('form.concentration_unit_ph') : '',
252
- },
253
- };
254
- case 'water_quantity':
255
- return {
256
- __type: 'input',
257
- label: i18n.t('form.water_quantity'),
258
- item: {
259
- name: `${namespace}.quantity`,
260
- type: 'number',
261
- step: 0.1,
262
- min: 0.1,
263
- max: 99999999.99, // database max is numeric(10, 2)
264
- placeholder: isCreateNew ? i18n.t('form.quantity_ph') : '',
265
- }
266
- };
267
- case 'quantity':
268
- return {
269
- __type: 'input',
270
- label: i18n.t('form.quantity'),
271
- item: {
272
- name: `${namespace}.quantity`,
273
- type: 'number',
274
- step: 0.1,
275
- min: 0.1,
276
- max: 99999999.99, // database max is numeric(10, 2)
277
- placeholder: isCreateNew ? i18n.t('form.quantity_ph') : '',
278
- }
279
- };
280
- case 'water_unit':
281
- return {
282
- __type: 'input',
283
- label: i18n.t('form.water_unit'),
284
- item: {
285
- name: `${namespace}.unit`,
286
- maxLength: 40,
287
- placeholder: isCreateNew ? i18n.t('form.water_unit_ph') : '',
288
- }
289
- };
290
- case 'unit':
291
- return {
292
- __type: 'input',
293
- label: i18n.t('form.unit'),
294
- item: {
295
- name: `${namespace}.unit`,
296
- maxLength: 40,
297
- placeholder: isCreateNew ? i18n.t('log.unit_arable_ph') : '',
298
- }
299
- };
300
- case 'fieldLocation':
301
- return {
302
- __type: 'input',
303
- label: i18n.t('log.fieldLocation'),
304
- item: {
305
- name: `${namespace}.fieldLocation`,
306
- maxLength: 64,
307
- placeholder: '',
308
- }
309
- };
310
- case 'location_arable':
311
- return {
312
- __type: 'input',
313
- label: i18n.t('form.location'),
314
- item: {
315
- name: `${namespace}.location`,
316
- maxLength: 40,
317
- placeholder: isCreateNew ? i18n.t('log.location_arable_ph') : '',
318
- }
319
- };
320
- case 'location_water':
321
- return {
322
- __type: 'input',
323
- label: i18n.t('form.location'),
324
- item: {
325
- name: `${namespace}.location`,
326
- maxLength: 40,
327
- placeholder: isCreateNew ? i18n.t('log.location_water_ph') : '',
328
- }
329
- };
330
- case 'location_livestock':
331
- return {
332
- __type: 'input',
333
- label: i18n.t('form.location'),
334
- item: {
335
- name: `${namespace}.location`,
336
- maxLength: 100,
337
- placeholder: isCreateNew ? i18n.t('log.location_livestock_ph') : '',
338
- }
339
- };
340
- case 'price':
341
- return {
342
- __type: 'input',
343
- label: i18n.t('form.price'),
344
- item: {
345
- name: `${namespace}.price`,
346
- type: 'number',
347
- step: 0.1,
348
- min: 0.1,
349
- max: 99999999.99, // database max is numeric(10, 2)
350
- placeholder: isCreateNew ? i18n.t('form.price_ph') : '',
351
- },
352
- };
353
- case 'tax':
354
- return {
355
- __type: 'input',
356
- label: i18n.t('form.tax'),
357
- item: {
358
- name: `${namespace}.tax`,
359
- type: 'number',
360
- step: 0.1,
361
- min: 0.1,
362
- max: 99999999.99, // database max is numeric(10, 2)
363
- placeholder: isCreateNew ? i18n.t('form.tax_ph') : '',
364
- },
365
- };
366
- case 'crop':
367
- return {
368
- __type: 'input',
369
- label: i18n.t('form.crop'),
370
- item: {
371
- name: `${namespace}.item`,
372
- placeholder: isCreateNew ? i18n.t('log.crop_ph') : '',
373
- }
374
- };
375
- case 'purchased_item':
376
- return {
377
- __type: 'input',
378
- label: i18n.t('form.purchase_summary'),
379
- item: {
380
- name: `${namespace}.item`,
381
- placeholder: isCreateNew ? i18n.t('log.crop_ph') : '',
382
- }
383
- };
384
- case 'livestock':
385
- return {
386
- __type: 'input',
387
- label: i18n.t('log.livestock'),
388
- item: {
389
- name: `${namespace}.livestock`,
390
- placeholder: isCreateNew ? i18n.t('log.livestock_ph') : '',
391
- }
392
- };
393
- case 'livestockIdentifiers':
394
- return {
395
- __type: 'input',
396
- label: i18n.t('log.id_tags'),
397
- item: {
398
- name: `${namespace}.livestockIdentifiers`,
399
- placeholder: isCreateNew ? i18n.t('log.id_tags_ph') : '',
400
- getter: (value: string[]) => value ? value.join(',') : '',
401
- setter: (value: string) => value.split(',')
402
- }
403
- };
404
- case 'livestockGroup':
405
- return {
406
- __type: 'input',
407
- label: i18n.t('log.group'),
408
- item: {
409
- name: `${namespace}.livestockGroup`,
410
- placeholder: isCreateNew ? i18n.t('log.group_ph') : '',
411
- }
412
- };
413
- case 'otherParty':
414
- return {
415
- __type: 'input',
416
- label: i18n.t('form.vendor'),
417
- item: {
418
- name: `${namespace}.otherParty`,
419
- }
420
- };
421
- case 'invoiceNumber':
422
- return {
423
- __type: 'input',
424
- label: i18n.t('log.invoice_number'),
425
- item: {
426
- // editable: false,
427
- locked: true,
428
- name: `${namespace}.referenceNumber`,
429
- }
430
- };
431
- case 'receiptNumber':
432
- return {
433
- __type: 'input',
434
- label: i18n.t('log.receipt_number'),
435
- item: {
436
- // editable: false,
437
- locked: true,
438
- name: `${namespace}.referenceNumber`,
439
- // placeholder: isCreateNew ? i18n.t('log.group_ph') : '',
440
- // getter: (value: string[]) => value ? value.join(',') : '',
441
- // setter: (value: string) => value.split(',')
442
- }
443
- };
444
-
445
- // Not allowed to edit
446
- // case 'childOrgId':
447
- // return {
448
- // __type: 'input',
449
- // label: i18n.t('log.receipt_for'),
450
- // item: {
451
- // name: `${namespace}.childOrgId`,
452
- // // placeholder: isCreateNew ? i18n.t('log.group_ph') : '',
453
- // // getter: (value: string[]) => value ? value.join(',') : '',
454
- // // setter: (value: string) => value.split(',')
455
- // }
456
- // };
457
- case 'void':
458
- return {
459
- __type: 'input_click',
460
- forceClickId: `input_click_${namespace}.voided`,
461
- label: i18n.t('form.void'),
462
- inputClassName: formValues[namespace]?.voided ? 'cl_red' : '',
463
- item: {
464
- // locked: () => true,
465
- focused: focusedName === (formId + '_void'),
466
- name: `${namespace}.voided`,
467
- placeholder: isCreateNew ? i18n.t(`form.void_ph`) : '',
468
- getter: (value: string) => i18n.t(value ? 'form.voided' : 'form.valid'),
469
- },
470
- popOverProps: {
471
- id: formId + '_void',
472
- ...basePopOverProps,
473
- iface: {
474
- name: 'PO_LIST',
475
- variables: {
476
- designClassName: 'w_250',
477
- className: 'max_h_40vh',
478
- options: [{
479
- __type: 'LIST_ITEM' as const,
480
- text: i18n.t('form.valid'),
481
- iconName: 'receipt-dollar',
482
- selected: !formValues[namespace]?.voided,
483
- name: `${namespace}.voided`,
484
- value: false,
485
- }, {
486
- __type: 'LIST_ITEM' as const,
487
- text: i18n.t('form.voided'),
488
- iconName: 'receipt-off',
489
- selected: formValues[namespace]?.voided === true,
490
- name: `${namespace}.voided`,
491
- value: true,
492
- }]
493
- }
494
- }
495
- }
496
- };
497
- case 'invoiceItems':
498
- return {
499
- __type: 'input_click',
500
- label: i18n.t('log.invoice_items'),
501
- forceClickId: `input_click_${namespace}.values`,
502
- item: {
503
- // locked: () => true,
504
- focused: focusedName === (formId + '_values'),
505
- name: `${namespace}.values`,
506
- placeholder: isCreateNew ? i18n.t(`log.invoice_items_ph`) : '',
507
- getter: (labelsAndValues: string[]) => {
508
- return labelsAndValues?.map((lv: any) => {
509
- return textWithBrackets(
510
- `${lv.quantity ? `${lv.quantity} ` : ''}${lv.unit ? `${lv.unit} ` : ''}${lv.label}`,
511
- formatCurrency(lv.value, false),
512
- );
513
- }).join(', ');
514
- },
515
- },
516
- popOverProps: {
517
- id: formId + '_invoiceItems',
518
- ...basePopOverProps,
519
- iface: {
520
- name: 'PO_LABELS_AND_VALUES',
521
- variables: {
522
- gridLayoutStyle: '70px 70px 1fr 85px',
523
- designClassName: 'w_400',
524
- className: 'max_h_40vh',
525
- // flipInputOrder: true,
526
- forceNumericValues: true,
527
- includeQuantity: true,
528
- includeUnit: true,
529
- name: `${namespace}.values`,
530
- labels: [i18n.t('form.quantity'), i18n.t('form.unit'), i18n.t('log.invoice_item'), `$ ${i18n.t('form.amount')}`],
531
- inputs: formValues[namespace]?.values || [],
532
- }
533
- }
534
- }
535
- };
536
- case 'marketCredits':
537
- return {
538
- __type: 'input_click',
539
- label: i18n.t('log.marketCredits'),
540
- forceClickId: `input_click_${namespace}.values`,
541
- item: {
542
- // locked: () => true,
543
- focused: focusedName === (formId + '_values'),
544
- name: `${namespace}.values`,
545
- placeholder: isCreateNew ? i18n.t(`log.marketCredits_ph`) : '',
546
- getter: (labelsAndValues: string[]) => {
547
- return labelsAndValues?.map((lv: any) => {
548
- return `${formatCurrency(lv.value, false)} ${lv.label}`;
549
- }).join(', ');
550
- },
551
- },
552
- popOverProps: {
553
- id: formId + '_marketCredits',
554
- ...basePopOverProps,
555
- iface: {
556
- name: 'PO_LABELS_AND_VALUES',
557
- variables: {
558
- gridLayoutStyle: '85px 1fr',
559
- designClassName: 'w_250',
560
- className: 'max_h_40vh',
561
- flipInputOrder: true,
562
- forceNumericValues: true,
563
- name: `${namespace}.values`,
564
- labels: [`$ ${i18n.t('form.amount')}`, i18n.t('log.name_of_credit')],
565
- inputs: formValues[namespace]?.values || [],
566
- }
567
- }
568
- }
569
- };
570
- default:
571
- console.warn(`Field ${field} is not defined in metadata schema.`);
572
- return null;
573
- }
574
- }).filter(Boolean);
575
-
576
- return schemaItems;
270
+ if (!def.allowedUnits?.length) {
271
+ return {
272
+ __type: 'input',
273
+ label: i18n.t('c.unit'),
274
+ item: {
275
+ name: fieldUnitName,
276
+ maxLength: LOG_UNIT_INPUT_MAX_LENGTH,
277
+ placeholder: '',
278
+ },
279
+ };
280
+ }
281
+
282
+ return {
283
+ __type: 'input_click',
284
+ forceClickId: `input_click_${fieldUnitName}`,
285
+ label: i18n.t('c.unit'),
286
+ item: {
287
+ focused: focusedName === `${formId}_field_${def.key}_unit`,
288
+ name: fieldUnitName,
289
+ placeholder: '',
290
+ getter: (value: string | null) => value || '',
291
+ popOverProps: {
292
+ id: `${formId}_field_${def.key}_unit`,
293
+ ...basePopOverProps,
294
+ iface: {
295
+ name: 'PO_LIST',
296
+ variables: {
297
+ designClassName: 'w_250',
298
+ className: 'max_h_40vh',
299
+ options: [
300
+ {
301
+ __type: 'LIST_ITEM' as const,
302
+ text: i18n.t('c.remove'),
303
+ selected: !currentUnit,
304
+ name: fieldUnitName,
305
+ value: null,
306
+ },
307
+ ...def.allowedUnits.map((unit) => ({
308
+ __type: 'LIST_ITEM' as const,
309
+ text: unit,
310
+ selected: currentUnit === unit,
311
+ name: fieldUnitName,
312
+ value: unit,
313
+ })),
314
+ ],
315
+ },
316
+ },
317
+ },
318
+ },
319
+ };
320
+ }
321
+
322
+ /*
323
+ * Build the shared itemized-values editor used by transaction-style logs.
324
+ */
325
+
326
+ function makeLogEntryDetailsValuesSchemaItem(
327
+ namespace: string,
328
+ detailsFormValues: Record<string, any>,
329
+ formId: string,
330
+ focusedName: string,
331
+ basePopOverProps: Record<string, any>,
332
+ required: boolean,
333
+ ) {
334
+ return {
335
+ __type: 'input_click',
336
+ label: formatLogTaxonomyFieldLabel(i18n.t('log.invoice_items'), required ? 'REQUIRED' : null),
337
+ forceClickId: `input_click_${namespace}.values`,
338
+ item: {
339
+ focused: focusedName === `${formId}_values`,
340
+ name: `${namespace}.values`,
341
+ required,
342
+ placeholder: i18n.t('log.invoice_items_ph'),
343
+ getter: (labelsAndValues: any[]) =>
344
+ labelsAndValues
345
+ ?.map((entry) =>
346
+ textWithBrackets(
347
+ `${entry.quantity ? `${entry.quantity} ` : ''}${entry.unit ? `${entry.unit} ` : ''}${entry.label}`,
348
+ formatCurrency(entry.value, false),
349
+ )
350
+ )
351
+ .join(', '),
352
+ },
353
+ popOverProps: {
354
+ id: `${formId}_values`,
355
+ ...basePopOverProps,
356
+ iface: {
357
+ name: 'PO_LABELS_AND_VALUES',
358
+ variables: {
359
+ gridLayoutStyle: '70px 70px 1fr 85px',
360
+ designClassName: 'w_400',
361
+ className: 'max_h_40vh',
362
+ forceNumericValues: true,
363
+ includeQuantity: true,
364
+ includeUnit: true,
365
+ name: `${namespace}.values`,
366
+ labels: [i18n.t('c.quantity'), i18n.t('c.unit'), i18n.t('log.invoice_item'), `$ ${i18n.t('c.amount')}`],
367
+ inputs: detailsFormValues.values || [],
368
+ },
369
+ },
370
+ },
371
+ };
577
372
  }
578
373
 
579
374
  /**
580
- * Get schema fields from log type
375
+ * Editor schema for registry-driven operations (Phase 8b): the envelope
376
+ * (activity/item/quantity/unit/price/fieldLocation/void) plus one typed input per
377
+ * applicable registry field def. Labels fall back i18n -> registry text ->
378
+ * humanized key because registry keys are data, not compile-time enums.
581
379
  */
582
380
 
583
- export function getSchemaFieldsFromLog(__typename: string, logType: LogTypeEnum): ValidMetadataFieldName[] {
584
-
585
- let schemaFields: ValidMetadataFieldName[];
586
- switch (__typename) {
587
- case 'LogArable': {
588
- const isWaterTesting = logType === 'WATER';
589
- const isSale = ['SALES'].includes(logType!);
590
- const isPurchase = ['SEED'].includes(logType!);
591
- const isSaleOrPurchase = isSale || isPurchase;
592
-
593
- schemaFields = [
594
- 'activity',
595
- isWaterTesting ? 'water_testing' : null,
596
- isWaterTesting ? 'concentration_unit' : null, // unit will be ignored in view mode
597
- isWaterTesting ? null : isSaleOrPurchase ? 'purchased_item' : 'crop',
598
- isWaterTesting ? 'water_quantity' : isSaleOrPurchase ? null : 'quantity',
599
- isWaterTesting ? 'water_unit' : isSaleOrPurchase ? null : 'unit', // unit will be ignored in view mode
600
- isSaleOrPurchase ? 'otherParty' : null,
601
- isSaleOrPurchase ? 'invoiceNumber' : null,
602
- isSaleOrPurchase ? 'invoiceItems' : null,
603
- isSaleOrPurchase ? 'tax' : null,
604
- isSaleOrPurchase ? 'void' : null,
605
- isSaleOrPurchase ? null : isWaterTesting ? 'location_water' : 'location_arable',
606
- 'location',
607
- 'fieldLocation',
608
- ];
609
- } break;
610
- case 'LogFarmersMarket': {
611
- const isReceipt = ['MARKET_RECEIPT'].includes(logType);
612
-
613
- schemaFields = [
614
- 'activity',
615
- isReceipt ? 'receiptNumber' : null,
616
- // 'childOrgId', // not editable
617
- isReceipt ? 'void' : null,
618
- isReceipt ? 'marketCredits' : null,
619
- 'location*fill',
620
- 'fieldLocation',
621
- ];
622
- } break;
623
- case 'LogGrowerNetwork': {
624
- schemaFields = [
625
- 'activity',
626
- 'childOrgName*fill',
627
- // 'break',
628
- 'location*fill',
629
- 'fieldLocation'
630
- ];
631
- } break;
632
- case 'LogLivestock': {
633
- const isLivestock = ['LIVESTOCK_LIFE_CYCLE', 'LIVESTOCK_TRACKING', 'LIVESTOCK_HEALTHCARE'].includes(logType);
634
- const isSupplyPurchase = logType === 'SUPPLY_PURCHASE';
635
- const isLandManagement = logType === 'PASTURE_LAND_MANAGEMENT';
636
-
637
- schemaFields = [
638
- 'activity',
639
- isLivestock ? 'livestock' : null,
640
- isLivestock ? 'livestockIdentifiers' : null,
641
- isLivestock ? 'livestockGroup' : null,
642
- isSupplyPurchase ? 'otherParty' : null,
643
- isSupplyPurchase ? 'invoiceNumber' : null,
644
- isSupplyPurchase ? 'invoiceItems' : null,
645
- isSupplyPurchase ? 'tax' : null,
646
- isLandManagement ? 'item_used' : null,
647
- isLivestock || isSupplyPurchase ? null : 'quantity',
648
- isLivestock || isSupplyPurchase ? null : 'unit',
649
- !isSupplyPurchase ? 'location_livestock' : null,
650
- isLivestock ? 'price' : null,
651
- ];
652
- } break;
653
- default:
654
- schemaFields = [];
655
- }
656
-
657
- return schemaFields.filter(Boolean);
381
+ function makeLogEntryDetailsMetadataSchema(
382
+ namespace: string,
383
+ formValues: Record<string, any>,
384
+ metadataParams: MakeMetadataSchemaParams,
385
+ basePopOverProps: Record<string, any>,
386
+ ) {
387
+ const { taxonomy, formId, focusedName, isCreateNew } = metadataParams;
388
+ if (!taxonomy) {
389
+ return [];
390
+ }
391
+
392
+ const detailsFormValues = formValues[namespace] || {};
393
+ const activityKey = detailsFormValues.activity;
394
+ const groupKey = getTaxonomyGroupKey(taxonomy, activityKey, detailsFormValues.__groupKey);
395
+ const activityGroups = getTaxonomyActivitiesGrouped({
396
+ ...taxonomy,
397
+ activities: taxonomy.activities.filter((activity) => !activity.systemOnly),
398
+ }).filter(([, activities]) => activities.length);
399
+ const isAccountingActivity = isAccountingLogActivity(activityKey);
400
+
401
+ const schemaItems: any[] = [
402
+ {
403
+ __type: 'input_click',
404
+ forceClickId: `input_click_${namespace}.activity`,
405
+ label: i18n.t('c.activity'),
406
+ item: {
407
+ focused: focusedName === `${formId}_activity`,
408
+ name: `${namespace}.activity`,
409
+ placeholder: isCreateNew ? i18n.t('c.activity_ph') : '',
410
+ getter: (value: string) => getTaxonomyActivityLabel(taxonomy, value),
411
+ popOverProps: {
412
+ id: `${formId}_activity`,
413
+ ...basePopOverProps,
414
+ iface: {
415
+ name: 'PO_LIST',
416
+ variables: {
417
+ designClassName: 'w_250',
418
+ className: 'max_h_40vh',
419
+ options: activityGroups.reduce((options, [groupKey, activities], index) => {
420
+ const groupOptions: any[] = [
421
+ {
422
+ __type: 'LIST_SUBTITLE' as const,
423
+ text: getTaxonomyGroupLabel(taxonomy, groupKey),
424
+ className: 'mt_sm',
425
+ },
426
+ ...activities.map((activity) => ({
427
+ __type: 'LIST_ITEM' as const,
428
+ text: getTaxonomyActivityLabel(taxonomy, activity.key),
429
+ textClassName: 'ft_xs',
430
+ rightIconClassName: 'ft_xs mb_2',
431
+ name: `${namespace}.activity`,
432
+ value: activity.key,
433
+ selected: activityKey === activity.key,
434
+ })),
435
+ ];
436
+
437
+ if (index < activityGroups.length - 1) {
438
+ groupOptions.push({ __type: 'BREAK' as const });
439
+ }
440
+
441
+ return options.concat(groupOptions);
442
+ }, [] as any[]),
443
+ },
444
+ },
445
+ },
446
+ },
447
+ },
448
+ {
449
+ __type: 'input',
450
+ label: formatLogTaxonomyFieldLabel(i18n.t('c.item'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'item', groupKey)),
451
+ item: {
452
+ name: `${namespace}.item`,
453
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'item', groupKey) === 'REQUIRED',
454
+ maxLength: 255,
455
+ placeholder: '',
456
+ },
457
+ },
458
+ {
459
+ __type: 'input',
460
+ label: formatLogTaxonomyFieldLabel(
461
+ getLogEntryDetailsEnvelopeFieldLabel('quantity', activityKey, groupKey),
462
+ getTaxonomyFieldRequirement(taxonomy, activityKey, 'quantity', groupKey),
463
+ ),
464
+ item: {
465
+ name: `${namespace}.quantity`,
466
+ type: 'number',
467
+ getter: getLogEntryDetailsNumericInputValue,
468
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'quantity', groupKey) === 'REQUIRED',
469
+ step: 0.1,
470
+ max: 99999999.99, // database max is numeric(10, 2)
471
+ placeholder: isCreateNew ? i18n.t('c.quantity_ph') : '',
472
+ },
473
+ },
474
+ {
475
+ __type: 'input',
476
+ label: formatLogTaxonomyFieldLabel(i18n.t('c.unit'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'unit', groupKey)),
477
+ item: {
478
+ name: `${namespace}.unit`,
479
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'unit', groupKey) === 'REQUIRED',
480
+ maxLength: LOG_UNIT_INPUT_MAX_LENGTH,
481
+ placeholder: '',
482
+ },
483
+ },
484
+ {
485
+ __type: 'input',
486
+ label: formatLogTaxonomyFieldLabel(i18n.t('c.price'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'price', groupKey)),
487
+ item: {
488
+ name: `${namespace}.price`,
489
+ type: 'number',
490
+ getter: getLogEntryDetailsNumericInputValue,
491
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'price', groupKey) === 'REQUIRED',
492
+ step: 0.01,
493
+ max: 99999999.99, // database max is numeric(10, 2)
494
+ placeholder: isCreateNew ? i18n.t('c.price_ph') : '',
495
+ },
496
+ },
497
+ {
498
+ __type: 'input',
499
+ label: formatLogTaxonomyFieldLabel(
500
+ i18n.t('c.vendor'),
501
+ getTaxonomyFieldRequirement(taxonomy, activityKey, 'otherParty', groupKey),
502
+ ),
503
+ item: {
504
+ name: `${namespace}.otherParty`,
505
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'otherParty', groupKey) === 'REQUIRED',
506
+ maxLength: 255,
507
+ placeholder: '',
508
+ },
509
+ },
510
+ ];
511
+
512
+ // One typed input per applicable registry field def
513
+ for (const def of getTaxonomyFieldDefsForActivity(taxonomy, activityKey, groupKey)) {
514
+ const fieldName = `${namespace}.fields.${def.key}`;
515
+ const fieldUnitName = `${namespace}.fieldUnits.${def.key}`;
516
+ const fieldLabel = getLogEntryDetailsFieldLabel(def.key);
517
+ const fieldRequirement = def.required ? 'REQUIRED' : getTaxonomyFieldRequirement(taxonomy, activityKey, def.key, groupKey);
518
+ const fieldIsRequired = fieldRequirement === 'REQUIRED';
519
+ const label = formatLogTaxonomyFieldLabel(fieldLabel, fieldRequirement);
520
+ const currentValue = detailsFormValues.fields?.[def.key];
521
+ const currentUnit = detailsFormValues.fieldUnits?.[def.key];
522
+
523
+ if (def.fieldType === 'SELECT' && def.options?.length) {
524
+ schemaItems.push({
525
+ __type: 'input_click',
526
+ forceClickId: `input_click_${fieldName}`,
527
+ label,
528
+ item: {
529
+ focused: focusedName === `${formId}_field_${def.key}`,
530
+ name: fieldName,
531
+ placeholder: '',
532
+ required: fieldIsRequired,
533
+ getter: (value: string) => value || '',
534
+ popOverProps: {
535
+ id: `${formId}_field_${def.key}`,
536
+ ...basePopOverProps,
537
+ iface: {
538
+ name: 'PO_LIST',
539
+ variables: {
540
+ designClassName: 'w_250',
541
+ className: 'max_h_40vh',
542
+ options: [
543
+ ...(!fieldIsRequired
544
+ ? [
545
+ {
546
+ __type: 'LIST_ITEM' as const,
547
+ text: i18n.t('c.remove'),
548
+ selected: currentValue === null || currentValue === undefined || currentValue === '',
549
+ name: fieldName,
550
+ value: null,
551
+ },
552
+ ]
553
+ : []),
554
+ ...def.options.map((option) => ({
555
+ __type: 'LIST_ITEM' as const,
556
+ text: option,
557
+ selected: currentValue === option,
558
+ name: fieldName,
559
+ value: option,
560
+ })),
561
+ ],
562
+ },
563
+ },
564
+ },
565
+ },
566
+ });
567
+ } else if (def.fieldType === 'BOOLEAN') {
568
+ schemaItems.push({
569
+ __type: 'input_click',
570
+ forceClickId: `input_click_${fieldName}`,
571
+ label,
572
+ item: {
573
+ focused: focusedName === `${formId}_field_${def.key}`,
574
+ name: fieldName,
575
+ placeholder: '',
576
+ required: fieldIsRequired,
577
+ getter: (value: boolean | null) => (typeof value === 'boolean' ? i18n.t(value ? 'c.yes' : 'c.no') : ''),
578
+ popOverProps: {
579
+ id: `${formId}_field_${def.key}`,
580
+ ...basePopOverProps,
581
+ iface: {
582
+ name: 'PO_LIST',
583
+ variables: {
584
+ designClassName: 'w_250',
585
+ className: 'max_h_40vh',
586
+ options: [
587
+ ...(!fieldIsRequired
588
+ ? [
589
+ {
590
+ __type: 'LIST_ITEM' as const,
591
+ text: i18n.t('c.remove'),
592
+ selected: currentValue === null || currentValue === undefined || currentValue === '',
593
+ name: fieldName,
594
+ value: null,
595
+ },
596
+ ]
597
+ : []),
598
+ {
599
+ __type: 'LIST_ITEM' as const,
600
+ text: i18n.t('c.yes'),
601
+ selected: currentValue === true,
602
+ name: fieldName,
603
+ value: true,
604
+ },
605
+ {
606
+ __type: 'LIST_ITEM' as const,
607
+ text: i18n.t('c.no'),
608
+ selected: currentValue === false,
609
+ name: fieldName,
610
+ value: false,
611
+ },
612
+ ],
613
+ },
614
+ },
615
+ },
616
+ },
617
+ });
618
+ } else if (def.fieldType === 'DATE' || def.fieldType === 'DATETIME') {
619
+ schemaItems.push({
620
+ __type: 'input',
621
+ label,
622
+ item: {
623
+ name: fieldName,
624
+ type: def.fieldType === 'DATE' ? 'date' : 'datetime-local',
625
+ required: fieldIsRequired,
626
+ step: def.fieldType === 'DATETIME' ? 60 : undefined,
627
+ placeholder: '',
628
+ },
629
+ });
630
+ } else if (def.fieldType === 'QUANTITY') {
631
+ schemaItems.push(
632
+ {
633
+ __type: 'input',
634
+ label,
635
+ item: {
636
+ name: fieldName,
637
+ type: 'number',
638
+ getter: getLogEntryDetailsNumericInputValue,
639
+ required: fieldIsRequired,
640
+ step: 0.1,
641
+ max: 99999999.99, // database max is numeric(10, 2)
642
+ placeholder: '',
643
+ },
644
+ },
645
+ makeLogEntryDetailsQuantityUnitSchemaItem(def, fieldUnitName, currentUnit, formId, focusedName, basePopOverProps),
646
+ );
647
+ } else if (['NUMBER', 'MONEY'].includes(def.fieldType)) {
648
+ schemaItems.push({
649
+ __type: 'input',
650
+ label,
651
+ item: {
652
+ name: fieldName,
653
+ type: 'number',
654
+ getter: getLogEntryDetailsNumericInputValue,
655
+ required: fieldIsRequired,
656
+ step: def.fieldType === 'MONEY' ? 0.01 : 0.1,
657
+ max: 99999999.99, // database max is numeric(10, 2)
658
+ placeholder: '',
659
+ },
660
+ });
661
+ } else {
662
+ schemaItems.push({
663
+ __type: 'input',
664
+ label,
665
+ item: {
666
+ name: fieldName,
667
+ required: fieldIsRequired,
668
+ maxLength: 255,
669
+ placeholder: '',
670
+ },
671
+ });
672
+ }
673
+ }
674
+
675
+ const valuesRequirement = getTaxonomyFieldRequirement(taxonomy, activityKey, 'values', groupKey);
676
+ if (valuesRequirement || detailsFormValues.values?.length) {
677
+ schemaItems.push(
678
+ makeLogEntryDetailsValuesSchemaItem(
679
+ namespace,
680
+ detailsFormValues,
681
+ formId,
682
+ focusedName,
683
+ basePopOverProps,
684
+ valuesRequirement === 'REQUIRED',
685
+ ),
686
+ );
687
+ }
688
+
689
+ schemaItems.push(
690
+ {
691
+ __type: 'input',
692
+ label: formatLogTaxonomyFieldLabel(
693
+ i18n.t('log.receipt_number'),
694
+ getTaxonomyFieldRequirement(taxonomy, activityKey, 'referenceNumber', groupKey),
695
+ ),
696
+ item: {
697
+ name: `${namespace}.referenceNumber`,
698
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'referenceNumber', groupKey) === 'REQUIRED',
699
+ maxLength: 120,
700
+ placeholder: '',
701
+ },
702
+ },
703
+ {
704
+ __type: 'input',
705
+ label: formatLogTaxonomyFieldLabel(
706
+ i18n.t('log.fieldLocation'),
707
+ getTaxonomyFieldRequirement(taxonomy, activityKey, 'fieldLocation', groupKey),
708
+ ),
709
+ item: {
710
+ name: `${namespace}.fieldLocation`,
711
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'fieldLocation', groupKey) === 'REQUIRED',
712
+ maxLength: 255,
713
+ placeholder: '',
714
+ },
715
+ },
716
+ {
717
+ __type: 'input_click',
718
+ forceClickId: `input_click_${namespace}.voided`,
719
+ label: formatLogTaxonomyFieldLabel(i18n.t('c.void'), getTaxonomyFieldRequirement(taxonomy, activityKey, 'voided', groupKey)),
720
+ inputClassName: detailsFormValues.voided ? 'cl_red' : '',
721
+ item: {
722
+ focused: focusedName === `${formId}_void`,
723
+ name: `${namespace}.voided`,
724
+ required: getTaxonomyFieldRequirement(taxonomy, activityKey, 'voided', groupKey) === 'REQUIRED',
725
+ placeholder: isCreateNew ? i18n.t(`c.void_ph`) : '',
726
+ getter: (value: string) => i18n.t(value ? 'c.voided' : 'c.valid'),
727
+ },
728
+ popOverProps: {
729
+ id: `${formId}_void`,
730
+ ...basePopOverProps,
731
+ iface: {
732
+ name: 'PO_LIST',
733
+ variables: {
734
+ designClassName: 'w_250',
735
+ className: 'max_h_40vh',
736
+ options: [
737
+ {
738
+ __type: 'LIST_ITEM' as const,
739
+ text: i18n.t('c.valid'),
740
+ iconName: 'receipt-dollar',
741
+ selected: !detailsFormValues.voided,
742
+ name: `${namespace}.voided`,
743
+ value: false,
744
+ },
745
+ {
746
+ __type: 'LIST_ITEM' as const,
747
+ text: i18n.t('c.voided'),
748
+ iconName: 'receipt-off',
749
+ selected: detailsFormValues.voided === true,
750
+ name: `${namespace}.voided`,
751
+ value: true,
752
+ },
753
+ ],
754
+ },
755
+ },
756
+ },
757
+ },
758
+ );
759
+
760
+ if (!isAccountingActivity) {
761
+ // Operation-wide finance field definitions must not leak accounting
762
+ // inputs into non-financial activity editors.
763
+ const financialFieldNames = [
764
+ `${namespace}.price`,
765
+ `${namespace}.otherParty`,
766
+ `${namespace}.fields.tax`,
767
+ `${namespace}.referenceNumber`,
768
+ `${namespace}.voided`,
769
+ ];
770
+ return schemaItems.filter((schemaItem) => !financialFieldNames.includes(schemaItem?.item?.name));
771
+ }
772
+
773
+ return schemaItems;
658
774
  }
659
775
 
660
776
  /**
@@ -662,162 +778,102 @@ export function getSchemaFieldsFromLog(__typename: string, logType: LogTypeEnum)
662
778
  */
663
779
 
664
780
  interface MakeMetadataSchemaParams {
665
- __typename: string;
666
- scrollAreaDOMId: string;
667
- formId: string;
668
- timeZone: string | null | undefined;
669
- focusedName: string;
670
- isCreateNew: boolean;
781
+ __typename: string;
782
+ scrollAreaDOMId: string;
783
+ formId: string;
784
+ timeZone: string | null | undefined;
785
+ focusedName: string;
786
+ isCreateNew: boolean;
787
+ taxonomy?: LogTaxonomyGQL | null;
671
788
  }
672
789
 
673
- export function makeLogMetadataSchema(
674
- formValues: Record<string, any> = {},
675
- metadataParams: MakeMetadataSchemaParams,
676
- ) {
677
- const { __typename, scrollAreaDOMId, formId, timeZone, focusedName, isCreateNew } = metadataParams;
678
-
679
- let activitiesList: any[] = [];
680
- let schemaItems: any[] = [];
681
-
682
- const basePopOverProps = {
683
- scrollAreaDOMId,
684
- zClassName: 'z9',
685
- position: 'bottom_left',
686
- offsetX: 0,
687
- offsetY: 7,
688
- };
689
-
690
- const minDate = new Date();
691
- minDate.setFullYear(minDate.getFullYear() - 10);
692
-
693
- const maxDate = new Date();
694
- maxDate.setMonth(maxDate.getMonth() + 1);
695
-
696
- const namespace = {
697
- LogArable: 'arableDetails',
698
- LogFarmersMarket: 'farmersMarketDetails',
699
- LogGrowerNetwork: 'growerNetworkDetails',
700
- LogLivestock: 'livestockDetails',
701
- }[__typename] || '';
702
-
703
- const logActivity = formValues[namespace]?.activity;
704
- const logType = getLogTypeFromActivity(__typename, logActivity)!;
705
- const schemaFields = getSchemaFieldsFromLog(__typename, logType);
706
-
707
- switch (__typename) {
708
- case 'LogArable': {
709
- activitiesList = ARABLE_ACTIVITIES_GROUPED;
710
- schemaItems = makeMetadataSchema(namespace, formValues, metadataParams, basePopOverProps, schemaFields);
711
- } break;
712
- case 'LogFarmersMarket': {
713
- activitiesList = FARMERS_MARKET_ACTIVITIES_GROUPED;
714
- schemaItems = makeMetadataSchema(namespace, formValues, metadataParams, basePopOverProps, schemaFields);
715
- } break;
716
- case 'LogGrowerNetwork': {
717
- activitiesList = GROWER_NETWORK_ACTIVITIES_GROUPED;
718
- schemaItems = makeMetadataSchema(namespace, formValues, metadataParams, basePopOverProps, schemaFields);
719
- } break;
720
- case 'LogLivestock': {
721
- activitiesList = LIVESTOCK_ACTIVITIES_GROUPED;
722
- schemaItems = makeMetadataSchema(namespace, formValues, metadataParams, basePopOverProps, schemaFields);
723
- } break;
724
- default:
725
- }
726
-
727
- if (logType) {
728
- activitiesList = activitiesList.filter(([type]) => type === logType);
729
- }
730
-
731
- // Date, time, createdBy is common across all log types
732
-
733
- if (schemaItems.length) {
734
- const timeZoneCode = getTimeZoneCode(timeZone);
735
-
736
- schemaItems = schemaItems.concat([{
737
- __type: 'input_click',
738
- forceClickId: 'input_click_date',
739
- label: i18n.t('form.date'),
740
- item: {
741
- name: 'date',
742
- focused: focusedName === (formId + '_date'),
743
- getter: (value: string) => getCalDate(new Date(value), timeZone).calDate,
744
- },
745
- popOverProps: {
746
- id: formId + '_date',
747
- ...basePopOverProps,
748
- iface: {
749
- name: 'PO_LIST',
750
- variables: {
751
- designClassName: 'w_350',
752
- className: 'max_h_40vh',
753
- initialState: {
754
- date: formValues.date ? new Date(formValues.date) : new Date(),
755
- },
756
- options: [{
757
- __type: 'DATE_PICKER',
758
- name: 'date',
759
- minDate,
760
- maxDate,
761
- }]
762
- }
763
- }
764
- }
765
- }, {
766
- __type: 'input_time_from_date',
767
- label: i18n.t(timeZoneCode ? 'form.time_with_zone' : 'form.time', { timeZone: timeZoneCode }),
768
- scrollAreaDOMId,
769
- item: {
770
- name: 'date', // date value will be used to extract time
771
- type: 'time',
772
- timeZone,
773
- },
774
- }]);
775
- }
776
-
777
- if (schemaItems[0] && activitiesList.length) {
778
- // First item is always activity
779
- const activityValue = getObject(formValues, schemaItems[0].item.name);
780
- schemaItems[0].item.popOverProps = {
781
- id: formId + '_activity',
782
- ...basePopOverProps,
783
- iface: {
784
- name: 'PO_LIST',
785
- variables: {
786
- designClassName: 'w_250',
787
- className: 'max_h_40vh',
788
- options: activitiesList.reduce((acc, [type, activities], i) => {
789
- const colorIndicator = getLogCategoryColor(type);
790
- const isEnd = i === activitiesList.length - 1;
791
-
792
- const updatedList = acc.concat({
793
- __type: 'LIST_SUBTITLE' as const,
794
- colorIndicator,
795
- text: i18n.t(`log.type_short.${type}`),
796
- className: 'mt_sm',
797
- textClassName: `cl_${colorIndicator}`,
798
- }).concat(activities.map((activity: string) => ({
799
- __type: 'LIST_ITEM' as const,
800
- // colorIndicator,
801
- text: i18n.t(`log.activity.${activity}`),
802
- textClassName: 'ft_xs',
803
- rightIconClassName: 'ft_xs mb_2',
804
- name: schemaItems[0].item.name,
805
- value: activity,
806
- selected: activityValue === activity,
807
- })));
808
-
809
- if (!isEnd) {
810
- updatedList.push({
811
- __type: 'BREAK' as const,
812
- });
813
- }
814
-
815
- return updatedList;
816
- }, [])
817
- }
818
- }
819
- };
820
- }
821
-
822
- return schemaItems;
790
+ /*
791
+ * Build the registry-driven generic log metadata editor schema.
792
+ */
793
+
794
+ export function makeLogMetadataSchema(formValues: Record<string, any> = {}, metadataParams: MakeMetadataSchemaParams) {
795
+ const { __typename, scrollAreaDOMId, formId, timeZone, focusedName } = metadataParams;
796
+
797
+ const basePopOverProps = {
798
+ scrollAreaDOMId,
799
+ zClassName: 'z9',
800
+ position: 'bottom_left',
801
+ offsetX: 0,
802
+ offsetY: 7,
803
+ };
804
+
805
+ const minDate = new Date();
806
+ minDate.setFullYear(minDate.getFullYear() - 10);
807
+
808
+ const maxDate = new Date();
809
+ maxDate.setMonth(maxDate.getMonth() + 1);
810
+
811
+ if (__typename !== 'LogEntryDetails') {
812
+ return [];
813
+ }
814
+ const namespace = LOG_DETAILS_INPUT_NAME_BY_TYPENAME.LogEntryDetails;
815
+
816
+ const logActivity = formValues[namespace]?.activity;
817
+ let schemaItems = makeLogEntryDetailsMetadataSchema(namespace, formValues, metadataParams, basePopOverProps);
818
+
819
+ // Date, time, createdBy is common across all log types
820
+
821
+ if (schemaItems.length) {
822
+ const timeZoneCode = getTimeZoneCode(timeZone);
823
+
824
+ schemaItems = schemaItems.concat([
825
+ {
826
+ __type: 'input_click',
827
+ forceClickId: 'input_click_date',
828
+ label: formatLogTaxonomyFieldLabel(
829
+ i18n.t('c.date'),
830
+ getTaxonomyFieldRequirement(metadataParams.taxonomy, logActivity, 'date', formValues[namespace]?.__groupKey),
831
+ ),
832
+ item: {
833
+ name: 'date',
834
+ focused: focusedName === formId + '_date',
835
+ getter: (value: string) => getCalDate(new Date(value), timeZone).calDate,
836
+ },
837
+ popOverProps: {
838
+ id: formId + '_date',
839
+ ...basePopOverProps,
840
+ iface: {
841
+ name: 'PO_LIST',
842
+ variables: {
843
+ designClassName: 'w_350',
844
+ className: 'max_h_40vh',
845
+ initialState: {
846
+ date: formValues.date ? new Date(formValues.date) : new Date(),
847
+ },
848
+ options: [
849
+ {
850
+ __type: 'DATE_PICKER',
851
+ name: 'date',
852
+ minDate,
853
+ maxDate,
854
+ },
855
+ ],
856
+ },
857
+ },
858
+ },
859
+ },
860
+ {
861
+ __type: 'input_time_from_date',
862
+ label: formatLogTaxonomyFieldLabel(
863
+ i18n.t(timeZoneCode ? 'c.time_with_zone' : 'c.time', {
864
+ timeZone: timeZoneCode,
865
+ }),
866
+ getTaxonomyFieldRequirement(metadataParams.taxonomy, logActivity, 'time', formValues[namespace]?.__groupKey),
867
+ ),
868
+ scrollAreaDOMId,
869
+ item: {
870
+ name: 'date', // date value will be used to extract time
871
+ type: 'time',
872
+ timeZone,
873
+ },
874
+ },
875
+ ]);
876
+ }
877
+
878
+ return schemaItems;
823
879
  }