derive-dashboards 0.10.0 → 0.11.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/body.mjs +5 -1
  3. package/dist/charts/data/words.d.mts +5 -0
  4. package/dist/charts/data/words.mjs +1 -0
  5. package/dist/charts/kinds/columns-data.mjs +4 -1
  6. package/dist/charts/kinds/grid-layout.mjs +84 -8
  7. package/dist/charts/kinds/grid-legend.mjs +27 -4
  8. package/dist/charts/kinds/grid-marks.mjs +56 -4
  9. package/dist/charts/kinds/grid.mjs +2 -1
  10. package/dist/charts/scale/value.mjs +15 -8
  11. package/dist/charts/scene/types.d.mts +1 -1
  12. package/dist/core/document/display-entries.mjs +9 -2
  13. package/dist/core/document/display.d.mts +4 -0
  14. package/dist/core/document/display.mjs +8 -0
  15. package/dist/core/engine/version.d.mts +1 -1
  16. package/dist/core/engine/version.mjs +1 -1
  17. package/dist/core/error/codes.d.mts +2 -0
  18. package/dist/core/error/codes.mjs +2 -0
  19. package/dist/core/index.d.mts +2 -2
  20. package/dist/core/index.mjs +2 -2
  21. package/dist/core/model/member.d.mts +6 -0
  22. package/dist/core/model/member.mjs +11 -1
  23. package/dist/core/model/types.d.mts +6 -0
  24. package/dist/core/model/validate/known-members.mjs +1 -0
  25. package/dist/core/model/validate/members.mjs +12 -1
  26. package/dist/core/query/closure.mjs +3 -1
  27. package/dist/core/result/columns.mjs +15 -2
  28. package/dist/core/result/types.d.mts +2 -0
  29. package/dist/core/schema/answer-parts.mjs +1 -0
  30. package/dist/core/schema/answers.d.mts +14 -0
  31. package/dist/core/schema/answers.mjs +4 -2
  32. package/dist/core/types/api.d.mts +7 -1
  33. package/dist/core/types/api.mjs +1 -1
  34. package/dist/endpoints/index.d.mts +5 -4
  35. package/dist/endpoints/meta.mjs +30 -12
  36. package/dist/endpoints/query.mjs +11 -5
  37. package/dist/endpoints/values.mjs +37 -23
  38. package/dist/execute.mjs +22 -1
  39. package/dist/labels.mjs +68 -0
  40. package/dist/listing.mjs +13 -0
  41. package/dist/react/Canvas.mjs +28 -2
  42. package/dist/react/builder/base.mjs +11 -6
  43. package/dist/react/builder/display.mjs +15 -2
  44. package/dist/react/builder/state.mjs +3 -3
  45. package/dist/react/builder/words.mjs +8 -0
  46. package/dist/react/dates-shown.mjs +27 -9
  47. package/dist/react/filters/bar.d.mts +1 -1
  48. package/dist/react/filters/bar.mjs +17 -7
  49. package/dist/react/filters/chip.mjs +5 -3
  50. package/dist/react/filters/context.mjs +2 -2
  51. package/dist/react/filters/dates-said.mjs +29 -11
  52. package/dist/react/filters/hooks.d.mts +8 -0
  53. package/dist/react/filters/hooks.mjs +39 -2
  54. package/dist/react/filters/menu.mjs +8 -18
  55. package/dist/react/filters/phone.mjs +3 -3
  56. package/dist/react/filters/values.mjs +47 -28
  57. package/dist/react/filters/words.mjs +2 -2
  58. package/dist/react/format.d.mts +1 -1
  59. package/dist/react/format.mjs +8 -2
  60. package/dist/react/renderers/moved.mjs +160 -0
  61. package/dist/react/renderers/number-before.mjs +2 -157
  62. package/dist/react/renderers/table-cells.mjs +97 -11
  63. package/dist/react/renderers/table-head.mjs +7 -1
  64. package/dist/react/renderers/table-measure.mjs +147 -25
  65. package/dist/react/renderers/table-over.mjs +72 -0
  66. package/dist/react/renderers/table-scale.mjs +54 -1
  67. package/dist/react/renderers/table-trend.mjs +55 -0
  68. package/dist/react/renderers/table.d.mts +5 -1
  69. package/dist/react/renderers/table.mjs +29 -6
  70. package/dist/react/theme-unlayered.css +1 -1
  71. package/dist/react/theme.css +1 -1
  72. package/package.json +1 -1
@@ -0,0 +1,68 @@
1
+ import { listingMeasure } from "./listing.mjs";
2
+ import { isMark, shownAsMember } from "derive-dashboards/core";
3
+ // src/labels.ts
4
+ /** Each value's name from rows that hold the value at `key` and its name at `name`; the first wins. */
5
+ function namesIn(rows, key, name) {
6
+ const labels = {};
7
+ for (const row of rows) {
8
+ const [k, n] = [row[key], row[name]];
9
+ if (typeof k === "string" && typeof n === "string" && !(k in labels)) labels[k] = n;
10
+ }
11
+ return labels;
12
+ }
13
+ /** The cells of one column across row sets, skipping marks. */
14
+ function cellsAt(index, sets) {
15
+ return sets.flatMap((rows) => (rows ?? []).flatMap((row) => {
16
+ const cell = row[index];
17
+ return cell === void 0 || isMark(cell) ? [] : [cell];
18
+ }));
19
+ }
20
+ /**
21
+ * The labels of an answer's dimension columns that are `shownAs` another: from the answer's own
22
+ * rows when it groups by the names too, else by one query grouped by the value and its name,
23
+ * under the same viewer and lock (the query's closure holds the names, so whoever may not read
24
+ * them was refused before). A value with no name is left out, and shows as itself.
25
+ */
26
+ function labelColumns(model, answer, run) {
27
+ const { query, columns, sets } = answer;
28
+ return Promise.all(columns.map(async (column, i) => {
29
+ if (column.role !== "dimension" || column.member === void 0) return column;
30
+ const shown = shownAsMember(model, query.source, column.member);
31
+ if (shown === void 0) return column;
32
+ const named = columns.findIndex((c) => c.role === "dimension" && c.member === shown);
33
+ if (named !== -1) return {
34
+ ...column,
35
+ labels: namesIn(sets.flatMap((r) => r ?? []), i, named)
36
+ };
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",
44
+ 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
+ });
62
+ return {
63
+ ...column,
64
+ labels: namesIn(read.rows, 0, 1)
65
+ };
66
+ }));
67
+ }
68
+ export { labelColumns };
@@ -0,0 +1,13 @@
1
+ import { HttpError } from "./http.mjs";
2
+ import { parseMemberId } from "derive-dashboards/core";
3
+ // src/listing.ts
4
+ /** The measure a query lists a source's values with: a plain count, the cheapest, else the first. */
5
+ function listingMeasure(model, member) {
6
+ const ref = parseMemberId(member);
7
+ const source = ref === void 0 ? void 0 : model.sources[ref.source];
8
+ const measures = source === void 0 ? [] : Object.entries(source.measures);
9
+ const measure = (measures.find(([, m]) => m.kind === "count" && !("distinct" in m)) ?? measures[0])?.[0];
10
+ if (ref === void 0 || measure === void 0) throw new HttpError(400, "QUERY_INVALID", `"${member}" is not a member whose values can be listed.`);
11
+ return `${ref.source}.${measure}`;
12
+ }
13
+ export { listingMeasure };
@@ -1,10 +1,11 @@
1
1
  import { useDashboards } from "./context.mjs";
2
- import { datesKey, datesShown, useDatesKept } from "./dates-shown.mjs";
2
+ import { datesKey, datesShown, sharedWidget, useDatesKept } from "./dates-shown.mjs";
3
3
  import { Grid } from "./Grid.mjs";
4
4
  import { Header } from "./Header.mjs";
5
5
  import { SaysDatesContext, useDatesSaid, useSaid } from "./says-dates.mjs";
6
6
  import { TabStrip } from "./TabStrip.mjs";
7
7
  import { linkTo } from "./view.mjs";
8
+ import { sharedDisplay } from "derive-dashboards/core";
8
9
  import { jsx, jsxs } from "react/jsx-runtime";
9
10
  // src/Canvas.tsx
10
11
  /** The filters a link carried that this dashboard does not have, named once. */
@@ -47,6 +48,28 @@ function useDatesText(board, tab) {
47
48
  return useDatesKept(datesShown(board.tiles, format), datesKey(tab.id, board.view.picks));
48
49
  }
49
50
  /**
51
+ * The range a widget's answer is of when the viewer has picked no dates: the dashboard's own,
52
+ * unless the widget keeps its query's (`keepDateRange`) or the dashboard has none.
53
+ */
54
+ function ownRange(doc, widgetId) {
55
+ const widget = doc.widgets[widgetId];
56
+ const own = widget?.queries["main"]?.time?.range;
57
+ return sharedDisplay(widget?.display).keepDateRange === true ? own : doc.scope.dateRange ?? own;
58
+ }
59
+ /**
60
+ * The dates shown in words, when they are counted back from now ("Last 13 weeks"): what the
61
+ * widget they are read from asks for. The date control says it before the dates while nothing
62
+ * is picked, so a reader knows the dates move with today. Undefined for dates that are fixed,
63
+ * or that the tiles do not share; kept while the tiles wait, as the dates are.
64
+ */
65
+ function usePeriodText(board, doc, tab) {
66
+ const { messages } = useDashboards();
67
+ const widget = sharedWidget(board.tiles);
68
+ const range = typeof widget === "string" ? ownRange(doc, widget) : void 0;
69
+ const named = range !== void 0 && "last" in range ? messages.range(range) : void 0;
70
+ return useDatesKept(widget === null ? null : named, datesKey(tab.id, board.view.picks));
71
+ }
72
+ /**
50
73
  * The host's filter bar (the built-in one by default), told the zone dates are read in and
51
74
  * the dates most tiles cover, which its date control says.
52
75
  */
@@ -59,7 +82,8 @@ function Filters(props) {
59
82
  picks: board.view.picks,
60
83
  onChange: board.view.setPicks,
61
84
  timezone: doc.scope.timezone ?? answeredZone(board.tiles.results),
62
- span: props.span
85
+ span: props.span,
86
+ period: props.period ?? void 0
63
87
  });
64
88
  }
65
89
  /**
@@ -85,6 +109,7 @@ function Canvas(props) {
85
109
  };
86
110
  const dates = useDatesSaid();
87
111
  const span = useDatesText(board, shown.tab);
112
+ const period = usePeriodText(board, shown.doc, shown.tab);
88
113
  return /* @__PURE__ */ jsxs(SaysDatesContext.Provider, {
89
114
  value: dates.claim,
90
115
  children: [
@@ -103,6 +128,7 @@ function Canvas(props) {
103
128
  board,
104
129
  doc: shown.doc,
105
130
  span,
131
+ period,
106
132
  options: props.dashboard.filterBar
107
133
  })
108
134
  }),
@@ -1,6 +1,6 @@
1
1
  import { keepsOthers, pruned } from "./display.mjs";
2
2
  import { fittingTitle, sourceIn } from "./labels.mjs";
3
- import { parseMemberId } from "derive-dashboards/core";
3
+ import { displayOf, parseMemberId } from "derive-dashboards/core";
4
4
  // src/builder/base.ts
5
5
  /** A new widget's range: the last 7 days, today included. */
6
6
  const DEFAULT_RANGE = {
@@ -93,15 +93,20 @@ function fitDisplay(before, given) {
93
93
  }
94
94
  /**
95
95
  * Whether a widget asks for its whole beside its buckets (`time.whole`): a number over time,
96
- * whose headline is the whole range's and never a bucket's.
96
+ * whose headline is the whole range's and never a bucket's, and a table over time that draws
97
+ * each row's buckets as a small chart (`display.trend`), whose rows are the whole's.
97
98
  */
98
- const wantsWhole = (kind, time) => kind === "number" && time.grain !== void 0;
99
- /** The state with its query's time asking for its whole exactly when its kind and grain want it. */
99
+ function wantsWhole(state, time) {
100
+ if (time.grain === void 0) return false;
101
+ if (state.kind === "number") return true;
102
+ return state.kind === "table" && (displayOf("table", state.display).trend ?? []).length > 0;
103
+ }
104
+ /** The state with its query's time asking for its whole exactly when its kind, grain and display want it. */
100
105
  function fitWhole(state) {
101
106
  const query = state.query;
102
107
  const time = query?.time;
103
108
  if (query === void 0 || time === void 0) return state;
104
- const wants = wantsWhole(state.kind, time);
109
+ const wants = wantsWhole(state, time);
105
110
  if (time.whole === true === wants) return state;
106
111
  const { whole: _had, ...without } = time;
107
112
  return {
@@ -191,4 +196,4 @@ function widgetOf(state) {
191
196
  ...Object.keys(display).length === 0 ? {} : { display }
192
197
  };
193
198
  }
194
- export { DEFAULT_RANGE, cleared, defaultTime, emptyBuilder, freshId, keptAside, lastPart, refersTo, setKind, setTitle, widgetOf, withQuery };
199
+ export { DEFAULT_RANGE, cleared, defaultTime, emptyBuilder, fitWhole, freshId, keptAside, lastPart, refersTo, setKind, setTitle, widgetOf, withQuery };
@@ -21,7 +21,8 @@ const NAMES_ANY = /* @__PURE__ */ new Set([
21
21
  const LEAST = {
22
22
  value: 2,
23
23
  secondary: 2,
24
- against: 2
24
+ against: 2,
25
+ parts: 2
25
26
  };
26
27
  /** Which entries an option of a kind names: values by core's rule, any by the list's; else none. */
27
28
  function namesOf(kind, name) {
@@ -69,11 +70,23 @@ function entriesFor(names, query) {
69
70
  ];
70
71
  }
71
72
  /**
73
+ * What a query must have for an option to draw anything: a small chart is of time buckets, and
74
+ * a change is from a period the query compares with.
75
+ */
76
+ const NEEDS = {
77
+ trend: (query) => query.time?.grain !== void 0,
78
+ change: (query) => query.time?.compare !== void 0
79
+ };
80
+ /** Whether an option would draw anything for a query: one that needs what the query lacks would not. */
81
+ const applies = (name, query) => !Object.hasOwn(NEEDS, name) || query !== void 0 && NEEDS[name]?.(query) === true;
82
+ /**
72
83
  * What the builder offers for a kind and a query, in the order it shows them. An option that
73
- * names entries is left out when the query has fewer than it needs to make a choice.
84
+ * names entries is left out when the query has fewer than it needs to make a choice, and one
85
+ * that would draw nothing for the query (`NEEDS`) is left out too.
74
86
  */
75
87
  function offers(kind, query) {
76
88
  return editedRules(kind).flatMap(([name, rule]) => {
89
+ if (!applies(name, query)) return [];
77
90
  if (!("names" in rule)) return [{
78
91
  name,
79
92
  shape: rule.shape,
@@ -1,4 +1,4 @@
1
- import { DEFAULT_RANGE, cleared, defaultTime, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
1
+ import { DEFAULT_RANGE, cleared, defaultTime, fitWhole, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
2
2
  import { setOption, toggleEntry } from "./display.mjs";
3
3
  import { addCondition, removeNode, setMode } from "./filter-tree.mjs";
4
4
  import { formulaRefs, parseMemberId } from "derive-dashboards/core";
@@ -201,9 +201,9 @@ function setDisplay(_meta, state, name, value) {
201
201
  /** Ticks or unticks one entry of an option that names several (a table's bars, a list's subtitle). */
202
202
  function toggleDisplay(_meta, state, change) {
203
203
  const { dropped: _last, ...rest } = state;
204
- return {
204
+ return fitWhole({
205
205
  ...rest,
206
206
  display: toggleEntry(displayIn(state), state.query, change)
207
- };
207
+ });
208
208
  }
209
209
  export { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setDisplay, setFilterMode, setTime, toggleDisplay };
@@ -75,6 +75,10 @@ const ENGLISH_BUILDER = {
75
75
  full: "Write amounts in full",
76
76
  bars: "Bars",
77
77
  heat: "Shade by value",
78
+ dots: "Dot against the total",
79
+ parts: "Part inside its whole",
80
+ trend: "Small chart over time",
81
+ change: "Change from the period before",
78
82
  compact: "Closer rows",
79
83
  title: "Row title",
80
84
  subtitle: "Under the title",
@@ -93,6 +97,10 @@ const ENGLISH_BUILDER = {
93
97
  full: "Write every amount in full. Without it, amounts of a thousand or more are rounded to whole units.",
94
98
  bars: "Draw a bar beside each value, its length measured against the column's largest value.",
95
99
  heat: "Shade each cell by its value, darker for more.",
100
+ dots: "Draw each value as a dot on a scale, with a tick where the total stands. For a rate or an average.",
101
+ parts: "Pick two values, one a part of the other: the part is drawn inside the whole's bar.",
102
+ change: "Write how each value moved against the period before, after the value. The tile needs a period to compare with.",
103
+ trend: "Draw how each row went over time, small, beside its value. The table then has one row for each group over the whole period.",
96
104
  compact: "Draw the rows closer together.",
97
105
  title: "What each row is titled by.",
98
106
  subtitle: "What is written under the title.",
@@ -38,21 +38,39 @@ function sharedAnswer(results, waiting = 0) {
38
38
  return [...results.values()].flatMap((result) => wasRead(result) ? [result] : []).find((result) => (spanKey(result) ?? "every date") === shared);
39
39
  }
40
40
  /**
41
+ * The answer that says the dates most tiles cover. A tile still waiting holds its last answer,
42
+ * which is of the picks before, so only the tiles that have answered say, and they say once
43
+ * they are most of the tiles whatever the rest answer: the first tile to answer does not speak
44
+ * for a dashboard of five. Undefined when the tiles share none. Null while a tile that could
45
+ * say is still waiting.
46
+ */
47
+ function sayingOf(tiles) {
48
+ const one = sharedAnswer(new Map([...tiles.results].filter(([widget]) => !tiles.pending.has(widget))), tiles.pending.size);
49
+ if (one !== void 0) return one;
50
+ return tiles.pending.size > 0 ? null : void 0;
51
+ }
52
+ /**
41
53
  * The dates most tiles cover, as the date control says them ("Aug 23 to Nov 20", or "All time"
42
- * where most read every date). A tile still
43
- * waiting holds its last answer, which is of the picks before, so only the tiles that have
44
- * answered say, and they say once they are most of the tiles whatever the rest answer: the
45
- * first tile to answer does not speak for a dashboard of five. Undefined when the tiles share
46
- * none. Null while a tile that could say is still waiting: the control then says neither the
47
- * dates of the picks before nor that there are none.
54
+ * where most read every date). Undefined when the tiles share none. Null while a tile that
55
+ * could say is still waiting: the control then says neither the dates of the picks before nor
56
+ * that there are none.
48
57
  */
49
58
  function datesShown(tiles, format) {
50
- const one = sharedAnswer(new Map([...tiles.results].filter(([widget]) => !tiles.pending.has(widget))), tiles.pending.size);
51
- if (one === void 0) return tiles.pending.size > 0 ? null : void 0;
59
+ const one = sayingOf(tiles);
60
+ if (one === void 0 || one === null) return one;
52
61
  const range = one.receipt.range;
53
62
  if (range === void 0) return format.messages.tileAllTime;
54
63
  return formatPeriod(range, format, one.receipt.calendar.timezone);
55
64
  }
65
+ /**
66
+ * A widget whose answer covers the dates most tiles do: the one the dates shown are read from,
67
+ * so what its query asks for ("the last 13 weeks") names them. Undefined when the tiles share
68
+ * no dates, null while that is not known yet, as `datesShown`.
69
+ */
70
+ function sharedWidget(tiles) {
71
+ const one = sayingOf(tiles);
72
+ return one === void 0 || one === null ? one : one.widgetId;
73
+ }
56
74
  /** What the dates shown are the dates of: the tab, and the dates the viewer picked. */
57
75
  const datesKey = (tab, picks) => JSON.stringify([tab, Object.entries(picks).filter(([, pick]) => isDateRange(pick))]);
58
76
  /**
@@ -73,4 +91,4 @@ function useDatesKept(dates, key) {
73
91
  });
74
92
  return dates;
75
93
  }
76
- export { EVERY_DATE, datesKey, datesShown, sharedSpan, spanKey, useDatesKept, wasRead };
94
+ export { EVERY_DATE, datesKey, datesShown, sharedSpan, sharedWidget, spanKey, useDatesKept, wasRead };
@@ -9,4 +9,4 @@ import { FilterBarProps } from "./hooks.mjs";
9
9
  * Every part carries a `dd-fb-*` class and the theme styles it in its own cascade layer, so your
10
10
  * CSS wins without `!important`; colors and sizes are the theme's `--dd-*` variables.
11
11
  */
12
- export declare function FilterBar({ controls, picks, onChange, timezone, span, ...options }: FilterBarProps & FilterBarOptions): import("react").JSX.Element | null;
12
+ export declare function FilterBar({ controls, picks, onChange, timezone, span, period, ...options }: FilterBarProps & FilterBarOptions): import("react").JSX.Element | null;
@@ -2,7 +2,7 @@ import { useDashboards } from "../context.mjs";
2
2
  import { useSaysDates } from "../says-dates.mjs";
3
3
  import { Chip } from "./chip.mjs";
4
4
  import { BarContext, useBar, useWords } from "./context.mjs";
5
- import { useFilterFields } from "./hooks.mjs";
5
+ import { useChosenLabels, useFilterFields } from "./hooks.mjs";
6
6
  import { FilterMenu } from "./menu.mjs";
7
7
  import { PhoneBar } from "./phone.mjs";
8
8
  import { useBarPicks, useFromLink, useNarrow, useShortcuts, useShown } from "./state.mjs";
@@ -11,20 +11,27 @@ import { createPortal } from "react-dom";
11
11
  import { jsx, jsxs } from "react/jsx-runtime";
12
12
  // src/filters/bar.tsx
13
13
  const PINNED = 4;
14
- /** "Your view · Reset", or "From a link · Reset" while the picks are still the link's. */
14
+ /**
15
+ * Reset, once the viewer has picked something: back to the dashboard's own filters. Whose the
16
+ * picks are is the button's title, so it is said a pointer away and read after its name ("Only
17
+ * you see these filters"), and it is written beside it while they are still a link's ("From a
18
+ * link"), since the viewer did not pick those.
19
+ */
15
20
  function Status({ linked, onReset }) {
16
21
  const words = useWords();
17
22
  const { messages } = useDashboards();
18
23
  const { picks } = useBar();
19
24
  if (Object.keys(picks).length === 0) return null;
25
+ const whose = linked ? words.fromLink : words.yourView;
20
26
  return /* @__PURE__ */ jsxs("div", {
21
27
  className: "dd-fb-status",
22
- children: [/* @__PURE__ */ jsx("span", {
28
+ children: [linked ? /* @__PURE__ */ jsx("span", {
23
29
  className: "dd-fb-quiet",
24
- children: linked ? words.fromLink : words.yourView
25
- }), /* @__PURE__ */ jsx("button", {
30
+ children: words.fromLink
31
+ }) : null, /* @__PURE__ */ jsx("button", {
26
32
  type: "button",
27
33
  className: "dd-fb-link",
34
+ title: whose,
28
35
  onClick: onReset,
29
36
  children: messages.reset
30
37
  })]
@@ -102,20 +109,23 @@ function DesktopBar({ controls, pinned, linked, removeLast, onReset }) {
102
109
  * Every part carries a `dd-fb-*` class and the theme styles it in its own cascade layer, so your
103
110
  * CSS wins without `!important`; colors and sizes are the theme's `--dd-*` variables.
104
111
  */
105
- function FilterBar({ controls, picks, onChange, timezone, span, ...options }) {
112
+ function FilterBar({ controls, picks, onChange, timezone, span, period, ...options }) {
106
113
  useSaysDates();
107
114
  const fields = useFilterFields(controls);
108
115
  const narrow = useNarrow();
109
116
  const { setPick, removeLast, reset, undo, takeBack } = useBarPicks(controls, picks, onChange);
110
117
  const linked = useFromLink(picks);
118
+ const labels = useChosenLabels(controls, picks, fields);
111
119
  if (controls.length === 0) return null;
112
120
  const bar = {
113
121
  fields,
114
122
  options,
115
123
  timezone,
116
124
  span,
125
+ period,
117
126
  picks,
118
- setPick
127
+ setPick,
128
+ labels
119
129
  };
120
130
  return /* @__PURE__ */ jsxs(BarContext.Provider, {
121
131
  value: bar,
@@ -97,12 +97,14 @@ function SetChip({ control, said, open, toggle }) {
97
97
  const { fields, picks, setPick } = useBar();
98
98
  const pick = valuePickOf(picks, control.id);
99
99
  const operator = control.kind === "filter" && pick !== void 0 && !isNumber(control, fields);
100
- const now = useDates(control, said).spoken;
100
+ const { spoken: now, beside, dates } = useDates(control, said);
101
+ const unset = said === void 0 && beside === void 0;
101
102
  return /* @__PURE__ */ jsxs("fieldset", {
102
103
  className: "dd-fb-chip",
104
+ "data-dates": control.kind === "date_range" ? "" : void 0,
103
105
  "aria-label": `${control.label} ${now}`,
104
106
  children: [
105
- /* @__PURE__ */ jsx(FieldSegment, {
107
+ dates === true ? null : /* @__PURE__ */ jsx(FieldSegment, {
106
108
  control,
107
109
  open,
108
110
  toggle
@@ -117,7 +119,7 @@ function SetChip({ control, said, open, toggle }) {
117
119
  /* @__PURE__ */ jsx("button", {
118
120
  type: "button",
119
121
  className: "dd-fb-seg dd-fb-value",
120
- "data-unset": said === void 0 || void 0,
122
+ "data-unset": unset || void 0,
121
123
  "aria-haspopup": "dialog",
122
124
  "aria-expanded": open,
123
125
  "aria-label": words.changeValues(control.label, now),
@@ -38,13 +38,13 @@ function useLocale() {
38
38
  }
39
39
  /** A value as words: the host's `formatValue`, else None, Yes or No in the bar's words, else the default. */
40
40
  function useFormat() {
41
- const { options } = useBar();
41
+ const { options, labels } = useBar();
42
42
  const words = useWords();
43
43
  const own = options.formatValue;
44
44
  const base = (control, value) => {
45
45
  if (value === null) return words.none;
46
46
  if (typeof value === "boolean") return value ? words.yes : words.no;
47
- return defaultFormat(control, value);
47
+ return (typeof value === "string" ? labels?.[control.id]?.[value] : void 0) ?? defaultFormat(control, value);
48
48
  };
49
49
  return own === void 0 ? base : (control, value) => own(control, value) ?? base(control, value);
50
50
  }
@@ -12,18 +12,31 @@ const datesOf = (span, loading) => span === null ? {
12
12
  };
13
13
  /**
14
14
  * What a date control with no pick says: the dashboard's dates, or that each widget has its
15
- * own. To the ear the dates shown are said as shown ("showing Aug 23 to Nov 20"), not as a
16
- * pick, which would read the same.
15
+ * own. Dates counted back from now are named first (`period`, "Last 13 weeks") with the dates
16
+ * beside them, as a pick of the same kind reads. To the ear the dates shown are said as shown
17
+ * ("showing Aug 23 to Nov 20"), not as a pick, which would read the same.
17
18
  */
18
- function unpicked(span, words) {
19
- const dates = datesOf(span, words.datesLoading);
20
- const heard = typeof span === "string" ? words.datesShowing(span) : dates.heard;
19
+ function unpicked(at, words) {
20
+ const dates = datesOf(at.span, words.datesLoading);
21
+ const heard = typeof at.span === "string" ? words.datesShowing(at.span) : dates.heard;
21
22
  const none = words.widgetDates;
22
- return {
23
- text: dates.seen ?? none,
23
+ if (at.period !== void 0 && typeof at.span === "string") return {
24
+ text: at.period,
25
+ beside: at.span,
26
+ spoken: `${at.period}, ${heard ?? ""}`,
27
+ dates: true
28
+ };
29
+ if (dates.seen === void 0) return {
30
+ text: none,
24
31
  beside: void 0,
25
32
  spoken: heard ?? none
26
33
  };
34
+ return {
35
+ text: dates.seen,
36
+ beside: void 0,
37
+ spoken: heard ?? none,
38
+ dates: true
39
+ };
27
40
  }
28
41
  /**
29
42
  * What a control says, given its pick in words (`said`). A date control says the dashboard's
@@ -33,25 +46,30 @@ function unpicked(span, words) {
33
46
  * eye, a word to the ear. Any other control says its pick, and nothing with none.
34
47
  */
35
48
  function useDates(control, said) {
36
- const { picks, span } = useBar();
49
+ const { picks, span, period } = useBar();
37
50
  const words = useWords();
38
51
  if (control.kind !== "date_range") return {
39
52
  text: said,
40
53
  beside: void 0,
41
54
  spoken: said ?? ""
42
55
  };
43
- if (said === void 0) return unpicked(span, words);
56
+ if (said === void 0) return unpicked({
57
+ span,
58
+ period
59
+ }, words);
44
60
  const dates = datesOf(span, words.datesLoading);
45
61
  const range = rangeOf(picks, control.id);
46
62
  if (range === void 0 || !("last" in range) || dates.seen === void 0) return {
47
63
  text: said,
48
64
  beside: void 0,
49
- spoken: said
65
+ spoken: said,
66
+ dates: true
50
67
  };
51
68
  return {
52
69
  text: said,
53
70
  beside: dates.seen,
54
- spoken: `${said}, ${dates.heard ?? ""}`
71
+ spoken: `${said}, ${dates.heard ?? ""}`,
72
+ dates: true
55
73
  };
56
74
  }
57
75
  export { useDates };
@@ -14,6 +14,12 @@ export type FilterBarProps = {
14
14
  * says neither.
15
15
  */
16
16
  span?: string | null | undefined;
17
+ /**
18
+ * Those dates in words, when they are counted back from now ("Last 13 weeks"). The date
19
+ * control says it before the dates while nothing is picked. Left out for dates that are
20
+ * fixed, or that the tiles do not share.
21
+ */
22
+ period?: string | undefined;
17
23
  };
18
24
  /** A control's values as a bar lists them: what is known, whether a read is under way or failed. */
19
25
  export type ValuesState = {
@@ -24,6 +30,8 @@ export type ValuesState = {
24
30
  /** It failed because the viewer is signed out: asking again cannot pass until they sign in. */
25
31
  signedOut: boolean;
26
32
  retry: () => void;
33
+ /** For a labelled field: each listed value's label. */
34
+ labels?: Readonly<Record<string, string>>;
27
35
  };
28
36
  /**
29
37
  * A filter control's values: its own list, or for "lookup" the values its member has that this
@@ -1,7 +1,7 @@
1
1
  import { useDashboards } from "../context.mjs";
2
2
  import { signedOut } from "../failure-words.mjs";
3
3
  import { ScopeContext } from "../scope.mjs";
4
- import { parseMemberId } from "derive-dashboards/core";
4
+ import { isValuePick, parseMemberId } from "derive-dashboards/core";
5
5
  import { useContext, useEffect, useMemo, useState } from "react";
6
6
  import useSWR from "swr";
7
7
  // src/filters/hooks.ts
@@ -54,6 +54,7 @@ function useControlValues(control, options = {}) {
54
54
  };
55
55
  return {
56
56
  values: fetched.data?.values ?? NONE,
57
+ ...fetched.data?.labels === void 0 ? {} : { labels: fetched.data.labels },
57
58
  loading: fetched.isLoading,
58
59
  failed: fetched.error !== void 0,
59
60
  signedOut: signedOut(fetched.error),
@@ -82,6 +83,42 @@ function useFilterFields(controls) {
82
83
  const { data } = useSWR(["dd-meta"], () => client.meta());
83
84
  return Object.fromEntries(controls.map((c) => [c.id, c.kind === "filter" ? fieldOf(data, c.member) : void 0]));
84
85
  }
86
+ /**
87
+ * The labels of the values chosen in labelled lookup controls, read once per change of the
88
+ * picks, so a chip says a name, never an id, even for a value no list has shown yet.
89
+ */
90
+ function useChosenLabels(controls, picks, fields) {
91
+ const { client } = useDashboards();
92
+ const scope = useContext(ScopeContext);
93
+ const wanted = controls.flatMap((c) => {
94
+ const pick = picks[c.id];
95
+ if (c.kind !== "filter" || fields[c.id]?.labelled !== true || !isValuePick(pick)) return [];
96
+ const keys = pick.values.filter((v) => typeof v === "string");
97
+ return keys.length === 0 ? [] : [{
98
+ controlId: c.id,
99
+ keys
100
+ }];
101
+ });
102
+ const draft = scope?.draft === true;
103
+ const key = scope === null || wanted.length === 0 ? null : [
104
+ "dd-chosen-labels",
105
+ scope.dashboardId,
106
+ draft,
107
+ JSON.stringify(wanted)
108
+ ];
109
+ const { data } = useSWR(key, () => Promise.all(wanted.map(async (w) => {
110
+ const page = await client.controlValues({
111
+ dashboardId: scope?.dashboardId ?? "",
112
+ controlId: w.controlId,
113
+ keys: w.keys,
114
+ limit: w.keys.length,
115
+ ...draft ? { draft: true } : {}
116
+ });
117
+ return [w.controlId, page.labels ?? {}];
118
+ })).then((pairs) => Object.fromEntries(pairs)));
119
+ return data ?? NO_LABELS;
120
+ }
121
+ const NO_LABELS = {};
85
122
  /** A value that settles: it follows `value` once it has not changed for `ms`. */
86
123
  function useDebounced(value, ms) {
87
124
  const [out, setOut] = useState(value);
@@ -95,4 +132,4 @@ function useDebounced(value, ms) {
95
132
  }, [value, ms]);
96
133
  return out;
97
134
  }
98
- export { fieldOf, useControlValues, useDebounced, useFilterFields };
135
+ export { fieldOf, useChosenLabels, useControlValues, useDebounced, useFilterFields };
@@ -12,6 +12,7 @@ function MenuButton({ anchor, open, hidden, onClick }) {
12
12
  const words = useWords();
13
13
  const keys = useBar().options.shortcuts !== false;
14
14
  const waiting = hidden > 0 ? words.moreFilters(hidden) : void 0;
15
+ const named = waiting === void 0 ? words.filter : `${words.filter}, ${waiting}`;
15
16
  return /* @__PURE__ */ jsxs("button", {
16
17
  ref: anchor,
17
18
  type: "button",
@@ -19,25 +20,14 @@ function MenuButton({ anchor, open, hidden, onClick }) {
19
20
  "aria-haspopup": "dialog",
20
21
  "aria-expanded": open,
21
22
  "aria-keyshortcuts": keys ? "F" : void 0,
22
- "aria-label": waiting === void 0 ? words.filter : `${words.filter}, ${waiting}`,
23
+ "aria-label": named,
24
+ title: keys ? `${named} (F)` : named,
23
25
  onClick,
24
- children: [
25
- /* @__PURE__ */ jsx("span", {
26
- className: "dd-fb-add-icon",
27
- "aria-hidden": true,
28
- children: "+"
29
- }),
30
- words.filter,
31
- waiting === void 0 ? null : /* @__PURE__ */ jsx("span", {
32
- className: "dd-fb-count",
33
- title: waiting,
34
- children: words.more(hidden)
35
- }),
36
- keys ? /* @__PURE__ */ jsx("kbd", {
37
- "aria-hidden": true,
38
- children: "F"
39
- }) : null
40
- ]
26
+ children: [/* @__PURE__ */ jsx("span", {
27
+ className: "dd-fb-add-icon",
28
+ "aria-hidden": true,
29
+ children: "+"
30
+ }), words.filter]
41
31
  });
42
32
  }
43
33
  /**