@platforma-sdk/model 1.53.14 → 1.54.7
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/annotations/converter.cjs +8 -32
- package/dist/annotations/converter.cjs.map +1 -1
- package/dist/annotations/converter.d.ts.map +1 -1
- package/dist/annotations/converter.js +7 -31
- package/dist/annotations/converter.js.map +1 -1
- package/dist/block_model.cjs +1 -0
- package/dist/block_model.cjs.map +1 -1
- package/dist/block_model.d.ts.map +1 -1
- package/dist/block_model.js +1 -0
- package/dist/block_model.js.map +1 -1
- package/dist/builder.cjs +1 -0
- package/dist/builder.cjs.map +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +1 -0
- package/dist/builder.js.map +1 -1
- package/dist/components/PlDataTable/index.d.ts +5 -0
- package/dist/components/PlDataTable/index.d.ts.map +1 -0
- package/dist/components/PlDataTable/labels.cjs +91 -0
- package/dist/components/PlDataTable/labels.cjs.map +1 -0
- package/dist/components/PlDataTable/labels.d.ts +7 -0
- package/dist/components/PlDataTable/labels.d.ts.map +1 -0
- package/dist/components/PlDataTable/labels.js +88 -0
- package/dist/components/PlDataTable/labels.js.map +1 -0
- package/dist/components/PlDataTable/state-migration.cjs +162 -0
- package/dist/components/PlDataTable/state-migration.cjs.map +1 -0
- package/dist/components/PlDataTable/state-migration.d.ts +94 -0
- package/dist/components/PlDataTable/state-migration.d.ts.map +1 -0
- package/dist/components/PlDataTable/state-migration.js +158 -0
- package/dist/components/PlDataTable/state-migration.js.map +1 -0
- package/dist/components/PlDataTable/table.cjs +188 -0
- package/dist/components/PlDataTable/table.cjs.map +1 -0
- package/dist/components/PlDataTable/table.d.ts +26 -0
- package/dist/components/PlDataTable/table.d.ts.map +1 -0
- package/dist/components/PlDataTable/table.js +184 -0
- package/dist/components/PlDataTable/table.js.map +1 -0
- package/dist/components/PlDataTable/v4.d.ts +157 -0
- package/dist/components/PlDataTable/v4.d.ts.map +1 -0
- package/dist/components/PlDataTable/v5.d.ts +113 -0
- package/dist/components/PlDataTable/v5.d.ts.map +1 -0
- package/dist/filters/converters/filterEmpty.cjs +49 -0
- package/dist/filters/converters/filterEmpty.cjs.map +1 -0
- package/dist/filters/converters/filterEmpty.d.ts +4 -0
- package/dist/filters/converters/filterEmpty.d.ts.map +1 -0
- package/dist/filters/converters/filterEmpty.js +46 -0
- package/dist/filters/converters/filterEmpty.js.map +1 -0
- package/dist/filters/converters/filterToQuery.cjs +244 -0
- package/dist/filters/converters/filterToQuery.cjs.map +1 -0
- package/dist/filters/converters/filterToQuery.d.ts +4 -0
- package/dist/filters/converters/filterToQuery.d.ts.map +1 -0
- package/dist/filters/converters/filterToQuery.js +242 -0
- package/dist/filters/converters/filterToQuery.js.map +1 -0
- package/dist/filters/{converter.cjs → converters/filterUiToExpressionImpl.cjs} +3 -2
- package/dist/filters/converters/filterUiToExpressionImpl.cjs.map +1 -0
- package/dist/filters/{converter.d.ts → converters/filterUiToExpressionImpl.d.ts} +2 -2
- package/dist/filters/converters/filterUiToExpressionImpl.d.ts.map +1 -0
- package/dist/filters/{converter.js → converters/filterUiToExpressionImpl.js} +3 -2
- package/dist/filters/converters/filterUiToExpressionImpl.js.map +1 -0
- package/dist/filters/converters/index.d.ts +3 -0
- package/dist/filters/converters/index.d.ts.map +1 -0
- package/dist/filters/distill.cjs +46 -0
- package/dist/filters/distill.cjs.map +1 -0
- package/dist/filters/distill.d.ts +6 -0
- package/dist/filters/distill.d.ts.map +1 -0
- package/dist/filters/distill.js +44 -0
- package/dist/filters/distill.js.map +1 -0
- package/dist/filters/index.d.ts +2 -1
- package/dist/filters/index.d.ts.map +1 -1
- package/dist/filters/types.d.ts +1 -117
- package/dist/filters/types.d.ts.map +1 -1
- package/dist/index.cjs +17 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/pframe_utils/columns.cjs +2 -0
- package/dist/pframe_utils/columns.cjs.map +1 -1
- package/dist/pframe_utils/columns.js +2 -0
- package/dist/pframe_utils/columns.js.map +1 -1
- package/dist/pframe_utils/index.cjs +2 -0
- package/dist/pframe_utils/index.cjs.map +1 -1
- package/dist/pframe_utils/index.js +2 -0
- package/dist/pframe_utils/index.js.map +1 -1
- package/dist/pframe_utils/querySpec.d.ts +2 -0
- package/dist/pframe_utils/querySpec.d.ts.map +1 -0
- package/dist/render/api.cjs +7 -0
- package/dist/render/api.cjs.map +1 -1
- package/dist/render/api.d.ts +3 -2
- package/dist/render/api.d.ts.map +1 -1
- package/dist/render/api.js +8 -1
- package/dist/render/api.js.map +1 -1
- package/dist/render/future.d.ts +1 -1
- package/dist/render/index.d.ts +2 -1
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/internal.cjs.map +1 -1
- package/dist/render/internal.d.ts +4 -1
- package/dist/render/internal.d.ts.map +1 -1
- package/dist/render/internal.js.map +1 -1
- package/dist/render/util/column_collection.cjs.map +1 -1
- package/dist/render/util/column_collection.d.ts +1 -1
- package/dist/render/util/column_collection.d.ts.map +1 -1
- package/dist/render/util/column_collection.js.map +1 -1
- package/dist/render/util/pcolumn_data.cjs.map +1 -1
- package/dist/render/util/pcolumn_data.d.ts +1 -1
- package/dist/render/util/pcolumn_data.d.ts.map +1 -1
- package/dist/render/util/pcolumn_data.js.map +1 -1
- package/package.json +9 -8
- package/src/annotations/converter.ts +12 -40
- package/src/block_model.ts +1 -0
- package/src/builder.ts +1 -0
- package/src/components/PlDataTable/index.ts +22 -0
- package/src/components/PlDataTable/labels.ts +101 -0
- package/src/components/PlDataTable/state-migration.ts +285 -0
- package/src/components/PlDataTable/table.ts +279 -0
- package/src/components/PlDataTable/v4.ts +193 -0
- package/src/components/PlDataTable/v5.ts +140 -0
- package/src/filters/converters/filterEmpty.test.ts +125 -0
- package/src/filters/converters/filterEmpty.ts +57 -0
- package/src/filters/converters/filterToQuery.test.ts +417 -0
- package/src/filters/converters/filterToQuery.ts +258 -0
- package/src/filters/{converter.test.ts → converters/filterUiToExpressionImpl.test.ts} +2 -2
- package/src/filters/{converter.ts → converters/filterUiToExpressionImpl.ts} +3 -2
- package/src/filters/converters/index.ts +2 -0
- package/src/filters/distill.ts +59 -0
- package/src/filters/index.ts +2 -1
- package/src/filters/types.ts +8 -48
- package/src/pframe_utils/querySpec.ts +1 -0
- package/src/render/api.ts +13 -6
- package/src/render/index.ts +2 -1
- package/src/render/internal.ts +11 -0
- package/src/render/util/column_collection.ts +1 -1
- package/src/render/util/pcolumn_data.ts +1 -1
- package/dist/components/PlDataTable.cjs +0 -307
- package/dist/components/PlDataTable.cjs.map +0 -1
- package/dist/components/PlDataTable.d.ts +0 -366
- package/dist/components/PlDataTable.d.ts.map +0 -1
- package/dist/components/PlDataTable.js +0 -297
- package/dist/components/PlDataTable.js.map +0 -1
- package/dist/filters/converter.cjs.map +0 -1
- package/dist/filters/converter.d.ts.map +0 -1
- package/dist/filters/converter.js.map +0 -1
- package/src/components/PlDataTable.ts +0 -794
|
@@ -1,49 +1,21 @@
|
|
|
1
1
|
import { when } from "@milaboratories/ptabler-expression-js";
|
|
2
|
-
import
|
|
3
|
-
import { convertFilterUiToExpressionImpl } from "../filters/converter";
|
|
2
|
+
import { convertFilterUiToExpressionImpl } from "../filters/converters/filterUiToExpressionImpl";
|
|
4
3
|
import type { ExpressionSpec, FilterSpecUi } from "./types";
|
|
5
|
-
|
|
6
|
-
function filterPredicate(item: FilterSpec): boolean {
|
|
7
|
-
// No need to convert empty steps
|
|
8
|
-
if (item.type == null) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (item.type === "or") {
|
|
13
|
-
return item.filters.length > 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (item.type === "and") {
|
|
17
|
-
return item.filters.length > 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (item.type === "not") {
|
|
21
|
-
return filterPredicate(item.filter);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Filter out any item that has undefined values in required fields
|
|
25
|
-
return !Object.values(item).some((v) => v === undefined);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function filterEmptyPeaces(item: FilterSpec): FilterSpec {
|
|
29
|
-
if (item.type === "or" || item.type === "and") {
|
|
30
|
-
const filtered = item.filters.map(filterEmptyPeaces).filter(filterPredicate);
|
|
31
|
-
return {
|
|
32
|
-
...item,
|
|
33
|
-
filters: filtered,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return item;
|
|
38
|
-
}
|
|
4
|
+
import { filterEmptyPieces } from "../filters/converters/filterEmpty";
|
|
39
5
|
|
|
40
6
|
export function convertFilterSpecsToExpressionSpecs(
|
|
41
7
|
annotationsUI: FilterSpecUi[],
|
|
42
8
|
): ExpressionSpec[] {
|
|
43
|
-
const validAnnotationsUI = annotationsUI
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
9
|
+
const validAnnotationsUI = annotationsUI
|
|
10
|
+
.map((step) => ({
|
|
11
|
+
label: step.label,
|
|
12
|
+
filter: filterEmptyPieces(step.filter),
|
|
13
|
+
}))
|
|
14
|
+
.filter(
|
|
15
|
+
(step): step is { label: string; filter: NonNullable<typeof step.filter> } =>
|
|
16
|
+
step.filter !== null,
|
|
17
|
+
);
|
|
18
|
+
|
|
47
19
|
return validAnnotationsUI.map(
|
|
48
20
|
(step): ExpressionSpec => ({
|
|
49
21
|
type: "alias",
|
package/src/block_model.ts
CHANGED
package/src/builder.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// If you need to export something from previous versions,
|
|
2
|
+
// that mean you don't forget update deps to the latest version of the package.
|
|
3
|
+
export type {
|
|
4
|
+
PlTableColumnId,
|
|
5
|
+
PlTableColumnIdJson,
|
|
6
|
+
PlDataTableGridStateCore,
|
|
7
|
+
PlDataTableSheet,
|
|
8
|
+
PlDataTableSheetState,
|
|
9
|
+
PlDataTableStateV2CacheEntry,
|
|
10
|
+
PTableParamsV2,
|
|
11
|
+
PlDataTableStateV2Normalized,
|
|
12
|
+
PlDataTableModel,
|
|
13
|
+
} from "./v5";
|
|
14
|
+
|
|
15
|
+
export type { PlDataTableStateV2 } from "./state-migration";
|
|
16
|
+
export {
|
|
17
|
+
upgradePlDataTableStateV2,
|
|
18
|
+
createDefaultPTableParams,
|
|
19
|
+
createPlDataTableStateV2,
|
|
20
|
+
} from "./state-migration";
|
|
21
|
+
|
|
22
|
+
export { isColumnHidden, isColumnOptional, createPlDataTableV2 } from "./table";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { AxisId, PColumn, PColumnIdAndSpec, PObjectId } from "@milaboratories/pl-model-common";
|
|
2
|
+
import {
|
|
3
|
+
getAxisId,
|
|
4
|
+
isLabelColumn,
|
|
5
|
+
matchAxisId,
|
|
6
|
+
PColumnName,
|
|
7
|
+
} from "@milaboratories/pl-model-common";
|
|
8
|
+
import type { AxisLabelProvider, ColumnProvider, PColumnDataUniversal } from "../../render";
|
|
9
|
+
import { PColumnCollection } from "../../render";
|
|
10
|
+
|
|
11
|
+
/** Get all label columns from the result pool */
|
|
12
|
+
export function getAllLabelColumns(
|
|
13
|
+
resultPool: AxisLabelProvider & ColumnProvider,
|
|
14
|
+
): PColumn<PColumnDataUniversal>[] | undefined {
|
|
15
|
+
return new PColumnCollection()
|
|
16
|
+
.addAxisLabelProvider(resultPool)
|
|
17
|
+
.addColumnProvider(resultPool)
|
|
18
|
+
.getColumns(
|
|
19
|
+
{
|
|
20
|
+
name: PColumnName.Label,
|
|
21
|
+
axes: [{}], // exactly one axis
|
|
22
|
+
},
|
|
23
|
+
{ dontWaitAllData: true, overrideLabelAnnotation: false },
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Get label columns matching the provided columns from the result pool */
|
|
28
|
+
export function getMatchingLabelColumns(
|
|
29
|
+
columns: PColumnIdAndSpec[],
|
|
30
|
+
allLabelColumns: PColumn<PColumnDataUniversal>[],
|
|
31
|
+
): PColumn<PColumnDataUniversal>[] {
|
|
32
|
+
// split input columns into label and value columns
|
|
33
|
+
const inputLabelColumns: typeof columns = [];
|
|
34
|
+
const inputValueColumns: typeof columns = [];
|
|
35
|
+
for (const column of columns) {
|
|
36
|
+
if (isLabelColumn(column.spec)) {
|
|
37
|
+
inputLabelColumns.push(column);
|
|
38
|
+
} else {
|
|
39
|
+
inputValueColumns.push(column);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// collect distinct axes of value columns
|
|
44
|
+
const unlabeledAxes: AxisId[] = [];
|
|
45
|
+
for (const column of inputValueColumns) {
|
|
46
|
+
for (const axis of column.spec.axesSpec) {
|
|
47
|
+
const axisId = getAxisId(axis);
|
|
48
|
+
if (!unlabeledAxes.some((id) => matchAxisId(id, axisId))) {
|
|
49
|
+
unlabeledAxes.push(axisId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// remove axes matched by input label columns
|
|
55
|
+
for (const labelColumn of inputLabelColumns) {
|
|
56
|
+
const labelAxisId = getAxisId(labelColumn.spec.axesSpec[0]);
|
|
57
|
+
const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));
|
|
58
|
+
if (labelMatch !== -1) {
|
|
59
|
+
unlabeledAxes.splice(labelMatch, 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// warning: changing this id will break backward compatibility
|
|
64
|
+
const colId = (id: PObjectId, domain?: Record<string, string>): PObjectId => {
|
|
65
|
+
let wid = id.toString();
|
|
66
|
+
if (domain) {
|
|
67
|
+
for (const k in domain) {
|
|
68
|
+
wid += k;
|
|
69
|
+
wid += domain[k];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return wid as PObjectId;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// search label columns for unmatched axes
|
|
76
|
+
const labelColumns: typeof allLabelColumns = [];
|
|
77
|
+
for (const labelColumn of allLabelColumns) {
|
|
78
|
+
const labelAxis = labelColumn.spec.axesSpec[0];
|
|
79
|
+
const labelAxisId = getAxisId(labelAxis);
|
|
80
|
+
const labelMatch = unlabeledAxes.findIndex((axisId) => matchAxisId(axisId, labelAxisId));
|
|
81
|
+
if (labelMatch !== -1) {
|
|
82
|
+
const axisId = unlabeledAxes[labelMatch];
|
|
83
|
+
const dataDomainLen = Object.keys(axisId.domain ?? {}).length;
|
|
84
|
+
const labelDomainLen = Object.keys(labelAxis.domain ?? {}).length;
|
|
85
|
+
if (dataDomainLen > labelDomainLen) {
|
|
86
|
+
labelColumns.push({
|
|
87
|
+
id: colId(labelColumn.id, axisId.domain),
|
|
88
|
+
spec: {
|
|
89
|
+
...labelColumn.spec,
|
|
90
|
+
axesSpec: [{ ...axisId, annotations: labelAxis.annotations }],
|
|
91
|
+
},
|
|
92
|
+
data: labelColumn.data,
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
labelColumns.push(labelColumn);
|
|
96
|
+
}
|
|
97
|
+
unlabeledAxes.splice(labelMatch, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return labelColumns;
|
|
101
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AxisId,
|
|
3
|
+
CanonicalizedJson,
|
|
4
|
+
PObjectId,
|
|
5
|
+
PTableColumnId,
|
|
6
|
+
PTableColumnSpec,
|
|
7
|
+
PTableRecordFilter,
|
|
8
|
+
PTableSorting,
|
|
9
|
+
} from "@milaboratories/pl-model-common";
|
|
10
|
+
import { canonicalizeJson } from "@milaboratories/pl-model-common";
|
|
11
|
+
import { distillFilter } from "../../filters";
|
|
12
|
+
import type { PlDataTableFilterState, PlTableFilter } from "./v4";
|
|
13
|
+
import type {
|
|
14
|
+
PlDataTableAdvancedFilter,
|
|
15
|
+
PlDataTableGridStateCore,
|
|
16
|
+
PlDataTableSheetState,
|
|
17
|
+
PlDataTableStateV2CacheEntry,
|
|
18
|
+
PlDataTableStateV2Normalized,
|
|
19
|
+
PTableParamsV2,
|
|
20
|
+
} from "./v5";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* PlDataTableV2 persisted state
|
|
24
|
+
*/
|
|
25
|
+
export type PlDataTableStateV2 =
|
|
26
|
+
// Old versions of the state
|
|
27
|
+
| {
|
|
28
|
+
// no version
|
|
29
|
+
gridState: {
|
|
30
|
+
columnOrder?: {
|
|
31
|
+
orderedColIds: CanonicalizedJson<PTableColumnSpec>[];
|
|
32
|
+
};
|
|
33
|
+
sort?: {
|
|
34
|
+
sortModel: {
|
|
35
|
+
colId: CanonicalizedJson<PTableColumnSpec>;
|
|
36
|
+
sort: "asc" | "desc";
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
columnVisibility?: {
|
|
40
|
+
hiddenColIds: CanonicalizedJson<PTableColumnSpec>[];
|
|
41
|
+
};
|
|
42
|
+
sourceId?: string;
|
|
43
|
+
sheets?: Record<CanonicalizedJson<AxisId>, string | number>;
|
|
44
|
+
};
|
|
45
|
+
pTableParams?: {
|
|
46
|
+
sorting?: PTableSorting[];
|
|
47
|
+
filters?: PTableRecordFilter[];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
| {
|
|
51
|
+
version: 2;
|
|
52
|
+
stateCache: {
|
|
53
|
+
sourceId: string;
|
|
54
|
+
gridState: {
|
|
55
|
+
columnOrder?: {
|
|
56
|
+
orderedColIds: CanonicalizedJson<PTableColumnSpec>[];
|
|
57
|
+
};
|
|
58
|
+
sort?: {
|
|
59
|
+
sortModel: {
|
|
60
|
+
colId: CanonicalizedJson<PTableColumnSpec>;
|
|
61
|
+
sort: "asc" | "desc";
|
|
62
|
+
}[];
|
|
63
|
+
};
|
|
64
|
+
columnVisibility?: {
|
|
65
|
+
hiddenColIds: CanonicalizedJson<PTableColumnSpec>[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
sheetsState: PlDataTableSheetState[];
|
|
69
|
+
}[];
|
|
70
|
+
pTableParams: {
|
|
71
|
+
hiddenColIds: PObjectId[] | null;
|
|
72
|
+
filters: PTableRecordFilter[];
|
|
73
|
+
sorting: PTableSorting[];
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
version: 3;
|
|
78
|
+
stateCache: {
|
|
79
|
+
sourceId: string;
|
|
80
|
+
gridState: {
|
|
81
|
+
columnOrder?: {
|
|
82
|
+
orderedColIds: CanonicalizedJson<PTableColumnSpec>[];
|
|
83
|
+
};
|
|
84
|
+
sort?: {
|
|
85
|
+
sortModel: {
|
|
86
|
+
colId: CanonicalizedJson<PTableColumnSpec>;
|
|
87
|
+
sort: "asc" | "desc";
|
|
88
|
+
}[];
|
|
89
|
+
};
|
|
90
|
+
columnVisibility?: {
|
|
91
|
+
hiddenColIds: CanonicalizedJson<PTableColumnSpec>[];
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
sheetsState: PlDataTableSheetState[];
|
|
95
|
+
filtersState: PlDataTableFilterState[];
|
|
96
|
+
}[];
|
|
97
|
+
pTableParams: PTableParamsV2;
|
|
98
|
+
}
|
|
99
|
+
| {
|
|
100
|
+
version: 4;
|
|
101
|
+
stateCache: {
|
|
102
|
+
sourceId: string;
|
|
103
|
+
gridState: PlDataTableGridStateCore;
|
|
104
|
+
sheetsState: PlDataTableSheetState[];
|
|
105
|
+
filtersState: PlDataTableFilterState[];
|
|
106
|
+
}[];
|
|
107
|
+
/** Old format; only fields used in migration are typed */
|
|
108
|
+
pTableParams: {
|
|
109
|
+
sourceId: string | null;
|
|
110
|
+
hiddenColIds: PObjectId[] | null;
|
|
111
|
+
sorting: PTableSorting[];
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// Normalized state
|
|
115
|
+
| PlDataTableStateV2Normalized;
|
|
116
|
+
|
|
117
|
+
/** Upgrade PlDataTableStateV2 to the latest version */
|
|
118
|
+
export function upgradePlDataTableStateV2(
|
|
119
|
+
state: PlDataTableStateV2 | undefined,
|
|
120
|
+
): PlDataTableStateV2Normalized {
|
|
121
|
+
// Block just added, had no state, model started earlier than the UI
|
|
122
|
+
if (!state) {
|
|
123
|
+
return createPlDataTableStateV2();
|
|
124
|
+
}
|
|
125
|
+
// v1 -> v2
|
|
126
|
+
if (!("version" in state)) {
|
|
127
|
+
// Non upgradeable as sourceId calculation algorithm has changed, resetting state to default
|
|
128
|
+
state = createPlDataTableStateV2();
|
|
129
|
+
}
|
|
130
|
+
// v2 -> v3
|
|
131
|
+
if (state.version === 2) {
|
|
132
|
+
state = {
|
|
133
|
+
version: 3,
|
|
134
|
+
stateCache: state.stateCache.map((entry) => ({
|
|
135
|
+
...entry,
|
|
136
|
+
filtersState: [],
|
|
137
|
+
})),
|
|
138
|
+
pTableParams: createDefaultPTableParams(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// v3 -> v4
|
|
142
|
+
if (state.version === 3) {
|
|
143
|
+
// Non upgradeable as column ids calculation algorithm has changed, resetting state to default
|
|
144
|
+
state = createPlDataTableStateV2();
|
|
145
|
+
}
|
|
146
|
+
// v4 -> v5: migrate per-column filters to tree-based format
|
|
147
|
+
if (state.version === 4) {
|
|
148
|
+
state = migrateV4toV5(state);
|
|
149
|
+
}
|
|
150
|
+
return state;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Migrate v4 state to v5: convert per-column filters to tree-based format */
|
|
154
|
+
function migrateV4toV5(
|
|
155
|
+
state: Extract<PlDataTableStateV2, { version: 4 }>,
|
|
156
|
+
): PlDataTableStateV2Normalized {
|
|
157
|
+
let idCounter = 0;
|
|
158
|
+
const nextId = () => ++idCounter;
|
|
159
|
+
|
|
160
|
+
const migratedCache: PlDataTableStateV2CacheEntry[] = state.stateCache.map((entry) => {
|
|
161
|
+
const leaves: PlDataTableAdvancedFilter[] = [];
|
|
162
|
+
for (const f of entry.filtersState) {
|
|
163
|
+
if (f.filter !== null && !f.filter.disabled) {
|
|
164
|
+
const column = canonicalizeJson<PTableColumnId>(f.id);
|
|
165
|
+
leaves.push(migrateTableFilter(column, f.filter.value, nextId));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const filtersState: PlDataTableAdvancedFilter | null =
|
|
169
|
+
leaves.length > 0 ? { id: nextId(), type: "and", filters: leaves } : null;
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
sourceId: entry.sourceId,
|
|
173
|
+
gridState: entry.gridState,
|
|
174
|
+
sheetsState: entry.sheetsState,
|
|
175
|
+
filtersState,
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const oldSourceId = state.pTableParams.sourceId;
|
|
180
|
+
const currentCache = oldSourceId
|
|
181
|
+
? migratedCache.find((e) => e.sourceId === oldSourceId)
|
|
182
|
+
: undefined;
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
version: 5,
|
|
186
|
+
stateCache: migratedCache,
|
|
187
|
+
pTableParams:
|
|
188
|
+
currentCache && oldSourceId
|
|
189
|
+
? {
|
|
190
|
+
sourceId: oldSourceId,
|
|
191
|
+
hiddenColIds: state.pTableParams.hiddenColIds,
|
|
192
|
+
filters: distillFilter(currentCache.filtersState),
|
|
193
|
+
sorting: state.pTableParams.sorting,
|
|
194
|
+
}
|
|
195
|
+
: createDefaultPTableParams(),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Migrate a single per-column PlTableFilter to a tree-based FilterSpec node */
|
|
200
|
+
function migrateTableFilter(
|
|
201
|
+
column: string,
|
|
202
|
+
filter: PlTableFilter,
|
|
203
|
+
nextId: () => number,
|
|
204
|
+
): PlDataTableAdvancedFilter {
|
|
205
|
+
const id = nextId();
|
|
206
|
+
switch (filter.type) {
|
|
207
|
+
case "isNA":
|
|
208
|
+
return { id, type: "isNA", column };
|
|
209
|
+
case "isNotNA":
|
|
210
|
+
return { id, type: "isNotNA", column };
|
|
211
|
+
case "number_equals":
|
|
212
|
+
return { id, type: "equal", column, x: filter.reference };
|
|
213
|
+
case "number_notEquals":
|
|
214
|
+
return { id, type: "notEqual", column, x: filter.reference };
|
|
215
|
+
case "number_greaterThan":
|
|
216
|
+
return { id, type: "greaterThan", column, x: filter.reference };
|
|
217
|
+
case "number_greaterThanOrEqualTo":
|
|
218
|
+
return { id, type: "greaterThanOrEqual", column, x: filter.reference };
|
|
219
|
+
case "number_lessThan":
|
|
220
|
+
return { id, type: "lessThan", column, x: filter.reference };
|
|
221
|
+
case "number_lessThanOrEqualTo":
|
|
222
|
+
return { id, type: "lessThanOrEqual", column, x: filter.reference };
|
|
223
|
+
case "number_between":
|
|
224
|
+
return {
|
|
225
|
+
id,
|
|
226
|
+
type: "and",
|
|
227
|
+
filters: [
|
|
228
|
+
filter.includeLowerBound
|
|
229
|
+
? { id: nextId(), type: "greaterThanOrEqual" as const, column, x: filter.lowerBound }
|
|
230
|
+
: { id: nextId(), type: "greaterThan" as const, column, x: filter.lowerBound },
|
|
231
|
+
filter.includeUpperBound
|
|
232
|
+
? { id: nextId(), type: "lessThanOrEqual" as const, column, x: filter.upperBound }
|
|
233
|
+
: { id: nextId(), type: "lessThan" as const, column, x: filter.upperBound },
|
|
234
|
+
],
|
|
235
|
+
};
|
|
236
|
+
case "string_equals":
|
|
237
|
+
return { id, type: "patternEquals", column, value: filter.reference };
|
|
238
|
+
case "string_notEquals":
|
|
239
|
+
return { id, type: "patternNotEquals", column, value: filter.reference };
|
|
240
|
+
case "string_contains":
|
|
241
|
+
return { id, type: "patternContainSubsequence", column, value: filter.reference };
|
|
242
|
+
case "string_doesNotContain":
|
|
243
|
+
return { id, type: "patternNotContainSubsequence", column, value: filter.reference };
|
|
244
|
+
case "string_matches":
|
|
245
|
+
return { id, type: "patternMatchesRegularExpression", column, value: filter.reference };
|
|
246
|
+
case "string_doesNotMatch":
|
|
247
|
+
return {
|
|
248
|
+
id,
|
|
249
|
+
type: "not",
|
|
250
|
+
filter: {
|
|
251
|
+
id: nextId(),
|
|
252
|
+
type: "patternMatchesRegularExpression",
|
|
253
|
+
column,
|
|
254
|
+
value: filter.reference,
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
case "string_containsFuzzyMatch":
|
|
258
|
+
return {
|
|
259
|
+
id,
|
|
260
|
+
type: "patternFuzzyContainSubsequence",
|
|
261
|
+
column,
|
|
262
|
+
value: filter.reference,
|
|
263
|
+
maxEdits: filter.maxEdits,
|
|
264
|
+
substitutionsOnly: filter.substitutionsOnly,
|
|
265
|
+
...(filter.wildcard !== undefined ? { wildcard: filter.wildcard } : {}),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export function createDefaultPTableParams(): PTableParamsV2 {
|
|
271
|
+
return {
|
|
272
|
+
sourceId: null,
|
|
273
|
+
hiddenColIds: null,
|
|
274
|
+
filters: null,
|
|
275
|
+
sorting: [],
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function createPlDataTableStateV2(): PlDataTableStateV2Normalized {
|
|
280
|
+
return {
|
|
281
|
+
version: 5,
|
|
282
|
+
stateCache: [],
|
|
283
|
+
pTableParams: createDefaultPTableParams(),
|
|
284
|
+
};
|
|
285
|
+
}
|