derive-dashboards 0.9.0 → 0.11.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.
- package/CHANGELOG.md +67 -0
- package/dist/body.mjs +5 -1
- package/dist/charts/data/words.d.mts +5 -0
- package/dist/charts/data/words.mjs +1 -0
- package/dist/charts/kinds/columns-data.mjs +4 -1
- package/dist/charts/kinds/grid-layout.mjs +84 -8
- package/dist/charts/kinds/grid-legend.mjs +27 -4
- package/dist/charts/kinds/grid-marks.mjs +56 -4
- package/dist/charts/kinds/grid.mjs +2 -1
- package/dist/charts/scale/value.mjs +15 -8
- package/dist/charts/scene/types.d.mts +1 -1
- package/dist/core/document/display-entries.mjs +9 -2
- package/dist/core/document/display.d.mts +7 -3
- package/dist/core/document/display.mjs +15 -2
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +2 -0
- package/dist/core/error/codes.mjs +2 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +3 -3
- package/dist/core/model/member.d.mts +6 -0
- package/dist/core/model/member.mjs +11 -1
- package/dist/core/model/types.d.mts +6 -0
- package/dist/core/model/validate/known-members.mjs +1 -0
- package/dist/core/model/validate/members.mjs +12 -1
- package/dist/core/query/closure.mjs +2 -0
- package/dist/core/query/drill/links.mjs +16 -4
- package/dist/core/result/columns.mjs +15 -2
- package/dist/core/result/types.d.mts +2 -0
- package/dist/core/schema/answer-parts.mjs +1 -0
- package/dist/core/schema/answers.d.mts +14 -0
- package/dist/core/schema/answers.mjs +4 -2
- package/dist/core/schema/tools.mjs +4 -0
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/endpoints/index.d.mts +5 -4
- package/dist/endpoints/meta.mjs +30 -12
- package/dist/endpoints/query.mjs +11 -5
- package/dist/endpoints/values.mjs +38 -24
- package/dist/execute.mjs +22 -1
- package/dist/labels.mjs +68 -0
- package/dist/listing.mjs +13 -0
- package/dist/react/Canvas.mjs +28 -2
- package/dist/react/Cell.mjs +1 -1
- package/dist/react/Dashboard.d.mts +2 -3
- package/dist/react/Tile.d.mts +1 -1
- package/dist/react/arrange-steps.mjs +99 -11
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/base.mjs +11 -6
- package/dist/react/builder/display.mjs +16 -2
- package/dist/react/builder/state.mjs +3 -3
- package/dist/react/builder/words.mjs +8 -0
- package/dist/react/dates-shown.mjs +27 -9
- package/dist/react/filters/bar.d.mts +1 -1
- package/dist/react/filters/bar.mjs +17 -7
- package/dist/react/filters/chip.mjs +5 -3
- package/dist/react/filters/context.mjs +2 -2
- package/dist/react/filters/dates-said.mjs +29 -11
- package/dist/react/filters/hooks.d.mts +8 -0
- package/dist/react/filters/hooks.mjs +39 -2
- package/dist/react/filters/menu.mjs +8 -18
- package/dist/react/filters/phone.mjs +3 -3
- package/dist/react/filters/values.mjs +47 -28
- package/dist/react/filters/words.mjs +2 -2
- package/dist/react/format.d.mts +1 -1
- package/dist/react/format.mjs +8 -2
- package/dist/react/renderers/moved.mjs +160 -0
- package/dist/react/renderers/number-before.mjs +2 -157
- package/dist/react/renderers/props.d.mts +3 -3
- package/dist/react/renderers/table-cells.mjs +97 -11
- package/dist/react/renderers/table-head.mjs +7 -1
- package/dist/react/renderers/table-measure.mjs +147 -25
- package/dist/react/renderers/table-over.mjs +72 -0
- package/dist/react/renderers/table-scale.mjs +54 -1
- package/dist/react/renderers/table-trend.mjs +55 -0
- package/dist/react/renderers/table.d.mts +5 -1
- package/dist/react/renderers/table.mjs +29 -6
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/package.json +1 -1
|
@@ -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).
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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 =
|
|
51
|
-
if (one === 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
|
-
/**
|
|
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:
|
|
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)
|
|
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":
|
|
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.
|
|
16
|
-
*
|
|
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(
|
|
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:
|
|
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(
|
|
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":
|
|
23
|
+
"aria-label": named,
|
|
24
|
+
title: keys ? `${named} (F)` : named,
|
|
23
25
|
onClick,
|
|
24
|
-
children: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
/**
|
|
@@ -16,7 +16,7 @@ function PickText({ control, said }) {
|
|
|
16
16
|
const { fields, picks } = useBar();
|
|
17
17
|
const { text, beside } = useDates(control, said);
|
|
18
18
|
if (control.kind === "date_range") return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
19
|
-
"data-unset": said === void 0 || void 0,
|
|
19
|
+
"data-unset": said === void 0 && beside === void 0 || void 0,
|
|
20
20
|
children: text
|
|
21
21
|
}), beside === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
22
22
|
className: "dd-fb-span",
|
|
@@ -34,7 +34,7 @@ function Pill({ control, onOpen }) {
|
|
|
34
34
|
const { fields, picks } = useBar();
|
|
35
35
|
const words = useWords();
|
|
36
36
|
const said = useSummary()(control);
|
|
37
|
-
const { spoken } = useDates(control, said);
|
|
37
|
+
const { spoken, dates } = useDates(control, said);
|
|
38
38
|
const pick = valuePickOf(picks, control.id);
|
|
39
39
|
const values = control.kind === "filter" && pick !== void 0 && !isNumber(control, fields);
|
|
40
40
|
return /* @__PURE__ */ jsxs("button", {
|
|
@@ -43,7 +43,7 @@ function Pill({ control, onOpen }) {
|
|
|
43
43
|
"aria-label": `${control.label} ${spoken}`,
|
|
44
44
|
onClick: onOpen,
|
|
45
45
|
children: [
|
|
46
|
-
/* @__PURE__ */ jsx("span", {
|
|
46
|
+
dates === true ? null : /* @__PURE__ */ jsx("span", {
|
|
47
47
|
className: "dd-fb-quiet",
|
|
48
48
|
children: control.label
|
|
49
49
|
}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useBar, useFormat, useWords } from "./context.mjs";
|
|
1
|
+
import { BarContext, useBar, useFormat, useWords } from "./context.mjs";
|
|
2
2
|
import { useControlValues, useDebounced } from "./hooks.mjs";
|
|
3
3
|
import { Combobox } from "./listbox.mjs";
|
|
4
4
|
import { chosenOf, isNegative, offersNone, takesMany } from "./logic.mjs";
|
|
@@ -61,7 +61,7 @@ function useShownValues(control, chosen, query) {
|
|
|
61
61
|
const none = offersNone(control);
|
|
62
62
|
const rest = read.values.filter((v) => !pinned.includes(v));
|
|
63
63
|
const tail = none && !pinned.includes(null) && !rest.includes(null) ? [null] : [];
|
|
64
|
-
const fits = (v) => format(control, v).toLowerCase().includes(needle) || !own && String(v).toLowerCase().includes(needle);
|
|
64
|
+
const fits = (v) => format(control, v).toLowerCase().includes(needle) || (read.labels?.[String(v)] ?? "").toLowerCase().includes(needle) || !own && String(v).toLowerCase().includes(needle);
|
|
65
65
|
return [
|
|
66
66
|
...pinned,
|
|
67
67
|
...rest,
|
|
@@ -69,6 +69,7 @@ function useShownValues(control, chosen, query) {
|
|
|
69
69
|
].filter((v) => (v !== null || none) && fits(v));
|
|
70
70
|
}, [
|
|
71
71
|
read.values,
|
|
72
|
+
read.labels,
|
|
72
73
|
pinned,
|
|
73
74
|
needle,
|
|
74
75
|
format,
|
|
@@ -151,33 +152,51 @@ function ValueList({ control, pick, onToggle, onClear, onBack, before }) {
|
|
|
151
152
|
const [query, setQuery] = useState("");
|
|
152
153
|
const { shown, pending, read } = useShownValues(control, chosen, query);
|
|
153
154
|
const options = optionsOf(control, shown, chosen, onToggle);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
155
|
+
const bar = useBar();
|
|
156
|
+
const named = useMemo(() => read.labels === void 0 ? bar : {
|
|
157
|
+
...bar,
|
|
158
|
+
labels: {
|
|
159
|
+
...bar.labels,
|
|
160
|
+
[control.id]: {
|
|
161
|
+
...bar.labels?.[control.id],
|
|
162
|
+
...read.labels
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, [
|
|
166
|
+
bar,
|
|
167
|
+
read.labels,
|
|
168
|
+
control.id
|
|
169
|
+
]);
|
|
170
|
+
return /* @__PURE__ */ jsx(BarContext.Provider, {
|
|
171
|
+
value: named,
|
|
172
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
173
|
+
className: "dd-fb-values",
|
|
174
|
+
children: [
|
|
175
|
+
/* @__PURE__ */ jsx(Combobox, {
|
|
176
|
+
label: words.search(control.label),
|
|
177
|
+
placeholder: words.search(control.label),
|
|
178
|
+
query,
|
|
179
|
+
onQuery: setQuery,
|
|
180
|
+
multiselect: takesMany(control, pick !== void 0 && isNegative(pick.op)),
|
|
181
|
+
busy: pending,
|
|
182
|
+
...onBack === void 0 ? {} : { onBack },
|
|
183
|
+
before,
|
|
184
|
+
empty: emptyWords(words, {
|
|
185
|
+
pending,
|
|
186
|
+
failed: read.failed,
|
|
187
|
+
label: control.label,
|
|
188
|
+
query
|
|
189
|
+
}),
|
|
190
|
+
options
|
|
171
191
|
}),
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
]
|
|
192
|
+
read.failed ? /* @__PURE__ */ jsx(ValuesFailed, { read }) : null,
|
|
193
|
+
/* @__PURE__ */ jsx(ValueFoot, {
|
|
194
|
+
count: chosen.length,
|
|
195
|
+
searching: pending && shown.length > 0,
|
|
196
|
+
onClear
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
})
|
|
181
200
|
});
|
|
182
201
|
}
|
|
183
202
|
export { Mark, ValueList, ValuesSummary };
|
|
@@ -22,7 +22,7 @@ const ENGLISH_FILTERS = {
|
|
|
22
22
|
changeValues: (label, values) => `Change ${label}: ${values}`,
|
|
23
23
|
remove: (label) => `Remove ${label} filter`,
|
|
24
24
|
filterBy: (label) => `Filter by ${label}`,
|
|
25
|
-
widgetDates: "
|
|
25
|
+
widgetDates: "Dashboard default",
|
|
26
26
|
datesLoading: "loading dates",
|
|
27
27
|
datesShowing: (dates) => `showing ${dates}`,
|
|
28
28
|
customRange: "Custom range",
|
|
@@ -37,7 +37,7 @@ const ENGLISH_FILTERS = {
|
|
|
37
37
|
to: "to",
|
|
38
38
|
notNumbers: "Enter numbers only.",
|
|
39
39
|
minOverMax: "The minimum must be no more than the maximum.",
|
|
40
|
-
yourView: "
|
|
40
|
+
yourView: "Only you see these filters",
|
|
41
41
|
fromLink: "From a link",
|
|
42
42
|
undo: "Undo",
|
|
43
43
|
done: "Done",
|
package/dist/react/format.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ import { NumberShape, ResultCell, ResultColumn } from "derive-dashboards/core";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function plotValue(cell: ResultCell): number | null;
|
|
9
9
|
/** What formatting reads of a column: its type, and a time bucket's grain or a money unit. */
|
|
10
|
-
export type Shape = Pick<ResultColumn, "id" | "role" | "type" | "grain" | "unit" | "format" | "signed" | "fraction"> & Pick<NumberShape, "beside">;
|
|
10
|
+
export type Shape = Pick<ResultColumn, "id" | "role" | "type" | "grain" | "unit" | "format" | "signed" | "fraction" | "labels"> & Pick<NumberShape, "beside">;
|
|
11
11
|
/**
|
|
12
12
|
* A cell as text for a person, in their locale and words. A renderer can pass its own props as
|
|
13
13
|
* `format`: they carry both.
|
package/dist/react/format.mjs
CHANGED
|
@@ -49,9 +49,15 @@ function formatCell(cell, column, format = {}) {
|
|
|
49
49
|
if (isMark(cell)) return isTotal(cell) ? messages.total : messages.other;
|
|
50
50
|
if (typeof cell === "boolean") return cell ? messages.drillYes : messages.drillNo;
|
|
51
51
|
if (typeof cell !== "string") return writerIn(locale).text(cell, column);
|
|
52
|
+
return stringText(cell, column, format);
|
|
53
|
+
}
|
|
54
|
+
/** A string cell: its label, else a number a driver sent as text, else text, a date or a time. */
|
|
55
|
+
function stringText(cell, column, format) {
|
|
56
|
+
const label = column?.labels?.[cell];
|
|
57
|
+
if (label !== void 0) return label;
|
|
52
58
|
const sent = numberSent(cell, column);
|
|
53
|
-
if (sent === void 0) return formatText(cell, column, locale, format.timeZone);
|
|
54
|
-
return writerIn(locale).text(sent, column);
|
|
59
|
+
if (sent === void 0) return formatText(cell, column, format.locale, format.timeZone);
|
|
60
|
+
return writerIn(format.locale).text(sent, column);
|
|
55
61
|
}
|
|
56
62
|
/** Decimal text as a driver may write it: a plus before it, a point with no digit before or after it. */
|
|
57
63
|
const plain = (text) => text.trim().replace(/^\+/u, "").replace(/^(-?)\./u, "$10.").replace(/\.$/u, "");
|