@platforma-sdk/model 1.90.20 → 1.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.cjs +2 -2
  2. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.cjs.map +1 -1
  3. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.d.ts.map +1 -1
  4. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.js +2 -2
  5. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV2.js.map +1 -1
  6. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs +5 -4
  7. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.cjs.map +1 -1
  8. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts +12 -0
  9. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.d.ts.map +1 -1
  10. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js +5 -4
  11. package/dist/components/PlDataTable/createPlDataTable/createPlDataTableV3.js.map +1 -1
  12. package/dist/components/PlDataTable/createPlDataTableSheet.cjs +7 -3
  13. package/dist/components/PlDataTable/createPlDataTableSheet.cjs.map +1 -1
  14. package/dist/components/PlDataTable/createPlDataTableSheet.d.ts +7 -2
  15. package/dist/components/PlDataTable/createPlDataTableSheet.d.ts.map +1 -1
  16. package/dist/components/PlDataTable/createPlDataTableSheet.js +7 -3
  17. package/dist/components/PlDataTable/createPlDataTableSheet.js.map +1 -1
  18. package/dist/components/PlDataTable/index.cjs +2 -0
  19. package/dist/components/PlDataTable/index.d.ts +2 -1
  20. package/dist/components/PlDataTable/index.js +2 -1
  21. package/dist/components/PlDataTable/state-migration.cjs.map +1 -1
  22. package/dist/components/PlDataTable/state-migration.d.ts +2 -2
  23. package/dist/components/PlDataTable/state-migration.d.ts.map +1 -1
  24. package/dist/components/PlDataTable/state-migration.js.map +1 -1
  25. package/dist/components/PlDataTable/tableParams.cjs +61 -15
  26. package/dist/components/PlDataTable/tableParams.cjs.map +1 -1
  27. package/dist/components/PlDataTable/tableParams.d.ts +8 -0
  28. package/dist/components/PlDataTable/tableParams.d.ts.map +1 -0
  29. package/dist/components/PlDataTable/tableParams.js +60 -16
  30. package/dist/components/PlDataTable/tableParams.js.map +1 -1
  31. package/dist/components/PlDataTable/typesV8.d.ts +18 -0
  32. package/dist/components/PlDataTable/typesV8.d.ts.map +1 -1
  33. package/dist/components/index.cjs +2 -0
  34. package/dist/components/index.d.ts +2 -1
  35. package/dist/components/index.js +2 -1
  36. package/dist/index.cjs +2 -0
  37. package/dist/index.d.ts +2 -1
  38. package/dist/index.js +2 -1
  39. package/dist/package.cjs +1 -1
  40. package/dist/package.js +1 -1
  41. package/package.json +1 -1
  42. package/src/components/PlDataTable/createPlDataTable/createPlDataTableV2.ts +2 -1
  43. package/src/components/PlDataTable/createPlDataTable/createPlDataTableV3.ts +20 -2
  44. package/src/components/PlDataTable/createPlDataTableSheet.ts +6 -1
  45. package/src/components/PlDataTable/index.ts +1 -0
  46. package/src/components/PlDataTable/state-migration.ts +5 -5
  47. package/src/components/PlDataTable/tableParams.test.ts +71 -0
  48. package/src/components/PlDataTable/tableParams.ts +66 -9
  49. package/src/components/PlDataTable/typesV8.ts +27 -6
@@ -29,7 +29,9 @@ import {
29
29
  collectSearchColumns,
30
30
  createSearchFilter,
31
31
  createSheetFilters,
32
+ isSheetFixedToOneValue,
32
33
  joinFilters,
34
+ joinSorting,
33
35
  readPlDataTableUserParams,
34
36
  } from "../tableParams";
35
37
  import type { MatchingMode } from "@milaboratories/pl-model-common";
@@ -75,7 +77,19 @@ export type createPlDataTableOptionsV3 = (
75
77
  tableState?: PlDataTableStateV2;
76
78
 
77
79
  filters?: PlDataTableFilters;
80
+ /**
81
+ * Filters applied on every render on top of everything the user set. They are
82
+ * not stored, not shown and cannot be removed by the user, so they follow the
83
+ * block value they are built from.
84
+ */
85
+ fixedFilters?: PlDataTableFilters;
78
86
  sorting?: PTableSorting[];
87
+ /**
88
+ * Sorting applied on every render ahead of the user's sorting, or of the
89
+ * default one while the user has not sorted, which then orders the rows within
90
+ * it. Not stored, not shown and cannot be removed by the user.
91
+ */
92
+ fixedSorting?: PTableSorting[];
79
93
  primaryJoinType?: "inner" | "full";
80
94
 
81
95
  labelsOptions?: DeriveLabelsOptions;
@@ -170,7 +184,7 @@ export function createPlDataTableV3<A, U>(
170
184
  })),
171
185
  isAxisHidden: (axis) =>
172
186
  !primaryAxisKeys.has(canonicalizeAxisId(axis)) || isColumnHidden(axis),
173
- sheetAxes: params.sheetsState.map((sheet) => sheet.axisId),
187
+ sheetAxes: params.sheetsState.filter(isSheetFixedToOneValue).map((sheet) => sheet.axisId),
174
188
  hiddenColIds: params.hiddenColIds,
175
189
  }),
176
190
  );
@@ -182,12 +196,16 @@ export function createPlDataTableV3<A, U>(
182
196
  params.userFilters,
183
197
  searchFilter,
184
198
  params.defaultFilters ?? remapedDefaultFilters,
199
+ remapFilterColumnIds(options.fixedFilters, resolver),
185
200
  ]),
186
201
  resolver,
187
202
  );
188
203
 
189
204
  const sorting = filterSorting(
190
- resolveSorting(params.sorting, remapSortingColumnIds(options.sorting, resolver)),
205
+ joinSorting(
206
+ remapSortingColumnIds(options.fixedSorting, resolver) ?? [],
207
+ resolveSorting(params.sorting, remapSortingColumnIds(options.sorting, resolver)),
208
+ ),
191
209
  resolver,
192
210
  );
193
211
 
@@ -2,11 +2,15 @@ import type { AxisSpec } from "@milaboratories/pl-model-common";
2
2
  import type { RenderCtxBase } from "../../render";
3
3
  import type { PlDataTableSheet } from "./typesV8";
4
4
 
5
- /** Create sheet entries for PlDataTable */
5
+ /**
6
+ * Create sheet entries for PlDataTable. The user picks one value of the axis at
7
+ * a time, or, with `selection: "multiple"`, any number of them or all.
8
+ */
6
9
  export function createPlDataTableSheet<A, U>(
7
10
  ctx: RenderCtxBase<A, U>,
8
11
  axis: AxisSpec,
9
12
  values: (string | number)[],
13
+ options: { selection: PlDataTableSheet["selection"] } = { selection: "single" },
10
14
  ): PlDataTableSheet {
11
15
  const labels = ctx.resultPool.findLabels(axis);
12
16
  return {
@@ -16,5 +20,6 @@ export function createPlDataTableSheet<A, U>(
16
20
  label: labels?.[v] ?? v.toString(),
17
21
  })),
18
22
  defaultValue: values[0],
23
+ selection: options.selection,
19
24
  };
20
25
  }
@@ -26,6 +26,7 @@ export {
26
26
  } from "./state-migration";
27
27
 
28
28
  export { createPlDataTableSheet } from "./createPlDataTableSheet";
29
+ export { isSheetFixedToOneValue } from "./tableParams";
29
30
  export { createPlDataTable, discoverTableColumnSnaphots } from "./createPlDataTable";
30
31
  export { createPlDataTableV2 } from "./createPlDataTable/createPlDataTableV2";
31
32
  export { createPlDataTableV3 } from "./createPlDataTable/createPlDataTableV3";
@@ -22,7 +22,6 @@ import type {
22
22
  PlDataTableFilters,
23
23
  PlDataTableFiltersWithMeta,
24
24
  PlDataTableGridStateCore,
25
- PlDataTableSheetState,
26
25
  PlDataTableStateV2CacheEntry,
27
26
  PlDataTableStateV2Normalized,
28
27
  PlTableColumnIdJson as PlTableColumnIdJsonV8,
@@ -32,6 +31,7 @@ import type {
32
31
  PlDataTableFilters as PlDataTableFiltersV7,
33
32
  PlDataTableFiltersWithMeta as PlDataTableFiltersWithMetaV7,
34
33
  PlDataTableGridStateCore as PlDataTableGridStateCoreV7,
34
+ PlDataTableSheetState as PlDataTableSheetStateV7,
35
35
  PlDataTableStateV2CacheEntry as PlDataTableStateV2V7CacheEntry,
36
36
  PlDataTableStateV2Normalized as PlDataTableStateV2V7,
37
37
  PlTableColumnIdJson,
@@ -96,7 +96,7 @@ export type PlDataTableStateV2 =
96
96
  hiddenColIds: CanonicalizedJson<PTableColumnSpec>[];
97
97
  };
98
98
  };
99
- sheetsState: PlDataTableSheetState[];
99
+ sheetsState: PlDataTableSheetStateV7[];
100
100
  }[];
101
101
  pTableParams: {
102
102
  hiddenColIds: PObjectId[] | null;
@@ -122,7 +122,7 @@ export type PlDataTableStateV2 =
122
122
  hiddenColIds: CanonicalizedJson<PTableColumnSpec>[];
123
123
  };
124
124
  };
125
- sheetsState: PlDataTableSheetState[];
125
+ sheetsState: PlDataTableSheetStateV7[];
126
126
  filtersState: PlDataTableFilterState[];
127
127
  }[];
128
128
  pTableParams: PTableParamsV2V7;
@@ -132,7 +132,7 @@ export type PlDataTableStateV2 =
132
132
  stateCache: {
133
133
  sourceId: string;
134
134
  gridState: PlDataTableGridStateV6;
135
- sheetsState: PlDataTableSheetState[];
135
+ sheetsState: PlDataTableSheetStateV7[];
136
136
  filtersState: PlDataTableFilterState[];
137
137
  }[];
138
138
  /** Old format; only fields used in migration are typed */
@@ -148,7 +148,7 @@ export type PlDataTableStateV2 =
148
148
  stateCache: {
149
149
  sourceId: string;
150
150
  gridState: PlDataTableGridStateV5;
151
- sheetsState: PlDataTableSheetState[];
151
+ sheetsState: PlDataTableSheetStateV7[];
152
152
  filtersState: null | PlDataTableFiltersWithMetaV7;
153
153
  defaultFiltersState: null | PlDataTableFiltersWithMetaV7;
154
154
  searchString?: string;
@@ -11,7 +11,9 @@ import {
11
11
  collectSearchColumns,
12
12
  createSearchFilter,
13
13
  createSheetFilters,
14
+ isSheetFixedToOneValue,
14
15
  joinFilters,
16
+ joinSorting,
15
17
  readPlDataTableUserParams,
16
18
  type PlDataTableFilterNode,
17
19
  type PlDataTableSearchCandidate,
@@ -125,6 +127,62 @@ describe("createSheetFilters", () => {
125
127
  { type: "equal", column: { type: "axis", id: roundAxis }, x: 3 },
126
128
  ]);
127
129
  });
130
+
131
+ test("selects the values picked on a sheet showing several", () => {
132
+ const column: PTableColumnId = { type: "axis", id: getAxisId(axis("sample")) };
133
+ expect(createSheetFilters([{ axisId: column.id, values: ["s1", "s2", 3] }])).toEqual([
134
+ {
135
+ type: "or",
136
+ filters: [
137
+ { type: "inSet", column, value: ["s1", "s2"] },
138
+ { type: "equal", column, x: 3 },
139
+ ],
140
+ },
141
+ ]);
142
+ expect(createSheetFilters([{ axisId: column.id, values: ["s1"] }])).toEqual([
143
+ { type: "inSet", column, value: ["s1"] },
144
+ ]);
145
+ });
146
+
147
+ test("filters nothing for a sheet taking all values or with none picked", () => {
148
+ const column: PTableColumnId = { type: "axis", id: getAxisId(axis("sample")) };
149
+ expect(createSheetFilters([{ axisId: column.id, allValues: true }])).toEqual([]);
150
+ expect(createSheetFilters([{ axisId: column.id, values: [] }])).toEqual([]);
151
+ });
152
+ });
153
+
154
+ describe("isSheetFixedToOneValue", () => {
155
+ const axisId = getAxisId(axis("sample"));
156
+
157
+ test("holds for a single value, also picked on a sheet showing several", () => {
158
+ expect(isSheetFixedToOneValue({ axisId, value: "s1" })).toBe(true);
159
+ expect(isSheetFixedToOneValue({ axisId, values: ["s1"] })).toBe(true);
160
+ });
161
+
162
+ test("does not hold for several values or all of them", () => {
163
+ expect(isSheetFixedToOneValue({ axisId, values: ["s1", "s2"] })).toBe(false);
164
+ expect(isSheetFixedToOneValue({ axisId, allValues: true })).toBe(false);
165
+ });
166
+ });
167
+
168
+ describe("joinSorting", () => {
169
+ const sample: PTableColumnId = { type: "axis", id: getAxisId(axis("sample")) };
170
+ const count: PTableColumnId = { type: "column", id: col("count") };
171
+
172
+ test("puts the fixed sorting first and drops the rest's entries on its columns", () => {
173
+ expect(
174
+ joinSorting(
175
+ [{ column: sample, ascending: true, naAndAbsentAreLeastValues: true }],
176
+ [
177
+ { column: count, ascending: false, naAndAbsentAreLeastValues: false },
178
+ { column: sample, ascending: false, naAndAbsentAreLeastValues: false },
179
+ ],
180
+ ),
181
+ ).toEqual([
182
+ { column: sample, ascending: true, naAndAbsentAreLeastValues: true },
183
+ { column: count, ascending: false, naAndAbsentAreLeastValues: false },
184
+ ]);
185
+ });
128
186
  });
129
187
 
130
188
  describe("collectSearchColumns", () => {
@@ -162,6 +220,19 @@ describe("collectSearchColumns", () => {
162
220
  expect(found).not.toContainEqual({ type: "axis", id: getAxisId(clone) });
163
221
  });
164
222
 
223
+ test("skips the label column of an axis a sheet fixes to one value", () => {
224
+ const found = collectSearchColumns({
225
+ columns,
226
+ isAxisHidden: () => false,
227
+ sheetAxes: [getAxisId(clone)],
228
+ hiddenColIds: null,
229
+ }).map((c) => c.id);
230
+ expect(found).toEqual([
231
+ { type: "axis", id: getAxisId(sample) },
232
+ { type: "column", id: col("count") },
233
+ ]);
234
+ });
235
+
165
236
  test("follows the user's hidden list instead of the optional defaults", () => {
166
237
  const found = collectSearchColumns({
167
238
  columns,
@@ -94,27 +94,56 @@ export function readPlDataTableUserParams(
94
94
  };
95
95
  }
96
96
 
97
- /** One filter per sheet, selecting the value picked on it. */
97
+ /**
98
+ * One filter per sheet, selecting the values picked on it. A sheet that takes
99
+ * all its values filters nothing, and so does one with no value picked: that
100
+ * choice is unfinished, and the UI never saves it but falls back to the
101
+ * sheet's default.
102
+ */
98
103
  export function createSheetFilters(sheetsState: PlDataTableSheetState[]): PlDataTableFilterNode[] {
99
- return sheetsState.map((sheet) => {
104
+ return sheetsState.flatMap((sheet): PlDataTableFilterNode[] => {
100
105
  const column: PTableColumnId = { type: "axis", id: sheet.axisId };
101
- return typeof sheet.value === "number"
102
- ? { type: "equal", column, x: sheet.value }
103
- : { type: "patternEquals", column, value: sheet.value };
106
+ if ("value" in sheet) return [singleValueFilter(column, sheet.value)];
107
+ if ("allValues" in sheet) return [];
108
+ return multiValueFilter(column, sheet.values);
104
109
  });
105
110
  }
106
111
 
112
+ /**
113
+ * Whether the sheet shows a single value. Every row then holds the same value
114
+ * of the sheet's axis, so the axis is neither shown nor searched.
115
+ */
116
+ export function isSheetFixedToOneValue(sheet: PlDataTableSheetState): boolean {
117
+ return "value" in sheet || ("values" in sheet && sheet.values.length === 1);
118
+ }
119
+
120
+ /**
121
+ * The sorting the table is built with: the block's fixed sorting first, then the
122
+ * rest, which is the user's sorting or the block's default while the user has
123
+ * not sorted. Entries of the rest on a column the fixed sorting already orders
124
+ * by are left out.
125
+ */
126
+ export function joinSorting(fixed: PTableSorting[], rest: PTableSorting[]): PTableSorting[] {
127
+ const fixedColumns = new Set(fixed.map((s) => canonicalizeJson<PTableColumnId>(s.column)));
128
+ return [
129
+ ...fixed,
130
+ ...rest.filter((s) => !fixedColumns.has(canonicalizeJson<PTableColumnId>(s.column))),
131
+ ];
132
+ }
133
+
107
134
  /**
108
135
  * The columns the fast search looks into: the visible ones, and the visible axes
109
136
  * except those a sheet fixes to a single value, where every row would match, and
110
137
  * those the table shows through their label column, whose raw values are never
111
- * on screen. Hidden are columns the block's rules hide, linker columns, and the
112
- * columns in the user's hidden list, or, while the user has not touched it, the
113
- * optional ones.
138
+ * on screen. The label column of an axis a sheet fixes to a single value is not
139
+ * shown either, for the same reason as the axis. Hidden are columns the block's
140
+ * rules hide, linker columns, and the columns in the user's hidden list, or,
141
+ * while the user has not touched it, the optional ones.
114
142
  */
115
143
  export function collectSearchColumns(params: {
116
144
  columns: PlDataTableSearchCandidate[];
117
145
  isAxisHidden: (axis: AxisSpec) => boolean;
146
+ /** Axes a sheet fixes to one value */
118
147
  sheetAxes: AxisId[];
119
148
  hiddenColIds: null | PTableColumnId[];
120
149
  }): PlDataTableSearchColumn[] {
@@ -131,7 +160,15 @@ export function collectSearchColumns(params: {
131
160
  !labeledAxes.some((labeled) => matchAxisId(labeled, id))
132
161
  );
133
162
  });
134
- const shownColumns = columns.filter((c) => c.visibility !== "hidden" && !isLinkerColumn(c.spec));
163
+ const shownColumns = columns.filter(
164
+ (c) =>
165
+ c.visibility !== "hidden" &&
166
+ !isLinkerColumn(c.spec) &&
167
+ !(
168
+ isLabelColumn(c.spec) &&
169
+ c.spec.axesSpec.some((axis) => sheetAxisKeys.has(axisKey(getAxisId(axis))))
170
+ ),
171
+ );
135
172
 
136
173
  const hidden = new Set(
137
174
  (
@@ -194,6 +231,26 @@ export type PlDataTableFilterNode = FilterSpecNode<PlDataTableFilterSpecLeaf>;
194
231
 
195
232
  // Internals
196
233
 
234
+ function singleValueFilter(column: PTableColumnId, value: string | number): PlDataTableFilterNode {
235
+ return typeof value === "number"
236
+ ? { type: "equal", column, x: value }
237
+ : { type: "patternEquals", column, value };
238
+ }
239
+
240
+ function multiValueFilter(
241
+ column: PTableColumnId,
242
+ values: (string | number)[],
243
+ ): PlDataTableFilterNode[] {
244
+ const texts = values.filter((v): v is string => typeof v === "string");
245
+ const parts: PlDataTableFilterNode[] = [
246
+ ...(texts.length > 0 ? [{ type: "inSet" as const, column, value: texts }] : []),
247
+ ...values.flatMap((v): PlDataTableFilterNode[] =>
248
+ typeof v === "number" ? [{ type: "equal", column, x: v }] : [],
249
+ ),
250
+ ];
251
+ return parts.length > 1 ? [{ type: "or", filters: parts }] : parts;
252
+ }
253
+
197
254
  function findEntry(
198
255
  state: PlDataTableStateV2Normalized,
199
256
  sourceId: null | string,
@@ -47,14 +47,35 @@ export type PlDataTableSheet = {
47
47
  options: ListOptionBase<string | number>[];
48
48
  /** default (selected) value */
49
49
  defaultValue?: string | number;
50
+ /** Whether the user picks one value of the axis at a time, or any number of them */
51
+ selection: "single" | "multiple";
50
52
  };
51
53
 
52
- export type PlDataTableSheetState = {
53
- /** id of the axis */
54
- axisId: AxisId;
55
- /** selected value */
56
- value: string | number;
57
- };
54
+ /**
55
+ * The values picked on a sheet. A sheet with `selection: "single"` stores one
56
+ * `value`; a sheet with `selection: "multiple"` stores the picked `values`, or
57
+ * `allValues` to take every value the sheet offers, including ones that appear
58
+ * later.
59
+ */
60
+ export type PlDataTableSheetState =
61
+ | {
62
+ /** id of the axis */
63
+ axisId: AxisId;
64
+ /** selected value */
65
+ value: string | number;
66
+ }
67
+ | {
68
+ /** id of the axis */
69
+ axisId: AxisId;
70
+ /** selected values */
71
+ values: (string | number)[];
72
+ }
73
+ | {
74
+ /** id of the axis */
75
+ axisId: AxisId;
76
+ /** every value of the sheet, including ones that appear later */
77
+ allValues: true;
78
+ };
58
79
 
59
80
  /** Tree-based filter state compatible with PlAdvancedFilter's RootFilter */
60
81
  export type PlDataTableFilterMeta = {