@jsb188/mday 1.1.10 → 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.
- package/package.json +105 -54
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +35 -9
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +20 -4
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +7 -410
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +13 -15
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +154 -6
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +56 -7
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1010 -777
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/schemas/organization.ts +49 -46
- package/src/types/account.d.ts +4 -1
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +175 -256
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +83 -12
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +2 -1
- package/src/types/log.d.ts +209 -341
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +83 -40
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +862 -30
- package/src/types/storage.d.ts +206 -125
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +149 -18
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +425 -410
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +112 -53
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +169 -176
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +510 -91
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4842 -39
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/workflow.ts +191 -23
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
package/src/utils/dataTable.ts
CHANGED
|
@@ -1,43 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stringifyJSON } from '@jsb188/app/utils/object.ts';
|
|
2
|
+
import {
|
|
3
|
+
formatCalDateInTimeZone,
|
|
4
|
+
parseDateInTimezone,
|
|
5
|
+
} from '@jsb188/app/utils/timeZone.ts';
|
|
2
6
|
import {
|
|
3
7
|
DATA_TABLE_COLUMN_MAX_WIDTH,
|
|
4
8
|
DATA_TABLE_COLUMN_MIN_WIDTH,
|
|
5
9
|
} from '../constants/dataTable.ts';
|
|
10
|
+
import { DATA_TABLE_FIELD_TYPE_SEMANTICS } from '../constants/dataTableFieldTypes.generated.ts';
|
|
11
|
+
import type { DataTableFieldTypeSemanticsKey } from './dataTableFieldTypeRegistry.ts';
|
|
6
12
|
import type {
|
|
7
13
|
DataTableDesignCellObj,
|
|
8
14
|
DataTableDesignObj,
|
|
9
|
-
DataTableDesignViewColumnObj,
|
|
10
|
-
DataTableDesignViewGeneratorDimensionObj,
|
|
11
|
-
DataTableDesignViewObj,
|
|
12
15
|
DataTableFieldTypeEnum,
|
|
13
16
|
DataTableRecordValue,
|
|
14
17
|
} from '../types/dataTable.d.ts';
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
19
|
+
const DATA_TABLE_ROW_IDENTIFIER_MAX_LENGTH = 120;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Parse one canonical non-negative PostgreSQL BIGINT without accepting unsafe
|
|
23
|
+
* JavaScript numbers, signed text, or values outside the database range.
|
|
24
|
+
*/
|
|
25
|
+
export function parseDataTableStorageBigInt(value: unknown): bigint | null {
|
|
26
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
typeof value !== 'number' &&
|
|
31
|
+
typeof value !== 'bigint' &&
|
|
32
|
+
typeof value !== 'string'
|
|
33
|
+
) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === 'string' && !/^(0|[1-9]\d*)$/.test(value)) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const parsed = BigInt(value);
|
|
42
|
+
return parsed >= 0n && parsed <= 9_223_372_036_854_775_807n ? parsed : null;
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Parse one canonical positive PostgreSQL BIGINT.
|
|
50
|
+
*/
|
|
51
|
+
export function parsePositiveDataTableStorageBigInt(
|
|
52
|
+
value: unknown,
|
|
53
|
+
): bigint | null {
|
|
54
|
+
const parsed = parseDataTableStorageBigInt(value);
|
|
55
|
+
return parsed !== null && parsed > 0n ? parsed : null;
|
|
56
|
+
}
|
|
34
57
|
|
|
35
58
|
/*
|
|
36
59
|
* Keep a user-resized dataTable column width inside the usable spreadsheet range.
|
|
37
60
|
*/
|
|
38
61
|
|
|
39
62
|
export function clampDataTableColumnWidth(width: number) {
|
|
40
|
-
return Math.min(
|
|
63
|
+
return Math.min(
|
|
64
|
+
DATA_TABLE_COLUMN_MAX_WIDTH,
|
|
65
|
+
Math.max(DATA_TABLE_COLUMN_MIN_WIDTH, Math.round(width)),
|
|
66
|
+
);
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
/*
|
|
@@ -45,46 +71,270 @@ export function clampDataTableColumnWidth(width: number) {
|
|
|
45
71
|
*/
|
|
46
72
|
|
|
47
73
|
function isPlainObject(value: any): value is Record<string, any> {
|
|
48
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
!!value &&
|
|
76
|
+
typeof value === 'object' &&
|
|
77
|
+
!(value instanceof Date) &&
|
|
78
|
+
!Array.isArray(value)
|
|
79
|
+
);
|
|
49
80
|
}
|
|
50
81
|
|
|
51
82
|
/*
|
|
52
|
-
* Return
|
|
83
|
+
* Return a normalized ordered list of design cell keys used to identify rows.
|
|
53
84
|
*/
|
|
85
|
+
export function normalizeDataTableDesignRowIdentifier(value: unknown) {
|
|
86
|
+
if (!Array.isArray(value)) {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
54
89
|
|
|
55
|
-
|
|
56
|
-
|
|
90
|
+
return value
|
|
91
|
+
.map((key) => (typeof key === 'string' ? key.trim() : ''))
|
|
92
|
+
.filter(Boolean);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* Return the saved ordered row identifier keys from a dataTable design object.
|
|
97
|
+
*/
|
|
98
|
+
export function getDataTableDesignRowIdentifier(
|
|
99
|
+
design: DataTableDesignObj | null | undefined,
|
|
100
|
+
) {
|
|
101
|
+
return normalizeDataTableDesignRowIdentifier(design?.rowIdentifier);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/*
|
|
105
|
+
* Return whether one value is missing for row-identifier purposes.
|
|
106
|
+
*/
|
|
107
|
+
function isMissingDataTableRowIdentifierValue(value: unknown) {
|
|
108
|
+
return (
|
|
109
|
+
value === null ||
|
|
110
|
+
value === undefined ||
|
|
111
|
+
(typeof value === 'string' && value.trim() === '')
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* Return a deterministic JSON-compatible value for one row identifier part.
|
|
117
|
+
*/
|
|
118
|
+
function normalizeDataTableRowIdentifierPart(value: unknown): unknown {
|
|
119
|
+
if (value instanceof Date) {
|
|
120
|
+
return value.toISOString();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (Array.isArray(value)) {
|
|
124
|
+
return value.map(normalizeDataTableRowIdentifierPart);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (isPlainObject(value)) {
|
|
128
|
+
if ('value' in value) {
|
|
129
|
+
return normalizeDataTableRowIdentifierPart(value.value);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return Object.keys(value)
|
|
133
|
+
.sort()
|
|
134
|
+
.reduce(
|
|
135
|
+
(acc, key) => {
|
|
136
|
+
acc[key] = normalizeDataTableRowIdentifierPart(value[key]);
|
|
137
|
+
return acc;
|
|
138
|
+
},
|
|
139
|
+
{} as Record<string, unknown>,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
* Return a stable text form for one normalized row identifier part.
|
|
148
|
+
*/
|
|
149
|
+
function stringifyDataTableRowIdentifierPart(value: unknown) {
|
|
150
|
+
if (typeof value === 'string') {
|
|
151
|
+
return value.trim();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (
|
|
155
|
+
typeof value === 'number' ||
|
|
156
|
+
typeof value === 'boolean' ||
|
|
157
|
+
typeof value === 'bigint'
|
|
158
|
+
) {
|
|
159
|
+
return String(value);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return stringifyJSON(value, true);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/*
|
|
166
|
+
* Return a compact FNV-1a hash for long canonical row identifier payloads.
|
|
167
|
+
*/
|
|
168
|
+
function hashDataTableRowIdentifierText(text: string) {
|
|
169
|
+
let hash = 0xcbf29ce484222325n;
|
|
170
|
+
const prime = 0x100000001b3n;
|
|
171
|
+
const mask = 0xffffffffffffffffn;
|
|
172
|
+
|
|
173
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
174
|
+
hash ^= BigInt(text.charCodeAt(i));
|
|
175
|
+
hash = (hash * prime) & mask;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return hash.toString(36);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/*
|
|
182
|
+
* Return a persisted row identifier from ordered design keys and raw values.
|
|
183
|
+
*/
|
|
184
|
+
export function buildDataTableDesignRowIdentifier(
|
|
185
|
+
rowIdentifierKeys: string[],
|
|
186
|
+
valuesByKey: Record<string, unknown>,
|
|
187
|
+
) {
|
|
188
|
+
const missingKeys: string[] = [];
|
|
189
|
+
const parts = rowIdentifierKeys.map((key) => {
|
|
190
|
+
const normalizedValue = normalizeDataTableRowIdentifierPart(
|
|
191
|
+
valuesByKey[key],
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (isMissingDataTableRowIdentifierValue(normalizedValue)) {
|
|
195
|
+
missingKeys.push(key);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return [key, stringifyDataTableRowIdentifierPart(normalizedValue)] as const;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
if (missingKeys.length) {
|
|
202
|
+
return {
|
|
203
|
+
identifier: null,
|
|
204
|
+
missingKeys,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const readableIdentifier = parts
|
|
209
|
+
.map(
|
|
210
|
+
([key, value]) =>
|
|
211
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`,
|
|
212
|
+
)
|
|
213
|
+
.join('|');
|
|
214
|
+
|
|
215
|
+
if (readableIdentifier.length <= DATA_TABLE_ROW_IDENTIFIER_MAX_LENGTH) {
|
|
216
|
+
return {
|
|
217
|
+
identifier: readableIdentifier,
|
|
218
|
+
missingKeys,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
identifier: `ri_${hashDataTableRowIdentifierText(readableIdentifier)}`,
|
|
224
|
+
missingKeys,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/*
|
|
229
|
+
* Return non-hidden master dataTable design cells in their saved order.
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
export function getOrderedDataTableDesignCells(
|
|
233
|
+
design: DataTableDesignObj | null | undefined,
|
|
234
|
+
) {
|
|
235
|
+
const cells = Array.isArray(design?.cells) ? design.cells : [];
|
|
236
|
+
const cellsByKey = new Map(cells.map((cell) => [cell.key, cell]));
|
|
237
|
+
const orderedCells = (design?.cellsOrder || [])
|
|
238
|
+
.map((key) => cellsByKey.get(key))
|
|
239
|
+
.filter((cell) => cell && !cell.hidden) as DataTableDesignCellObj[];
|
|
240
|
+
const orderedKeys = new Set(orderedCells.map((cell) => cell.key));
|
|
241
|
+
const remainingCells = cells.filter(
|
|
242
|
+
(cell) => !cell.hidden && !orderedKeys.has(cell.key),
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
return orderedCells.concat(remainingCells);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Field type keys whose registry semantics family is one of S, derived from
|
|
249
|
+
* the const-asserted registry snapshot so helper type predicates narrow to
|
|
250
|
+
* exactly the registry-bound keys. */
|
|
251
|
+
type DataTableFieldTypeOfSemantics<S extends DataTableFieldTypeSemanticsKey> = {
|
|
252
|
+
[K in keyof typeof DATA_TABLE_FIELD_TYPE_SEMANTICS]: (typeof DATA_TABLE_FIELD_TYPE_SEMANTICS)[K] extends S
|
|
253
|
+
? K
|
|
254
|
+
: never;
|
|
255
|
+
}[keyof typeof DATA_TABLE_FIELD_TYPE_SEMANTICS];
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Return the registry semantics family one dataTable field type binds to.
|
|
259
|
+
*/
|
|
260
|
+
function getDataTableFieldTypeSemanticsKey(
|
|
261
|
+
fieldType: DataTableFieldTypeEnum | null | undefined,
|
|
262
|
+
): DataTableFieldTypeSemanticsKey | undefined {
|
|
263
|
+
return (
|
|
264
|
+
DATA_TABLE_FIELD_TYPE_SEMANTICS as Record<
|
|
265
|
+
string,
|
|
266
|
+
DataTableFieldTypeSemanticsKey
|
|
267
|
+
>
|
|
268
|
+
)[fieldType || ''];
|
|
57
269
|
}
|
|
58
270
|
|
|
59
271
|
/*
|
|
60
272
|
* Return whether one dataTable field type stores and compares values as numbers.
|
|
61
273
|
*/
|
|
62
274
|
|
|
63
|
-
export function isDataTableNumberLikeFieldType(
|
|
64
|
-
|
|
275
|
+
export function isDataTableNumberLikeFieldType(
|
|
276
|
+
fieldType: DataTableFieldTypeEnum | null | undefined,
|
|
277
|
+
): fieldType is DataTableFieldTypeOfSemantics<'NUMBER'> {
|
|
278
|
+
return getDataTableFieldTypeSemanticsKey(fieldType) === 'NUMBER';
|
|
65
279
|
}
|
|
66
280
|
|
|
67
281
|
/*
|
|
68
282
|
* Return whether one dataTable field type stores and compares values as dates.
|
|
69
283
|
*/
|
|
70
284
|
|
|
71
|
-
export function isDataTableDateLikeFieldType(
|
|
72
|
-
|
|
285
|
+
export function isDataTableDateLikeFieldType(
|
|
286
|
+
fieldType: DataTableFieldTypeEnum | null | undefined,
|
|
287
|
+
): fieldType is DataTableFieldTypeOfSemantics<'DATE' | 'WEEK'> {
|
|
288
|
+
const semanticsKey = getDataTableFieldTypeSemanticsKey(fieldType);
|
|
289
|
+
return semanticsKey === 'DATE' || semanticsKey === 'WEEK';
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/*
|
|
293
|
+
* Return typed cell fields for an already-formatted display value.
|
|
294
|
+
*/
|
|
295
|
+
export function getDataTableDisplayCellTypedValues(
|
|
296
|
+
value: unknown,
|
|
297
|
+
fieldType: DataTableFieldTypeEnum | null | undefined,
|
|
298
|
+
) {
|
|
299
|
+
const stringValue =
|
|
300
|
+
value === null || value === undefined ? '' : String(value);
|
|
301
|
+
const hasValue = stringValue.trim() !== '';
|
|
302
|
+
const numberValue =
|
|
303
|
+
isDataTableNumberLikeFieldType(fieldType) && hasValue
|
|
304
|
+
? Number(stringValue)
|
|
305
|
+
: null;
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
textValue:
|
|
309
|
+
fieldType === 'DATETIME' || isDataTableDateLikeFieldType(fieldType)
|
|
310
|
+
? null
|
|
311
|
+
: stringValue,
|
|
312
|
+
numberValue:
|
|
313
|
+
numberValue !== null && Number.isFinite(numberValue) ? numberValue : null,
|
|
314
|
+
booleanValue: null,
|
|
315
|
+
dateValue:
|
|
316
|
+
isDataTableDateLikeFieldType(fieldType) && hasValue ? stringValue : null,
|
|
317
|
+
datetimeValue: fieldType === 'DATETIME' && hasValue ? stringValue : null,
|
|
318
|
+
};
|
|
73
319
|
}
|
|
74
320
|
|
|
75
321
|
/*
|
|
76
322
|
* Return whether one dataTable field type displays a calendar week range.
|
|
77
323
|
*/
|
|
78
324
|
|
|
79
|
-
export function isDataTableWeekFieldType(
|
|
80
|
-
|
|
325
|
+
export function isDataTableWeekFieldType(
|
|
326
|
+
fieldType: DataTableFieldTypeEnum | null | undefined,
|
|
327
|
+
): fieldType is DataTableFieldTypeOfSemantics<'WEEK'> {
|
|
328
|
+
return getDataTableFieldTypeSemanticsKey(fieldType) === 'WEEK';
|
|
81
329
|
}
|
|
82
330
|
|
|
83
331
|
/*
|
|
84
332
|
* Return the UTC day-of-week index used as the start for a week field type.
|
|
85
333
|
*/
|
|
86
334
|
|
|
87
|
-
function getDataTableWeekStartDay(
|
|
335
|
+
function getDataTableWeekStartDay(
|
|
336
|
+
fieldType: DataTableFieldTypeEnum | null | undefined,
|
|
337
|
+
) {
|
|
88
338
|
return fieldType === 'WEEK_OF_SUN' ? 0 : 1;
|
|
89
339
|
}
|
|
90
340
|
|
|
@@ -122,9 +372,11 @@ function isValidDataTableDateKey(value: string) {
|
|
|
122
372
|
const [year, month, day] = value.split('-').map(Number);
|
|
123
373
|
const date = new Date(Date.UTC(year, month - 1, day));
|
|
124
374
|
|
|
125
|
-
return
|
|
375
|
+
return (
|
|
376
|
+
date.getUTCFullYear() === year &&
|
|
126
377
|
date.getUTCMonth() === month - 1 &&
|
|
127
|
-
date.getUTCDate() === day
|
|
378
|
+
date.getUTCDate() === day
|
|
379
|
+
);
|
|
128
380
|
}
|
|
129
381
|
|
|
130
382
|
/*
|
|
@@ -150,6 +402,48 @@ function parseDateKey(value: string | null | undefined) {
|
|
|
150
402
|
return date;
|
|
151
403
|
}
|
|
152
404
|
|
|
405
|
+
/*
|
|
406
|
+
* Return whether one date-like string includes an explicit time component.
|
|
407
|
+
*/
|
|
408
|
+
function dataTableDateStringHasTimeComponent(value: string) {
|
|
409
|
+
return /(?:T|\s+\d{1,2}:\d{2}|\d{1,2}:\d{2}\s*(?:am|pm)\b)/i.test(
|
|
410
|
+
value.trim(),
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/*
|
|
415
|
+
* Return a date key parsed from date-only strings without applying timezone conversion.
|
|
416
|
+
*/
|
|
417
|
+
function getDataTableDateOnlyStringCalendarKey(value: string) {
|
|
418
|
+
const stringValue = value.trim();
|
|
419
|
+
if (!stringValue || dataTableDateStringHasTimeComponent(stringValue)) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (isValidDataTableDateKey(stringValue)) {
|
|
424
|
+
return stringValue;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const slashDate = stringValue.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
|
|
428
|
+
if (slashDate) {
|
|
429
|
+
const [, monthText, dayText, yearText] = slashDate;
|
|
430
|
+
const month = Number(monthText);
|
|
431
|
+
const day = Number(dayText);
|
|
432
|
+
const dateKey = `${yearText}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
|
433
|
+
|
|
434
|
+
return isValidDataTableDateKey(dateKey) ? dateKey : null;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const parsedDate = new Date(stringValue);
|
|
438
|
+
if (!Number.isFinite(parsedDate.getTime())) {
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const dateKey = formatDateKey(parsedDate);
|
|
443
|
+
|
|
444
|
+
return isValidDataTableDateKey(dateKey) ? dateKey : null;
|
|
445
|
+
}
|
|
446
|
+
|
|
153
447
|
/*
|
|
154
448
|
* Return a YYYY-MM-DD string for one date using UTC calendar fields.
|
|
155
449
|
*/
|
|
@@ -195,7 +489,10 @@ function isValidDataTableDateValue(value: DataTableRecordValue | Date) {
|
|
|
195
489
|
* Return the calendar date key represented by one date value in a timezone.
|
|
196
490
|
*/
|
|
197
491
|
|
|
198
|
-
function getDataTableDateValueCalendarKey(
|
|
492
|
+
function getDataTableDateValueCalendarKey(
|
|
493
|
+
value: DataTableRecordValue | Date,
|
|
494
|
+
timeZone?: string | null,
|
|
495
|
+
) {
|
|
199
496
|
const scalarValue = getDataTableRecordScalarValue(value);
|
|
200
497
|
|
|
201
498
|
if (scalarValue instanceof Date) {
|
|
@@ -203,11 +500,17 @@ function getDataTableDateValueCalendarKey(value: DataTableRecordValue | Date, ti
|
|
|
203
500
|
}
|
|
204
501
|
|
|
205
502
|
const stringValue = String(scalarValue);
|
|
206
|
-
|
|
207
|
-
|
|
503
|
+
const dateOnlyKey = getDataTableDateOnlyStringCalendarKey(stringValue);
|
|
504
|
+
if (dateOnlyKey) {
|
|
505
|
+
return dateOnlyKey;
|
|
208
506
|
}
|
|
209
507
|
|
|
210
|
-
const parsedDate = parseDateInTimezone(
|
|
508
|
+
const parsedDate = parseDateInTimezone(
|
|
509
|
+
stringValue,
|
|
510
|
+
timeZone,
|
|
511
|
+
0,
|
|
512
|
+
stringValue.includes('T'),
|
|
513
|
+
);
|
|
211
514
|
if (Number.isFinite(parsedDate.getTime())) {
|
|
212
515
|
return formatCalDateInTimeZone(parsedDate, timeZone || null);
|
|
213
516
|
}
|
|
@@ -222,14 +525,20 @@ function getDataTableDateValueCalendarKey(value: DataTableRecordValue | Date, ti
|
|
|
222
525
|
export function getDataTableDateValueKey(value: DataTableRecordValue | Date) {
|
|
223
526
|
const scalarValue = getDataTableRecordScalarValue(value);
|
|
224
527
|
|
|
225
|
-
return scalarValue instanceof Date
|
|
528
|
+
return scalarValue instanceof Date
|
|
529
|
+
? scalarValue.toISOString().split('T')[0]
|
|
530
|
+
: String(scalarValue).split('T')[0];
|
|
226
531
|
}
|
|
227
532
|
|
|
228
533
|
/*
|
|
229
534
|
* Return a date string normalized to the configured dataTable week start.
|
|
230
535
|
*/
|
|
231
536
|
|
|
232
|
-
export function normalizeDataTableWeekDateValue(
|
|
537
|
+
export function normalizeDataTableWeekDateValue(
|
|
538
|
+
value: DataTableRecordValue | Date,
|
|
539
|
+
fieldType: DataTableFieldTypeEnum,
|
|
540
|
+
timeZone?: string | null,
|
|
541
|
+
) {
|
|
233
542
|
const dateKey = getDataTableDateValueCalendarKey(value, timeZone);
|
|
234
543
|
const date = parseDateKey(dateKey);
|
|
235
544
|
if (!date || !isDataTableWeekFieldType(fieldType)) {
|
|
@@ -246,15 +555,24 @@ export function normalizeDataTableWeekDateValue(value: DataTableRecordValue | Da
|
|
|
246
555
|
* Return a date string normalized for storage by one date-like dataTable field.
|
|
247
556
|
*/
|
|
248
557
|
|
|
249
|
-
export function normalizeDataTableDateLikeValue(
|
|
250
|
-
|
|
558
|
+
export function normalizeDataTableDateLikeValue(
|
|
559
|
+
value: DataTableRecordValue | Date,
|
|
560
|
+
fieldType: DataTableFieldTypeEnum,
|
|
561
|
+
timeZone?: string | null,
|
|
562
|
+
) {
|
|
563
|
+
return isDataTableWeekFieldType(fieldType)
|
|
564
|
+
? normalizeDataTableWeekDateValue(value, fieldType, timeZone)
|
|
565
|
+
: getDataTableDateValueCalendarKey(value, timeZone);
|
|
251
566
|
}
|
|
252
567
|
|
|
253
568
|
/*
|
|
254
569
|
* Return the canonical ISO datetime string for a dataTable datetime value in one timezone.
|
|
255
570
|
*/
|
|
256
571
|
|
|
257
|
-
export function normalizeDataTableDateTimeValue(
|
|
572
|
+
export function normalizeDataTableDateTimeValue(
|
|
573
|
+
value: DataTableRecordValue | Date,
|
|
574
|
+
timeZone?: string | null,
|
|
575
|
+
) {
|
|
258
576
|
const scalarValue = getDataTableRecordScalarValue(value);
|
|
259
577
|
|
|
260
578
|
return parseDateInTimezone(
|
|
@@ -271,7 +589,8 @@ export function normalizeDataTableDateTimeValue(value: DataTableRecordValue | Da
|
|
|
271
589
|
|
|
272
590
|
function isValidDataTableDateTimeValue(value: DataTableRecordValue) {
|
|
273
591
|
const scalarValue = getDataTableRecordScalarValue(value);
|
|
274
|
-
const date =
|
|
592
|
+
const date =
|
|
593
|
+
scalarValue instanceof Date ? scalarValue : new Date(String(scalarValue));
|
|
275
594
|
|
|
276
595
|
return Number.isFinite(date.getTime());
|
|
277
596
|
}
|
|
@@ -281,7 +600,9 @@ function isValidDataTableDateTimeValue(value: DataTableRecordValue) {
|
|
|
281
600
|
*/
|
|
282
601
|
|
|
283
602
|
function isDataTableOptionValue(cell: DataTableDesignCellObj, value: unknown) {
|
|
284
|
-
const validValues = new Set(
|
|
603
|
+
const validValues = new Set(
|
|
604
|
+
(cell.options || []).map((option) => String(option.value)),
|
|
605
|
+
);
|
|
285
606
|
|
|
286
607
|
return validValues.has(String(value));
|
|
287
608
|
}
|
|
@@ -299,17 +620,17 @@ function getNormalizedDataTableOptionText(value: unknown) {
|
|
|
299
620
|
*/
|
|
300
621
|
|
|
301
622
|
function isDataTableSelectOptionNormalizeField(cell: DataTableDesignCellObj) {
|
|
302
|
-
return cell.fieldType === 'SELECT' ||
|
|
303
|
-
cell.fieldType === 'SELECT_OR_TEXT' ||
|
|
304
|
-
cell.humanFieldType === 'SELECT' ||
|
|
305
|
-
cell.humanFieldType === 'SELECT_OR_TEXT';
|
|
623
|
+
return cell.fieldType === 'SELECT' || cell.fieldType === 'SELECT_OR_TEXT';
|
|
306
624
|
}
|
|
307
625
|
|
|
308
626
|
/*
|
|
309
627
|
* Return the saved option value when one select-style cell input matches an option value or label.
|
|
310
628
|
*/
|
|
311
629
|
|
|
312
|
-
export function normalizeDataTableSelectOptionValue(
|
|
630
|
+
export function normalizeDataTableSelectOptionValue(
|
|
631
|
+
cell: DataTableDesignCellObj,
|
|
632
|
+
value: DataTableRecordValue,
|
|
633
|
+
) {
|
|
313
634
|
if (value === null || !isDataTableSelectOptionNormalizeField(cell)) {
|
|
314
635
|
return value;
|
|
315
636
|
}
|
|
@@ -319,10 +640,11 @@ export function normalizeDataTableSelectOptionValue(cell: DataTableDesignCellObj
|
|
|
319
640
|
}
|
|
320
641
|
|
|
321
642
|
const normalizedValue = getNormalizedDataTableOptionText(value);
|
|
322
|
-
const option = (cell.options || []).find(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
643
|
+
const option = (cell.options || []).find(
|
|
644
|
+
(item) =>
|
|
645
|
+
getNormalizedDataTableOptionText(item.value) === normalizedValue ||
|
|
646
|
+
getNormalizedDataTableOptionText(item.label) === normalizedValue,
|
|
647
|
+
);
|
|
326
648
|
|
|
327
649
|
return option ? option.value : value;
|
|
328
650
|
}
|
|
@@ -339,11 +661,17 @@ export function getDataTableCellValueValidationError(
|
|
|
339
661
|
return null;
|
|
340
662
|
}
|
|
341
663
|
|
|
342
|
-
if (
|
|
664
|
+
if (
|
|
665
|
+
isDataTableNumberLikeFieldType(cell.fieldType) &&
|
|
666
|
+
!isValidDataTableNumberValue(value)
|
|
667
|
+
) {
|
|
343
668
|
return `${cell.key} must be a valid number.`;
|
|
344
669
|
}
|
|
345
670
|
|
|
346
|
-
if (
|
|
671
|
+
if (
|
|
672
|
+
isDataTableDateLikeFieldType(cell.fieldType) &&
|
|
673
|
+
!isValidDataTableDateValue(value)
|
|
674
|
+
) {
|
|
347
675
|
return `${cell.key} must be a valid date.`;
|
|
348
676
|
}
|
|
349
677
|
|
|
@@ -351,13 +679,25 @@ export function getDataTableCellValueValidationError(
|
|
|
351
679
|
return `${cell.key} must be a valid datetime.`;
|
|
352
680
|
}
|
|
353
681
|
|
|
354
|
-
if (
|
|
682
|
+
if (
|
|
683
|
+
cell.fieldType === 'SELECT' &&
|
|
684
|
+
cell.options?.length &&
|
|
685
|
+
!isDataTableOptionValue(cell, value)
|
|
686
|
+
) {
|
|
355
687
|
return `${cell.key} must be one of: ${(cell.options || []).map((option) => option.value).join(', ')}`;
|
|
356
688
|
}
|
|
357
689
|
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
690
|
+
if (
|
|
691
|
+
cell.fieldType === 'SELECT_OR_TEXT' &&
|
|
692
|
+
!isDataTableOptionValue(cell, value) &&
|
|
693
|
+
typeof value !== 'string'
|
|
694
|
+
) {
|
|
695
|
+
const optionsText = (cell.options || [])
|
|
696
|
+
.map((option) => option.value)
|
|
697
|
+
.join(', ');
|
|
698
|
+
return optionsText
|
|
699
|
+
? `${cell.key} must be one of: ${optionsText}, or a text string.`
|
|
700
|
+
: `${cell.key} must be a text string.`;
|
|
361
701
|
}
|
|
362
702
|
|
|
363
703
|
if (cell.fieldType === 'MULTI_SELECT') {
|
|
@@ -366,10 +706,14 @@ export function getDataTableCellValueValidationError(
|
|
|
366
706
|
}
|
|
367
707
|
|
|
368
708
|
if (cell.options?.length) {
|
|
369
|
-
const invalidValues = value.filter(
|
|
709
|
+
const invalidValues = value.filter(
|
|
710
|
+
(item) => !isDataTableOptionValue(cell, item),
|
|
711
|
+
);
|
|
370
712
|
if (invalidValues.length) {
|
|
371
|
-
return
|
|
372
|
-
|
|
713
|
+
return (
|
|
714
|
+
`${cell.key} contains invalid option values: ${invalidValues.map((item) => String(item)).join(', ')}. ` +
|
|
715
|
+
`Allowed values: ${(cell.options || []).map((option) => option.value).join(', ')}`
|
|
716
|
+
);
|
|
373
717
|
}
|
|
374
718
|
}
|
|
375
719
|
}
|
|
@@ -399,7 +743,10 @@ function getDataTableWeekDisplayMonthDay(date: Date, showMonth: boolean) {
|
|
|
399
743
|
* Return the display text for one date as a dataTable week range.
|
|
400
744
|
*/
|
|
401
745
|
|
|
402
|
-
export function formatDataTableWeekDateRange(
|
|
746
|
+
export function formatDataTableWeekDateRange(
|
|
747
|
+
value: DataTableRecordValue | Date,
|
|
748
|
+
fieldType: DataTableFieldTypeEnum,
|
|
749
|
+
) {
|
|
403
750
|
if (!isDataTableWeekFieldType(fieldType)) {
|
|
404
751
|
return '';
|
|
405
752
|
}
|
|
@@ -411,76 +758,14 @@ export function formatDataTableWeekDateRange(value: DataTableRecordValue | Date,
|
|
|
411
758
|
|
|
412
759
|
const end = addDays(start, 6);
|
|
413
760
|
const startText = getDataTableWeekDisplayMonthDay(start, true);
|
|
414
|
-
const endText = getDataTableWeekDisplayMonthDay(
|
|
761
|
+
const endText = getDataTableWeekDisplayMonthDay(
|
|
762
|
+
end,
|
|
763
|
+
start.getUTCMonth() !== end.getUTCMonth(),
|
|
764
|
+
);
|
|
415
765
|
|
|
416
766
|
return `${startText} - ${endText}`;
|
|
417
767
|
}
|
|
418
768
|
|
|
419
|
-
/*
|
|
420
|
-
* Return whether one saved view has a usable generated grouped-row model.
|
|
421
|
-
*/
|
|
422
|
-
|
|
423
|
-
export function isDataTableViewGeneratedRowsView(view: DataTableDesignViewObj | null | undefined) {
|
|
424
|
-
return view?.rowModel?.type === 'GROUPED_ROWS' &&
|
|
425
|
-
typeof view.rowModel.generator?.keyPrefix === 'string' &&
|
|
426
|
-
!!view.rowModel.generator.keyPrefix;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/*
|
|
430
|
-
* Return validated stored views from a dataTable design object.
|
|
431
|
-
*/
|
|
432
|
-
|
|
433
|
-
export function getDataTableDesignViews(design: DataTableDesignObj | null | undefined) {
|
|
434
|
-
const views = design?.views;
|
|
435
|
-
if (!Array.isArray(views)) {
|
|
436
|
-
return [];
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
return views.filter((view) => {
|
|
440
|
-
return (
|
|
441
|
-
isPlainObject(view) &&
|
|
442
|
-
typeof view.id === 'string' &&
|
|
443
|
-
!!view.id &&
|
|
444
|
-
typeof view.name === 'string' &&
|
|
445
|
-
!!view.name &&
|
|
446
|
-
view.layout === 'GRID' &&
|
|
447
|
-
Array.isArray(view.columns)
|
|
448
|
-
);
|
|
449
|
-
}) as DataTableDesignViewObj[];
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/*
|
|
453
|
-
* Return the stored views in the order that dataTable tabs should display them.
|
|
454
|
-
*/
|
|
455
|
-
|
|
456
|
-
export function getOrderedDataTableDesignViews(design: DataTableDesignObj | null | undefined) {
|
|
457
|
-
const views = getDataTableDesignViews(design);
|
|
458
|
-
const viewsById = new Map(views.map((view) => [view.id, view]));
|
|
459
|
-
const orderedViews = (design?.viewsOrder || [])
|
|
460
|
-
.map((viewId) => viewsById.get(viewId))
|
|
461
|
-
.filter(Boolean) as DataTableDesignViewObj[];
|
|
462
|
-
const orderedIds = new Set(orderedViews.map((view) => view.id));
|
|
463
|
-
const remainingViews = views.filter((view) => !orderedIds.has(view.id));
|
|
464
|
-
|
|
465
|
-
return orderedViews.concat(remainingViews);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/*
|
|
469
|
-
* Return the displayable columns for one dataTable view in saved order.
|
|
470
|
-
*/
|
|
471
|
-
|
|
472
|
-
export function getOrderedDataTableDesignViewColumns(view: DataTableDesignViewObj | null | undefined) {
|
|
473
|
-
const columns = Array.isArray(view?.columns) ? view.columns : [];
|
|
474
|
-
const columnsByKey = new Map(columns.map((column) => [column.key, column]));
|
|
475
|
-
const orderedColumns = (view?.columnsOrder || [])
|
|
476
|
-
.map((columnKey) => columnsByKey.get(columnKey))
|
|
477
|
-
.filter(Boolean) as DataTableDesignViewColumnObj[];
|
|
478
|
-
const orderedKeys = new Set(orderedColumns.map((column) => column.key));
|
|
479
|
-
const remainingColumns = columns.filter((column) => !orderedKeys.has(column.key));
|
|
480
|
-
|
|
481
|
-
return orderedColumns.concat(remainingColumns);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
769
|
/*
|
|
485
770
|
* Return every column key once, honoring a saved order before appending missing keys.
|
|
486
771
|
*/
|
|
@@ -525,7 +810,10 @@ export function moveVisibleDataTableColumnKeyInOrder(params: {
|
|
|
525
810
|
toVisibleIndex: number;
|
|
526
811
|
visibleColumnKeys: string[];
|
|
527
812
|
}) {
|
|
528
|
-
const fullOrder = getCompleteDataTableColumnOrder(
|
|
813
|
+
const fullOrder = getCompleteDataTableColumnOrder(
|
|
814
|
+
params.allColumnKeys,
|
|
815
|
+
params.savedOrder,
|
|
816
|
+
);
|
|
529
817
|
const visibleKeySet = new Set(params.visibleColumnKeys);
|
|
530
818
|
const visibleOrder = fullOrder.filter((key) => visibleKeySet.has(key));
|
|
531
819
|
const fromIndex = visibleOrder.indexOf(params.fromKey);
|
|
@@ -536,7 +824,10 @@ export function moveVisibleDataTableColumnKeyInOrder(params: {
|
|
|
536
824
|
|
|
537
825
|
const nextVisibleOrder = visibleOrder.slice(0);
|
|
538
826
|
const [movedKey] = nextVisibleOrder.splice(fromIndex, 1);
|
|
539
|
-
const toIndex = Math.max(
|
|
827
|
+
const toIndex = Math.max(
|
|
828
|
+
0,
|
|
829
|
+
Math.min(params.toVisibleIndex, nextVisibleOrder.length),
|
|
830
|
+
);
|
|
540
831
|
|
|
541
832
|
if (!movedKey) {
|
|
542
833
|
return fullOrder;
|
|
@@ -556,279 +847,3 @@ export function moveVisibleDataTableColumnKeyInOrder(params: {
|
|
|
556
847
|
return nextKey;
|
|
557
848
|
});
|
|
558
849
|
}
|
|
559
|
-
|
|
560
|
-
/*
|
|
561
|
-
* Return the inclusive start and end dates for one generated date series.
|
|
562
|
-
*/
|
|
563
|
-
|
|
564
|
-
function getDataTableViewDateSeriesRange(
|
|
565
|
-
dateSeries: NonNullable<NonNullable<DataTableDesignViewObj['rowModel']>['generator']>['dateSeries'],
|
|
566
|
-
referenceDate: Date,
|
|
567
|
-
) {
|
|
568
|
-
if (!dateSeries?.range) {
|
|
569
|
-
return null;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (dateSeries.range.type === 'FIXED') {
|
|
573
|
-
const start = parseDateKey(dateSeries.range.start);
|
|
574
|
-
const end = parseDateKey(dateSeries.range.end);
|
|
575
|
-
|
|
576
|
-
return start && end && start.getTime() <= end.getTime() ? { start, end } : null;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
if (dateSeries.range.type === 'CURRENT_MONTH') {
|
|
580
|
-
const start = new Date(Date.UTC(referenceDate.getUTCFullYear(), referenceDate.getUTCMonth(), 1));
|
|
581
|
-
const end = new Date(Date.UTC(referenceDate.getUTCFullYear(), referenceDate.getUTCMonth() + 1, 0));
|
|
582
|
-
|
|
583
|
-
return { start, end };
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
return null;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/*
|
|
590
|
-
* Return generated date points for one date series.
|
|
591
|
-
*/
|
|
592
|
-
|
|
593
|
-
function getDataTableViewDateSeriesValues(
|
|
594
|
-
dateSeries: NonNullable<NonNullable<DataTableDesignViewObj['rowModel']>['generator']>['dateSeries'],
|
|
595
|
-
referenceDate: Date,
|
|
596
|
-
) {
|
|
597
|
-
const range = getDataTableViewDateSeriesRange(dateSeries, referenceDate);
|
|
598
|
-
if (!dateSeries?.key || !range) {
|
|
599
|
-
return [];
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
const values: Array<{
|
|
603
|
-
key: string;
|
|
604
|
-
value: string;
|
|
605
|
-
label: string;
|
|
606
|
-
grain: 'DAY' | 'WEEK';
|
|
607
|
-
sourceCellKey: string;
|
|
608
|
-
}> = [];
|
|
609
|
-
let current = range.start;
|
|
610
|
-
|
|
611
|
-
while (current.getTime() <= range.end.getTime()) {
|
|
612
|
-
if (dateSeries.grain === 'DAY' || (dateSeries.grain === 'WEEK' && current.getUTCDay() === 1)) {
|
|
613
|
-
const value = formatDateKey(current);
|
|
614
|
-
values.push({
|
|
615
|
-
key: dateSeries.key,
|
|
616
|
-
value,
|
|
617
|
-
label: value,
|
|
618
|
-
grain: dateSeries.grain,
|
|
619
|
-
sourceCellKey: dateSeries.sourceCellKey || dateSeries.key,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
current = addDays(current, 1);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
return values;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
/*
|
|
630
|
-
* Return generated dimension values from static values or master cell options.
|
|
631
|
-
*/
|
|
632
|
-
|
|
633
|
-
function getDataTableViewGeneratorDimensionValues(
|
|
634
|
-
dimension: DataTableDesignViewGeneratorDimensionObj,
|
|
635
|
-
masterCellsByKey: Map<string, DataTableDesignCellObj>,
|
|
636
|
-
) {
|
|
637
|
-
if (!dimension?.key || !dimension.source) {
|
|
638
|
-
return [];
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
if (dimension.source.type === 'STATIC_VALUES') {
|
|
642
|
-
return (dimension.source.values || [])
|
|
643
|
-
.filter((value) => typeof value?.value === 'string' && !!value.value)
|
|
644
|
-
.map((value) => ({
|
|
645
|
-
key: dimension.key,
|
|
646
|
-
value: value.value,
|
|
647
|
-
label: value.label || value.value,
|
|
648
|
-
sourceCellKey: null,
|
|
649
|
-
}));
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if (dimension.source.type === 'MASTER_CELL_OPTIONS') {
|
|
653
|
-
const cellKey = dimension.source.cellKey;
|
|
654
|
-
const cell = masterCellsByKey.get(cellKey);
|
|
655
|
-
|
|
656
|
-
return (cell?.options || [])
|
|
657
|
-
.filter((option) => typeof option?.value === 'string' && !!option.value)
|
|
658
|
-
.map((option) => ({
|
|
659
|
-
key: dimension.key,
|
|
660
|
-
value: option.value,
|
|
661
|
-
label: option.label || option.value,
|
|
662
|
-
sourceCellKey: cellKey,
|
|
663
|
-
}));
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
return [];
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/*
|
|
670
|
-
* Return all dimension value groups for a generated grouped-row view.
|
|
671
|
-
*/
|
|
672
|
-
|
|
673
|
-
function getDataTableViewGeneratorValueGroups(
|
|
674
|
-
view: DataTableDesignViewObj,
|
|
675
|
-
masterCells: DataTableDesignCellObj[],
|
|
676
|
-
referenceDate: Date,
|
|
677
|
-
) {
|
|
678
|
-
const generator = view.rowModel?.generator;
|
|
679
|
-
const masterCellsByKey = new Map(masterCells.map((cell) => [cell.key, cell]));
|
|
680
|
-
const groups: Array<Array<{
|
|
681
|
-
key: string;
|
|
682
|
-
value: string;
|
|
683
|
-
label: string;
|
|
684
|
-
grain?: 'DAY' | 'WEEK';
|
|
685
|
-
sourceCellKey?: string | null;
|
|
686
|
-
}>> = [];
|
|
687
|
-
|
|
688
|
-
const dateValues = getDataTableViewDateSeriesValues(generator?.dateSeries, referenceDate);
|
|
689
|
-
if (dateValues.length) {
|
|
690
|
-
groups.push(dateValues);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
(generator?.dimensions || []).forEach((dimension) => {
|
|
694
|
-
const values = getDataTableViewGeneratorDimensionValues(dimension, masterCellsByKey);
|
|
695
|
-
if (values.length) {
|
|
696
|
-
groups.push(values);
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
|
|
700
|
-
return groups;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/*
|
|
704
|
-
* Return every cartesian combination of generated date and dimension values.
|
|
705
|
-
*/
|
|
706
|
-
|
|
707
|
-
function getDataTableViewGeneratorCombinations(
|
|
708
|
-
groups: Array<Array<{
|
|
709
|
-
key: string;
|
|
710
|
-
value: string;
|
|
711
|
-
label: string;
|
|
712
|
-
grain?: 'DAY' | 'WEEK';
|
|
713
|
-
sourceCellKey?: string | null;
|
|
714
|
-
}>>,
|
|
715
|
-
) {
|
|
716
|
-
return groups.reduce((combinations, group) => {
|
|
717
|
-
if (!combinations.length) {
|
|
718
|
-
return group.map((value) => [value]);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
return combinations.flatMap((combination) => group.map((value) => combination.concat(value)));
|
|
722
|
-
}, [] as Array<Array<{
|
|
723
|
-
key: string;
|
|
724
|
-
value: string;
|
|
725
|
-
label: string;
|
|
726
|
-
grain?: 'DAY' | 'WEEK';
|
|
727
|
-
sourceCellKey?: string | null;
|
|
728
|
-
}>>);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/*
|
|
732
|
-
* Return the stable row key for one generated row combination.
|
|
733
|
-
*/
|
|
734
|
-
|
|
735
|
-
function getDataTableViewGeneratedRowKey(
|
|
736
|
-
keyPrefix: string,
|
|
737
|
-
combination: Array<{
|
|
738
|
-
key: string;
|
|
739
|
-
value: string;
|
|
740
|
-
}>,
|
|
741
|
-
) {
|
|
742
|
-
const segments = combination.map((value) => `${value.key}=${encodeURIComponent(value.value)}`);
|
|
743
|
-
|
|
744
|
-
return `${keyPrefix}:${segments.join(':')}`;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
/*
|
|
748
|
-
* Return generated row definitions for one grouped-row view generator.
|
|
749
|
-
*/
|
|
750
|
-
|
|
751
|
-
export function getDataTableViewGeneratedRowDefinitions(
|
|
752
|
-
view: DataTableDesignViewObj,
|
|
753
|
-
masterCells: DataTableDesignCellObj[],
|
|
754
|
-
referenceDate: Date = new Date(),
|
|
755
|
-
) {
|
|
756
|
-
if (!isDataTableViewGeneratedRowsView(view)) {
|
|
757
|
-
return [];
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
const generator = view.rowModel!.generator!;
|
|
761
|
-
const groups = getDataTableViewGeneratorValueGroups(view, masterCells, referenceDate);
|
|
762
|
-
const combinations = getDataTableViewGeneratorCombinations(groups);
|
|
763
|
-
|
|
764
|
-
return combinations.map((combination, index) => {
|
|
765
|
-
const cellValues = combination.reduce((values, value) => {
|
|
766
|
-
values[value.key] = value.label;
|
|
767
|
-
return values;
|
|
768
|
-
}, {} as Record<string, string | number>);
|
|
769
|
-
const dateValue = combination.find((value) => value.key === generator.dateSeries?.key);
|
|
770
|
-
const dimensionValues = combination.filter((value) => value.key !== generator.dateSeries?.key);
|
|
771
|
-
|
|
772
|
-
return {
|
|
773
|
-
viewRowKey: getDataTableViewGeneratedRowKey(generator.keyPrefix, combination),
|
|
774
|
-
position: index + 1,
|
|
775
|
-
cellValues,
|
|
776
|
-
criteria: {
|
|
777
|
-
date: dateValue && dateValue.grain
|
|
778
|
-
? {
|
|
779
|
-
key: dateValue.key,
|
|
780
|
-
value: dateValue.value,
|
|
781
|
-
grain: dateValue.grain,
|
|
782
|
-
sourceCellKey: dateValue.sourceCellKey || dateValue.key,
|
|
783
|
-
}
|
|
784
|
-
: undefined,
|
|
785
|
-
dimensions: dimensionValues.map((value) => ({
|
|
786
|
-
key: value.key,
|
|
787
|
-
value: value.value,
|
|
788
|
-
sourceCellKey: value.sourceCellKey,
|
|
789
|
-
})),
|
|
790
|
-
},
|
|
791
|
-
} satisfies GeneratedDataTableViewRowDefinition;
|
|
792
|
-
});
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/*
|
|
796
|
-
* Convert a view column into the same design-cell shape used by the grid renderer.
|
|
797
|
-
*/
|
|
798
|
-
|
|
799
|
-
export function mapDataTableDesignViewColumnToCell(
|
|
800
|
-
column: DataTableDesignViewColumnObj,
|
|
801
|
-
masterCellsByKey: Map<string, DataTableDesignCellObj>,
|
|
802
|
-
) {
|
|
803
|
-
const masterCell = isDataTableViewMasterCellColumn(column)
|
|
804
|
-
? masterCellsByKey.get(column.source!.cellKey!)
|
|
805
|
-
: null;
|
|
806
|
-
|
|
807
|
-
return {
|
|
808
|
-
key: column.key,
|
|
809
|
-
label: column.label || masterCell?.label || column.key,
|
|
810
|
-
humanLabel: column.humanLabel ?? null,
|
|
811
|
-
iconName: column.iconName ?? masterCell?.iconName ?? null,
|
|
812
|
-
fieldType: masterCell?.fieldType || column.fieldType || column.humanFieldType as DataTableFieldTypeEnum,
|
|
813
|
-
humanFieldType: column.humanFieldType,
|
|
814
|
-
format: masterCell?.format ?? null,
|
|
815
|
-
source: column.source?.type === 'RELATED_RECORD' && column.source.path && column.source.table
|
|
816
|
-
? {
|
|
817
|
-
path: column.source.path,
|
|
818
|
-
table: column.source.table,
|
|
819
|
-
}
|
|
820
|
-
: masterCell?.source || null,
|
|
821
|
-
options: column.options || masterCell?.options || [],
|
|
822
|
-
openLink: column.openLink ?? masterCell?.openLink,
|
|
823
|
-
humansOnly: masterCell?.humansOnly,
|
|
824
|
-
humansCannotEdit: column.humansCannotEdit ?? masterCell?.humansCannotEdit ?? (
|
|
825
|
-
column.source?.type !== 'MASTER_CELL' &&
|
|
826
|
-
column.source?.type !== 'CUSTOM'
|
|
827
|
-
),
|
|
828
|
-
indexed: masterCell?.indexed,
|
|
829
|
-
width: column.width ?? null,
|
|
830
|
-
viewSource: column.source || null,
|
|
831
|
-
} as DataTableDesignCellObj & {
|
|
832
|
-
viewSource?: DataTableDesignViewColumnObj['source'] | null;
|
|
833
|
-
};
|
|
834
|
-
}
|