derive-dashboards 0.1.0 → 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 +8 -5
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/add.mjs +130 -0
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/cli.mjs +14 -12
- package/dist/cli/config.mjs +12 -1
- package/dist/cli/doctor.mjs +147 -0
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- package/dist/cli/init.mjs +3 -2
- package/dist/cli/json.mjs +21 -0
- package/dist/cli/layers.mjs +33 -0
- 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/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/document/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/filter.mjs +2 -2
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/leaf.mjs +9 -4
- package/dist/core/engine/members.mjs +2 -2
- 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 +33 -1
- package/dist/core/error/codes.mjs +30 -2
- package/dist/core/index.d.mts +13 -7
- package/dist/core/index.mjs +9 -5
- 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 +19 -3
- package/dist/core/model/types.d.mts +21 -19
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/members.mjs +7 -4
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- package/dist/core/policy/bind-query.d.mts +12 -0
- package/dist/core/policy/bind-query.mjs +53 -0
- 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/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.d.mts +12 -2
- package/dist/core/query/segments.mjs +5 -2
- package/dist/core/result/columns.mjs +20 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/aliases.d.mts +7 -0
- package/dist/core/schema/aliases.mjs +77 -0
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2109 -128
- package/dist/core/schema/answers.mjs +11 -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 +6 -3
- package/dist/core/schema/index.mjs +6 -3
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +82 -1
- package/dist/core/schema/query.mjs +9 -5
- 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 +21 -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/dashboards.mjs +4 -0
- 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 +3 -3
- package/dist/endpoints/dashboards.mjs +28 -5
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +245 -4
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/meta.mjs +10 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +34 -27
- package/dist/handler.mjs +5 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/llms.txt +22 -0
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +69 -11
- 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 +40 -6
- 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/postgres-store.mjs +1 -0
- package/dist/react/Canvas.mjs +28 -5
- package/dist/react/Cell.mjs +2 -1
- package/dist/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +62 -22
- package/dist/react/DashboardList.mjs +52 -24
- package/dist/react/DashboardListRow.mjs +49 -0
- package/dist/react/Discard.mjs +12 -4
- package/dist/react/Editing.mjs +19 -5
- package/dist/react/FilterBar.d.mts +7 -9
- package/dist/react/Grid.mjs +19 -24
- package/dist/react/Header.mjs +10 -1
- package/dist/react/History.mjs +5 -0
- package/dist/react/Parts.mjs +6 -2
- package/dist/react/ReadFailed.mjs +23 -0
- 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/Spaces.mjs +15 -1
- package/dist/react/Tile.d.mts +3 -1
- package/dist/react/Tile.mjs +84 -32
- 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/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +28 -1
- package/dist/react/context.mjs +25 -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 +101 -0
- package/dist/react/drill/words.mjs +79 -0
- package/dist/react/english.mjs +29 -6
- 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.d.mts +3 -3
- package/dist/react/format.mjs +45 -16
- package/dist/react/index.d.mts +34 -5
- package/dist/react/index.mjs +15 -4
- package/dist/react/messages.d.mts +47 -2
- package/dist/react/place.mjs +7 -3
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +116 -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 +54 -0
- package/dist/react/series.mjs +191 -0
- package/dist/react/theme.css +2734 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +7 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +4 -0
- package/dist/react/useDashboard.mjs +8 -1
- package/dist/react/useTiles.mjs +50 -15
- package/dist/react/view-grid.mjs +16 -0
- 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/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 -6
- package/dist/recharts/charts.mjs +2 -114
- package/dist/recharts/index.d.mts +5 -3
- package/dist/recharts/index.mjs +6 -3
- package/dist/recharts/line.d.mts +2 -0
- package/dist/recharts/line.mjs +111 -0
- package/dist/recharts/marks.mjs +112 -0
- package/dist/recharts/parts.mjs +88 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/recharts/table.mjs +71 -0
- package/dist/records-read.mjs +44 -0
- package/dist/registry/filter-bar.json +26 -0
- package/dist/skills/derive-dashboards/SKILL.md +69 -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 +12 -10
- package/dist/react/FilterBar.mjs +0 -119
- 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,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;
|
|
@@ -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
|
+
};
|