@platforma-sdk/model 1.29.2 → 1.29.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/PFrameForGraphs.d.ts.map +1 -1
- package/dist/components/PlDataTable.d.ts +38 -4
- package/dist/components/PlDataTable.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +583 -479
- package/dist/index.mjs.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/components/PFrameForGraphs.test.ts +37 -0
- package/src/components/PFrameForGraphs.ts +21 -7
- package/src/components/PlDataTable.ts +250 -67
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PlatformaSDKVersion = "1.29.
|
|
1
|
+
export declare const PlatformaSDKVersion = "1.29.13";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platforma-sdk/model",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.13",
|
|
4
4
|
"description": "Platforma.bio SDK / Block Model",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"utility-types": "^3.11.0",
|
|
22
22
|
"canonicalize": "~2.1.0",
|
|
23
23
|
"zod": "~3.23.8",
|
|
24
|
-
"@milaboratories/pl-model-common": "^1.13.
|
|
24
|
+
"@milaboratories/pl-model-common": "^1.13.7",
|
|
25
25
|
"@milaboratories/pl-error-like": "^1.12.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"jest": "^29.7.0",
|
|
32
32
|
"@jest/globals": "^29.7.0",
|
|
33
33
|
"ts-jest": "^29.2.6",
|
|
34
|
-
"@platforma-
|
|
35
|
-
"@
|
|
34
|
+
"@milaboratories/platforma-build-configs": "1.0.3",
|
|
35
|
+
"@platforma-sdk/eslint-config": "1.0.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"type-check": "node ./scripts/save-package-version.cjs && tsc --noEmit --composite false",
|
|
@@ -187,6 +187,43 @@ describe('PFrameForGraph', () => {
|
|
|
187
187
|
expect(enrichedColumns.map((c) => c.id)).toEqual(['id1', 'id2', 'id3'])
|
|
188
188
|
})
|
|
189
189
|
|
|
190
|
+
test('enrichColumnsWithCompatibleMetadata doesn\'t add column with identical spec', () => {
|
|
191
|
+
const columnSpec1: PColumnSpec = {
|
|
192
|
+
kind: 'PColumn',
|
|
193
|
+
name: 'column1',
|
|
194
|
+
valueType: 'Int',
|
|
195
|
+
axesSpec: [
|
|
196
|
+
{type: 'String', name: 'axis1', domain: {key1: 'a'}},
|
|
197
|
+
{type: 'String', name: 'axis2', domain: {key1: 'b'}},
|
|
198
|
+
]
|
|
199
|
+
};
|
|
200
|
+
const metaColumnSpec1: PColumnSpec = {
|
|
201
|
+
kind: 'PColumn',
|
|
202
|
+
name: 'metadata1',
|
|
203
|
+
valueType: 'Int',
|
|
204
|
+
axesSpec: [{type: 'String', name: 'axis1'}]
|
|
205
|
+
};
|
|
206
|
+
const metaColumnSpec2: PColumnSpec = {
|
|
207
|
+
kind: 'PColumn',
|
|
208
|
+
name: 'metadata2',
|
|
209
|
+
valueType: 'String',
|
|
210
|
+
axesSpec: [{type: 'String', name: 'axis1', domain: {key1: 'a'}}]
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const columns: PColumn<TreeNodeAccessor | PColumnValues>[] = [
|
|
214
|
+
{id: 'id1' as PObjectId, spec: columnSpec1, data: []},
|
|
215
|
+
] as PColumn<PColumnValues>[];
|
|
216
|
+
const upstream: PColumn<TreeNodeAccessor | PColumnValues>[] = [
|
|
217
|
+
{id: 'id2' as PObjectId, spec: columnSpec1, data: []},
|
|
218
|
+
{id: 'id3' as PObjectId, spec: metaColumnSpec1, data: []},
|
|
219
|
+
{id: 'id4' as PObjectId, spec: metaColumnSpec2, data: []},
|
|
220
|
+
] as PColumn<PColumnValues>[];
|
|
221
|
+
|
|
222
|
+
const enrichedColumns = enrichColumnsWithCompatible(columns, upstream);
|
|
223
|
+
expect(enrichedColumns.map((c) => c.id)).toEqual(['id1', 'id3', 'id4'])
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
|
|
190
227
|
test('Labels of added columns include added domains, but not include common domains', () => {
|
|
191
228
|
const columnSpec1: PColumnSpec = {
|
|
192
229
|
kind: 'PColumn',
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AxisId,
|
|
3
|
+
CanonicalizedJson,
|
|
3
4
|
PColumn,
|
|
5
|
+
PColumnSpecId,
|
|
4
6
|
PColumnValues,
|
|
5
7
|
PFrameHandle,
|
|
6
8
|
PObjectId,
|
|
7
9
|
ValueType } from '@milaboratories/pl-model-common';
|
|
8
10
|
import {
|
|
11
|
+
canonicalizeJson,
|
|
9
12
|
getAxisId,
|
|
13
|
+
getPColumnSpecId,
|
|
10
14
|
isPColumn,
|
|
11
15
|
matchAxisId,
|
|
12
16
|
} from '@milaboratories/pl-model-common';
|
|
@@ -172,19 +176,29 @@ export function enrichColumnsWithCompatible(
|
|
|
172
176
|
mainColumns: PColumn<TreeNodeAccessor | PColumnValues>[],
|
|
173
177
|
secondaryColumns: PColumn<TreeNodeAccessor | PColumnValues>[],
|
|
174
178
|
): PColumn<TreeNodeAccessor | PColumnValues>[] {
|
|
175
|
-
const
|
|
179
|
+
const mainColumnsIds = new Set<PObjectId>();
|
|
180
|
+
const mainColumnsBySpec = new Map<CanonicalizedJson<PColumnSpecId>, typeof mainColumns[number]>();
|
|
181
|
+
mainColumns.forEach((column) => {
|
|
182
|
+
mainColumnsIds.add(column.id);
|
|
183
|
+
mainColumnsBySpec.set(canonicalizeJson(getPColumnSpecId(column.spec)), column);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const secondaryColumnsBySpec = new Map<CanonicalizedJson<PColumnSpecId>, typeof secondaryColumns[number]>();
|
|
176
187
|
for (const secondaryColumn of secondaryColumns) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
188
|
+
if (mainColumnsIds.has(secondaryColumn.id)) continue;
|
|
189
|
+
|
|
190
|
+
const spec = canonicalizeJson(getPColumnSpecId(secondaryColumn.spec));
|
|
191
|
+
if (mainColumnsBySpec.has(spec)) continue;
|
|
192
|
+
|
|
193
|
+
for (const mainColumn of mainColumnsBySpec.values()) {
|
|
181
194
|
if (checkCompatibility(mainColumn, secondaryColumn)) {
|
|
182
|
-
|
|
195
|
+
secondaryColumnsBySpec.set(spec, secondaryColumn);
|
|
183
196
|
break;
|
|
184
197
|
}
|
|
185
198
|
}
|
|
186
199
|
}
|
|
187
|
-
|
|
200
|
+
|
|
201
|
+
return [...mainColumnsBySpec.values(), ...secondaryColumnsBySpec.values()];
|
|
188
202
|
}
|
|
189
203
|
|
|
190
204
|
const VALUE_TYPES: ValueType[] = [
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AxisSpec,
|
|
3
|
+
CanonicalizedJson,
|
|
3
4
|
DataInfo,
|
|
4
5
|
JoinEntry,
|
|
5
6
|
PColumn,
|
|
@@ -7,17 +8,39 @@ import type {
|
|
|
7
8
|
PColumnSpec,
|
|
8
9
|
PColumnValues,
|
|
9
10
|
PObjectId,
|
|
11
|
+
PTableColumnIdColumn,
|
|
12
|
+
PTableColumnSpec,
|
|
13
|
+
PTableDef,
|
|
10
14
|
PTableHandle,
|
|
11
15
|
PTableRecordFilter,
|
|
16
|
+
PTableRecordSingleValueFilterV2,
|
|
12
17
|
PTableSorting,
|
|
13
18
|
} from '@milaboratories/pl-model-common';
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
import { canonicalizeJson, getAxisId, getColumnIdAndSpec, matchAxisId } from '@milaboratories/pl-model-common';
|
|
20
|
+
import type { AxisLabelProvider, ColumnProvider, RenderCtx } from '../render';
|
|
21
|
+
import { PColumnCollection, TreeNodeAccessor } from '../render';
|
|
22
|
+
|
|
23
|
+
/** Canonicalized PTableColumnSpec JSON string */
|
|
24
|
+
export type PTableColumnSpecJson = CanonicalizedJson<PTableColumnSpec>;
|
|
25
|
+
|
|
26
|
+
/** Encode `PTableColumnId` as canonicalized JSON string */
|
|
27
|
+
export function strinfigyPTableColumnId(spec: PTableColumnSpec): PTableColumnSpecJson {
|
|
28
|
+
const type = spec.type;
|
|
29
|
+
switch (type) {
|
|
30
|
+
case 'axis':
|
|
31
|
+
return canonicalizeJson(spec);
|
|
32
|
+
case 'column':
|
|
33
|
+
return canonicalizeJson(spec);
|
|
34
|
+
default:
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
36
|
+
throw Error(`unsupported column type: ${type satisfies never}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Parse `PTableColumnId` from JSON string */
|
|
41
|
+
export function parsePTableColumnId(str: PTableColumnSpecJson): PTableColumnSpec {
|
|
42
|
+
return JSON.parse(str) as PTableColumnSpec;
|
|
43
|
+
}
|
|
21
44
|
|
|
22
45
|
/** Data table state */
|
|
23
46
|
export type PlDataTableGridState = {
|
|
@@ -44,7 +67,7 @@ export type PlDataTableGridState = {
|
|
|
44
67
|
/** Includes column visibility */
|
|
45
68
|
columnVisibility?: {
|
|
46
69
|
/** All colIds which were hidden */
|
|
47
|
-
hiddenColIds:
|
|
70
|
+
hiddenColIds: PTableColumnSpecJson[];
|
|
48
71
|
};
|
|
49
72
|
/** current sheet selections */
|
|
50
73
|
sheets?: Record<string, string | number>;
|
|
@@ -319,49 +342,29 @@ export type CreatePlDataTableOps = {
|
|
|
319
342
|
coreJoinType?: 'inner' | 'full';
|
|
320
343
|
};
|
|
321
344
|
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
* @param columns column list
|
|
327
|
-
* @param tableState table ui state
|
|
328
|
-
* @returns
|
|
329
|
-
*/
|
|
330
|
-
export function createPlDataTable<A, U>(
|
|
331
|
-
ctx: RenderCtx<A, U>,
|
|
332
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
333
|
-
tableState: PlDataTableState | undefined
|
|
334
|
-
): PTableHandle | undefined;
|
|
335
|
-
export function createPlDataTable<A, U>(
|
|
336
|
-
ctx: RenderCtx<A, U>,
|
|
337
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
338
|
-
tableState: PlDataTableState | undefined,
|
|
339
|
-
ops: CreatePlDataTableOps
|
|
340
|
-
): PTableHandle | undefined;
|
|
341
|
-
/** @deprecated use method with extended ops as the last argument */
|
|
342
|
-
export function createPlDataTable<A, U>(
|
|
343
|
-
ctx: RenderCtx<A, U>,
|
|
344
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
345
|
-
tableState: PlDataTableState | undefined,
|
|
346
|
-
filters: PTableRecordFilter[]
|
|
347
|
-
): PTableHandle | undefined;
|
|
348
|
-
export function createPlDataTable<A, U>(
|
|
349
|
-
ctx: RenderCtx<A, U>,
|
|
350
|
-
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
351
|
-
tableState: PlDataTableState | undefined,
|
|
352
|
-
ops?: PTableRecordFilter[] | CreatePlDataTableOps,
|
|
353
|
-
): PTableHandle | undefined {
|
|
354
|
-
// ops migration for backward compatibility with previous deprecated API
|
|
355
|
-
if (Array.isArray(ops)) {
|
|
356
|
-
ops = { filters: ops };
|
|
357
|
-
}
|
|
345
|
+
/** Check if column is a label column */
|
|
346
|
+
export function isLabelColumn(column: PColumnSpec) {
|
|
347
|
+
return column.axesSpec.length === 1 && column.name === 'pl7.app/label';
|
|
348
|
+
}
|
|
358
349
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
350
|
+
/** Get all label columns from the result pool */
|
|
351
|
+
export function getAllLabelColumns(
|
|
352
|
+
resultPool: AxisLabelProvider & ColumnProvider,
|
|
353
|
+
): PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[] | undefined {
|
|
354
|
+
return new PColumnCollection()
|
|
355
|
+
.addAxisLabelProvider(resultPool)
|
|
356
|
+
.addColumnProvider(resultPool)
|
|
357
|
+
.getColumns({
|
|
358
|
+
name: 'pl7.app/label',
|
|
359
|
+
axes: [{}], // exactly one axis
|
|
360
|
+
}, { dontWaitAllData: true });
|
|
361
|
+
}
|
|
364
362
|
|
|
363
|
+
/** Get label columns matching the provided columns from the result pool */
|
|
364
|
+
export function getMatchingLabelColumns(
|
|
365
|
+
columns: PColumnIdAndSpec[],
|
|
366
|
+
allLabelColumns: PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[],
|
|
367
|
+
): PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[] {
|
|
365
368
|
const colId = (id: PObjectId, domain?: Record<string, string>) => {
|
|
366
369
|
let wid = id.toString();
|
|
367
370
|
if (domain) {
|
|
@@ -373,12 +376,11 @@ export function createPlDataTable<A, U>(
|
|
|
373
376
|
return wid;
|
|
374
377
|
};
|
|
375
378
|
|
|
376
|
-
const labelColumns = new Map<string,
|
|
377
|
-
|
|
379
|
+
const labelColumns = new Map<string, typeof allLabelColumns[number]>();
|
|
378
380
|
for (const col of columns) {
|
|
379
381
|
for (const axis of col.spec.axesSpec) {
|
|
380
382
|
const axisId = getAxisId(axis);
|
|
381
|
-
for (const labelColumn of
|
|
383
|
+
for (const labelColumn of allLabelColumns) {
|
|
382
384
|
const labelAxis = labelColumn.spec.axesSpec[0];
|
|
383
385
|
const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);
|
|
384
386
|
if (matchAxisId(axisId, labelAxisId)) {
|
|
@@ -403,38 +405,219 @@ export function createPlDataTable<A, U>(
|
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
407
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
[...columns, ...labelColumns.values()].some(
|
|
409
|
-
(a) => a.data instanceof TreeNodeAccessor && !a.data.getIsReadyOrError(),
|
|
410
|
-
)
|
|
411
|
-
)
|
|
412
|
-
return undefined;
|
|
408
|
+
return [...labelColumns.values()];
|
|
409
|
+
}
|
|
413
410
|
|
|
411
|
+
/** Check if all columns are computed */
|
|
412
|
+
export function allColumnsComputed(
|
|
413
|
+
columns: PColumn<PColumnValues | TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[],
|
|
414
|
+
): boolean {
|
|
415
|
+
type Data = typeof columns[number]['data'];
|
|
416
|
+
const isValues = (d: Data): d is PColumnValues => Array.isArray(d);
|
|
417
|
+
const isAccessor = (d: Data): d is TreeNodeAccessor => d instanceof TreeNodeAccessor;
|
|
418
|
+
const isDataInfo = (d: Data): d is DataInfo<TreeNodeAccessor> =>
|
|
419
|
+
typeof d === 'object' && 'type' in d;
|
|
420
|
+
|
|
421
|
+
return columns
|
|
422
|
+
.map((c) => c.data)
|
|
423
|
+
.every((d): boolean => {
|
|
424
|
+
if (isValues(d)) {
|
|
425
|
+
return true;
|
|
426
|
+
} else if (isAccessor(d)) {
|
|
427
|
+
return d.getIsReadyOrError();
|
|
428
|
+
} else if (isDataInfo(d)) {
|
|
429
|
+
const type = d.type;
|
|
430
|
+
switch (type) {
|
|
431
|
+
case 'Json':
|
|
432
|
+
return true;
|
|
433
|
+
case 'JsonPartitioned':
|
|
434
|
+
return Object.values(d.parts).every((p) => p.getIsReadyOrError());
|
|
435
|
+
case 'BinaryPartitioned':
|
|
436
|
+
return Object.values(d.parts)
|
|
437
|
+
.every((p) => p.index.getIsReadyOrError() && p.values.getIsReadyOrError());
|
|
438
|
+
}
|
|
439
|
+
} else {
|
|
440
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
441
|
+
throw Error(`unsupported column data type: ${d satisfies never}`);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function createPTableDef(
|
|
447
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
448
|
+
labelColumns: PColumn<TreeNodeAccessor | DataInfo<TreeNodeAccessor>>[],
|
|
449
|
+
coreJoinType: 'inner' | 'full',
|
|
450
|
+
filters: PTableRecordSingleValueFilterV2[],
|
|
451
|
+
sorting: PTableSorting[],
|
|
452
|
+
coreColumnPredicate?: ((spec: PColumnSpec) => boolean),
|
|
453
|
+
): PTableDef<PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>> {
|
|
414
454
|
let coreColumns = columns;
|
|
415
455
|
const secondaryColumns: typeof columns = [];
|
|
416
456
|
|
|
417
|
-
if (
|
|
457
|
+
if (coreColumnPredicate) {
|
|
418
458
|
coreColumns = [];
|
|
419
459
|
for (const c of columns)
|
|
420
|
-
if (
|
|
460
|
+
if (coreColumnPredicate(c.spec)) coreColumns.push(c);
|
|
421
461
|
else secondaryColumns.push(c);
|
|
422
462
|
}
|
|
423
463
|
|
|
424
|
-
secondaryColumns.push(...labelColumns
|
|
464
|
+
secondaryColumns.push(...labelColumns);
|
|
425
465
|
|
|
426
|
-
return
|
|
466
|
+
return {
|
|
427
467
|
src: {
|
|
428
468
|
type: 'outer',
|
|
429
469
|
primary: {
|
|
430
|
-
type:
|
|
470
|
+
type: coreJoinType,
|
|
431
471
|
entries: coreColumns.map((c) => ({ type: 'column', column: c })),
|
|
432
472
|
},
|
|
433
473
|
secondary: secondaryColumns.map((c) => ({ type: 'column', column: c })),
|
|
434
474
|
},
|
|
435
|
-
filters
|
|
436
|
-
sorting
|
|
437
|
-
}
|
|
475
|
+
filters,
|
|
476
|
+
sorting,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Create p-table handle given ui table state
|
|
482
|
+
*
|
|
483
|
+
* @param ctx context
|
|
484
|
+
* @param columns column list
|
|
485
|
+
* @param tableState table ui state
|
|
486
|
+
* @returns PlAgDataTable table source
|
|
487
|
+
*/
|
|
488
|
+
export function createPlDataTable<A, U>(
|
|
489
|
+
ctx: RenderCtx<A, U>,
|
|
490
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
491
|
+
tableState: PlDataTableState | undefined
|
|
492
|
+
): PTableHandle | undefined;
|
|
493
|
+
export function createPlDataTable<A, U>(
|
|
494
|
+
ctx: RenderCtx<A, U>,
|
|
495
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
496
|
+
tableState: PlDataTableState | undefined,
|
|
497
|
+
ops: CreatePlDataTableOps
|
|
498
|
+
): PTableHandle | undefined;
|
|
499
|
+
/** @deprecated use method with extended ops as the last argument */
|
|
500
|
+
export function createPlDataTable<A, U>(
|
|
501
|
+
ctx: RenderCtx<A, U>,
|
|
502
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
503
|
+
tableState: PlDataTableState | undefined,
|
|
504
|
+
filters: PTableRecordFilter[]
|
|
505
|
+
): PTableHandle | undefined;
|
|
506
|
+
export function createPlDataTable<A, U>(
|
|
507
|
+
ctx: RenderCtx<A, U>,
|
|
508
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
509
|
+
tableState: PlDataTableState | undefined,
|
|
510
|
+
ops?: PTableRecordFilter[] | CreatePlDataTableOps,
|
|
511
|
+
): PTableHandle | undefined {
|
|
512
|
+
// ops migration for backward compatibility with previous deprecated API
|
|
513
|
+
if (Array.isArray(ops)) {
|
|
514
|
+
ops = { filters: ops };
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const coreJoinType = ops?.coreJoinType ?? 'full';
|
|
518
|
+
const filters: PTableRecordSingleValueFilterV2[]
|
|
519
|
+
= [...(ops?.filters ?? []), ...(tableState?.pTableParams?.filters ?? [])];
|
|
520
|
+
const sorting: PTableSorting[] = tableState?.pTableParams?.sorting ?? [];
|
|
521
|
+
|
|
522
|
+
const allLabelColumns = getAllLabelColumns(ctx.resultPool);
|
|
523
|
+
if (!allLabelColumns) return undefined;
|
|
524
|
+
|
|
525
|
+
const labelColumns = getMatchingLabelColumns(columns.map(getColumnIdAndSpec), allLabelColumns);
|
|
526
|
+
|
|
527
|
+
// if at least one column is not yet computed, we can't show the table
|
|
528
|
+
if (!allColumnsComputed([...columns, ...labelColumns])) return undefined;
|
|
529
|
+
|
|
530
|
+
return ctx.createPTable(
|
|
531
|
+
createPTableDef(columns, labelColumns, coreJoinType, filters, sorting, ops?.coreColumnPredicate));
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** PlAgDataTable model */
|
|
535
|
+
export type PlDataTableModel = {
|
|
536
|
+
/** p-table specification (full, including hidden columns) */
|
|
537
|
+
tableSpec: PTableColumnSpec[];
|
|
538
|
+
/** p-table handle (integration of visible columns data) */
|
|
539
|
+
tableHandle: PTableHandle;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
/** Check if column is hidden by default */
|
|
543
|
+
export function isColumnOptional(spec: { annotations?: Record<string, string> }): boolean {
|
|
544
|
+
return spec.annotations?.['pl7.app/table/visibility'] === 'optional';
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Create p-table spec and handle given ui table state
|
|
549
|
+
*
|
|
550
|
+
* @param ctx context
|
|
551
|
+
* @param columns column list
|
|
552
|
+
* @param tableState table ui state
|
|
553
|
+
* @returns PlAgDataTableV2 table source
|
|
554
|
+
*/
|
|
555
|
+
export function createPlDataTableV2<A, U>(
|
|
556
|
+
ctx: RenderCtx<A, U>,
|
|
557
|
+
columns: PColumn<TreeNodeAccessor | PColumnValues | DataInfo<TreeNodeAccessor>>[],
|
|
558
|
+
mainColumnPredicate: (spec: PColumnSpec) => boolean,
|
|
559
|
+
tableState: PlDataTableState | undefined,
|
|
560
|
+
ops?: CreatePlDataTableOps,
|
|
561
|
+
): PlDataTableModel | undefined {
|
|
562
|
+
const coreJoinType = ops?.coreJoinType ?? 'full';
|
|
563
|
+
const filters: PTableRecordSingleValueFilterV2[]
|
|
564
|
+
= [...(ops?.filters ?? []), ...(tableState?.pTableParams?.filters ?? [])];
|
|
565
|
+
const sorting: PTableSorting[] = tableState?.pTableParams?.sorting ?? [];
|
|
566
|
+
|
|
567
|
+
const mainColumn = columns.find((c) => mainColumnPredicate(c.spec));
|
|
568
|
+
if (!mainColumn) return undefined;
|
|
569
|
+
|
|
570
|
+
const allLabelColumns = getAllLabelColumns(ctx.resultPool);
|
|
571
|
+
if (!allLabelColumns) return undefined;
|
|
572
|
+
|
|
573
|
+
const spec: PTableColumnSpec[] = [
|
|
574
|
+
...mainColumn.spec.axesSpec.map((axis) => ({
|
|
575
|
+
type: 'axis',
|
|
576
|
+
id: getAxisId(axis),
|
|
577
|
+
spec: axis,
|
|
578
|
+
} satisfies PTableColumnSpec)),
|
|
579
|
+
...[...columns, ...allLabelColumns].map((c) => ({
|
|
580
|
+
type: 'column',
|
|
581
|
+
id: c.id,
|
|
582
|
+
spec: c.spec,
|
|
583
|
+
} satisfies PTableColumnSpec)),
|
|
584
|
+
];
|
|
585
|
+
|
|
586
|
+
const hiddenColumns = new Set<PObjectId>(((): PObjectId[] => {
|
|
587
|
+
// Inner join works as a filter - all columns must be present
|
|
588
|
+
if (coreJoinType === 'inner') return [];
|
|
589
|
+
|
|
590
|
+
const hiddenColIds = tableState?.gridState.columnVisibility?.hiddenColIds
|
|
591
|
+
?.map(parsePTableColumnId)
|
|
592
|
+
.filter((c) => c.type === 'column')
|
|
593
|
+
.map((c) => c.id);
|
|
594
|
+
if (hiddenColIds) return hiddenColIds;
|
|
595
|
+
|
|
596
|
+
return columns
|
|
597
|
+
.filter((c) => isColumnOptional(c.spec))
|
|
598
|
+
.map((c) => c.id);
|
|
599
|
+
})());
|
|
600
|
+
|
|
601
|
+
// Main column must always be included in join to integrate all other columns
|
|
602
|
+
hiddenColumns.delete(mainColumn.id);
|
|
603
|
+
// Filters decrease the number of result rows, sorting changes the order of result rows
|
|
604
|
+
[...filters.map((f) => f.column), ...sorting.map((s) => s.column)]
|
|
605
|
+
.filter((c): c is PTableColumnIdColumn => c.type === 'column')
|
|
606
|
+
.map((c) => hiddenColumns.delete(c.id));
|
|
607
|
+
|
|
608
|
+
const visibleColumns = columns.filter((c) => !hiddenColumns.has(c.id));
|
|
609
|
+
const labelColumns = getMatchingLabelColumns(visibleColumns.map(getColumnIdAndSpec), allLabelColumns);
|
|
610
|
+
|
|
611
|
+
// if at least one column is not yet computed, we can't show the table
|
|
612
|
+
if (!allColumnsComputed([...visibleColumns, ...labelColumns])) return undefined;
|
|
613
|
+
|
|
614
|
+
const handle = ctx.createPTable(
|
|
615
|
+
createPTableDef(columns, labelColumns, coreJoinType, filters, sorting, ops?.coreColumnPredicate));
|
|
616
|
+
|
|
617
|
+
return {
|
|
618
|
+
tableSpec: spec,
|
|
619
|
+
tableHandle: handle,
|
|
620
|
+
} satisfies PlDataTableModel;
|
|
438
621
|
}
|
|
439
622
|
|
|
440
623
|
/** Create sheet entries for PlDataTable */
|