derive-dashboards 0.1.1 → 0.2.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/README.md +5 -3
- package/dist/cli/add.mjs +130 -0
- package/dist/cli/cli.mjs +14 -12
- package/dist/cli/config.mjs +12 -1
- package/dist/cli/doctor.mjs +147 -0
- package/dist/cli/init.mjs +3 -2
- package/dist/cli/json.mjs +21 -0
- package/dist/cli/layers.mjs +33 -0
- package/dist/core/document/layout.mjs +1 -1
- package/dist/core/document/view-layout.d.mts +14 -0
- package/dist/core/document/view-layout.mjs +157 -0
- package/dist/core/engine/filter.mjs +2 -2
- package/dist/core/engine/leaf.mjs +9 -4
- package/dist/core/engine/members.mjs +1 -1
- 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 -1
- package/dist/core/error/codes.mjs +2 -1
- package/dist/core/index.d.mts +5 -3
- package/dist/core/index.mjs +5 -3
- package/dist/core/model/member.mjs +5 -2
- package/dist/core/model/types.d.mts +13 -13
- package/dist/core/model/validate/members.mjs +7 -4
- package/dist/core/policy/bind-query.d.mts +12 -0
- package/dist/core/policy/bind-query.mjs +53 -0
- package/dist/core/query/filter.d.mts +6 -0
- package/dist/core/query/picks.d.mts +8 -2
- package/dist/core/query/picks.mjs +11 -4
- package/dist/core/query/segments.mjs +2 -1
- package/dist/core/result/columns.mjs +6 -3
- package/dist/core/schema/aliases.d.mts +7 -0
- package/dist/core/schema/aliases.mjs +77 -0
- package/dist/core/schema/answers.d.mts +1 -0
- package/dist/core/schema/answers.mjs +1 -0
- package/dist/core/schema/index.d.mts +3 -2
- package/dist/core/schema/index.mjs +3 -2
- package/dist/core/schema/query.d.mts +81 -0
- package/dist/core/schema/query.mjs +9 -5
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/dashboards.mjs +4 -0
- package/dist/editing.mjs +2 -2
- package/dist/endpoints/dashboards.mjs +17 -2
- package/dist/endpoints/index.d.mts +12 -2
- package/dist/endpoints/meta.mjs +10 -1
- package/dist/execute.mjs +20 -11
- package/dist/handler.mjs +5 -1
- package/dist/llms.txt +22 -0
- package/dist/mcp/format.mjs +42 -8
- package/dist/mcp/query.mjs +34 -4
- package/dist/postgres-store.mjs +1 -0
- package/dist/react/Canvas.mjs +28 -5
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.mjs +15 -3
- package/dist/react/DashboardList.mjs +22 -22
- package/dist/react/DashboardListRow.mjs +49 -0
- package/dist/react/Discard.mjs +5 -2
- package/dist/react/Editing.mjs +19 -5
- package/dist/react/FilterBar.d.mts +7 -9
- package/dist/react/Grid.mjs +7 -19
- package/dist/react/Header.mjs +1 -1
- package/dist/react/History.mjs +5 -0
- package/dist/react/ReadFailed.mjs +23 -0
- package/dist/react/Spaces.mjs +15 -1
- package/dist/react/Tile.d.mts +2 -0
- package/dist/react/Tile.mjs +35 -7
- package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
- package/dist/react/arrange-steps.mjs +16 -13
- package/dist/react/arrange.mjs +10 -3
- package/dist/react/builder/Calcs.mjs +35 -11
- package/dist/react/builder/FilterEditor.mjs +196 -0
- package/dist/react/builder/Filters.mjs +172 -116
- package/dist/react/builder/Formula.mjs +82 -0
- package/dist/react/builder/Groups.mjs +1 -0
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/builder/RangeEditor.mjs +184 -0
- package/dist/react/builder/Sections.mjs +41 -6
- package/dist/react/builder/Time.mjs +138 -60
- package/dist/react/builder/Values.mjs +85 -0
- package/dist/react/builder/WidgetBuilder.mjs +50 -49
- package/dist/react/builder/base.d.mts +5 -0
- package/dist/react/builder/base.mjs +33 -8
- package/dist/react/builder/calc.mjs +15 -1
- package/dist/react/builder/escape.d.mts +1 -0
- package/dist/react/builder/escape.mjs +62 -0
- package/dist/react/builder/filter-tree.d.mts +9 -0
- package/dist/react/builder/filter-tree.mjs +186 -0
- package/dist/react/builder/formula-parse.d.mts +18 -0
- package/dist/react/builder/formula-parse.mjs +136 -0
- package/dist/react/builder/labels.d.mts +1 -1
- package/dist/react/builder/state.d.mts +2 -1
- package/dist/react/builder/state.mjs +23 -37
- package/dist/react/builder/useBuilder.d.mts +12 -1
- package/dist/react/builder/useBuilder.mjs +6 -3
- package/dist/react/builder/words.d.mts +59 -0
- package/dist/react/builder/words.mjs +73 -0
- package/dist/react/context.d.mts +13 -0
- package/dist/react/context.mjs +9 -3
- package/dist/react/drill/useDrill.d.mts +1 -1
- package/dist/react/drill/words.d.mts +3 -0
- package/dist/react/drill/words.mjs +2 -0
- package/dist/react/english.mjs +20 -5
- package/dist/react/filters/bar.d.mts +12 -0
- package/dist/react/filters/bar.mjs +135 -0
- package/dist/react/filters/calendar.mjs +193 -0
- package/dist/react/filters/chip.mjs +174 -0
- package/dist/react/filters/context.d.mts +22 -0
- package/dist/react/filters/context.mjs +78 -0
- package/dist/react/filters/dates.mjs +89 -0
- package/dist/react/filters/days.d.mts +36 -0
- package/dist/react/filters/days.mjs +87 -0
- package/dist/react/filters/field-step.mjs +81 -0
- package/dist/react/filters/hooks.d.mts +34 -0
- package/dist/react/filters/hooks.mjs +94 -0
- package/dist/react/filters/listbox.mjs +131 -0
- package/dist/react/filters/logic.d.mts +59 -0
- package/dist/react/filters/logic.mjs +109 -0
- package/dist/react/filters/menu-search.mjs +211 -0
- package/dist/react/filters/menu.mjs +85 -0
- package/dist/react/filters/number.mjs +127 -0
- package/dist/react/filters/numbers.d.mts +47 -0
- package/dist/react/filters/numbers.mjs +151 -0
- package/dist/react/filters/operator.mjs +104 -0
- package/dist/react/filters/phone.mjs +104 -0
- package/dist/react/filters/popover.d.mts +19 -0
- package/dist/react/filters/popover.mjs +153 -0
- package/dist/react/filters/rules.d.mts +8 -0
- package/dist/react/filters/rules.mjs +55 -0
- package/dist/react/filters/sheet.mjs +196 -0
- package/dist/react/filters/state.mjs +132 -0
- package/dist/react/filters/suggest.d.mts +47 -0
- package/dist/react/filters/suggest.mjs +97 -0
- package/dist/react/filters/values.mjs +166 -0
- package/dist/react/filters/words.d.mts +81 -0
- package/dist/react/filters/words.mjs +73 -0
- package/dist/react/format.mjs +11 -4
- package/dist/react/index.d.mts +11 -5
- package/dist/react/index.mjs +8 -4
- package/dist/react/messages.d.mts +34 -2
- package/dist/react/place.mjs +7 -3
- package/dist/react/renderers/index.mjs +65 -3
- package/dist/react/renderers/list.mjs +6 -6
- package/dist/react/series.d.mts +25 -8
- package/dist/react/series.mjs +135 -39
- package/dist/react/theme.css +930 -19
- package/dist/react/useBoard.d.mts +2 -0
- package/dist/react/useDashboard.d.mts +3 -0
- package/dist/react/useDashboard.mjs +6 -0
- package/dist/react/view-grid.mjs +16 -0
- package/dist/recharts/axes.mjs +28 -0
- package/dist/recharts/axis.mjs +84 -0
- package/dist/recharts/bar.d.mts +7 -0
- package/dist/recharts/bar.mjs +140 -0
- package/dist/recharts/charts.d.mts +4 -5
- package/dist/recharts/charts.mjs +2 -208
- package/dist/recharts/index.d.mts +3 -1
- package/dist/recharts/index.mjs +4 -1
- package/dist/recharts/line.d.mts +2 -0
- package/dist/recharts/line.mjs +111 -0
- package/dist/recharts/marks.mjs +47 -18
- package/dist/recharts/parts.mjs +88 -0
- package/dist/recharts/table.mjs +71 -0
- package/dist/records-read.mjs +1 -1
- package/dist/registry/filter-bar.json +26 -0
- package/dist/skills/derive-dashboards/SKILL.md +69 -0
- package/package.json +6 -2
- package/dist/react/FilterBar.mjs +0 -119
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_RANGE, cleared, defaultTime, freshId, lastPart, refersTo, withQuery } from "./base.mjs";
|
|
2
|
+
import { addCondition, removeNode, setMode } from "./filter-tree.mjs";
|
|
2
3
|
import { formulaRefs } from "derive-dashboards/core";
|
|
3
4
|
// src/builder/state.ts
|
|
4
5
|
/** The builder's changes to measures, groups, time and filters. Calcs are in `calc.ts`. */
|
|
@@ -121,7 +122,7 @@ function timeOf(current, change) {
|
|
|
121
122
|
if (dimension === void 0) return void 0;
|
|
122
123
|
return {
|
|
123
124
|
dimension,
|
|
124
|
-
range: change.range ?? current.range ??
|
|
125
|
+
range: change.range ?? current.range ?? DEFAULT_RANGE,
|
|
125
126
|
...grainOf(change.grain ?? current.grain),
|
|
126
127
|
...compareOf(change.compare ?? current.compare)
|
|
127
128
|
};
|
|
@@ -156,46 +157,31 @@ function setTime(meta, state, change) {
|
|
|
156
157
|
removed: gone.map((c) => c.label ?? c.id)
|
|
157
158
|
};
|
|
158
159
|
}
|
|
159
|
-
/** The filter
|
|
160
|
-
function
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
/** The query with its filter replaced; none when the filter is gone. */
|
|
161
|
+
function withFilter(meta, state, filter) {
|
|
162
|
+
const query = state.query;
|
|
163
|
+
if (query === void 0) return state;
|
|
164
|
+
const { filters: _old, ...without } = query;
|
|
165
|
+
return withQuery(meta, state, filter === void 0 ? without : {
|
|
166
|
+
...without,
|
|
167
|
+
filters: filter
|
|
168
|
+
});
|
|
163
169
|
}
|
|
164
|
-
/**
|
|
170
|
+
/** Adds a condition: at the top, to a group, or (`group: "new"`) as a new group of one. */
|
|
165
171
|
function addFilter(meta, state, filter) {
|
|
166
172
|
const query = state.query;
|
|
167
|
-
if (query === void 0
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
let n = current.length + 1;
|
|
171
|
-
while (taken.has(`f${n}`)) n += 1;
|
|
172
|
-
const op = filter.negate === true ? "notIn" : "in";
|
|
173
|
-
const leaf = {
|
|
174
|
-
id: `f${n}`,
|
|
175
|
-
member: filter.member,
|
|
176
|
-
op,
|
|
177
|
-
values: [...filter.values]
|
|
178
|
-
};
|
|
179
|
-
return withQuery(meta, state, {
|
|
180
|
-
...query,
|
|
181
|
-
filters: {
|
|
182
|
-
id: "filters",
|
|
183
|
-
all: [...current, leaf]
|
|
184
|
-
}
|
|
185
|
-
});
|
|
173
|
+
if (query === void 0) return state;
|
|
174
|
+
const { group, ...condition } = filter;
|
|
175
|
+
return withFilter(meta, state, addCondition(query.filters, condition, group));
|
|
186
176
|
}
|
|
177
|
+
/** Removes a condition, a group, or a part the builder keeps as written. */
|
|
187
178
|
function removeFilter(meta, state, id) {
|
|
179
|
+
return state.query === void 0 ? state : withFilter(meta, state, removeNode(state.query.filters, id));
|
|
180
|
+
}
|
|
181
|
+
/** How the top matches its parts, or (with `group`) how a group matches its conditions. */
|
|
182
|
+
function setFilterMode(meta, state, change) {
|
|
188
183
|
const query = state.query;
|
|
189
184
|
if (query === void 0) return state;
|
|
190
|
-
|
|
191
|
-
const { filters: _old, ...without } = query;
|
|
192
|
-
const next = rest.length === 0 ? without : {
|
|
193
|
-
...without,
|
|
194
|
-
filters: {
|
|
195
|
-
id: "filters",
|
|
196
|
-
all: rest
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
return withQuery(meta, state, next);
|
|
185
|
+
return withFilter(meta, state, setMode(query.filters, change.mode, change.group));
|
|
200
186
|
}
|
|
201
|
-
export { addFilter, addGroup, addMeasure, cutGroup,
|
|
187
|
+
export { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setFilterMode, setTime };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { GroupMode } from "./filter-tree.mjs";
|
|
1
2
|
import { BuilderState } from "./base.mjs";
|
|
2
3
|
import { CalcPreset } from "./calc.mjs";
|
|
3
4
|
import { TimeChange } from "./state.mjs";
|
|
5
|
+
import "./escape.mjs";
|
|
4
6
|
import { Widget } from "derive-dashboards/core";
|
|
5
7
|
/**
|
|
6
8
|
* The widget builder without its look: the widget being built, the viewer's meta, the live
|
|
@@ -25,11 +27,20 @@ export declare function useBuilder(initial?: Widget): {
|
|
|
25
27
|
setTime: (change: TimeChange) => void;
|
|
26
28
|
addFilter: (filter: {
|
|
27
29
|
member: string;
|
|
30
|
+
op: import("derive-dashboards/core").Op;
|
|
28
31
|
values: readonly import("derive-dashboards/core").Primitive[];
|
|
29
|
-
|
|
32
|
+
group?: string;
|
|
33
|
+
}) => void;
|
|
34
|
+
setFilterMode: (change: {
|
|
35
|
+
mode: GroupMode;
|
|
36
|
+
group?: string;
|
|
30
37
|
}) => void;
|
|
31
38
|
removeFilter: (id: string) => void;
|
|
32
39
|
addCalc: (preset: CalcPreset) => void;
|
|
40
|
+
addFormula: (calc: {
|
|
41
|
+
label: string;
|
|
42
|
+
formula: import("derive-dashboards/core").StoredFormulaNode;
|
|
43
|
+
}) => void;
|
|
33
44
|
updateCalc: (id: string, change: {
|
|
34
45
|
label?: string;
|
|
35
46
|
format?: import("derive-dashboards/core").Format;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useDashboards } from "../context.mjs";
|
|
2
2
|
import { emptyBuilder, setKind, setTitle, widgetOf } from "./base.mjs";
|
|
3
|
-
import { addCalc, presetsFor, removeCalc, updateCalc } from "./calc.mjs";
|
|
3
|
+
import { addCalc, addFormula, presetsFor, removeCalc, updateCalc } from "./calc.mjs";
|
|
4
4
|
import { labelOf } from "./labels.mjs";
|
|
5
5
|
import { measureHint } from "./options.mjs";
|
|
6
|
-
import { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setTime } from "./state.mjs";
|
|
6
|
+
import { addFilter, addGroup, addMeasure, cutGroup, moveGroup, removeFilter, removeGroup, removeMeasure, setFilterMode, setTime } from "./state.mjs";
|
|
7
7
|
import { usePreview } from "./usePreview.mjs";
|
|
8
|
+
import { useEscapeToLeave } from "./escape.mjs";
|
|
8
9
|
import { useState } from "react";
|
|
9
10
|
import useSWR from "swr";
|
|
10
11
|
// src/builder/useBuilder.ts
|
|
@@ -34,8 +35,10 @@ function useBuilder(initial) {
|
|
|
34
35
|
moveGroup: on(moveGroup),
|
|
35
36
|
setTime: on(setTime),
|
|
36
37
|
addFilter: on(addFilter),
|
|
38
|
+
setFilterMode: on(setFilterMode),
|
|
37
39
|
removeFilter: on(removeFilter),
|
|
38
40
|
addCalc: on(addCalc),
|
|
41
|
+
addFormula: on(addFormula),
|
|
39
42
|
updateCalc: on(updateCalc),
|
|
40
43
|
removeCalc: on(removeCalc),
|
|
41
44
|
setTitle: on(setTitle),
|
|
@@ -57,4 +60,4 @@ function useBuilder(initial) {
|
|
|
57
60
|
}
|
|
58
61
|
};
|
|
59
62
|
}
|
|
60
|
-
export { useBuilder };
|
|
63
|
+
export { useBuilder, useEscapeToLeave };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { GroupMode } from "./filter-tree.mjs";
|
|
2
|
+
import { FormulaProblem } from "./formula-parse.mjs";
|
|
3
|
+
import { Grain, Op } from "derive-dashboards/core";
|
|
4
|
+
/** The units a rolling range counts in. */
|
|
5
|
+
export type RangeUnit = Exclude<Grain, "hour">;
|
|
6
|
+
export type BuilderMessages = {
|
|
7
|
+
/** The chip that opens the custom range editor. */
|
|
8
|
+
customRange: string;
|
|
9
|
+
/** The names of the time row's two selects: how time splits, and which days it covers. */
|
|
10
|
+
timeField: string;
|
|
11
|
+
/** A quick range's short name on its button: "7D", "12M". */
|
|
12
|
+
shortRange: (r: {
|
|
13
|
+
last: number;
|
|
14
|
+
unit: string;
|
|
15
|
+
}) => string;
|
|
16
|
+
/** The labels of a fixed range's first and last day. */
|
|
17
|
+
fromDay: string;
|
|
18
|
+
toDay: string;
|
|
19
|
+
breakdown: string;
|
|
20
|
+
timeRange: string;
|
|
21
|
+
/** A range that moves with today: "Last 6 months". */
|
|
22
|
+
rolling: string;
|
|
23
|
+
/** A range of fixed days. */
|
|
24
|
+
betweenDates: string;
|
|
25
|
+
last: string;
|
|
26
|
+
/** A rolling range's last unit counts so far: "Including today", "Including this month so far". */
|
|
27
|
+
withCurrent: (unit: RangeUnit) => string;
|
|
28
|
+
/** The plural of a unit, for the unit picker: "months". */
|
|
29
|
+
units: Record<RangeUnit, string>;
|
|
30
|
+
/** The unit picker's name, for a screen reader. */
|
|
31
|
+
unit: string;
|
|
32
|
+
rangeTo: string;
|
|
33
|
+
bothDaysIncluded: string;
|
|
34
|
+
endBeforeStart: string;
|
|
35
|
+
/** Each operator as the filter editor offers it: "more than", "doesn't contain". */
|
|
36
|
+
ops: Record<Op, string>;
|
|
37
|
+
/** A condition's test in words: "is done, review", "between 2 and 8", "is empty". */
|
|
38
|
+
filterTest: (op: Op, values: readonly string[]) => string;
|
|
39
|
+
/** How a group or the whole filter matches: all, any or none of its parts. */
|
|
40
|
+
modes: Record<GroupMode, string>;
|
|
41
|
+
/** "Rows matching" … "all" … "of these:". */
|
|
42
|
+
matching: string;
|
|
43
|
+
ofThese: string;
|
|
44
|
+
addGroup: string;
|
|
45
|
+
addToGroup: string;
|
|
46
|
+
removeGroup: string;
|
|
47
|
+
/** A part set in code the builder cannot edit, kept as it is on Save. */
|
|
48
|
+
keptAsWritten: string;
|
|
49
|
+
keptNested: string;
|
|
50
|
+
value: string;
|
|
51
|
+
/** Under between: "Both ends included." */
|
|
52
|
+
bothEnds: string;
|
|
53
|
+
/** The chip that opens a formula of your own. */
|
|
54
|
+
formula: string;
|
|
55
|
+
/** Under a formula that reads: what it uses, and what a division by zero shows. */
|
|
56
|
+
formulaUses: (names: readonly string[]) => string;
|
|
57
|
+
formulaProblem: (problem: FormulaProblem) => string;
|
|
58
|
+
addCalculation: string;
|
|
59
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/builder/words.ts
|
|
2
|
+
const ENGLISH_OPS = {
|
|
3
|
+
equals: "is",
|
|
4
|
+
in: "is",
|
|
5
|
+
notEquals: "is not",
|
|
6
|
+
notIn: "is not",
|
|
7
|
+
contains: "contains",
|
|
8
|
+
notContains: "doesn't contain",
|
|
9
|
+
startsWith: "starts with",
|
|
10
|
+
gt: "more than",
|
|
11
|
+
gte: "at least",
|
|
12
|
+
lt: "less than",
|
|
13
|
+
lte: "at most",
|
|
14
|
+
between: "between",
|
|
15
|
+
set: "has a value",
|
|
16
|
+
notSet: "is empty"
|
|
17
|
+
};
|
|
18
|
+
const ENGLISH_BUILDER = {
|
|
19
|
+
customRange: "Custom",
|
|
20
|
+
timeField: "Field",
|
|
21
|
+
shortRange: (r) => `${String(r.last)}${r.unit.charAt(0).toUpperCase()}`,
|
|
22
|
+
fromDay: "From",
|
|
23
|
+
toDay: "To",
|
|
24
|
+
breakdown: "Breakdown",
|
|
25
|
+
timeRange: "Range",
|
|
26
|
+
rolling: "Rolling",
|
|
27
|
+
betweenDates: "Between dates",
|
|
28
|
+
last: "Last",
|
|
29
|
+
withCurrent: (unit) => unit === "day" ? "Including today" : `Including this ${unit} so far`,
|
|
30
|
+
unit: "Unit",
|
|
31
|
+
units: {
|
|
32
|
+
day: "days",
|
|
33
|
+
week: "weeks",
|
|
34
|
+
month: "months",
|
|
35
|
+
quarter: "quarters",
|
|
36
|
+
year: "years"
|
|
37
|
+
},
|
|
38
|
+
rangeTo: "to",
|
|
39
|
+
bothDaysIncluded: "Both days included, in the dashboard's time zone.",
|
|
40
|
+
endBeforeStart: "The end is before the start.",
|
|
41
|
+
ops: ENGLISH_OPS,
|
|
42
|
+
filterTest: (op, values) => {
|
|
43
|
+
const word = ENGLISH_OPS[op];
|
|
44
|
+
if (op === "set" || op === "notSet") return word;
|
|
45
|
+
if (op === "between") return `between ${values[0] ?? ""} and ${values[1] ?? ""}`;
|
|
46
|
+
return `${word} ${values.join(", ")}`;
|
|
47
|
+
},
|
|
48
|
+
modes: {
|
|
49
|
+
all: "all",
|
|
50
|
+
any: "any",
|
|
51
|
+
none: "none"
|
|
52
|
+
},
|
|
53
|
+
matching: "Rows matching",
|
|
54
|
+
ofThese: "of these:",
|
|
55
|
+
addGroup: "+ Group",
|
|
56
|
+
addToGroup: "+ Add to this group",
|
|
57
|
+
removeGroup: "Remove group",
|
|
58
|
+
keptAsWritten: "set in code, kept as is",
|
|
59
|
+
keptNested: "Conditions set in code, kept as written",
|
|
60
|
+
value: "Value",
|
|
61
|
+
bothEnds: "Both ends included.",
|
|
62
|
+
formula: "Formula",
|
|
63
|
+
formulaUses: (names) => `Uses ${names.join(", ")}. A division by zero shows as empty.`,
|
|
64
|
+
formulaProblem: (p) => {
|
|
65
|
+
if (p.kind === "empty") return "Write a formula, like Hours logged / Tasks.";
|
|
66
|
+
if (p.kind === "unknown") return `"${p.text}" is not a measure here, at character ${String(p.at)}.`;
|
|
67
|
+
if (p.kind === "unclosed") return `The bracket at character ${String(p.at)} is never closed.`;
|
|
68
|
+
if (p.kind === "unopened") return `A closing bracket has no opening one, at character ${String(p.at)}.`;
|
|
69
|
+
return `Expected a number, a measure or a bracket at character ${String(p.at)}.`;
|
|
70
|
+
},
|
|
71
|
+
addCalculation: "Add calculation"
|
|
72
|
+
};
|
|
73
|
+
export { ENGLISH_BUILDER };
|
package/dist/react/context.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DashboardsClient } from "./client.mjs";
|
|
2
|
+
import { FilterBarProps } from "./filters/hooks.mjs";
|
|
3
|
+
import "./FilterBar.mjs";
|
|
2
4
|
import { Messages } from "./messages.mjs";
|
|
3
5
|
import { TileRenderer } from "./renderers/index.mjs";
|
|
4
6
|
import { ComponentType, MouseEvent, ReactNode } from "react";
|
|
@@ -14,6 +16,7 @@ export type LinkProps = {
|
|
|
14
16
|
export type LinkComponent = ComponentType<LinkProps>;
|
|
15
17
|
type Value = {
|
|
16
18
|
client: DashboardsClient;
|
|
19
|
+
components: Components;
|
|
17
20
|
link?: LinkComponent;
|
|
18
21
|
renderers: Record<string, TileRenderer>;
|
|
19
22
|
locale?: string;
|
|
@@ -39,8 +42,18 @@ export type DashboardsProviderProps = {
|
|
|
39
42
|
authorName?: (author: Author) => string | undefined;
|
|
40
43
|
/** The link component every link the library draws uses, so they go through your router. */
|
|
41
44
|
link?: LinkComponent;
|
|
45
|
+
/**
|
|
46
|
+
* Parts of the dashboard you draw yourself, each given the same props as the built-in one:
|
|
47
|
+
* `{ FilterBar }` swaps the filter bar, for example the shadcn one
|
|
48
|
+
* (`npx shadcn@latest add ./node_modules/derive-dashboards/dist/registry/filter-bar.json`).
|
|
49
|
+
*/
|
|
50
|
+
components?: Partial<Components>;
|
|
42
51
|
children: ReactNode;
|
|
43
52
|
};
|
|
53
|
+
/** The parts a host may draw itself. Each defaults to the library's own. */
|
|
54
|
+
export type Components = {
|
|
55
|
+
FilterBar: ComponentType<FilterBarProps>;
|
|
56
|
+
};
|
|
44
57
|
export declare function DashboardsProvider(props: DashboardsProviderProps): import("react").JSX.Element;
|
|
45
58
|
export declare function useDashboards(): Value;
|
|
46
59
|
export {};
|
package/dist/react/context.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FilterBar } from "./filters/bar.mjs";
|
|
1
2
|
import { ENGLISH } from "./english.mjs";
|
|
2
3
|
import { BUILTIN_RENDERERS } from "./renderers/index.mjs";
|
|
3
4
|
import { createContext, useContext, useMemo } from "react";
|
|
@@ -18,7 +19,7 @@ const Context = createContext(null);
|
|
|
18
19
|
/** A cache of the provider's own, so answers never mix with the host's or another viewer's. */
|
|
19
20
|
const ownCache = { provider: () => /* @__PURE__ */ new Map() };
|
|
20
21
|
function DashboardsProvider(props) {
|
|
21
|
-
const { client, renderers, locale, messages, viewerKey, authorName, link, children } = props;
|
|
22
|
+
const { client, renderers, locale, messages, viewerKey, authorName, link, components, children } = props;
|
|
22
23
|
const cacheScope = `${viewerKey ?? ""}:${String(clientId(client))}`;
|
|
23
24
|
const value = useMemo(() => ({
|
|
24
25
|
client,
|
|
@@ -33,7 +34,11 @@ function DashboardsProvider(props) {
|
|
|
33
34
|
...messages
|
|
34
35
|
},
|
|
35
36
|
...authorName === void 0 ? {} : { authorName },
|
|
36
|
-
...link === void 0 ? {} : { link }
|
|
37
|
+
...link === void 0 ? {} : { link },
|
|
38
|
+
components: {
|
|
39
|
+
FilterBar,
|
|
40
|
+
...components
|
|
41
|
+
}
|
|
37
42
|
}), [
|
|
38
43
|
client,
|
|
39
44
|
cacheScope,
|
|
@@ -41,7 +46,8 @@ function DashboardsProvider(props) {
|
|
|
41
46
|
locale,
|
|
42
47
|
messages,
|
|
43
48
|
authorName,
|
|
44
|
-
link
|
|
49
|
+
link,
|
|
50
|
+
components
|
|
45
51
|
]);
|
|
46
52
|
return /* @__PURE__ */ jsx(SWRConfig, {
|
|
47
53
|
value: ownCache,
|
|
@@ -32,7 +32,7 @@ export declare function useDrill({ state, onStateChange }: DrillOptions): {
|
|
|
32
32
|
hasMore: boolean;
|
|
33
33
|
loadingMore: boolean;
|
|
34
34
|
};
|
|
35
|
-
status: "
|
|
35
|
+
status: "error" | "ready" | "loading";
|
|
36
36
|
/** A new view of the same step is loading: the last one stays, its controls with it. */
|
|
37
37
|
updating: boolean;
|
|
38
38
|
error: Error | undefined;
|
|
@@ -70,6 +70,9 @@ export type DrillMessages = {
|
|
|
70
70
|
drillCut: string;
|
|
71
71
|
/** A number's value in the period before: "Before: 30". */
|
|
72
72
|
drillBefore: (value: string) => string;
|
|
73
|
+
/** A number tile's change against the period before: "+17 from 0", or no change. */
|
|
74
|
+
beforeChange: (change: string, before: string) => string;
|
|
75
|
+
beforeSame: (before: string) => string;
|
|
73
76
|
/** A step that is the whole of the period before, in the breadcrumb. */
|
|
74
77
|
drillPeriodBefore: string;
|
|
75
78
|
/** The Items table's first column when the source names no noun. */
|
|
@@ -52,6 +52,8 @@ const ENGLISH_DRILL = {
|
|
|
52
52
|
drillSearch: "Search",
|
|
53
53
|
drillOnly: (numerator, count) => `Only ${numerator} (${count})`,
|
|
54
54
|
drillBefore: (value) => `Before: ${value}`,
|
|
55
|
+
beforeChange: (change, before) => `${change} from ${before}`,
|
|
56
|
+
beforeSame: (before) => `No change from ${before}`,
|
|
55
57
|
drillPeriodBefore: "The period before",
|
|
56
58
|
drillItem: "Item",
|
|
57
59
|
drillCut: "Only the first rows of this answer open; narrow the filters to open the rest.",
|
package/dist/react/english.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { ENGLISH_BUILDER } from "./builder/words.mjs";
|
|
1
2
|
import { ENGLISH_DRILL } from "./drill/words.mjs";
|
|
3
|
+
import { relativeLabel } from "./filters/days.mjs";
|
|
2
4
|
import { ENGLISH_REVIEW } from "./review-words.mjs";
|
|
3
5
|
// src/english.ts
|
|
4
6
|
/** Every word the built-in components show, in English: the default `messages`. */
|
|
5
7
|
const ENGLISH = {
|
|
6
8
|
...ENGLISH_REVIEW,
|
|
7
9
|
...ENGLISH_DRILL,
|
|
10
|
+
...ENGLISH_BUILDER,
|
|
8
11
|
other: "Other",
|
|
9
12
|
total: "Total",
|
|
10
13
|
empty: "None",
|
|
@@ -13,6 +16,7 @@ const ENGLISH = {
|
|
|
13
16
|
noAccess: "You don't have access to this data",
|
|
14
17
|
noData: "No data for this range",
|
|
15
18
|
noRows: "No rows",
|
|
19
|
+
soFar: "so far",
|
|
16
20
|
dashboardFailed: "This dashboard could not be loaded.",
|
|
17
21
|
dashboardUnreachable: "Can't reach the server. Showing what was last loaded; it updates when the connection is back.",
|
|
18
22
|
dashboardMissing: "This dashboard isn't here. It may not be published yet, or it was removed.",
|
|
@@ -25,11 +29,7 @@ const ENGLISH = {
|
|
|
25
29
|
rowsBehind: (title) => `Rows behind ${title}`,
|
|
26
30
|
notFilteredBy: (controls) => `Not filtered by ${controls.join(", ")}`,
|
|
27
31
|
firstRows: (count) => `Showing the first ${count} rows`,
|
|
28
|
-
range:
|
|
29
|
-
if (last === 1 && includeCurrent) return `This ${unit}`;
|
|
30
|
-
const plural = last === 1 ? unit : `${unit}s`;
|
|
31
|
-
return `Last ${last} ${includeCurrent ? "" : "complete "}${plural}`;
|
|
32
|
-
},
|
|
32
|
+
range: relativeLabel,
|
|
33
33
|
untitledWidget: "Untitled widget",
|
|
34
34
|
save: "Save",
|
|
35
35
|
cancel: "Cancel",
|
|
@@ -103,6 +103,17 @@ const ENGLISH = {
|
|
|
103
103
|
previous: "previous period"
|
|
104
104
|
},
|
|
105
105
|
removedCalcs: (names) => `Removed ${names.join(", ")}: a change compares the whole range with the one before, so it needs no breakdown and a comparison.`,
|
|
106
|
+
noMainQuery: (title) => `${title} has no main query, so the builder cannot edit it. Change it where it was made (in code, or by its plugin).`,
|
|
107
|
+
notDrawn: (labels) => `Not drawn here: ${labels.join(", ")}. Show it as a table to see ${labels.length === 1 ? "it" : "them"}.`,
|
|
108
|
+
chartTable: ({ title, kind, points }) => `${title}, a ${kind} chart of ${String(points)} ${points === 1 ? "point" : "points"}`,
|
|
109
|
+
chartPoints: "Points to open (arrow keys move between them)",
|
|
110
|
+
keptAside: ({ display, queries, fields }) => {
|
|
111
|
+
return `Kept as they are: ${[
|
|
112
|
+
...display ? ["its display settings"] : [],
|
|
113
|
+
...fields.length === 0 ? [] : [`its own ${fields.join(", ")}`],
|
|
114
|
+
...queries.length === 0 ? [] : [`its ${queries.map((q) => `"${q}"`).join(", ")} ${queries.length === 1 ? "query" : "queries"}`]
|
|
115
|
+
].join(" and ")}. This builder edits the title, the chart and the main query.`;
|
|
116
|
+
},
|
|
106
117
|
followsFilters: (labels) => labels.length === 0 ? "On the dashboard: no dashboard filter applies to it." : `On the dashboard: follows its ${labels.join(", ")} ${labels.length === 1 ? "filter" : "filters"}.`,
|
|
107
118
|
reorder: "Drag, or use the arrow keys, to reorder",
|
|
108
119
|
edit: "Edit",
|
|
@@ -110,6 +121,7 @@ const ENGLISH = {
|
|
|
110
121
|
editing: "Editing. Only you see these changes until you publish.",
|
|
111
122
|
publish: "Publish",
|
|
112
123
|
discard: "Discard",
|
|
124
|
+
doneEditing: "Done",
|
|
113
125
|
addWidget: "+ Add widget",
|
|
114
126
|
addToDashboard: "Add to dashboard",
|
|
115
127
|
editWidget: (title) => `Edit ${title}`,
|
|
@@ -130,6 +142,9 @@ const ENGLISH = {
|
|
|
130
142
|
unreachable: "Can't reach the server. Your draft is safe as last saved; try again.",
|
|
131
143
|
removedTile: (title) => `Removed “${title}”. Undo brings it back.`,
|
|
132
144
|
tileUnreachable: "Couldn't load this tile. Check the connection and reload.",
|
|
145
|
+
readFailed: "Could not load this list.",
|
|
146
|
+
noValues: "No values to pick.",
|
|
147
|
+
copyByHand: "The browser would not copy it. Select the text below and copy it.",
|
|
133
148
|
changesDiscarded: "Changes discarded",
|
|
134
149
|
draftChanged: "Your draft changed in another tab. It has been reloaded; make that change again.",
|
|
135
150
|
draftClosed: "This draft was closed. Start editing again.",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FilterBarOptions } from "./context.mjs";
|
|
2
|
+
import { FilterBarProps } from "./hooks.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* The dashboard's filter bar, built in: one chip per filter, F to add one with typed suggestions,
|
|
5
|
+
* Shift+F to remove the last, Undo, Reset. Unset filters past the first `pinned` wait in the
|
|
6
|
+
* Filter menu, so a dashboard with many filters keeps one calm row; on a phone everything moves
|
|
7
|
+
* into a sheet. It reads field types, tones, buckets and units from the model.
|
|
8
|
+
*
|
|
9
|
+
* Every part carries a `dd-fb-*` class and the theme styles it in its own cascade layer, so your
|
|
10
|
+
* CSS wins without `!important`; colors and sizes are the theme's `--dd-*` variables.
|
|
11
|
+
*/
|
|
12
|
+
export declare function FilterBar({ controls, picks, onChange, timezone, ...options }: FilterBarProps & FilterBarOptions): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { Chip } from "./chip.mjs";
|
|
3
|
+
import { BarContext, useBar, useWords } from "./context.mjs";
|
|
4
|
+
import { useFilterFields } from "./hooks.mjs";
|
|
5
|
+
import { FilterMenu } from "./menu.mjs";
|
|
6
|
+
import { PhoneBar } from "./phone.mjs";
|
|
7
|
+
import { useBarPicks, useFromLink, useNarrow, useShortcuts, useShown } from "./state.mjs";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { createPortal } from "react-dom";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
// src/filters/bar.tsx
|
|
12
|
+
const PINNED = 4;
|
|
13
|
+
/** "Your view · Reset", or "From a link · Reset" while the picks are still the link's. */
|
|
14
|
+
function Status({ linked, onReset }) {
|
|
15
|
+
const words = useWords();
|
|
16
|
+
const { messages } = useDashboards();
|
|
17
|
+
const { picks } = useBar();
|
|
18
|
+
if (Object.keys(picks).length === 0) return null;
|
|
19
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
20
|
+
className: "dd-fb-status",
|
|
21
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
22
|
+
className: "dd-fb-quiet",
|
|
23
|
+
children: linked ? words.fromLink : words.yourView
|
|
24
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
25
|
+
type: "button",
|
|
26
|
+
className: "dd-fb-link",
|
|
27
|
+
onClick: onReset,
|
|
28
|
+
children: messages.reset
|
|
29
|
+
})]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** "Status filter removed · Undo", for a few seconds after a removal. */
|
|
33
|
+
function UndoToast({ undo, onUndo }) {
|
|
34
|
+
const words = useWords();
|
|
35
|
+
if (undo === null) return null;
|
|
36
|
+
return createPortal(/* @__PURE__ */ jsxs("div", {
|
|
37
|
+
className: "dd-fb dd-fb-toast",
|
|
38
|
+
role: "status",
|
|
39
|
+
"aria-live": "polite",
|
|
40
|
+
children: [undo.cleared ? words.cleared : words.removed(undo.labels), /* @__PURE__ */ jsx("button", {
|
|
41
|
+
type: "button",
|
|
42
|
+
className: "dd-fb-toast-action",
|
|
43
|
+
onClick: () => {
|
|
44
|
+
onUndo(undo);
|
|
45
|
+
},
|
|
46
|
+
children: words.undo
|
|
47
|
+
})]
|
|
48
|
+
}), document.body);
|
|
49
|
+
}
|
|
50
|
+
/** On a wider screen: the date chip, the shown filters' chips, Filter, and the status. */
|
|
51
|
+
function DesktopBar({ controls, pinned, linked, removeLast, onReset }) {
|
|
52
|
+
const words = useWords();
|
|
53
|
+
const { picks } = useBar();
|
|
54
|
+
const [menu, setMenu] = useState(false);
|
|
55
|
+
const [openId, setOpenId] = useState(null);
|
|
56
|
+
const { visible, hidden } = useShown(controls, picks, pinned);
|
|
57
|
+
const openMenu = () => {
|
|
58
|
+
setMenu(true);
|
|
59
|
+
};
|
|
60
|
+
useShortcuts(openMenu, removeLast);
|
|
61
|
+
const date = controls.find((c) => c.kind === "date_range");
|
|
62
|
+
const setOpen = (id) => (o) => {
|
|
63
|
+
setOpenId(o ? id : null);
|
|
64
|
+
};
|
|
65
|
+
const chip = (c) => /* @__PURE__ */ jsx(Chip, {
|
|
66
|
+
control: c,
|
|
67
|
+
open: openId === c.id,
|
|
68
|
+
setOpen: setOpen(c.id)
|
|
69
|
+
}, c.id);
|
|
70
|
+
const last = visible.at(-1);
|
|
71
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
72
|
+
className: "dd-fb dd-fb-bar",
|
|
73
|
+
role: "toolbar",
|
|
74
|
+
"aria-label": words.filters(0),
|
|
75
|
+
children: [
|
|
76
|
+
date === void 0 ? null : chip(date),
|
|
77
|
+
visible.slice(0, -1).map((c) => chip(c)),
|
|
78
|
+
/* @__PURE__ */ jsxs("span", {
|
|
79
|
+
className: "dd-fb-keep",
|
|
80
|
+
children: [last === void 0 ? null : chip(last), /* @__PURE__ */ jsx(FilterMenu, {
|
|
81
|
+
controls,
|
|
82
|
+
open: menu,
|
|
83
|
+
setOpen: setMenu,
|
|
84
|
+
openChip: setOpenId,
|
|
85
|
+
hidden
|
|
86
|
+
})]
|
|
87
|
+
}),
|
|
88
|
+
/* @__PURE__ */ jsx(Status, {
|
|
89
|
+
linked,
|
|
90
|
+
onReset
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The dashboard's filter bar, built in: one chip per filter, F to add one with typed suggestions,
|
|
97
|
+
* Shift+F to remove the last, Undo, Reset. Unset filters past the first `pinned` wait in the
|
|
98
|
+
* Filter menu, so a dashboard with many filters keeps one calm row; on a phone everything moves
|
|
99
|
+
* into a sheet. It reads field types, tones, buckets and units from the model.
|
|
100
|
+
*
|
|
101
|
+
* Every part carries a `dd-fb-*` class and the theme styles it in its own cascade layer, so your
|
|
102
|
+
* CSS wins without `!important`; colors and sizes are the theme's `--dd-*` variables.
|
|
103
|
+
*/
|
|
104
|
+
function FilterBar({ controls, picks, onChange, timezone, ...options }) {
|
|
105
|
+
const fields = useFilterFields(controls);
|
|
106
|
+
const narrow = useNarrow();
|
|
107
|
+
const { setPick, removeLast, reset, undo, takeBack } = useBarPicks(controls, picks, onChange);
|
|
108
|
+
const linked = useFromLink(picks);
|
|
109
|
+
if (controls.length === 0) return null;
|
|
110
|
+
const bar = {
|
|
111
|
+
fields,
|
|
112
|
+
options,
|
|
113
|
+
timezone,
|
|
114
|
+
picks,
|
|
115
|
+
setPick
|
|
116
|
+
};
|
|
117
|
+
return /* @__PURE__ */ jsxs(BarContext.Provider, {
|
|
118
|
+
value: bar,
|
|
119
|
+
children: [narrow ? /* @__PURE__ */ jsx(PhoneBar, {
|
|
120
|
+
controls,
|
|
121
|
+
removeLast,
|
|
122
|
+
onReset: reset
|
|
123
|
+
}) : /* @__PURE__ */ jsx(DesktopBar, {
|
|
124
|
+
controls,
|
|
125
|
+
pinned: options.pinned ?? PINNED,
|
|
126
|
+
linked,
|
|
127
|
+
removeLast,
|
|
128
|
+
onReset: reset
|
|
129
|
+
}), /* @__PURE__ */ jsx(UndoToast, {
|
|
130
|
+
undo,
|
|
131
|
+
onUndo: takeBack
|
|
132
|
+
})]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export { FilterBar };
|