@jsb188/mday 1.1.2
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.
- package/package.json +142 -0
- package/src/constants/agentMemory.ts +166 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +146 -0
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +21 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2199 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +60 -0
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +132 -0
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +85 -0
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +879 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +93 -0
- package/src/types/account.d.ts +81 -0
- package/src/types/agentMemory.d.ts +100 -0
- package/src/types/agentNote.d.ts +441 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +159 -0
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +231 -0
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +65 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +338 -0
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +350 -0
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +847 -0
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +481 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +435 -0
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1173 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +311 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +379 -0
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +357 -0
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +669 -0
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +262 -0
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +506 -0
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { isLogFieldApplicableToActivity } from './logTaxonomy.helpers.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import { formatDisplayDate, getCalDate } from '@jsb188/app/utils/datetime.ts';
|
|
4
|
+
import { formatCurrency } from '@jsb188/app/utils/number.ts';
|
|
5
|
+
import { ucFirst } from '@jsb188/app/utils/string.ts';
|
|
6
|
+
import { parseDateInTimezone } from '@jsb188/app/utils/timeZone.ts';
|
|
7
|
+
import type {
|
|
8
|
+
LogEntryDetailsFieldGQL,
|
|
9
|
+
LogEntryDetailsGQL,
|
|
10
|
+
LogTaxonomyActivityGQL,
|
|
11
|
+
LogTaxonomyFieldDefGQL,
|
|
12
|
+
LogTaxonomyGQL,
|
|
13
|
+
} from '../types/log.d.ts';
|
|
14
|
+
|
|
15
|
+
export type LogTaxonomyFieldRequirement = 'REQUIRED' | 'OR_REQUIRED' | null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Display helpers for registry-driven log operations (Phase 8b). Registry
|
|
19
|
+
* keys are data, not compile-time enums, so every label falls back from
|
|
20
|
+
* i18n → registry text → humanized key instead of assuming a translation
|
|
21
|
+
* exists. Kept separate from utils/logTaxonomy.ts, which is seed-critical
|
|
22
|
+
* (the frozen registry seed derives from it) and must stay dependency-free.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Humanize a registry key (SNAKE_CASE or camelCase) for display when no
|
|
27
|
+
* i18n label exists
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export function humanizeRegistryKey(key?: string | null): string {
|
|
31
|
+
if (!key) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
const spaced = key
|
|
35
|
+
.replace(/[_-]+/g, ' ')
|
|
36
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
37
|
+
.toLowerCase();
|
|
38
|
+
return ucFirst(spaced);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* Display label for a registry activity key: i18n wins, then the registry
|
|
43
|
+
* agentText, then the humanized key
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export function getTaxonomyActivityLabel(taxonomy: LogTaxonomyGQL | null | undefined, activityKey?: string | null): string {
|
|
47
|
+
if (!activityKey) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
if (i18n.has(`log.activity.${activityKey}`)) {
|
|
51
|
+
return i18n.t(`log.activity.${activityKey}`);
|
|
52
|
+
}
|
|
53
|
+
const agentText = taxonomy?.activities?.find((activity) => activity.key === activityKey)?.agentText;
|
|
54
|
+
return agentText ? ucFirst(agentText) : humanizeRegistryKey(activityKey);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
* Registry group key for an activity key
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
export function getTaxonomyGroupKey(
|
|
62
|
+
taxonomy: LogTaxonomyGQL | null | undefined,
|
|
63
|
+
activityKey?: string | null,
|
|
64
|
+
fallbackGroupKey?: string | null,
|
|
65
|
+
): string | null {
|
|
66
|
+
if (!activityKey) {
|
|
67
|
+
return fallbackGroupKey ?? null;
|
|
68
|
+
}
|
|
69
|
+
return taxonomy?.activities?.find((activity) => activity.key === activityKey)?.groupKey ?? fallbackGroupKey ?? null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* Resolve one activity's effective required-field rule. Activity settings
|
|
74
|
+
* replace the group setting when present, including an explicit empty list.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export function getTaxonomyFieldRequirement(
|
|
78
|
+
taxonomy: LogTaxonomyGQL | null | undefined,
|
|
79
|
+
activityKey: string | null | undefined,
|
|
80
|
+
fieldKey: string,
|
|
81
|
+
fallbackGroupKey?: string | null,
|
|
82
|
+
): LogTaxonomyFieldRequirement {
|
|
83
|
+
const activity = taxonomy?.activities.find((candidate) => candidate.key === activityKey);
|
|
84
|
+
const group = taxonomy?.groups.find((candidate) => candidate.key === (activity?.groupKey ?? fallbackGroupKey));
|
|
85
|
+
const requiredFields = activity?.requiredFields ?? group?.requiredFields ?? [];
|
|
86
|
+
const orRequiredFields = activity?.orRequiredFields ?? group?.orRequiredFields ?? [];
|
|
87
|
+
|
|
88
|
+
if (requiredFields.includes(fieldKey)) {
|
|
89
|
+
return 'REQUIRED';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return orRequiredFields.includes(fieldKey) ? 'OR_REQUIRED' : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* Add the compact required-state marker used by registry-driven editor
|
|
97
|
+
* labels without assuming the label itself came from i18n.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
export function formatLogTaxonomyFieldLabel(label: string, requirement: LogTaxonomyFieldRequirement): string {
|
|
101
|
+
if (requirement === 'REQUIRED') {
|
|
102
|
+
return `${label} *`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return requirement === 'OR_REQUIRED' ? `${label} (${i18n.t('c.one_of_these_required')})` : label;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Display label for a registry group: i18n wins, then the registry label,
|
|
110
|
+
* then the humanized key
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
export function getTaxonomyGroupLabel(
|
|
114
|
+
taxonomy: LogTaxonomyGQL | null | undefined,
|
|
115
|
+
groupKey?: string | null,
|
|
116
|
+
operation?: string | null,
|
|
117
|
+
short = true,
|
|
118
|
+
): string {
|
|
119
|
+
if (!groupKey) {
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
if (groupKey === 'MARKET_OPERATION' || (groupKey === 'OPERATION' && (operation || taxonomy?.operation) === 'FARMERS_MARKET')) {
|
|
123
|
+
return i18n.t(short ? 'log.type_short.MARKET_OPERATION' : 'log.market_operations');
|
|
124
|
+
}
|
|
125
|
+
const labelKey = `log.${short ? 'type_short' : 'type'}.${groupKey}`;
|
|
126
|
+
if (i18n.has(labelKey)) return i18n.t(labelKey);
|
|
127
|
+
const label = taxonomy?.groups?.find((group) => group.key === groupKey)?.label;
|
|
128
|
+
return label || humanizeRegistryKey(groupKey);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Group taxonomy activities in the taxonomy group's display order
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
export function getTaxonomyActivitiesGrouped(taxonomy: LogTaxonomyGQL): [string, LogTaxonomyActivityGQL[]][] {
|
|
136
|
+
const activitiesByGroup = new Map<string, LogTaxonomyActivityGQL[]>();
|
|
137
|
+
for (const activity of taxonomy.activities) {
|
|
138
|
+
if (!activity.groupKey) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const activities = activitiesByGroup.get(activity.groupKey) || [];
|
|
143
|
+
activities.push(activity);
|
|
144
|
+
activitiesByGroup.set(activity.groupKey, activities);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return taxonomy.groups.map((group) => [group.key, activitiesByGroup.get(group.key) || []]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/*
|
|
151
|
+
* Field defs that apply to one activity: activity-scoped defs match their
|
|
152
|
+
* activity only, group-scoped defs match the activity's group, unscoped defs
|
|
153
|
+
* apply operation-wide
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
export function getTaxonomyFieldDefsForActivity(
|
|
157
|
+
taxonomy: LogTaxonomyGQL | null | undefined,
|
|
158
|
+
activityKey?: string | null,
|
|
159
|
+
fallbackGroupKey?: string | null,
|
|
160
|
+
): LogTaxonomyFieldDefGQL[] {
|
|
161
|
+
const groupKey = getTaxonomyGroupKey(taxonomy, activityKey, fallbackGroupKey);
|
|
162
|
+
return (taxonomy?.fieldDefs || []).filter((def) =>
|
|
163
|
+
isLogFieldApplicableToActivity(
|
|
164
|
+
{
|
|
165
|
+
...def,
|
|
166
|
+
config: {
|
|
167
|
+
includedActivityKeys: def.includedActivityKeys ?? undefined,
|
|
168
|
+
excludedActivityKeys: def.excludedActivityKeys ?? undefined,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
activityKey,
|
|
172
|
+
groupKey,
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/*
|
|
178
|
+
* Display label for a field def key
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
export function getLogEntryDetailsFieldLabel(key?: string | null): string {
|
|
182
|
+
if (!key) {
|
|
183
|
+
return '';
|
|
184
|
+
}
|
|
185
|
+
if (key === 'rackNumber') {
|
|
186
|
+
return i18n.t('c.rack');
|
|
187
|
+
}
|
|
188
|
+
if (i18n.has(`log.${key}`)) {
|
|
189
|
+
return i18n.t(`log.${key}`);
|
|
190
|
+
}
|
|
191
|
+
if (i18n.has(`c.${key}`)) {
|
|
192
|
+
return i18n.t(`c.${key}`);
|
|
193
|
+
}
|
|
194
|
+
return humanizeRegistryKey(key);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/*
|
|
198
|
+
* Preserve the domain label for envelope fields whose meaning is narrowed by
|
|
199
|
+
* the selected registry activity or group.
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
export function getLogEntryDetailsEnvelopeFieldLabel(key: string, activityKey?: string | null, groupKey?: string | null): string {
|
|
203
|
+
if (key === 'quantity' && activityKey === 'COLD_STORAGE_TEMPERATURE') {
|
|
204
|
+
return i18n.t('c.temperature');
|
|
205
|
+
}
|
|
206
|
+
if (key === 'quantity' && groupKey === 'WATER') {
|
|
207
|
+
return i18n.t('c.water_quantity');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return getLogEntryDetailsFieldLabel(key);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/*
|
|
214
|
+
* Return a canonical calendar-date value or null for an invalid value.
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
export function normalizeLogEntryDetailsDateValue(value?: string | null): string | null {
|
|
218
|
+
const trimmedValue = String(value || '').trim();
|
|
219
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(trimmedValue)) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const parsedDate = new Date(`${trimmedValue}T00:00:00.000Z`);
|
|
224
|
+
return Number.isFinite(parsedDate.getTime()) && parsedDate.toISOString().slice(0, 10) === trimmedValue ? trimmedValue : null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/*
|
|
228
|
+
* Convert a canonical instant into the local value required by a
|
|
229
|
+
* datetime-local input, honoring the organization timezone when available.
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
export function getLogEntryDetailsDateTimeInputValue(value?: string | null, timeZone?: string | null): string | null {
|
|
233
|
+
const date = value ? new Date(value) : null;
|
|
234
|
+
if (!date || !Number.isFinite(date.getTime())) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const { calDate, time } = getCalDate(date, timeZone);
|
|
239
|
+
return `${calDate}T${time.slice(0, 5)}`;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/*
|
|
243
|
+
* Convert a datetime-local input value into the canonical ISO instant used by
|
|
244
|
+
* the GraphQL mutation contract.
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
export function normalizeLogEntryDetailsDateTimeValue(value?: string | null, timeZone?: string | null): string | null {
|
|
248
|
+
const trimmedValue = String(value || '').trim();
|
|
249
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/.test(trimmedValue)) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const parsedDate = parseDateInTimezone(trimmedValue, timeZone, 0, true);
|
|
254
|
+
return Number.isFinite(parsedDate.getTime()) ? parsedDate.toISOString() : null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Read one typed GraphQL value as a plain form scalar in display units.
|
|
259
|
+
* DATETIME is converted for its local input.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
export function getLogEntryDetailsFieldValue(
|
|
263
|
+
field: LogEntryDetailsFieldGQL,
|
|
264
|
+
timeZone?: string | null,
|
|
265
|
+
): string | number | boolean | null {
|
|
266
|
+
if (field.fieldType === 'DATE') {
|
|
267
|
+
return normalizeLogEntryDetailsDateValue(field.dateValue ?? field.textValue);
|
|
268
|
+
}
|
|
269
|
+
if (field.fieldType === 'DATETIME') {
|
|
270
|
+
return getLogEntryDetailsDateTimeInputValue(field.datetimeValue ?? field.textValue, timeZone);
|
|
271
|
+
}
|
|
272
|
+
return field.textValue ?? field.numberValue ?? field.booleanValue ?? null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/*
|
|
276
|
+
* Read one registry field by key from either a GraphQL field array, an editor
|
|
277
|
+
* field map, or a materialized server metadata object.
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
export function getLogEntryDetailsFieldValueByKey(
|
|
281
|
+
details: Record<string, any> | null | undefined,
|
|
282
|
+
key: string,
|
|
283
|
+
timeZone?: string | null,
|
|
284
|
+
): string | number | boolean | null {
|
|
285
|
+
const directValue = details?.[key];
|
|
286
|
+
if (directValue !== null && directValue !== undefined) {
|
|
287
|
+
return directValue;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const fields = details?.fields;
|
|
291
|
+
if (Array.isArray(fields)) {
|
|
292
|
+
const field = fields.find((candidate) => candidate?.key === key);
|
|
293
|
+
return field ? getLogEntryDetailsFieldValue(field, timeZone) : null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (fields && typeof fields === 'object') {
|
|
297
|
+
return fields[key] ?? null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/*
|
|
304
|
+
* Read and validate one numeric registry field without turning an empty or
|
|
305
|
+
* invalid value into zero.
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
export function getLogEntryDetailsNumberFieldValue(details: Record<string, any> | null | undefined, key: string): number | null {
|
|
309
|
+
const value = getLogEntryDetailsFieldValueByKey(details, key);
|
|
310
|
+
if (value === '' || value === null || value === undefined) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const numberValue = Number(value);
|
|
315
|
+
return Number.isFinite(numberValue) ? numberValue : null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/*
|
|
319
|
+
* Format one rack position's temperature reading, preserving zero and negative values.
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
export function getLogTemperatureText(details: LogEntryDetailsGQL, position: 'top' | 'middle' | 'bottom'): string {
|
|
323
|
+
const unit = getLogEntryDetailsFieldValueByKey(details, 'temperatureUnit');
|
|
324
|
+
return formatLogTemperatureValue(
|
|
325
|
+
getLogEntryDetailsNumberFieldValue(details, `${position}Temperature`),
|
|
326
|
+
unit == null ? null : String(unit),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/*
|
|
331
|
+
* Format a measured temperature consistently across metadata and tables without
|
|
332
|
+
* inventing a missing unit or discarding an unfamiliar saved unit.
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
export function formatLogTemperatureValue(temperature: number | null, unit?: string | null): string {
|
|
336
|
+
if (temperature === null) return '';
|
|
337
|
+
return `${temperature}${unit === 'C' || unit === 'F' ? ` °${unit}` : unit ? ` ${unit}` : ''}`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/*
|
|
341
|
+
* Read one QUANTITY registry field's unit from either GraphQL, editor, or
|
|
342
|
+
* materialized metadata details.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
export function getLogEntryDetailsFieldUnitByKey(details: Record<string, any> | null | undefined, key: string): string | null {
|
|
346
|
+
const directUnit = details?.[`${key}Unit`];
|
|
347
|
+
if (directUnit !== null && directUnit !== undefined) {
|
|
348
|
+
return String(directUnit);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const fields = details?.fields;
|
|
352
|
+
if (Array.isArray(fields)) {
|
|
353
|
+
const unit = fields.find((candidate) => candidate?.key === key)?.unit;
|
|
354
|
+
return unit === null || unit === undefined ? null : String(unit);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const mappedUnit = details?.fieldUnits?.[key];
|
|
358
|
+
return mappedUnit === null || mappedUnit === undefined ? null : String(mappedUnit);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/*
|
|
362
|
+
* Format one typed field value for read-only display
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
export function formatLogEntryDetailsFieldValue(field: LogEntryDetailsFieldGQL, timeZone?: string | null): string {
|
|
366
|
+
const value = getLogEntryDetailsFieldValue(field, timeZone);
|
|
367
|
+
if (value === null || value === undefined) {
|
|
368
|
+
return '';
|
|
369
|
+
}
|
|
370
|
+
if (field.fieldType === 'MONEY') {
|
|
371
|
+
return formatCurrency(value as number, false);
|
|
372
|
+
}
|
|
373
|
+
if (field.fieldType === 'BOOLEAN') {
|
|
374
|
+
return i18n.t(value ? 'c.yes' : 'c.no');
|
|
375
|
+
}
|
|
376
|
+
if (field.fieldType === 'DATE') {
|
|
377
|
+
return formatDisplayDate(String(value), timeZone);
|
|
378
|
+
}
|
|
379
|
+
if (field.fieldType === 'DATETIME') {
|
|
380
|
+
const datetimeValue = field.datetimeValue ?? field.textValue;
|
|
381
|
+
const parsedDate = datetimeValue ? new Date(datetimeValue) : null;
|
|
382
|
+
return parsedDate && Number.isFinite(parsedDate.getTime()) ? formatDisplayDate(parsedDate, timeZone) : String(value);
|
|
383
|
+
}
|
|
384
|
+
const unitText = field.unit ? ` ${field.unit}` : '';
|
|
385
|
+
return `${value}${unitText}`;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/*
|
|
389
|
+
* Return whether a typed store value is a custom field that belongs in the
|
|
390
|
+
* generic details list. flagColor is a storage slot rendered elsewhere.
|
|
391
|
+
*/
|
|
392
|
+
|
|
393
|
+
export function isLogEntryDetailsCustomField(field: LogEntryDetailsFieldGQL): boolean {
|
|
394
|
+
return !!field.key && field.key !== 'flagColor';
|
|
395
|
+
}
|