derive-dashboards 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- package/dist/core/conformance/cases.d.mts +3 -0
- package/dist/core/conformance/cases.mjs +20 -4
- package/dist/core/conformance/check.mjs +6 -3
- package/dist/core/conformance/drill-cases.mjs +120 -0
- package/dist/core/document/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/members.mjs +1 -1
- package/dist/core/engine/postgres.mjs +1 -1
- package/dist/core/engine/record-layout.d.mts +11 -0
- package/dist/core/engine/record-layout.mjs +7 -7
- package/dist/core/engine/records.d.mts +3 -2
- package/dist/core/engine/records.mjs +2 -1
- package/dist/core/engine/segmented.mjs +5 -2
- package/dist/core/engine/sql-records.mjs +2 -1
- package/dist/core/engine/statement.mjs +37 -3
- package/dist/core/engine/types.d.mts +3 -0
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +31 -0
- package/dist/core/error/codes.mjs +28 -1
- package/dist/core/index.d.mts +9 -5
- package/dist/core/index.mjs +5 -3
- package/dist/core/model/catalog/check.mjs +1 -1
- package/dist/core/model/hints.d.mts +36 -0
- package/dist/core/model/member.d.mts +4 -2
- package/dist/core/model/member.mjs +16 -3
- package/dist/core/model/types.d.mts +8 -6
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- package/dist/core/query/alias.mjs +7 -1
- package/dist/core/query/drill/compose.d.mts +22 -0
- package/dist/core/query/drill/compose.mjs +85 -0
- package/dist/core/query/drill/fields.d.mts +21 -0
- package/dist/core/query/drill/fields.mjs +91 -0
- package/dist/core/query/drill/internal.d.mts +11 -0
- package/dist/core/query/drill/items.d.mts +29 -0
- package/dist/core/query/drill/items.mjs +98 -0
- package/dist/core/query/drill/line.d.mts +31 -0
- package/dist/core/query/drill/line.mjs +183 -0
- package/dist/core/query/drill/links.d.mts +33 -0
- package/dist/core/query/drill/links.mjs +31 -0
- package/dist/core/query/drill/operand.mjs +7 -0
- package/dist/core/query/drill/scopes.d.mts +22 -0
- package/dist/core/query/drill/scopes.mjs +58 -0
- package/dist/core/query/drill/selection.d.mts +37 -0
- package/dist/core/query/drill/selection.mjs +144 -0
- package/dist/core/query/drill/steps.d.mts +14 -0
- package/dist/core/query/drill/steps.mjs +35 -0
- package/dist/core/query/drill/synthetic-expr.mjs +85 -0
- package/dist/core/query/drill/synthetic.d.mts +22 -0
- package/dist/core/query/drill/synthetic.mjs +165 -0
- package/dist/core/query/drill/time.d.mts +11 -0
- package/dist/core/query/drill/time.mjs +71 -0
- package/dist/core/query/drill/types.d.mts +155 -0
- package/dist/core/query/drill/types.mjs +4 -0
- package/dist/core/query/drill/views.d.mts +62 -0
- package/dist/core/query/drill/views.mjs +257 -0
- package/dist/core/query/segments.d.mts +12 -2
- package/dist/core/query/segments.mjs +3 -1
- package/dist/core/result/columns.mjs +17 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2108 -128
- package/dist/core/schema/answers.mjs +10 -113
- package/dist/core/schema/commands.d.mts +2 -2
- package/dist/core/schema/document.d.mts +1 -1
- package/dist/core/schema/drill-answers.mjs +179 -0
- package/dist/core/schema/drill.d.mts +260 -0
- package/dist/core/schema/drill.mjs +107 -0
- package/dist/core/schema/index.d.mts +4 -2
- package/dist/core/schema/index.mjs +4 -2
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +1 -1
- package/dist/core/schema/tools.mjs +1 -1
- package/dist/core/schema/view.d.mts +0 -35
- package/dist/core/schema/view.mjs +19 -24
- package/dist/core/store/schema.d.mts +5 -0
- package/dist/core/store/schema.mjs +10 -0
- package/dist/core/types/api.d.mts +15 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +210 -0
- package/dist/core/types/options.d.mts +21 -0
- package/dist/core/types/viewer.d.mts +5 -0
- package/dist/cursor-seal.d.mts +8 -0
- package/dist/cursor-seal.mjs +98 -0
- package/dist/dashboard-id.mjs +1 -1
- package/dist/drill-access.mjs +93 -0
- package/dist/drill-change.mjs +76 -0
- package/dist/drill-crumbs.mjs +113 -0
- package/dist/drill-distinct.mjs +130 -0
- package/dist/drill-explain.mjs +64 -0
- package/dist/drill-identity.mjs +35 -0
- package/dist/drill-item-id.mjs +35 -0
- package/dist/drill-items.mjs +132 -0
- package/dist/drill-open.mjs +169 -0
- package/dist/drill-seal.mjs +170 -0
- package/dist/drill-secret.mjs +14 -0
- package/dist/drill-share.mjs +53 -0
- package/dist/drill-summary.mjs +158 -0
- package/dist/drill-targets.mjs +53 -0
- package/dist/drill-totals.mjs +8 -0
- package/dist/drill-views.mjs +175 -0
- package/dist/drill.mjs +157 -0
- package/dist/editing.mjs +2 -2
- package/dist/endpoints/dashboards.mjs +11 -3
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +233 -2
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +15 -17
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +27 -3
- package/dist/mcp/index.d.mts +15 -4
- package/dist/mcp/index.mjs +13 -7
- package/dist/mcp/query.d.mts +7 -2
- package/dist/mcp/query.mjs +7 -3
- package/dist/node-postgres.d.mts +8 -4
- package/dist/node-postgres.mjs +29 -6
- package/dist/owner.mjs +3 -3
- package/dist/postgres-connection.d.mts +8 -2
- package/dist/postgres-connection.mjs +2 -1
- package/dist/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +51 -23
- package/dist/react/DashboardList.mjs +30 -2
- package/dist/react/Discard.mjs +7 -2
- package/dist/react/Grid.mjs +12 -5
- package/dist/react/Header.mjs +9 -0
- package/dist/react/Parts.mjs +6 -2
- package/dist/react/ReviewPanel.mjs +13 -2
- package/dist/react/RowBody.d.mts +19 -0
- package/dist/react/RowBody.mjs +55 -0
- package/dist/react/Tile.d.mts +1 -1
- package/dist/react/Tile.mjs +54 -30
- package/dist/react/builder/state.d.mts +1 -1
- package/dist/react/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +15 -1
- package/dist/react/context.mjs +19 -4
- package/dist/react/drill/Bars.mjs +179 -0
- package/dist/react/drill/Controls.mjs +173 -0
- package/dist/react/drill/DashboardTile.d.mts +18 -0
- package/dist/react/drill/DashboardTile.mjs +107 -0
- package/dist/react/drill/DrillPanel.d.mts +31 -0
- package/dist/react/drill/DrillPanel.mjs +104 -0
- package/dist/react/drill/DrillTabs.mjs +52 -0
- package/dist/react/drill/Header.mjs +131 -0
- package/dist/react/drill/Items.d.mts +22 -0
- package/dist/react/drill/Items.mjs +164 -0
- package/dist/react/drill/ItemsFoot.mjs +60 -0
- package/dist/react/drill/Notes.mjs +58 -0
- package/dist/react/drill/PanelBody.mjs +74 -0
- package/dist/react/drill/PanelStates.mjs +37 -0
- package/dist/react/drill/board.d.mts +18 -0
- package/dist/react/drill/board.mjs +91 -0
- package/dist/react/drill/counts.mjs +14 -0
- package/dist/react/drill/host.mjs +26 -0
- package/dist/react/drill/item-parts.d.mts +5 -0
- package/dist/react/drill/item-parts.mjs +76 -0
- package/dist/react/drill/item-type.d.mts +26 -0
- package/dist/react/drill/item-type.mjs +7 -0
- package/dist/react/drill/lazy.d.mts +6 -0
- package/dist/react/drill/lazy.mjs +17 -0
- package/dist/react/drill/pages.mjs +48 -0
- package/dist/react/drill/panel-focus.mjs +51 -0
- package/dist/react/drill/props.d.mts +25 -0
- package/dist/react/drill/props.mjs +72 -0
- package/dist/react/drill/state.d.mts +18 -0
- package/dist/react/drill/state.mjs +68 -0
- package/dist/react/drill/useDrill.d.mts +46 -0
- package/dist/react/drill/useDrill.mjs +194 -0
- package/dist/react/drill/words.d.mts +98 -0
- package/dist/react/drill/words.mjs +77 -0
- package/dist/react/english.mjs +9 -1
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +34 -12
- package/dist/react/index.d.mts +27 -4
- package/dist/react/index.mjs +10 -3
- package/dist/react/messages.d.mts +14 -1
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +54 -14
- package/dist/react/renderers/list.d.mts +22 -0
- package/dist/react/renderers/list.mjs +118 -0
- package/dist/react/review-words.mjs +1 -1
- package/dist/react/review.mjs +2 -2
- package/dist/react/scope.mjs +2 -7
- package/dist/react/series.d.mts +37 -0
- package/dist/react/series.mjs +95 -0
- package/dist/react/theme.css +1823 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +5 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +1 -0
- package/dist/react/useDashboard.mjs +2 -1
- package/dist/react/useTiles.mjs +50 -15
- package/dist/react/view.d.mts +9 -0
- package/dist/react/view.mjs +22 -10
- package/dist/reading.d.mts +2 -0
- package/dist/reading.mjs +9 -1
- package/dist/recharts/charts.d.mts +0 -1
- package/dist/recharts/charts.mjs +128 -34
- package/dist/recharts/index.d.mts +2 -2
- package/dist/recharts/index.mjs +2 -2
- package/dist/recharts/marks.mjs +83 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/records-read.mjs +44 -0
- package/dist/store/apply.mjs +5 -5
- package/dist/store/commands.mjs +4 -4
- package/dist/store/discard.mjs +7 -7
- package/dist/store/drafts.mjs +5 -5
- package/dist/store/editor.mjs +1 -1
- package/dist/store/publish.mjs +12 -12
- package/dist/store/reader.mjs +41 -22
- package/dist/store/review.mjs +16 -16
- package/dist/store/rows.mjs +20 -20
- package/dist/store/undo.mjs +3 -3
- package/dist/store/unpublished.mjs +4 -4
- package/dist/store/versions.mjs +14 -14
- package/dist/testing/adapter-suite.mjs +4 -4
- package/dist/tiles.mjs +37 -3
- package/package.json +8 -10
- package/dist/react/Records.d.mts +0 -12
- package/dist/react/Records.mjs +0 -97
- package/src/adapter/sql-adapter.ts +0 -95
- package/src/adapter/statement.ts +0 -185
- package/src/authorize.ts +0 -73
- package/src/body.ts +0 -169
- package/src/bounded.ts +0 -43
- package/src/cache.ts +0 -192
- package/src/checks.ts +0 -170
- package/src/custom-source.ts +0 -59
- package/src/dashboard-id.ts +0 -36
- package/src/dashboards.ts +0 -132
- package/src/editing.ts +0 -148
- package/src/endpoints/access.ts +0 -41
- package/src/endpoints/dashboards.ts +0 -92
- package/src/endpoints/drafts.ts +0 -138
- package/src/endpoints/index.ts +0 -21
- package/src/endpoints/meta.ts +0 -137
- package/src/endpoints/query.ts +0 -86
- package/src/endpoints/read.ts +0 -92
- package/src/endpoints/review.ts +0 -89
- package/src/endpoints/values.ts +0 -62
- package/src/endpoints/versions.ts +0 -104
- package/src/execute.ts +0 -207
- package/src/handler.ts +0 -232
- package/src/http.ts +0 -66
- package/src/index.ts +0 -163
- package/src/introspect.ts +0 -205
- package/src/mcp/api.ts +0 -59
- package/src/mcp/format.ts +0 -67
- package/src/mcp/index.ts +0 -151
- package/src/mcp/query.ts +0 -153
- package/src/mcp/resolve.ts +0 -114
- package/src/node-postgres.ts +0 -81
- package/src/owner.ts +0 -36
- package/src/postgres-connection.ts +0 -143
- package/src/postgres-store.ts +0 -82
- package/src/principal.ts +0 -39
- package/src/reading.ts +0 -56
- package/src/request-rows.ts +0 -23
- package/src/request.ts +0 -22
- package/src/storage.ts +0 -63
- package/src/store/apply.ts +0 -129
- package/src/store/commands.ts +0 -75
- package/src/store/conflicts.ts +0 -98
- package/src/store/create-tables.ts +0 -104
- package/src/store/discard.ts +0 -42
- package/src/store/drafts.ts +0 -133
- package/src/store/editor.ts +0 -28
- package/src/store/log.ts +0 -28
- package/src/store/publish.ts +0 -199
- package/src/store/publisher.ts +0 -21
- package/src/store/reader.ts +0 -139
- package/src/store/review.ts +0 -239
- package/src/store/rows.ts +0 -250
- package/src/store/tenant.ts +0 -28
- package/src/store/undo.ts +0 -56
- package/src/store/unpublished.ts +0 -33
- package/src/store/versions.ts +0 -106
- package/src/store/writer.ts +0 -19
- package/src/testing/adapter-suite.ts +0 -239
- package/src/testing/index.ts +0 -2
- package/src/tile-doc.ts +0 -46
- package/src/tiles.ts +0 -120
package/dist/react/Tile.d.mts
CHANGED
|
@@ -14,7 +14,7 @@ type Props = {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
|
|
17
|
-
* on request. It draws again only when one of its props changes.
|
|
17
|
+
* on request (Rows opens its drill on Items). It draws again only when one of its props changes.
|
|
18
18
|
*/
|
|
19
19
|
export declare const Tile: import("react").MemoExoticComponent<(props: Props) => import("react").JSX.Element>;
|
|
20
20
|
export {};
|
package/dist/react/Tile.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useDashboards } from "./context.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useTileDrill } from "./drill/host.mjs";
|
|
3
|
+
import { formatInstantAt } from "./format.mjs";
|
|
4
|
+
import { memo } from "react";
|
|
4
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
// src/Tile.tsx
|
|
6
7
|
/** Refusals that last only until the dashboard is read again, never shown as errors. */
|
|
7
8
|
const PASSING = /* @__PURE__ */ new Set(["VERSION_CONFLICT", "TILE_UNKNOWN"]);
|
|
8
9
|
/** The answer's state when there is nothing to draw yet or instead: waiting, refused, unreadable, empty. */
|
|
9
|
-
function TileState({ result, loading }) {
|
|
10
|
+
function TileState({ result, loading, empty }) {
|
|
10
11
|
const { messages } = useDashboards();
|
|
11
12
|
if (result === void 0 || "error" in result && PASSING.has(result.error.code)) {
|
|
12
13
|
const busy = result !== void 0 || loading;
|
|
@@ -31,24 +32,30 @@ function TileState({ result, loading }) {
|
|
|
31
32
|
});
|
|
32
33
|
return /* @__PURE__ */ jsx("div", {
|
|
33
34
|
className: "dd-tile-state",
|
|
34
|
-
children:
|
|
35
|
+
children: empty
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
/** Whether an answer has rows to draw. */
|
|
38
39
|
const drawable = (result) => result !== void 0 && !("error" in result) && result.unreadable !== true && result.rows.length > 0;
|
|
39
40
|
/** The answer drawn: a memo of its own, so a change to the tile's buttons or badge never draws the chart again. */
|
|
40
|
-
const Body = memo(function Body({ widget, result, loading }) {
|
|
41
|
-
const { renderers, locale, messages } = useDashboards();
|
|
42
|
-
if (!drawable(result))
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const Body = memo(function Body({ widget, result, loading, drill }) {
|
|
42
|
+
const { renderers, locale, messages, link } = useDashboards();
|
|
43
|
+
if (!drawable(result)) {
|
|
44
|
+
const empty = widget.display?.["empty"];
|
|
45
|
+
return /* @__PURE__ */ jsx(TileState, {
|
|
46
|
+
result,
|
|
47
|
+
loading,
|
|
48
|
+
empty: typeof empty === "string" ? empty : messages.noData
|
|
49
|
+
});
|
|
50
|
+
}
|
|
46
51
|
const Renderer = renderers[widget.kind] ?? renderers["table"];
|
|
47
52
|
return Renderer === void 0 ? null : /* @__PURE__ */ jsx(Renderer, {
|
|
48
53
|
answer: result,
|
|
49
54
|
widget,
|
|
50
55
|
messages,
|
|
51
|
-
...locale === void 0 ? {} : { locale }
|
|
56
|
+
...locale === void 0 ? {} : { locale },
|
|
57
|
+
...drill === void 0 ? {} : { drill },
|
|
58
|
+
...link === void 0 ? {} : { link }
|
|
52
59
|
});
|
|
53
60
|
});
|
|
54
61
|
/** Notes under a tile: a viewer's filter that could not apply, or an answer cut at the row cap. */
|
|
@@ -56,27 +63,48 @@ function Notes({ result, controlLabels }) {
|
|
|
56
63
|
const { messages } = useDashboards();
|
|
57
64
|
if (result === void 0 || "error" in result) return null;
|
|
58
65
|
const dropped = result.receipt.coverage.dropped.map((id) => controlLabels?.get(id) ?? id);
|
|
59
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
67
|
+
dropped.length === 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
68
|
+
className: "dd-tile-note",
|
|
69
|
+
children: messages.notFilteredBy(dropped)
|
|
70
|
+
}),
|
|
71
|
+
result.status === "truncated" ? /* @__PURE__ */ jsx("p", {
|
|
72
|
+
className: "dd-tile-note",
|
|
73
|
+
children: messages.firstRows(result.rows.length)
|
|
74
|
+
}) : null,
|
|
75
|
+
result.drill?.reason === void 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
76
|
+
className: "dd-tile-note",
|
|
77
|
+
children: messages.drillCut
|
|
78
|
+
})
|
|
79
|
+
] });
|
|
66
80
|
}
|
|
67
81
|
/** Whether a tile has rows behind it to show: an answer the viewer can read. */
|
|
68
82
|
const hasRows = (result) => result !== void 0 && !("error" in result) && result.unreadable !== true && result.rows.length > 0;
|
|
83
|
+
/** The time a tile's answer covers, as it read it ("Oct 15, 2026 to Nov 14, 2026"), so a reader knows its window. */
|
|
84
|
+
function Span({ result }) {
|
|
85
|
+
const format = useDashboards();
|
|
86
|
+
if (result === void 0 || "error" in result) return null;
|
|
87
|
+
const range = result.receipt.range;
|
|
88
|
+
if (range === void 0) return null;
|
|
89
|
+
const zone = result.receipt.calendar.timezone;
|
|
90
|
+
const day = (at) => formatInstantAt(at, "day", format.locale, zone);
|
|
91
|
+
return /* @__PURE__ */ jsx("p", {
|
|
92
|
+
className: "dd-tile-span",
|
|
93
|
+
children: format.messages.drillRange(day(range.from), day(range.to))
|
|
94
|
+
});
|
|
95
|
+
}
|
|
69
96
|
/**
|
|
70
97
|
* One widget: its title, then its answer, a refusal, or an empty state; and the rows behind it
|
|
71
|
-
* on request. It draws again only when one of its props changes.
|
|
98
|
+
* on request (Rows opens its drill on Items). It draws again only when one of its props changes.
|
|
72
99
|
*/
|
|
73
100
|
const Tile = memo(function Tile(props) {
|
|
74
101
|
const { messages } = useDashboards();
|
|
75
|
-
const
|
|
102
|
+
const drill = useTileDrill(props.widgetId, props.result);
|
|
76
103
|
return /* @__PURE__ */ jsxs("section", {
|
|
77
104
|
className: "dd-tile",
|
|
78
105
|
"aria-busy": props.loading,
|
|
79
106
|
"data-kind": props.widget.kind,
|
|
107
|
+
"data-widget": props.widgetId,
|
|
80
108
|
children: [
|
|
81
109
|
/* @__PURE__ */ jsxs("header", {
|
|
82
110
|
className: "dd-tile-header",
|
|
@@ -84,36 +112,32 @@ const Tile = memo(function Tile(props) {
|
|
|
84
112
|
/* @__PURE__ */ jsx("h3", {
|
|
85
113
|
className: "dd-tile-title",
|
|
86
114
|
title: props.widget.title,
|
|
115
|
+
tabIndex: -1,
|
|
87
116
|
children: props.widget.title
|
|
88
117
|
}),
|
|
89
118
|
props.badge,
|
|
90
119
|
/* @__PURE__ */ jsxs("span", {
|
|
91
120
|
className: "dd-tile-actions",
|
|
92
|
-
children: [hasRows(props.result) ? /* @__PURE__ */ jsx("button", {
|
|
121
|
+
children: [hasRows(props.result) && drill !== void 0 ? /* @__PURE__ */ jsx("button", {
|
|
93
122
|
type: "button",
|
|
94
123
|
className: "dd-tile-rows",
|
|
95
124
|
"aria-label": messages.rowsBehind(props.widget.title),
|
|
96
125
|
onClick: () => {
|
|
97
|
-
|
|
126
|
+
drill.openAll();
|
|
98
127
|
},
|
|
99
128
|
children: messages.rows
|
|
100
129
|
}) : null, props.actions]
|
|
101
130
|
})
|
|
102
131
|
]
|
|
103
132
|
}),
|
|
104
|
-
|
|
105
|
-
widgetId: props.widgetId,
|
|
106
|
-
widget: props.widget,
|
|
107
|
-
onClose: () => {
|
|
108
|
-
setOpen(false);
|
|
109
|
-
}
|
|
110
|
-
}) : null,
|
|
133
|
+
/* @__PURE__ */ jsx(Span, { result: props.result }),
|
|
111
134
|
/* @__PURE__ */ jsx("div", {
|
|
112
135
|
className: "dd-tile-body",
|
|
113
136
|
children: /* @__PURE__ */ jsx(Body, {
|
|
114
137
|
widget: props.widget,
|
|
115
138
|
result: props.result,
|
|
116
|
-
loading: props.result === void 0 && props.loading
|
|
139
|
+
loading: props.result === void 0 && props.loading,
|
|
140
|
+
drill
|
|
117
141
|
})
|
|
118
142
|
}),
|
|
119
143
|
/* @__PURE__ */ jsx(Notes, { ...props })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./base.mjs";
|
|
2
2
|
import "./labels.mjs";
|
|
3
|
-
import { DateRange, Grain, StoredQuery } from "derive-dashboards/core";
|
|
3
|
+
import { DateRange, Grain, Primitive, StoredQuery } from "derive-dashboards/core";
|
|
4
4
|
type Time = NonNullable<StoredQuery["time"]>;
|
|
5
5
|
/** A change to the time part. A grain of "total" is one total; a compare of "none" drops it. */
|
|
6
6
|
export type TimeChange = {
|
package/dist/react/client.d.mts
CHANGED
|
@@ -20,6 +20,8 @@ export type DashboardsClient = {
|
|
|
20
20
|
memberValues(request: BodyOf<"/meta/values">): Answer<"/meta/values">;
|
|
21
21
|
/** A page of the rows behind a tile, under the same filters as its answer. */
|
|
22
22
|
records(request: BodyOf<"/dashboards/records">): Answer<"/dashboards/records">;
|
|
23
|
+
/** The rows behind a mark: of a dashboard's tile, or (origin `query`) of a free query. */
|
|
24
|
+
drill(request: BodyOf<"/dashboards/drill">, signal?: AbortSignal): Answer<"/dashboards/drill">;
|
|
23
25
|
/** The caller's open draft of a dashboard, or a new one from its current version. */
|
|
24
26
|
startDraft(dashboardId: string): Answer<"/dashboards/draft/start">;
|
|
25
27
|
/** A draft of a new dashboard, which only its maker sees until they publish it; `requestId` makes a retry create it once. */
|
package/dist/react/client.mjs
CHANGED
|
@@ -85,6 +85,7 @@ function methods(core) {
|
|
|
85
85
|
getDashboard: (dashboardId) => core("/dashboards/get", { dashboardId }),
|
|
86
86
|
controlValues: (body) => core("/dashboards/control-values", body),
|
|
87
87
|
records: (body) => core("/dashboards/records", body),
|
|
88
|
+
drill: (body, signal) => body.state.origin.kind === "query" ? core("/query/drill", body, signal) : core("/dashboards/drill", body, signal),
|
|
88
89
|
queryRun: (query, signal) => core("/query/run", { query }, signal),
|
|
89
90
|
memberValues: (body) => core("/meta/values", body),
|
|
90
91
|
startDraft: (dashboardId) => core("/dashboards/draft/start", { dashboardId }),
|
package/dist/react/context.d.mts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { DashboardsClient } from "./client.mjs";
|
|
2
2
|
import { Messages } from "./messages.mjs";
|
|
3
3
|
import { TileRenderer } from "./renderers/index.mjs";
|
|
4
|
-
import { ReactNode } from "react";
|
|
4
|
+
import { ComponentType, MouseEvent, ReactNode } from "react";
|
|
5
5
|
import { Author } from "derive-dashboards/core";
|
|
6
|
+
/** The props every link the library draws passes: a router's link component takes them. */
|
|
7
|
+
export type LinkProps = {
|
|
8
|
+
href: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
|
|
12
|
+
};
|
|
13
|
+
/** A link component, such as Next.js's `Link`; a plain `<a>` by default. */
|
|
14
|
+
export type LinkComponent = ComponentType<LinkProps>;
|
|
6
15
|
type Value = {
|
|
7
16
|
client: DashboardsClient;
|
|
17
|
+
link?: LinkComponent;
|
|
8
18
|
renderers: Record<string, TileRenderer>;
|
|
9
19
|
locale?: string;
|
|
10
20
|
messages: Messages;
|
|
11
21
|
authorName?: (author: Author) => string | undefined;
|
|
22
|
+
/** Who answers and for whom: the viewer's key and the client, so no cache serves another viewer. */
|
|
23
|
+
cacheScope: string;
|
|
12
24
|
};
|
|
13
25
|
export type DashboardsProviderProps = {
|
|
14
26
|
client: DashboardsClient;
|
|
@@ -25,6 +37,8 @@ export type DashboardsProviderProps = {
|
|
|
25
37
|
viewerKey?: string;
|
|
26
38
|
/** A person's or agent's name, for the history; without it, versions show only when. */
|
|
27
39
|
authorName?: (author: Author) => string | undefined;
|
|
40
|
+
/** The link component every link the library draws uses, so they go through your router. */
|
|
41
|
+
link?: LinkComponent;
|
|
28
42
|
children: ReactNode;
|
|
29
43
|
};
|
|
30
44
|
export declare function DashboardsProvider(props: DashboardsProviderProps): import("react").JSX.Element;
|
package/dist/react/context.mjs
CHANGED
|
@@ -4,13 +4,25 @@ import { createContext, useContext, useMemo } from "react";
|
|
|
4
4
|
import { SWRConfig } from "swr";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
// src/context.tsx
|
|
7
|
+
/** A stable number per client, so a new client starts its own caches. */
|
|
8
|
+
const clientIds = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
const counted = { clients: 0 };
|
|
10
|
+
function clientId(client) {
|
|
11
|
+
const known = clientIds.get(client);
|
|
12
|
+
if (known !== void 0) return known;
|
|
13
|
+
counted.clients += 1;
|
|
14
|
+
clientIds.set(client, counted.clients);
|
|
15
|
+
return counted.clients;
|
|
16
|
+
}
|
|
7
17
|
const Context = createContext(null);
|
|
8
18
|
/** A cache of the provider's own, so answers never mix with the host's or another viewer's. */
|
|
9
19
|
const ownCache = { provider: () => /* @__PURE__ */ new Map() };
|
|
10
20
|
function DashboardsProvider(props) {
|
|
11
|
-
const { client, renderers, locale, messages, viewerKey, authorName, children } = props;
|
|
21
|
+
const { client, renderers, locale, messages, viewerKey, authorName, link, children } = props;
|
|
22
|
+
const cacheScope = `${viewerKey ?? ""}:${String(clientId(client))}`;
|
|
12
23
|
const value = useMemo(() => ({
|
|
13
24
|
client,
|
|
25
|
+
cacheScope,
|
|
14
26
|
renderers: {
|
|
15
27
|
...BUILTIN_RENDERERS,
|
|
16
28
|
...renderers
|
|
@@ -20,13 +32,16 @@ function DashboardsProvider(props) {
|
|
|
20
32
|
...ENGLISH,
|
|
21
33
|
...messages
|
|
22
34
|
},
|
|
23
|
-
...authorName === void 0 ? {} : { authorName }
|
|
35
|
+
...authorName === void 0 ? {} : { authorName },
|
|
36
|
+
...link === void 0 ? {} : { link }
|
|
24
37
|
}), [
|
|
25
38
|
client,
|
|
39
|
+
cacheScope,
|
|
26
40
|
renderers,
|
|
27
41
|
locale,
|
|
28
42
|
messages,
|
|
29
|
-
authorName
|
|
43
|
+
authorName,
|
|
44
|
+
link
|
|
30
45
|
]);
|
|
31
46
|
return /* @__PURE__ */ jsx(SWRConfig, {
|
|
32
47
|
value: ownCache,
|
|
@@ -34,7 +49,7 @@ function DashboardsProvider(props) {
|
|
|
34
49
|
value,
|
|
35
50
|
children
|
|
36
51
|
})
|
|
37
|
-
},
|
|
52
|
+
}, cacheScope);
|
|
38
53
|
}
|
|
39
54
|
function useDashboards() {
|
|
40
55
|
const value = useContext(Context);
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { formatBucket, formatCell, plotValue } from "../format.mjs";
|
|
3
|
+
import { rowEntry } from "./state.mjs";
|
|
4
|
+
import { isMark } from "derive-dashboards/core";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/drill/Bars.tsx
|
|
7
|
+
/** A row's name: its time bucket or its group, as the tile names it ("No assignee" for no value). */
|
|
8
|
+
function rowName(view, row, format) {
|
|
9
|
+
const [cell = null] = row;
|
|
10
|
+
const [column] = view.answer.columns;
|
|
11
|
+
return isMark(cell) || cell === null || cell === "" ? markName(cell, column?.label ?? "", format) : valueName(cell, column, format);
|
|
12
|
+
}
|
|
13
|
+
/** Other, Total, or "No assignee" for a group with no value. */
|
|
14
|
+
const markName = (cell, label, format) => isMark(cell) ? cell.mark === "other" ? format.messages.other : format.messages.total : format.messages.drillNone(label);
|
|
15
|
+
/** A group's value as the tile names it: a time bucket at its grain, else the formatted value. */
|
|
16
|
+
function valueName(cell, column, format) {
|
|
17
|
+
if (column?.grain !== void 0 && typeof cell === "string") return formatBucket(cell, column.grain, format.locale);
|
|
18
|
+
return formatCell(cell, column, format);
|
|
19
|
+
}
|
|
20
|
+
/** The line's column: the one named, else the first value column. */
|
|
21
|
+
const lineAt = (view, entry) => {
|
|
22
|
+
const named = view.answer.columns.findIndex((c) => c.id === entry);
|
|
23
|
+
return named >= 0 ? named : view.answer.columns.findIndex((c) => c.id.startsWith("m"));
|
|
24
|
+
};
|
|
25
|
+
/** A change with its sign: "+6" when it went up. */
|
|
26
|
+
const signed = (text, size) => size > 0 && !text.startsWith("+") ? `+${text}` : text;
|
|
27
|
+
const isAll = (row) => row.some((c) => isMark(c) && c.mark === "all");
|
|
28
|
+
/**
|
|
29
|
+
* Each row as a bar: sized by its value, or for a Breakdown of the change by its change, and
|
|
30
|
+
* read as the value, or as now, before and the change. A total is not drawn.
|
|
31
|
+
*/
|
|
32
|
+
function barsOf(view, entry, format) {
|
|
33
|
+
const { columns } = view.answer;
|
|
34
|
+
const at = lineAt(view, entry);
|
|
35
|
+
const before = columns.findIndex((c) => c.id === "c1");
|
|
36
|
+
const rows = view.answer.rows.map((row, i) => ({
|
|
37
|
+
row,
|
|
38
|
+
selection: rowEntry(view.drill, i)
|
|
39
|
+
})).filter(({ row }) => !isAll(row));
|
|
40
|
+
const change = columns.findIndex((c) => c.id === "c2");
|
|
41
|
+
const compared = view.change === true && rows.some(({ row }) => (row[change] ?? null) !== null);
|
|
42
|
+
const sized = compared ? change : at;
|
|
43
|
+
const max = Math.max(0, ...rows.map(({ row }) => Math.abs(plotValue(row[sized] ?? null) ?? 0)));
|
|
44
|
+
const text = (row, i) => formatCell(row[i] ?? null, columns[i], format);
|
|
45
|
+
return rows.map(({ row, selection }) => {
|
|
46
|
+
const size = plotValue(row[sized] ?? null) ?? 0;
|
|
47
|
+
return {
|
|
48
|
+
bar: {
|
|
49
|
+
name: rowName(view, row, format),
|
|
50
|
+
width: max === 0 ? 0 : Math.abs(size) / max * 100,
|
|
51
|
+
negative: size < 0,
|
|
52
|
+
text: compared && (row[before] ?? null) !== null ? format.messages.drillChange(text(row, at), formatCell(row[before] ?? null, columns[at], format), signed(text(row, sized), size)) : text(row, at)
|
|
53
|
+
},
|
|
54
|
+
selection
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** One bar: its name, its bar to scale, its value; a button when it goes deeper. */
|
|
59
|
+
function BarRow(props) {
|
|
60
|
+
const { bar, selection } = props;
|
|
61
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
62
|
+
/* @__PURE__ */ jsx("span", {
|
|
63
|
+
className: "dd-drill-bar-name",
|
|
64
|
+
children: bar.name
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ jsx("span", {
|
|
67
|
+
className: "dd-drill-bar-track",
|
|
68
|
+
"aria-hidden": "true",
|
|
69
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
70
|
+
className: "dd-drill-bar",
|
|
71
|
+
"data-negative": bar.negative,
|
|
72
|
+
style: { inlineSize: `${bar.width}%` }
|
|
73
|
+
})
|
|
74
|
+
}),
|
|
75
|
+
/* @__PURE__ */ jsx("span", {
|
|
76
|
+
className: "dd-drill-bar-value",
|
|
77
|
+
children: bar.text
|
|
78
|
+
})
|
|
79
|
+
] });
|
|
80
|
+
const label = `${bar.name}, ${bar.text}`;
|
|
81
|
+
if (selection === void 0) return /* @__PURE__ */ jsx("div", {
|
|
82
|
+
className: "dd-drill-bar-row",
|
|
83
|
+
children: body
|
|
84
|
+
});
|
|
85
|
+
return /* @__PURE__ */ jsx("button", {
|
|
86
|
+
type: "button",
|
|
87
|
+
className: "dd-drill-bar-row",
|
|
88
|
+
"aria-label": label,
|
|
89
|
+
onClick: () => {
|
|
90
|
+
props.onOpen(selection);
|
|
91
|
+
},
|
|
92
|
+
children: body
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** A Breakdown of the change's total row and where its before and change sit, when it has one to say. */
|
|
96
|
+
function comparedTotal(view) {
|
|
97
|
+
const total = view.answer.rows.find((row) => isAll(row));
|
|
98
|
+
const { columns } = view.answer;
|
|
99
|
+
const before = columns.findIndex((c) => c.id === "c1");
|
|
100
|
+
const change = columns.findIndex((c) => c.id === "c2");
|
|
101
|
+
if (view.change !== true || total === void 0 || change < 0) return;
|
|
102
|
+
return (total[before] ?? null) === null ? void 0 : {
|
|
103
|
+
total,
|
|
104
|
+
before,
|
|
105
|
+
change
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** The whole change in a Breakdown of the change: "vs 169, +33", from its total row. */
|
|
109
|
+
function changeLine(view, entry, format) {
|
|
110
|
+
const compared = comparedTotal(view);
|
|
111
|
+
if (compared === void 0) return void 0;
|
|
112
|
+
const { total, before, change } = compared;
|
|
113
|
+
const { columns } = view.answer;
|
|
114
|
+
const at = lineAt(view, entry);
|
|
115
|
+
const size = plotValue(total[change] ?? null) ?? 0;
|
|
116
|
+
return format.messages.drillVersus(formatCell(total[before] ?? null, columns[at], format), signed(formatCell(total[change] ?? null, columns[change], format), size));
|
|
117
|
+
}
|
|
118
|
+
/** Over time as columns, oldest to newest: each bucket a column to scale, a button when it goes deeper. */
|
|
119
|
+
function Columns(props) {
|
|
120
|
+
return /* @__PURE__ */ jsx("ol", {
|
|
121
|
+
className: "dd-drill-columns",
|
|
122
|
+
children: props.bars.map(({ bar, selection }, i) => {
|
|
123
|
+
const label = `${bar.name}, ${bar.text}`;
|
|
124
|
+
const column = /* @__PURE__ */ jsx("span", {
|
|
125
|
+
className: "dd-drill-column",
|
|
126
|
+
"data-negative": bar.negative,
|
|
127
|
+
style: { blockSize: `${Math.max(bar.width, 2)}%` }
|
|
128
|
+
});
|
|
129
|
+
return /* @__PURE__ */ jsx("li", {
|
|
130
|
+
title: label,
|
|
131
|
+
children: selection === void 0 ? /* @__PURE__ */ jsx("span", {
|
|
132
|
+
role: "img",
|
|
133
|
+
"aria-label": label,
|
|
134
|
+
children: column
|
|
135
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
136
|
+
type: "button",
|
|
137
|
+
"aria-label": label,
|
|
138
|
+
onClick: () => {
|
|
139
|
+
props.onOpen(selection);
|
|
140
|
+
},
|
|
141
|
+
children: column
|
|
142
|
+
})
|
|
143
|
+
}, i);
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A Breakdown as a list of bars, or Over time as columns: each group or bucket with its value
|
|
149
|
+
* to scale and, when it drills, a button that goes one step deeper. A total is not drawn; a
|
|
150
|
+
* Breakdown of the change says the whole change first.
|
|
151
|
+
*/
|
|
152
|
+
function Bars(props) {
|
|
153
|
+
const format = useDashboards();
|
|
154
|
+
const { view } = props;
|
|
155
|
+
const bars = barsOf(view, props.entry, format);
|
|
156
|
+
if (bars.length === 0) return /* @__PURE__ */ jsx("p", {
|
|
157
|
+
className: "dd-tile-state",
|
|
158
|
+
children: view.search === void 0 ? format.messages.drillNoGroups : format.messages.drillNoMatch
|
|
159
|
+
});
|
|
160
|
+
if (view.by === "trend") return /* @__PURE__ */ jsx(Columns, {
|
|
161
|
+
bars,
|
|
162
|
+
onOpen: props.onOpen
|
|
163
|
+
});
|
|
164
|
+
const change = changeLine(view, props.entry, format);
|
|
165
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [change === void 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
166
|
+
className: "dd-drill-versus",
|
|
167
|
+
children: change
|
|
168
|
+
}), /* @__PURE__ */ jsx("ul", {
|
|
169
|
+
className: "dd-drill-bars",
|
|
170
|
+
"data-by": view.by,
|
|
171
|
+
"data-change": view.change === true,
|
|
172
|
+
children: bars.map(({ bar, selection }, i) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(BarRow, {
|
|
173
|
+
bar,
|
|
174
|
+
selection,
|
|
175
|
+
onOpen: props.onOpen
|
|
176
|
+
}) }, i))
|
|
177
|
+
})] });
|
|
178
|
+
}
|
|
179
|
+
export { Bars };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { formatCell, formatInstantAt } from "../format.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/drill/Controls.tsx
|
|
6
|
+
/** Over time's range in words and its grain picker. */
|
|
7
|
+
function TrendControls({ d }) {
|
|
8
|
+
const format = useDashboards();
|
|
9
|
+
const { messages } = format;
|
|
10
|
+
const shown = d.shown;
|
|
11
|
+
if (shown?.by !== "trend") return null;
|
|
12
|
+
const zone = d.summary?.receipt.calendar.timezone;
|
|
13
|
+
const range = shown.range;
|
|
14
|
+
const day = (text) => formatInstantAt(text, "day", format.locale, zone);
|
|
15
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
16
|
+
className: "dd-drill-controls",
|
|
17
|
+
children: [range === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
18
|
+
className: "dd-drill-range",
|
|
19
|
+
children: messages.drillRange(day(range.from), day(range.to))
|
|
20
|
+
}), (shown.grains ?? []).length < 2 ? null : /* @__PURE__ */ jsxs("label", {
|
|
21
|
+
className: "dd-drill-by",
|
|
22
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
23
|
+
className: "dd-sr-only",
|
|
24
|
+
children: messages.drillViews.trend
|
|
25
|
+
}), /* @__PURE__ */ jsx("select", {
|
|
26
|
+
value: shown.grain ?? "",
|
|
27
|
+
onChange: (e) => {
|
|
28
|
+
d.setView({
|
|
29
|
+
by: "trend",
|
|
30
|
+
grain: e.target.value
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
children: (shown.grains ?? []).map((g) => /* @__PURE__ */ jsx("option", {
|
|
34
|
+
value: g,
|
|
35
|
+
children: messages.drillGrains[g]
|
|
36
|
+
}, g))
|
|
37
|
+
})]
|
|
38
|
+
})]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Breakdown's field picker, and a search in a field with more values than it draws; Over time's grain. */
|
|
42
|
+
function FieldPicker({ d }) {
|
|
43
|
+
const { messages } = useDashboards();
|
|
44
|
+
const shown = d.shown;
|
|
45
|
+
if (shown?.by === "trend") return /* @__PURE__ */ jsx(TrendControls, { d });
|
|
46
|
+
if (shown?.by !== "breakdown") return null;
|
|
47
|
+
const member = shown.member ?? "";
|
|
48
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
49
|
+
className: "dd-drill-controls",
|
|
50
|
+
children: [/* @__PURE__ */ jsxs("label", {
|
|
51
|
+
className: "dd-drill-by",
|
|
52
|
+
children: [
|
|
53
|
+
messages.drillBy,
|
|
54
|
+
" ",
|
|
55
|
+
/* @__PURE__ */ jsx("select", {
|
|
56
|
+
value: member,
|
|
57
|
+
onChange: (e) => {
|
|
58
|
+
d.setView({
|
|
59
|
+
by: "breakdown",
|
|
60
|
+
member: e.target.value
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
children: shown.offered.map((f) => /* @__PURE__ */ jsx("option", {
|
|
64
|
+
value: f.id,
|
|
65
|
+
children: f.label
|
|
66
|
+
}, f.id))
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
}), shown.searchable === true ? /* @__PURE__ */ jsx(Search, {
|
|
70
|
+
d,
|
|
71
|
+
member,
|
|
72
|
+
text: shown.search ?? ""
|
|
73
|
+
}) : null]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** A search in a field's values; it asks again a moment after the person stops typing. */
|
|
77
|
+
function Search({ d, member, text }) {
|
|
78
|
+
const { messages } = useDashboards();
|
|
79
|
+
const [typed, setTyped] = useState(text);
|
|
80
|
+
const { setView } = d;
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (typed === text) return;
|
|
83
|
+
const wait = setTimeout(() => {
|
|
84
|
+
setView({
|
|
85
|
+
by: "breakdown",
|
|
86
|
+
member,
|
|
87
|
+
...typed === "" ? {} : { search: typed }
|
|
88
|
+
});
|
|
89
|
+
}, 300);
|
|
90
|
+
return () => {
|
|
91
|
+
clearTimeout(wait);
|
|
92
|
+
};
|
|
93
|
+
}, [
|
|
94
|
+
typed,
|
|
95
|
+
text,
|
|
96
|
+
member,
|
|
97
|
+
setView
|
|
98
|
+
]);
|
|
99
|
+
return /* @__PURE__ */ jsx("input", {
|
|
100
|
+
type: "search",
|
|
101
|
+
className: "dd-drill-search",
|
|
102
|
+
"aria-label": messages.drillSearch,
|
|
103
|
+
placeholder: messages.drillSearch,
|
|
104
|
+
value: typed,
|
|
105
|
+
onChange: (e) => {
|
|
106
|
+
setTyped(e.target.value);
|
|
107
|
+
},
|
|
108
|
+
onKeyDown: (e) => {
|
|
109
|
+
if (e.key !== "Escape" || typed === "") return;
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
setTyped("");
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** A ratio's Items: a toggle that lists only the rows its numerator counts. */
|
|
116
|
+
function OnlyToggle({ d }) {
|
|
117
|
+
const format = useDashboards();
|
|
118
|
+
const numerator = d.items.view?.numerator;
|
|
119
|
+
if (numerator === void 0) return null;
|
|
120
|
+
const count = numerator.count === void 0 ? "" : formatCell(numerator.count, { type: "int" }, format);
|
|
121
|
+
const only = numerator.only === true;
|
|
122
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
123
|
+
type: "button",
|
|
124
|
+
className: "dd-drill-only",
|
|
125
|
+
"aria-pressed": only,
|
|
126
|
+
onClick: () => {
|
|
127
|
+
d.setView(only ? { by: "items" } : {
|
|
128
|
+
by: "items",
|
|
129
|
+
numerator: true
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
children: format.messages.drillOnly(numerator.label, count)
|
|
133
|
+
}), numerator.unmarked === true ? /* @__PURE__ */ jsx("p", {
|
|
134
|
+
className: "dd-tile-note",
|
|
135
|
+
children: format.messages.drillReasons.RATIO_UNMARKED
|
|
136
|
+
}) : null] });
|
|
137
|
+
}
|
|
138
|
+
/** A formula's parts: each measure it reads with its value, each opening its own drill. */
|
|
139
|
+
function Operands({ d }) {
|
|
140
|
+
const format = useDashboards();
|
|
141
|
+
const shown = d.shown;
|
|
142
|
+
if (shown?.by !== "explanation") return null;
|
|
143
|
+
return /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsx("h4", { children: format.messages.drillOperands }), /* @__PURE__ */ jsx("ul", {
|
|
144
|
+
className: "dd-drill-operands",
|
|
145
|
+
children: shown.operands.map((o) => {
|
|
146
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
147
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
148
|
+
o.label,
|
|
149
|
+
" ",
|
|
150
|
+
/* @__PURE__ */ jsx("span", {
|
|
151
|
+
className: "dd-drill-scope",
|
|
152
|
+
children: format.messages.drillScope[o.scope]
|
|
153
|
+
})
|
|
154
|
+
] }),
|
|
155
|
+
" ",
|
|
156
|
+
/* @__PURE__ */ jsx("strong", { children: formatCell(o.value, {}, format) })
|
|
157
|
+
] });
|
|
158
|
+
const state = o.state;
|
|
159
|
+
return /* @__PURE__ */ jsx("li", { children: state === void 0 || !o.can.ok ? /* @__PURE__ */ jsx("div", {
|
|
160
|
+
className: "dd-drill-bar-row",
|
|
161
|
+
children: body
|
|
162
|
+
}) : /* @__PURE__ */ jsx("button", {
|
|
163
|
+
type: "button",
|
|
164
|
+
className: "dd-drill-bar-row",
|
|
165
|
+
onClick: () => {
|
|
166
|
+
d.openState(state);
|
|
167
|
+
},
|
|
168
|
+
children: body
|
|
169
|
+
}) }, `${o.entry}-${o.scope}`);
|
|
170
|
+
})
|
|
171
|
+
})] });
|
|
172
|
+
}
|
|
173
|
+
export { FieldPicker, OnlyToggle, Operands };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DashboardDrillProps } from "./board.mjs";
|
|
2
|
+
import { DrillChange } from "./state.mjs";
|
|
3
|
+
import { DrillState, Picks } from "derive-dashboards/core";
|
|
4
|
+
export type DashboardTileProps = DashboardDrillProps & {
|
|
5
|
+
dashboardId: string;
|
|
6
|
+
widgetId: string;
|
|
7
|
+
/** The dashboard's filters, set by the host (a record page's own id, say). */
|
|
8
|
+
picks?: Picks;
|
|
9
|
+
/** The drill open under the tile, when the host keeps it (in its URL, say); its own otherwise. */
|
|
10
|
+
state?: DrillState | undefined;
|
|
11
|
+
/** The drill changed: with `state`, the host keeps the next one. */
|
|
12
|
+
onStateChange?: DrillChange;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* One tile of a dashboard on its own, for a record page or a report: drawn as on its dashboard,
|
|
16
|
+
* with the same drill. Unless the host takes a drill (`onDrill`), it opens under the tile.
|
|
17
|
+
*/
|
|
18
|
+
export declare function DashboardTile(props: DashboardTileProps): import("react").JSX.Element;
|