derive-dashboards 0.12.0 → 0.12.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # derive-dashboards
2
2
 
3
+ ## 0.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fb1fe09: A drill's path names a value shown as another by its name: drilling into a sheet's row reads "Outdoor brands", never its id.
8
+
3
9
  ## 0.12.0
4
10
 
5
11
  ### Minor Changes
@@ -59,7 +59,7 @@ async function compareGroups(opened, state, requested) {
59
59
  }, [view.member]);
60
60
  return forOpener({
61
61
  state: normalizedDrillState(state, o.path, view),
62
- path: crumbs(o),
62
+ path: await crumbs(o),
63
63
  view: {
64
64
  by: "comparison",
65
65
  answer: wire(answer),
@@ -1,3 +1,5 @@
1
+ import { execute } from "./execute.mjs";
2
+ import { namesOf } from "./labels.mjs";
1
3
  import { bucketWithin, resultColumns } from "derive-dashboards/core";
2
4
  // src/drill-crumbs.ts
3
5
  /** A field's label as a column of the tile would read it. */
@@ -36,7 +38,7 @@ function groupCrumb(fields) {
36
38
  * One step as a breadcrumb: its fields and its values; a time point with its grain and the part
37
39
  * of it the window reads (`range`), so the panel says "so far" of a week still running.
38
40
  */
39
- function crumbOf(o, step, range) {
41
+ function crumbOf(o, step, range, names) {
40
42
  if ("bucket" in step) {
41
43
  const { member, from, to, grain } = step.bucket;
42
44
  return {
@@ -62,7 +64,7 @@ function crumbOf(o, step, range) {
62
64
  };
63
65
  return groupCrumb(step.group.map((g) => ({
64
66
  label: fieldLabel(o, g.member),
65
- value: g.value
67
+ value: typeof g.value === "string" ? names.get(g.member)?.[g.value] ?? g.value : g.value
66
68
  })));
67
69
  }
68
70
  /**
@@ -96,16 +98,37 @@ function selectionOf(steps) {
96
98
  * One selection as a breadcrumb, marked when it is of the period before. A time step reads the
97
99
  * part of its bucket that selection's own window covers.
98
100
  */
99
- function selectionCrumb(o, selection) {
101
+ function selectionCrumb(o, selection, names) {
100
102
  const range = selection.previous === true ? o.pinned.compare : o.pinned.range;
101
- const crumb = selectionOf(selection.steps.map((step) => crumbOf(o, step, range)));
103
+ const crumb = selectionOf(selection.steps.map((step) => crumbOf(o, step, range, names)));
102
104
  return selection.previous === true ? {
103
105
  ...crumb,
104
106
  previous: true
105
107
  } : crumb;
106
108
  }
107
- /** The path as breadcrumbs, one per selection, in order. */
108
- const crumbs = (o) => o.selections.map((s) => selectionCrumb(o, s));
109
+ /** The names the path's grouped values read as, read under the drill's own viewer and lock. */
110
+ async function pathNames(o) {
111
+ const grouped = o.selections.flatMap((s) => s.steps.flatMap((step) => "group" in step ? step.group : []));
112
+ const values = Map.groupBy(grouped, (g) => g.member);
113
+ const { model } = o.x.rt.options;
114
+ const read = await Promise.all([...values].map(async ([member, steps]) => {
115
+ const at = {
116
+ source: o.x.query.source,
117
+ member,
118
+ keys: steps.map((g) => g.value)
119
+ };
120
+ return [member, await namesOf(model, at, (query) => execute({
121
+ ...o.x,
122
+ query
123
+ }))];
124
+ }));
125
+ return new Map(read.flatMap(([m, n]) => n === void 0 ? [] : [[m, n]]));
126
+ }
127
+ /** The path as breadcrumbs, one per selection, in order, each value as people read it. */
128
+ async function crumbs(o) {
129
+ const names = await pathNames(o);
130
+ return o.selections.map((s) => selectionCrumb(o, s, names));
131
+ }
109
132
  /**
110
133
  * What of a receipt a viewer who did not draw the link may read: a fixed list, so a field added
111
134
  * to receipts later is held back until it is listed here. The filter (it states the drill's
package/dist/drill.mjs CHANGED
@@ -119,7 +119,7 @@ async function runDrill(rt, principal, request, body) {
119
119
  const state = normalizedDrillState(body.state, r.o.path, plain);
120
120
  return forOpener({
121
121
  ...r.summed === void 0 ? {} : { summary: r.summed.summary },
122
- path: crumbs(r.o),
122
+ path: await crumbs(r.o),
123
123
  state,
124
124
  view: shown
125
125
  }, r.o.foreign);
package/dist/labels.mjs CHANGED
@@ -18,6 +18,37 @@ function cellsAt(index, sets) {
18
18
  }));
19
19
  }
20
20
  /**
21
+ * The names of some values of a dimension shown as another, read by one query grouped by the
22
+ * value and its name under the same viewer and lock (the query's closure holds the names, so
23
+ * whoever may not read them was refused before). Undefined for a dimension shown as itself.
24
+ */
25
+ async function namesOf(model, at, run) {
26
+ const shown = shownAsMember(model, at.source, at.member);
27
+ if (shown === void 0) return void 0;
28
+ const keys = [...new Set(at.keys.filter((v) => typeof v === "string"))];
29
+ if (keys.length === 0) return {};
30
+ return namesIn((await run({
31
+ kind: "aggregate",
32
+ source: at.source,
33
+ measures: [{
34
+ id: "m1",
35
+ measure: listingMeasure(model, at.member)
36
+ }],
37
+ dimensions: [{
38
+ id: "d1",
39
+ member: at.member
40
+ }, {
41
+ id: "d2",
42
+ member: shown
43
+ }],
44
+ filters: {
45
+ member: at.member,
46
+ op: "in",
47
+ values: keys
48
+ }
49
+ })).rows, 0, 1);
50
+ }
51
+ /**
21
52
  * The labels of an answer's dimension columns that are `shownAs` another: from the answer's own
22
53
  * rows when it groups by the names too, else by one query grouped by the value and its name,
23
54
  * under the same viewer and lock (the query's closure holds the names, so whoever may not read
@@ -34,35 +65,16 @@ function labelColumns(model, answer, run) {
34
65
  ...column,
35
66
  labels: namesIn(sets.flatMap((r) => r ?? []), i, named)
36
67
  };
37
- const keys = [...new Set(cellsAt(i, sets).filter((v) => typeof v === "string"))];
38
- if (keys.length === 0) return {
39
- ...column,
40
- labels: {}
41
- };
42
- const read = await run({
43
- kind: "aggregate",
68
+ const keys = cellsAt(i, sets);
69
+ const at = {
44
70
  source: query.source,
45
- measures: [{
46
- id: "m1",
47
- measure: listingMeasure(model, column.member)
48
- }],
49
- dimensions: [{
50
- id: "d1",
51
- member: column.member
52
- }, {
53
- id: "d2",
54
- member: shown
55
- }],
56
- filters: {
57
- member: column.member,
58
- op: "in",
59
- values: keys
60
- }
61
- });
71
+ member: column.member,
72
+ keys
73
+ };
62
74
  return {
63
75
  ...column,
64
- labels: namesIn(read.rows, 0, 1)
76
+ labels: await namesOf(model, at, run) ?? {}
65
77
  };
66
78
  }));
67
79
  }
68
- export { labelColumns };
80
+ export { labelColumns, namesOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "derive-dashboards",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Open-source embedded dashboards for your product: the server, the engine, React components, charts and the CLI, in one package.",
5
5
  "type": "module",
6
6
  "license": "MIT",