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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { Tile } from "../Tile.mjs";
|
|
3
|
+
import { useDashboard } from "../useDashboard.mjs";
|
|
4
|
+
import { useTiles } from "../useTiles.mjs";
|
|
5
|
+
import { DrillHostContext } from "./host.mjs";
|
|
6
|
+
import { DrillPanel } from "./lazy.mjs";
|
|
7
|
+
import { useMemo, useRef, useState } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/drill/DashboardTile.tsx
|
|
10
|
+
const NO_EVENTS = {};
|
|
11
|
+
/** The tile's drill host: drills start at this tile; the host may take one, else it opens here. */
|
|
12
|
+
function useTileHost(props, picks, open) {
|
|
13
|
+
const latest = useRef({
|
|
14
|
+
props,
|
|
15
|
+
open
|
|
16
|
+
});
|
|
17
|
+
latest.current = {
|
|
18
|
+
props,
|
|
19
|
+
open
|
|
20
|
+
};
|
|
21
|
+
const { dashboardId, drill } = props;
|
|
22
|
+
return useMemo(() => drill === false ? null : {
|
|
23
|
+
origin: (id) => ({
|
|
24
|
+
kind: "dashboard",
|
|
25
|
+
dashboardId,
|
|
26
|
+
widgetId: id,
|
|
27
|
+
picks
|
|
28
|
+
}),
|
|
29
|
+
onDrill: (state) => {
|
|
30
|
+
let prevented = false;
|
|
31
|
+
latest.current.props.onDrill?.({
|
|
32
|
+
state,
|
|
33
|
+
preventDefault: () => {
|
|
34
|
+
prevented = true;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!prevented) latest.current.open(state);
|
|
38
|
+
}
|
|
39
|
+
}, [
|
|
40
|
+
dashboardId,
|
|
41
|
+
picks,
|
|
42
|
+
drill
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One tile of a dashboard on its own, for a record page or a report: drawn as on its dashboard,
|
|
47
|
+
* with the same drill. Unless the host takes a drill (`onDrill`), it opens under the tile.
|
|
48
|
+
*/
|
|
49
|
+
function DashboardTile(props) {
|
|
50
|
+
const { messages } = useDashboards();
|
|
51
|
+
const { dashboardId, widgetId } = props;
|
|
52
|
+
const picks = useMemo(() => props.picks ?? {}, [props.picks]);
|
|
53
|
+
const loaded = useDashboard(dashboardId, NO_EVENTS, false);
|
|
54
|
+
const widget = loaded.doc?.widgets[widgetId];
|
|
55
|
+
const tab = {
|
|
56
|
+
id: "tile",
|
|
57
|
+
title: "",
|
|
58
|
+
layout: [{
|
|
59
|
+
widget: widgetId,
|
|
60
|
+
x: 0,
|
|
61
|
+
y: 0,
|
|
62
|
+
w: 12,
|
|
63
|
+
h: 4
|
|
64
|
+
}]
|
|
65
|
+
};
|
|
66
|
+
const tiles = useTiles({
|
|
67
|
+
dashboardId,
|
|
68
|
+
doc: loaded.doc,
|
|
69
|
+
tab,
|
|
70
|
+
picks,
|
|
71
|
+
source: { version: loaded.version },
|
|
72
|
+
onStale: loaded.refresh
|
|
73
|
+
});
|
|
74
|
+
const [own, setOwn] = useState();
|
|
75
|
+
const controlled = "state" in props;
|
|
76
|
+
const drill = controlled ? props.state : own;
|
|
77
|
+
const change = (next, history) => {
|
|
78
|
+
if (!controlled) setOwn(next);
|
|
79
|
+
props.onStateChange?.(next, history);
|
|
80
|
+
};
|
|
81
|
+
const host = useTileHost(props, picks, (state) => {
|
|
82
|
+
change(state, "push");
|
|
83
|
+
});
|
|
84
|
+
if (widget === void 0) return /* @__PURE__ */ jsx("div", {
|
|
85
|
+
className: "dd-tile-state",
|
|
86
|
+
"aria-busy": loaded.error ? void 0 : true,
|
|
87
|
+
children: loaded.error ? messages.dashboardMissing : messages.loading
|
|
88
|
+
});
|
|
89
|
+
return /* @__PURE__ */ jsx(DrillHostContext.Provider, {
|
|
90
|
+
value: host,
|
|
91
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
92
|
+
className: "dd-dashboard-tile",
|
|
93
|
+
children: [/* @__PURE__ */ jsx(Tile, {
|
|
94
|
+
widgetId,
|
|
95
|
+
widget,
|
|
96
|
+
result: tiles.results.get(widgetId),
|
|
97
|
+
loading: tiles.pending.has(widgetId)
|
|
98
|
+
}), /* @__PURE__ */ jsx(DrillPanel, {
|
|
99
|
+
...props,
|
|
100
|
+
state: drill,
|
|
101
|
+
title: widget.title,
|
|
102
|
+
onStateChange: change
|
|
103
|
+
})]
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export { DashboardTile };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ItemOptions } from "./Items.mjs";
|
|
2
|
+
import { DrillChange } from "./state.mjs";
|
|
3
|
+
import { DrillController } from "./useDrill.mjs";
|
|
4
|
+
import { ComponentType, ReactNode } from "react";
|
|
5
|
+
import { DrillState } from "derive-dashboards/core";
|
|
6
|
+
export type PanelOptions = ItemOptions & {
|
|
7
|
+
/** The panel's title: the tile's. */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** Close; by default, the state goes to undefined. */
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
/** Buttons of the host's own, under the views. */
|
|
12
|
+
actions?: ReactNode;
|
|
13
|
+
/** Replace the states the panel draws. */
|
|
14
|
+
components?: {
|
|
15
|
+
Loading?: ComponentType;
|
|
16
|
+
Empty?: ComponentType;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The panel over a drill state the host keeps (`state`, `onStateChange`), or over a controller it
|
|
21
|
+
* already holds (`controller`, from `useDrill`), which carries the state itself.
|
|
22
|
+
*/
|
|
23
|
+
export type DrillPanelProps = PanelOptions & ({
|
|
24
|
+
state: DrillState | undefined;
|
|
25
|
+
onStateChange: DrillChange;
|
|
26
|
+
controller?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
controller: DrillController;
|
|
29
|
+
state?: undefined;
|
|
30
|
+
onStateChange?: undefined;
|
|
31
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { Tabs } from "./DrillTabs.mjs";
|
|
3
|
+
import { Crumbs, DrillHead, Value, crumbText } from "./Header.mjs";
|
|
4
|
+
import { Main } from "./PanelBody.mjs";
|
|
5
|
+
import { SeeRows } from "./PanelStates.mjs";
|
|
6
|
+
import { useFocusReturn, usePeek } from "./panel-focus.mjs";
|
|
7
|
+
import { useDrill } from "./useDrill.mjs";
|
|
8
|
+
import { useRef } from "react";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
// src/drill/DrillPanel.tsx
|
|
11
|
+
/** The panel over its own controller. */
|
|
12
|
+
function OwnController(props) {
|
|
13
|
+
const d = useDrill({
|
|
14
|
+
state: props.state,
|
|
15
|
+
onStateChange: props.onStateChange
|
|
16
|
+
});
|
|
17
|
+
return /* @__PURE__ */ jsx(Panel, {
|
|
18
|
+
...props,
|
|
19
|
+
d
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** Escape closes the drill; the dashboard's own Escape would close it again, so it stops here. */
|
|
23
|
+
function closeOnEscape(event, close) {
|
|
24
|
+
if (event.key !== "Escape") return;
|
|
25
|
+
event.stopPropagation();
|
|
26
|
+
close();
|
|
27
|
+
}
|
|
28
|
+
/** The step before by name: its value, or the tile's title for its total (a number tile's root). */
|
|
29
|
+
function parentText(parent, title, named) {
|
|
30
|
+
if (parent === void 0) return void 0;
|
|
31
|
+
return parent.kind === "total" ? title : named(parent);
|
|
32
|
+
}
|
|
33
|
+
/** The widget a dashboard's drill opened from: its tile is lit, and focus goes back to it. */
|
|
34
|
+
const widgetOf = (state) => state?.origin.kind === "dashboard" ? state.origin.widgetId : void 0;
|
|
35
|
+
function Panel({ d, ...props }) {
|
|
36
|
+
const format = useDashboards();
|
|
37
|
+
const panel = useRef(null);
|
|
38
|
+
useFocusReturn(panel, widgetOf(d.state));
|
|
39
|
+
const [peek, expand] = usePeek();
|
|
40
|
+
if (d.state === void 0) return null;
|
|
41
|
+
const title = props.title ?? format.messages.drillTitle;
|
|
42
|
+
const close = props.onClose ?? d.close;
|
|
43
|
+
const zone = d.summary?.receipt.calendar.timezone;
|
|
44
|
+
const parent = d.path.at(-2);
|
|
45
|
+
return /* @__PURE__ */ jsxs("aside", {
|
|
46
|
+
ref: panel,
|
|
47
|
+
className: "dd-panel dd-drill",
|
|
48
|
+
"aria-label": title,
|
|
49
|
+
"data-peek": peek,
|
|
50
|
+
onKeyDown: (event) => {
|
|
51
|
+
closeOnEscape(event, close);
|
|
52
|
+
},
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ jsx(DrillHead, {
|
|
55
|
+
title,
|
|
56
|
+
step: JSON.stringify(d.state.path),
|
|
57
|
+
onBack: d.back,
|
|
58
|
+
onClose: close
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx(Crumbs, {
|
|
61
|
+
root: title,
|
|
62
|
+
path: d.path,
|
|
63
|
+
timeZone: zone,
|
|
64
|
+
onGoTo: d.goTo
|
|
65
|
+
}),
|
|
66
|
+
d.summary === void 0 ? null : /* @__PURE__ */ jsx(Value, {
|
|
67
|
+
summary: d.summary,
|
|
68
|
+
parent: parentText(parent, title, (c) => crumbText(c, format, zone)),
|
|
69
|
+
onRefresh: d.retry
|
|
70
|
+
}),
|
|
71
|
+
peek ? /* @__PURE__ */ jsx(SeeRows, {
|
|
72
|
+
d,
|
|
73
|
+
onExpand: expand
|
|
74
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
75
|
+
/* @__PURE__ */ jsx(Tabs, { d }),
|
|
76
|
+
/* @__PURE__ */ jsx(Main, {
|
|
77
|
+
d,
|
|
78
|
+
props,
|
|
79
|
+
close
|
|
80
|
+
}),
|
|
81
|
+
props.actions === void 0 ? null : /* @__PURE__ */ jsx("div", {
|
|
82
|
+
className: "dd-panel-foot",
|
|
83
|
+
children: props.actions
|
|
84
|
+
})
|
|
85
|
+
] })
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The rows behind a mark, beside the dashboard or wherever the host places it: the path as
|
|
91
|
+
* breadcrumbs, the value and the rows behind it, the views (Breakdown, Over time, Items, and
|
|
92
|
+
* Explanation for a formula), each a click deeper. It sits on `useDrill` (its own, or the
|
|
93
|
+
* host's `controller`); its state is the host's, told back through `onStateChange` with
|
|
94
|
+
* whether Back should undo the change. Closing gives focus back to what opened it.
|
|
95
|
+
*/
|
|
96
|
+
function DrillPanel(props) {
|
|
97
|
+
const { controller } = props;
|
|
98
|
+
if (controller !== void 0) return /* @__PURE__ */ jsx(Panel, {
|
|
99
|
+
...props,
|
|
100
|
+
d: controller
|
|
101
|
+
});
|
|
102
|
+
return /* @__PURE__ */ jsx(OwnController, { ...props });
|
|
103
|
+
}
|
|
104
|
+
export { DrillPanel };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/drill/DrillTabs.tsx
|
|
4
|
+
const VIEWS = [
|
|
5
|
+
"breakdown",
|
|
6
|
+
"trend",
|
|
7
|
+
"items",
|
|
8
|
+
"explanation"
|
|
9
|
+
];
|
|
10
|
+
/** The views as tabs, a roving tab stop moved by the arrow keys; one the drill cannot show is disabled, with its reason. */
|
|
11
|
+
function Tabs({ d }) {
|
|
12
|
+
const { messages } = useDashboards();
|
|
13
|
+
const can = d.summary?.can;
|
|
14
|
+
if (can === void 0) return null;
|
|
15
|
+
const shown = VIEWS.filter((v) => can[v].ok || d.view?.by === v);
|
|
16
|
+
const open = (v) => {
|
|
17
|
+
const first = d.summary?.offered[0]?.id;
|
|
18
|
+
const view = v === "breakdown" && first !== void 0 ? {
|
|
19
|
+
by: v,
|
|
20
|
+
member: first
|
|
21
|
+
} : { by: v };
|
|
22
|
+
d.setView(view);
|
|
23
|
+
};
|
|
24
|
+
const onKey = (event) => {
|
|
25
|
+
if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
|
|
26
|
+
const tabs = [...event.currentTarget.querySelectorAll("[role=tab]:not(:disabled)")];
|
|
27
|
+
const { target } = event;
|
|
28
|
+
tabs[((target instanceof HTMLButtonElement ? tabs.indexOf(target) : -1) + (event.key === "ArrowRight" ? 1 : tabs.length - 1)) % tabs.length]?.focus();
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */ jsx("div", {
|
|
31
|
+
className: "dd-drill-tabs",
|
|
32
|
+
role: "tablist",
|
|
33
|
+
onKeyDown: onKey,
|
|
34
|
+
children: shown.map((v) => {
|
|
35
|
+
const ok = can[v];
|
|
36
|
+
const selected = d.view?.by === v;
|
|
37
|
+
return /* @__PURE__ */ jsx("button", {
|
|
38
|
+
type: "button",
|
|
39
|
+
role: "tab",
|
|
40
|
+
"aria-selected": selected,
|
|
41
|
+
tabIndex: selected ? 0 : -1,
|
|
42
|
+
disabled: !ok.ok,
|
|
43
|
+
title: ok.ok ? void 0 : messages.drillReasons[ok.code],
|
|
44
|
+
onClick: () => {
|
|
45
|
+
open(v);
|
|
46
|
+
},
|
|
47
|
+
children: messages.drillViews[v]
|
|
48
|
+
}, v);
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export { Tabs };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { formatCell, formatInstantAt } from "../format.mjs";
|
|
3
|
+
import { countOf, countText } from "./counts.mjs";
|
|
4
|
+
import { Notes, valueColumn } from "./Notes.mjs";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
// src/drill/Header.tsx
|
|
8
|
+
/** A number of rows in words: "36 orders" with the source's noun, else "36 rows". */
|
|
9
|
+
function rowsText(count, summary, format) {
|
|
10
|
+
if (count === void 0) return count;
|
|
11
|
+
const text = countText(count, format);
|
|
12
|
+
const noun = summary.noun;
|
|
13
|
+
if (noun === void 0) return format.messages.drillRows(text);
|
|
14
|
+
return `${text} ${countOf(count) === 1 ? noun.one : noun.other}`;
|
|
15
|
+
}
|
|
16
|
+
/** Whether the line is the row count itself (a count of its rows), so the header says it once. */
|
|
17
|
+
const sameCount = (summary) => summary.counted === true && summary.itemCount !== void 0 && JSON.stringify(summary.itemCount) === JSON.stringify(summary.value);
|
|
18
|
+
/** The source's noun alone, for a count that is its rows: "orders". */
|
|
19
|
+
function nounOnly(summary, format) {
|
|
20
|
+
const n = countOf(summary.value);
|
|
21
|
+
if (summary.noun === void 0) return format.messages.drillNoun(n);
|
|
22
|
+
return n === 1 ? summary.noun.one : summary.noun.other;
|
|
23
|
+
}
|
|
24
|
+
/** The panel's head: Back, its title, Close. The title takes focus whenever the step changes. */
|
|
25
|
+
function DrillHead(props) {
|
|
26
|
+
const { messages } = useDashboards();
|
|
27
|
+
const heading = useRef(null);
|
|
28
|
+
const { step } = props;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (step !== "") heading.current?.focus({ preventScroll: true });
|
|
31
|
+
}, [step]);
|
|
32
|
+
return /* @__PURE__ */ jsxs("header", {
|
|
33
|
+
className: "dd-panel-head dd-drill-head",
|
|
34
|
+
children: [
|
|
35
|
+
/* @__PURE__ */ jsxs("button", {
|
|
36
|
+
type: "button",
|
|
37
|
+
className: "dd-button dd-quiet",
|
|
38
|
+
onClick: props.onBack,
|
|
39
|
+
children: ["‹ ", messages.drillBack]
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ jsx("h3", {
|
|
42
|
+
ref: heading,
|
|
43
|
+
tabIndex: -1,
|
|
44
|
+
children: props.title
|
|
45
|
+
}),
|
|
46
|
+
/* @__PURE__ */ jsx("button", {
|
|
47
|
+
type: "button",
|
|
48
|
+
className: "dd-button dd-quiet",
|
|
49
|
+
"aria-keyshortcuts": "Escape",
|
|
50
|
+
onClick: props.onClose,
|
|
51
|
+
children: messages.close
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** One breadcrumb's text: a time point at its grain in the dashboard's zone, Other of its field, a missing value by its field. */
|
|
57
|
+
/** A step that is not one value: Other, the whole tile, or a search. */
|
|
58
|
+
function markedText(c, messages) {
|
|
59
|
+
if (c.kind === "other") return messages.drillOtherOf(c.label);
|
|
60
|
+
if (c.kind === "total") return c.previous === true ? messages.drillPeriodBefore : messages.total;
|
|
61
|
+
if (c.kind === "search") return `"${typeof c.value === "string" ? c.value : JSON.stringify(c.value)}"`;
|
|
62
|
+
}
|
|
63
|
+
function crumbText(c, format, timeZone) {
|
|
64
|
+
const { messages } = format;
|
|
65
|
+
if (c.parts !== void 0) return c.parts.filter((p) => p.kind !== "search").map((p) => crumbText(p, format, timeZone)).join(" · ");
|
|
66
|
+
const marked = markedText(c, messages);
|
|
67
|
+
if (marked !== void 0) return marked;
|
|
68
|
+
if (c.value === null) return messages.drillNone(c.label);
|
|
69
|
+
if (c.kind === "time" && typeof c.value === "string") {
|
|
70
|
+
const date = formatInstantAt(c.value, c.grain ?? "day", format.locale, timeZone);
|
|
71
|
+
return c.grain === "week" ? messages.drillWeekOf(date) : date;
|
|
72
|
+
}
|
|
73
|
+
return formatCell(c.value, {}, format);
|
|
74
|
+
}
|
|
75
|
+
/** The path as breadcrumbs: the tile, then each step, each going back to it. */
|
|
76
|
+
function Crumbs(props) {
|
|
77
|
+
const format = useDashboards();
|
|
78
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
79
|
+
className: "dd-drill-crumbs",
|
|
80
|
+
"aria-label": format.messages.drillTitle,
|
|
81
|
+
children: /* @__PURE__ */ jsxs("ol", { children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
|
|
82
|
+
type: "button",
|
|
83
|
+
onClick: () => {
|
|
84
|
+
props.onGoTo(0);
|
|
85
|
+
},
|
|
86
|
+
children: format.messages.drillRoot(props.root)
|
|
87
|
+
}) }), props.path.map((c, i) => c.kind === "total" ? null : /* @__PURE__ */ jsx("li", {
|
|
88
|
+
"aria-current": i === props.path.length - 1 ? "step" : void 0,
|
|
89
|
+
children: i === props.path.length - 1 ? /* @__PURE__ */ jsx("span", { children: crumbText(c, format, props.timeZone) }) : /* @__PURE__ */ jsx("button", {
|
|
90
|
+
type: "button",
|
|
91
|
+
onClick: () => {
|
|
92
|
+
props.onGoTo(i + 1);
|
|
93
|
+
},
|
|
94
|
+
children: crumbText(c, format, props.timeZone)
|
|
95
|
+
})
|
|
96
|
+
}, `${c.label}-${String(i)}`))] })
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** "396 tasks with Hours (57 without)", or the rows alone. */
|
|
100
|
+
function rowsLine(summary, format) {
|
|
101
|
+
const rows = rowsText(summary.itemCount, summary, format);
|
|
102
|
+
if (rows === void 0 || summary.operand === void 0) return rows;
|
|
103
|
+
const without = summary.rows === void 0 ? void 0 : countOf(summary.rows) - countOf(summary.itemCount);
|
|
104
|
+
const missing = without === void 0 || without <= 0 ? void 0 : formatCell(without, { type: "int" }, format);
|
|
105
|
+
return format.messages.drillWith(rows, summary.operand, missing);
|
|
106
|
+
}
|
|
107
|
+
/** The value, the rows behind it when they differ, its share, and what the viewer should know about it. */
|
|
108
|
+
function Value({ summary, parent, onRefresh }) {
|
|
109
|
+
const format = useDashboards();
|
|
110
|
+
const value = formatCell(summary.value, valueColumn(summary), format);
|
|
111
|
+
const rows = rowsLine(summary, format);
|
|
112
|
+
const share = summary.share === void 0 ? void 0 : new Intl.NumberFormat(format.locale, { style: "percent" }).format(summary.share.value);
|
|
113
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
114
|
+
className: "dd-drill-value",
|
|
115
|
+
children: [/* @__PURE__ */ jsxs("p", { children: [
|
|
116
|
+
/* @__PURE__ */ jsx("strong", { children: value }),
|
|
117
|
+
rows === void 0 ? null : sameCount(summary) ? /* @__PURE__ */ jsxs("span", { children: [" ", nounOnly(summary, format)] }) : /* @__PURE__ */ jsxs("span", { children: [" · ", rows] }),
|
|
118
|
+
share === void 0 ? null : /* @__PURE__ */ jsxs("span", { children: [
|
|
119
|
+
" ",
|
|
120
|
+
"·",
|
|
121
|
+
" ",
|
|
122
|
+
format.messages.drillShare(share, summary.share?.of === "parent" ? parent : void 0)
|
|
123
|
+
] })
|
|
124
|
+
] }), /* @__PURE__ */ jsx(Notes, {
|
|
125
|
+
summary,
|
|
126
|
+
value,
|
|
127
|
+
onRefresh
|
|
128
|
+
})]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
export { Crumbs, DrillHead, Value, crumbText };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Item } from "../index.mjs";
|
|
2
|
+
import { ItemParts } from "./item-parts.mjs";
|
|
3
|
+
import { ComponentType, MouseEvent, ReactNode } from "react";
|
|
4
|
+
import { DrillItem, DrillItemsView, ItemLinks } from "derive-dashboards/core";
|
|
5
|
+
/** What a host's own item row is given: the item's link and parts, and how to open it. */
|
|
6
|
+
export type ItemHelpers = ItemParts & {
|
|
7
|
+
href?: string;
|
|
8
|
+
open?: () => void;
|
|
9
|
+
view: DrillItemsView;
|
|
10
|
+
};
|
|
11
|
+
/** Where an item goes and what a click on it does: the host's, by prop. */
|
|
12
|
+
export type ItemOptions = {
|
|
13
|
+
/** Where each source's items open, by source (typed by source once the server is registered). */
|
|
14
|
+
itemLinks?: ItemLinks;
|
|
15
|
+
/** An item's link; `undefined` means this item has none, even when `itemLinks` has a template. */
|
|
16
|
+
itemHref?: (item: Item) => string | undefined;
|
|
17
|
+
/** A plain left click; Cmd, Ctrl, Shift or a middle click still open the link. */
|
|
18
|
+
onItem?: (item: Item, context: {
|
|
19
|
+
event?: MouseEvent;
|
|
20
|
+
}) => void;
|
|
21
|
+
renderItem?: (item: Item, helpers: ItemHelpers) => ReactNode;
|
|
22
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { formatCell } from "../format.mjs";
|
|
3
|
+
import { RowBody } from "../RowBody.mjs";
|
|
4
|
+
import { columnShape, itemParts, readMode, writeMode } from "./item-parts.mjs";
|
|
5
|
+
import { asItem } from "./item-type.mjs";
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import { itemLink } from "derive-dashboards/core";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
// src/drill/Items.tsx
|
|
10
|
+
const plainClick = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
11
|
+
/**
|
|
12
|
+
* An item's link: the host's `itemHref` when it gives one (its `undefined` turns the link off),
|
|
13
|
+
* else its source's `itemLinks` template, else the server's. A hidden key never has one.
|
|
14
|
+
*/
|
|
15
|
+
const hrefOf = (options, item) => options.itemHref === void 0 ? itemLink(options.itemLinks, item) ?? item.link : options.itemHref(asItem(item));
|
|
16
|
+
/** How an item opens: as a link, a button, or not at all. */
|
|
17
|
+
function Opener(props) {
|
|
18
|
+
const { link: Link = "a" } = useDashboards();
|
|
19
|
+
const { item, options } = props;
|
|
20
|
+
const href = hrefOf(options, item);
|
|
21
|
+
const onItem = options.onItem;
|
|
22
|
+
if (href === void 0 && onItem === void 0) return /* @__PURE__ */ jsx("div", {
|
|
23
|
+
className: props.className,
|
|
24
|
+
children: props.children
|
|
25
|
+
});
|
|
26
|
+
if (href === void 0) return /* @__PURE__ */ jsx("button", {
|
|
27
|
+
type: "button",
|
|
28
|
+
className: props.className,
|
|
29
|
+
onClick: (event) => onItem?.(asItem(item), { event }),
|
|
30
|
+
children: props.children
|
|
31
|
+
});
|
|
32
|
+
const onClick = (event) => {
|
|
33
|
+
if (onItem === void 0 || !plainClick(event)) return;
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
onItem(asItem(item), { event });
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ jsx(Link, {
|
|
38
|
+
href,
|
|
39
|
+
className: props.className,
|
|
40
|
+
onClick,
|
|
41
|
+
children: props.children
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** A noun as a column heading: "task" reads "Task". */
|
|
45
|
+
const headOf = (noun) => noun === void 0 ? void 0 : `${noun.charAt(0).toLocaleUpperCase()}${noun.slice(1)}`;
|
|
46
|
+
/**
|
|
47
|
+
* Every column of the items as a plain table. Its first column names each row as the list does
|
|
48
|
+
* (its title, or "Task 12" when no field names it) and opens the item; the title's own column is
|
|
49
|
+
* not repeated.
|
|
50
|
+
*/
|
|
51
|
+
function Table(props) {
|
|
52
|
+
const format = useDashboards();
|
|
53
|
+
const { view } = props;
|
|
54
|
+
const cell = {
|
|
55
|
+
...format,
|
|
56
|
+
timeZone: props.timeZone
|
|
57
|
+
};
|
|
58
|
+
const rest = view.columns.filter((c) => c.member !== view.title);
|
|
59
|
+
const named = view.columns.find((c) => c.member === view.title);
|
|
60
|
+
return /* @__PURE__ */ jsx("div", {
|
|
61
|
+
className: "dd-records-scroll",
|
|
62
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
63
|
+
className: "dd-table",
|
|
64
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
65
|
+
scope: "col",
|
|
66
|
+
children: named?.label ?? headOf(props.noun) ?? format.messages.drillItem
|
|
67
|
+
}), rest.map((c) => /* @__PURE__ */ jsx("th", {
|
|
68
|
+
scope: "col",
|
|
69
|
+
children: c.label
|
|
70
|
+
}, c.member))] }) }), /* @__PURE__ */ jsx("tbody", { children: props.items.map((item, i) => /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
71
|
+
scope: "row",
|
|
72
|
+
children: /* @__PURE__ */ jsx(Opener, {
|
|
73
|
+
item,
|
|
74
|
+
options: props.options,
|
|
75
|
+
className: "dd-item-cell",
|
|
76
|
+
children: itemParts(view, item, {
|
|
77
|
+
n: i + 1,
|
|
78
|
+
noun: props.noun
|
|
79
|
+
}, cell).title
|
|
80
|
+
})
|
|
81
|
+
}), rest.map((c) => /* @__PURE__ */ jsx("td", { children: formatCell(item.values[c.member] ?? null, columnShape(c), cell) }, c.member))] }, item.id)) })]
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** One item with the host's own row: its parts, its link, and how to open it. */
|
|
86
|
+
function helpersOf(options, item, base) {
|
|
87
|
+
const href = hrefOf(options, item);
|
|
88
|
+
const onItem = options.onItem;
|
|
89
|
+
return {
|
|
90
|
+
...base,
|
|
91
|
+
...href === void 0 ? {} : { href },
|
|
92
|
+
...onItem === void 0 ? {} : { open: () => {
|
|
93
|
+
onItem(asItem(item), {});
|
|
94
|
+
} }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** The items as a list: the default row, or the host's own (`renderItem`). After Show more, the first new row takes focus. */
|
|
98
|
+
function List(props) {
|
|
99
|
+
const format = useDashboards();
|
|
100
|
+
const { view, options } = props;
|
|
101
|
+
const list = useRef(null);
|
|
102
|
+
const seen = useRef(props.items.length);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const before = seen.current;
|
|
105
|
+
seen.current = props.items.length;
|
|
106
|
+
if (props.items.length <= before || before === 0) return;
|
|
107
|
+
list.current?.children[before]?.querySelector("a, button, [tabindex]")?.focus();
|
|
108
|
+
}, [props.items.length]);
|
|
109
|
+
const cell = {
|
|
110
|
+
...format,
|
|
111
|
+
timeZone: props.timeZone
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
114
|
+
className: "dd-items",
|
|
115
|
+
ref: list,
|
|
116
|
+
children: props.items.map((item, i) => {
|
|
117
|
+
const parts = itemParts(view, item, {
|
|
118
|
+
n: i + 1,
|
|
119
|
+
noun: props.noun
|
|
120
|
+
}, cell);
|
|
121
|
+
const render = options.renderItem;
|
|
122
|
+
const opens = hrefOf(options, item) !== void 0 || options.onItem !== void 0;
|
|
123
|
+
return /* @__PURE__ */ jsx("li", { children: render === void 0 ? /* @__PURE__ */ jsx(Opener, {
|
|
124
|
+
item,
|
|
125
|
+
options,
|
|
126
|
+
className: "dd-item",
|
|
127
|
+
children: /* @__PURE__ */ jsx(RowBody, {
|
|
128
|
+
row: {
|
|
129
|
+
...parts,
|
|
130
|
+
opens
|
|
131
|
+
},
|
|
132
|
+
family: "item"
|
|
133
|
+
})
|
|
134
|
+
}) : render(asItem(item), helpersOf(options, item, {
|
|
135
|
+
...parts,
|
|
136
|
+
view
|
|
137
|
+
})) }, item.id);
|
|
138
|
+
})
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** The items as a list (the default) or a table, the choice kept in this browser. */
|
|
142
|
+
function Items(props) {
|
|
143
|
+
const format = useDashboards();
|
|
144
|
+
const { view, Empty } = props;
|
|
145
|
+
const [mode, setMode] = useState(() => readMode(view.source));
|
|
146
|
+
if (props.items.length === 0) return Empty === void 0 ? /* @__PURE__ */ jsx("p", {
|
|
147
|
+
className: "dd-tile-state",
|
|
148
|
+
children: format.messages.drillNoItems
|
|
149
|
+
}) : /* @__PURE__ */ jsx(Empty, {});
|
|
150
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("fieldset", {
|
|
151
|
+
className: "dd-drill-modes",
|
|
152
|
+
"aria-label": format.messages.drillViews.items,
|
|
153
|
+
children: ["list", "table"].map((m) => /* @__PURE__ */ jsx("button", {
|
|
154
|
+
type: "button",
|
|
155
|
+
"aria-pressed": mode === m,
|
|
156
|
+
onClick: () => {
|
|
157
|
+
setMode(m);
|
|
158
|
+
writeMode(view.source, m);
|
|
159
|
+
},
|
|
160
|
+
children: m === "list" ? format.messages.drillList : format.messages.drillTable
|
|
161
|
+
}, m))
|
|
162
|
+
}), mode === "table" ? /* @__PURE__ */ jsx(Table, { ...props }) : /* @__PURE__ */ jsx(List, { ...props })] });
|
|
163
|
+
}
|
|
164
|
+
export { Items };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { countText } from "./counts.mjs";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/drill/ItemsFoot.tsx
|
|
5
|
+
/**
|
|
6
|
+
* How many items the list holds: under "Only <numerator>" the numerator's rows; a distinct
|
|
7
|
+
* count's list is its distinct values (its value), not the rows behind them; else the rows.
|
|
8
|
+
*/
|
|
9
|
+
function listCount(view, summary) {
|
|
10
|
+
if (view.numerator?.only === true) return view.numerator.count;
|
|
11
|
+
return summary.semantics === "distinct" ? summary.value : summary.itemCount;
|
|
12
|
+
}
|
|
13
|
+
/** Items' count and sort, then Show more while there are more, with a retry when a page fails. */
|
|
14
|
+
function ItemsFoot({ d }) {
|
|
15
|
+
const format = useDashboards();
|
|
16
|
+
const { messages } = format;
|
|
17
|
+
const view = d.items.view;
|
|
18
|
+
if (view === void 0 || d.summary === void 0) return null;
|
|
19
|
+
const count = listCount(view, d.summary);
|
|
20
|
+
const total = count === void 0 ? void 0 : countText(count, format);
|
|
21
|
+
const sort = sortText(view, messages);
|
|
22
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
23
|
+
/* @__PURE__ */ jsxs("p", {
|
|
24
|
+
className: "dd-records-count",
|
|
25
|
+
"aria-live": "polite",
|
|
26
|
+
children: [
|
|
27
|
+
messages.drillShowing(d.items.items.length, total),
|
|
28
|
+
" · ",
|
|
29
|
+
sort
|
|
30
|
+
]
|
|
31
|
+
}),
|
|
32
|
+
d.items.moreError === void 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
33
|
+
className: "dd-tile-error",
|
|
34
|
+
role: "alert",
|
|
35
|
+
children: messages.drillFailed
|
|
36
|
+
}),
|
|
37
|
+
d.items.hasMore ? /* @__PURE__ */ jsx(More, { d }) : null
|
|
38
|
+
] });
|
|
39
|
+
}
|
|
40
|
+
/** How the Items are sorted, in words: the declared order, or by the value. */
|
|
41
|
+
function sortText(view, messages) {
|
|
42
|
+
if (view.sort !== "records" || view.sorted === void 0) return messages.drillSort[view.sort];
|
|
43
|
+
const field = view.columns.find((c) => c.member === view.sorted?.member)?.label ?? "";
|
|
44
|
+
return messages.drillSorted(field, view.sorted.dir, view.sorted.time);
|
|
45
|
+
}
|
|
46
|
+
/** Show more, or Loading while a page comes, or Try again when the last one failed. */
|
|
47
|
+
function More({ d }) {
|
|
48
|
+
const { messages } = useDashboards();
|
|
49
|
+
const label = d.items.loadingMore ? messages.loading : d.items.moreError === void 0 ? messages.showMore : messages.drillRetry;
|
|
50
|
+
return /* @__PURE__ */ jsx("button", {
|
|
51
|
+
type: "button",
|
|
52
|
+
className: "dd-records-more",
|
|
53
|
+
"aria-disabled": d.items.loadingMore,
|
|
54
|
+
onClick: () => {
|
|
55
|
+
if (!d.items.loadingMore) d.items.more();
|
|
56
|
+
},
|
|
57
|
+
children: label
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export { ItemsFoot };
|