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
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { useDashboards } from "../context.mjs";
|
|
2
|
+
import { useEscapeToLeave } from "./escape.mjs";
|
|
2
3
|
import { CalcSection } from "./Calcs.mjs";
|
|
3
4
|
import { FilterSection } from "./Filters.mjs";
|
|
4
5
|
import { GroupSection } from "./Groups.mjs";
|
|
5
6
|
import { Preview } from "./Preview.mjs";
|
|
6
|
-
import { Chip, MeasureSection } from "./Sections.mjs";
|
|
7
|
+
import { Chip, KeptNote, MeasureSection, OpenSection } from "./Sections.mjs";
|
|
7
8
|
import { TimeSection } from "./Time.mjs";
|
|
8
9
|
import { useBuilder } from "./useBuilder.mjs";
|
|
9
10
|
import { useEffect, useRef, useState } from "react";
|
|
10
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
// src/builder/WidgetBuilder.tsx
|
|
12
13
|
/** The usual kinds first; any other renderer the host registered follows, by its kind. */
|
|
13
14
|
const USUAL = [
|
|
@@ -97,51 +98,41 @@ function DashboardNote({ b, controls }) {
|
|
|
97
98
|
/** Rare things, folded: the widget as JSON, to hand to an agent or keep in code. */
|
|
98
99
|
function OptionsSection({ b }) {
|
|
99
100
|
const { messages } = useDashboards();
|
|
100
|
-
const [copied, setCopied] = useState(
|
|
101
|
+
const [copied, setCopied] = useState("no");
|
|
101
102
|
const widget = b.widget;
|
|
102
103
|
if (widget === void 0) return null;
|
|
104
|
+
const json = JSON.stringify(widget, null, 2);
|
|
103
105
|
const copy = async () => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
try {
|
|
107
|
+
await navigator.clipboard.writeText(json);
|
|
108
|
+
setCopied("yes");
|
|
109
|
+
} catch {
|
|
110
|
+
setCopied("refused");
|
|
111
|
+
}
|
|
106
112
|
};
|
|
107
113
|
return /* @__PURE__ */ jsxs("details", {
|
|
108
114
|
className: "dd-builder-section",
|
|
109
|
-
children: [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsx("summary", { children: messages.options }),
|
|
117
|
+
/* @__PURE__ */ jsx("button", {
|
|
118
|
+
type: "button",
|
|
119
|
+
className: "dd-button",
|
|
120
|
+
onClick: () => void copy(),
|
|
121
|
+
children: copied === "yes" ? messages.copied : messages.copyJson
|
|
122
|
+
}),
|
|
123
|
+
copied === "refused" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
|
|
124
|
+
className: "dd-builder-note",
|
|
125
|
+
role: "status",
|
|
126
|
+
children: messages.copyByHand
|
|
127
|
+
}), /* @__PURE__ */ jsx("textarea", {
|
|
128
|
+
className: "dd-builder-json",
|
|
129
|
+
readOnly: true,
|
|
130
|
+
value: json,
|
|
131
|
+
"aria-label": messages.copyJson,
|
|
132
|
+
ref: (el) => el?.select()
|
|
133
|
+
})] }) : null
|
|
134
|
+
]
|
|
129
135
|
});
|
|
130
|
-
latest.current = {
|
|
131
|
-
widget,
|
|
132
|
-
onCancel
|
|
133
|
-
};
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
const onKey = (event) => {
|
|
136
|
-
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
137
|
-
if (latest.current.widget === start.current) latest.current.onCancel();
|
|
138
|
-
else if (!isTyping(event)) document.querySelector("[data-builder-cancel]")?.focus();
|
|
139
|
-
};
|
|
140
|
-
globalThis.addEventListener("keydown", onKey);
|
|
141
|
-
return () => {
|
|
142
|
-
globalThis.removeEventListener("keydown", onKey);
|
|
143
|
-
};
|
|
144
|
-
}, []);
|
|
145
136
|
}
|
|
146
137
|
/**
|
|
147
138
|
* The widget builder: one full page. Pick a measure by searching, then group, filter, add a
|
|
@@ -150,9 +141,13 @@ function useEscapeToLeave(widget, onCancel) {
|
|
|
150
141
|
*/
|
|
151
142
|
function WidgetBuilder({ initial, backLabel, controls, error, ...actions }) {
|
|
152
143
|
const b = useBuilder(initial);
|
|
153
|
-
|
|
144
|
+
const { messages } = useDashboards();
|
|
145
|
+
const [open, setOpen] = useState(initial === void 0 ? messages.measure : void 0);
|
|
146
|
+
const root = useRef(null);
|
|
147
|
+
useEscapeToLeave(root, JSON.stringify(b.widget), actions.onCancel);
|
|
154
148
|
return /* @__PURE__ */ jsxs("div", {
|
|
155
149
|
className: "dd-builder",
|
|
150
|
+
ref: root,
|
|
156
151
|
children: [
|
|
157
152
|
backLabel === void 0 ? null : /* @__PURE__ */ jsxs("button", {
|
|
158
153
|
type: "button",
|
|
@@ -173,14 +168,19 @@ function WidgetBuilder({ initial, backLabel, controls, error, ...actions }) {
|
|
|
173
168
|
className: "dd-builder-body",
|
|
174
169
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
175
170
|
className: "dd-builder-panel",
|
|
176
|
-
children: [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
171
|
+
children: [/* @__PURE__ */ jsxs(OpenSection.Provider, {
|
|
172
|
+
value: {
|
|
173
|
+
open,
|
|
174
|
+
setOpen
|
|
175
|
+
},
|
|
176
|
+
children: [
|
|
177
|
+
/* @__PURE__ */ jsx(MeasureSection, { b }),
|
|
178
|
+
/* @__PURE__ */ jsx(TimeSection, { b }),
|
|
179
|
+
/* @__PURE__ */ jsx(GroupSection, { b }),
|
|
180
|
+
/* @__PURE__ */ jsx(FilterSection, { b }),
|
|
181
|
+
/* @__PURE__ */ jsx(CalcSection, { b })
|
|
182
|
+
]
|
|
183
|
+
}), /* @__PURE__ */ jsx(OptionsSection, { b })]
|
|
184
184
|
}), /* @__PURE__ */ jsxs("div", {
|
|
185
185
|
className: "dd-builder-main",
|
|
186
186
|
children: [
|
|
@@ -189,6 +189,7 @@ function WidgetBuilder({ initial, backLabel, controls, error, ...actions }) {
|
|
|
189
189
|
b,
|
|
190
190
|
controls
|
|
191
191
|
}),
|
|
192
|
+
/* @__PURE__ */ jsx(KeptNote, { b }),
|
|
192
193
|
/* @__PURE__ */ jsx(Preview, {
|
|
193
194
|
b,
|
|
194
195
|
data: true
|
|
@@ -16,4 +16,9 @@ export type BuilderState = {
|
|
|
16
16
|
query: StoredQuery | undefined;
|
|
17
17
|
/** Calcs the last change removed because they no longer fit, by name; cleared by the next. */
|
|
18
18
|
removed?: readonly string[];
|
|
19
|
+
/**
|
|
20
|
+
* The widget it opened, when it edits one: what the builder does not edit (its display
|
|
21
|
+
* settings, other named queries, a plugin's own fields) is saved back as it was.
|
|
22
|
+
*/
|
|
23
|
+
base?: Widget;
|
|
19
24
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { fittingTitle, sourceIn } from "./labels.mjs";
|
|
2
2
|
// src/builder/base.ts
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/** A new widget's range: the last 7 days, today included. */
|
|
4
|
+
const DEFAULT_RANGE = {
|
|
5
|
+
last: 7,
|
|
5
6
|
unit: "day",
|
|
6
7
|
includeCurrent: true
|
|
7
8
|
};
|
|
8
9
|
function emptyBuilder(widget) {
|
|
9
|
-
const query = widget?.queries
|
|
10
|
+
const query = widget?.queries.main;
|
|
10
11
|
if (widget === void 0 || query === void 0) return {
|
|
11
12
|
title: "",
|
|
12
13
|
titleSet: false,
|
|
@@ -19,7 +20,24 @@ function emptyBuilder(widget) {
|
|
|
19
20
|
titleSet: true,
|
|
20
21
|
kind: widget.kind,
|
|
21
22
|
kindSet: true,
|
|
22
|
-
query
|
|
23
|
+
query,
|
|
24
|
+
base: widget
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** The fields every widget has; anything else on one is a host's or a plugin's own. */
|
|
28
|
+
const WIDGET_FIELDS = /* @__PURE__ */ new Set([
|
|
29
|
+
"kind",
|
|
30
|
+
"title",
|
|
31
|
+
"queries",
|
|
32
|
+
"display"
|
|
33
|
+
]);
|
|
34
|
+
/** What the builder keeps but does not edit: display settings, other queries, host fields. */
|
|
35
|
+
function keptAside(state) {
|
|
36
|
+
const base = state.base;
|
|
37
|
+
return {
|
|
38
|
+
display: base?.display !== void 0 && Object.keys(base.display).length > 0,
|
|
39
|
+
queries: Object.keys(base?.queries ?? {}).filter((name) => name !== "main"),
|
|
40
|
+
fields: Object.keys(base ?? {}).filter((name) => !WIDGET_FIELDS.has(name))
|
|
23
41
|
};
|
|
24
42
|
}
|
|
25
43
|
const lastPart = (member) => member.split(".").at(-1) ?? member;
|
|
@@ -77,7 +95,7 @@ function defaultTime(meta, name) {
|
|
|
77
95
|
const time = sourceIn(meta, name)?.dimensions.find((d) => d.type === "time");
|
|
78
96
|
return time === void 0 ? void 0 : {
|
|
79
97
|
dimension: time.id,
|
|
80
|
-
range:
|
|
98
|
+
range: DEFAULT_RANGE
|
|
81
99
|
};
|
|
82
100
|
}
|
|
83
101
|
function setKind(state, kind) {
|
|
@@ -99,13 +117,20 @@ function setTitle(meta, state, title) {
|
|
|
99
117
|
titleSet: true
|
|
100
118
|
};
|
|
101
119
|
}
|
|
102
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* The widget to save, or undefined until it has a measure. An edited widget keeps everything the
|
|
122
|
+
* builder does not edit; only its kind, title and main query change.
|
|
123
|
+
*/
|
|
103
124
|
function widgetOf(state) {
|
|
104
125
|
if (state.query === void 0) return void 0;
|
|
105
126
|
return {
|
|
127
|
+
...state.base,
|
|
106
128
|
kind: state.kind,
|
|
107
129
|
title: state.title || "Untitled widget",
|
|
108
|
-
queries: {
|
|
130
|
+
queries: {
|
|
131
|
+
...state.base?.queries,
|
|
132
|
+
main: state.query
|
|
133
|
+
}
|
|
109
134
|
};
|
|
110
135
|
}
|
|
111
|
-
export {
|
|
136
|
+
export { DEFAULT_RANGE, cleared, defaultTime, emptyBuilder, freshId, keptAside, lastPart, refersTo, setKind, setTitle, widgetOf, withQuery };
|
|
@@ -107,4 +107,18 @@ function removeCalc(meta, state, id) {
|
|
|
107
107
|
calc
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
/** Adds a calculation of the widget's own, from a formula the builder has already read. */
|
|
111
|
+
function addFormula(meta, state, calc) {
|
|
112
|
+
const query = state.query;
|
|
113
|
+
if (query === void 0) return state;
|
|
114
|
+
const next = {
|
|
115
|
+
id: freshId(query, calc.label),
|
|
116
|
+
formula: calc.formula,
|
|
117
|
+
label: calc.label
|
|
118
|
+
};
|
|
119
|
+
return withQuery(meta, state, {
|
|
120
|
+
...query,
|
|
121
|
+
calc: [...query.calc ?? [], next]
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export { addCalc, addFormula, presetsFor, removeCalc, updateCalc };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
// src/builder/escape.ts
|
|
3
|
+
/** Whether a key went to a field the person is typing in, where Escape is theirs. */
|
|
4
|
+
const isTyping = (event) => event.target instanceof HTMLElement && event.target.closest("input, textarea, select, [contenteditable]") !== null;
|
|
5
|
+
/** The builder a person last worked in: an Escape sent to the page (no focus) is its. */
|
|
6
|
+
let active = null;
|
|
7
|
+
/** Whether this Escape is this builder's: sent inside it, or to the page while it is the active one. */
|
|
8
|
+
function owns(root, event) {
|
|
9
|
+
const at = event.target instanceof Element ? event.target : null;
|
|
10
|
+
if (at !== null && at !== document.body) return root.contains(at);
|
|
11
|
+
return active === root;
|
|
12
|
+
}
|
|
13
|
+
/** Marks a builder active when it mounts and whenever focus or a press goes into it. */
|
|
14
|
+
function useActive(ref) {
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const root = ref.current;
|
|
17
|
+
if (root === null) return;
|
|
18
|
+
active = root;
|
|
19
|
+
const mark = () => {
|
|
20
|
+
active = root;
|
|
21
|
+
};
|
|
22
|
+
root.addEventListener("focusin", mark);
|
|
23
|
+
root.addEventListener("pointerdown", mark);
|
|
24
|
+
return () => {
|
|
25
|
+
root.removeEventListener("focusin", mark);
|
|
26
|
+
root.removeEventListener("pointerdown", mark);
|
|
27
|
+
if (active === root) active = null;
|
|
28
|
+
};
|
|
29
|
+
}, [ref]);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Escape leaves an untouched builder as Cancel does, unless a picker already took it. With
|
|
33
|
+
* unsaved work it never throws it away: outside a field it moves focus to this builder's Cancel,
|
|
34
|
+
* so leaving is one more deliberate key; in a field it is the field's. With two builders on a
|
|
35
|
+
* page, each answers only the Escapes that are its own.
|
|
36
|
+
*/
|
|
37
|
+
function useEscapeToLeave(ref, widget, onCancel) {
|
|
38
|
+
const start = useRef(widget);
|
|
39
|
+
const latest = useRef({
|
|
40
|
+
widget,
|
|
41
|
+
onCancel
|
|
42
|
+
});
|
|
43
|
+
latest.current = {
|
|
44
|
+
widget,
|
|
45
|
+
onCancel
|
|
46
|
+
};
|
|
47
|
+
useActive(ref);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const onKey = (event) => {
|
|
50
|
+
const root = ref.current;
|
|
51
|
+
if (event.key !== "Escape" || event.defaultPrevented || root === null) return;
|
|
52
|
+
if (!owns(root, event)) return;
|
|
53
|
+
if (latest.current.widget === start.current) latest.current.onCancel();
|
|
54
|
+
else if (!isTyping(event)) root.querySelector("[data-builder-cancel]")?.focus();
|
|
55
|
+
};
|
|
56
|
+
globalThis.addEventListener("keydown", onKey);
|
|
57
|
+
return () => {
|
|
58
|
+
globalThis.removeEventListener("keydown", onKey);
|
|
59
|
+
};
|
|
60
|
+
}, [ref]);
|
|
61
|
+
}
|
|
62
|
+
export { useEscapeToLeave };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Op, Primitive } from "derive-dashboards/core";
|
|
2
|
+
/**
|
|
3
|
+
* A widget's filter as the builder edits it: rows matching all (or any) of the top's children.
|
|
4
|
+
* A child is a condition, a group of conditions matching all, any or none of them, or a part the
|
|
5
|
+
* builder cannot edit (a viewer value, a variable, deeper nesting), which it keeps as written.
|
|
6
|
+
*/
|
|
7
|
+
type Mode = "all" | "any";
|
|
8
|
+
export type GroupMode = Mode | "none";
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/builder/filter-tree.ts
|
|
2
|
+
const TOP = "filters";
|
|
3
|
+
const conditionOf = (node) => "values" in node ? {
|
|
4
|
+
id: node.id,
|
|
5
|
+
member: node.member,
|
|
6
|
+
op: node.op,
|
|
7
|
+
values: node.values
|
|
8
|
+
} : void 0;
|
|
9
|
+
/** Conditions only, or undefined when any part is not one. */
|
|
10
|
+
function conditionsOf(nodes) {
|
|
11
|
+
const out = nodes.map((n) => conditionOf(n));
|
|
12
|
+
return out.every((c) => c !== void 0) ? out : void 0;
|
|
13
|
+
}
|
|
14
|
+
/** A group's conditions and how it matches them, or undefined when it is not one the builder edits. */
|
|
15
|
+
function groupParts(node) {
|
|
16
|
+
if ("all" in node) return {
|
|
17
|
+
mode: "all",
|
|
18
|
+
list: node.all
|
|
19
|
+
};
|
|
20
|
+
if ("any" in node) return {
|
|
21
|
+
mode: "any",
|
|
22
|
+
list: node.any
|
|
23
|
+
};
|
|
24
|
+
if ("not" in node && "any" in node.not) return {
|
|
25
|
+
mode: "none",
|
|
26
|
+
list: node.not.any
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function childOf(node) {
|
|
30
|
+
const leaf = conditionOf(node);
|
|
31
|
+
if (leaf !== void 0) return {
|
|
32
|
+
kind: "condition",
|
|
33
|
+
node: leaf
|
|
34
|
+
};
|
|
35
|
+
const parts = groupParts(node);
|
|
36
|
+
const conditions = parts === void 0 ? void 0 : conditionsOf(parts.list);
|
|
37
|
+
if (parts === void 0 || conditions === void 0 || conditions.length === 0) return {
|
|
38
|
+
kind: "kept",
|
|
39
|
+
node
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
kind: "group",
|
|
43
|
+
id: node.id,
|
|
44
|
+
mode: parts.mode,
|
|
45
|
+
conditions
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** The tree of a stored filter: its top `all` or `any`, or the one node under an implied all. */
|
|
49
|
+
function treeOf(filter) {
|
|
50
|
+
if (filter === void 0) return {
|
|
51
|
+
mode: "all",
|
|
52
|
+
children: []
|
|
53
|
+
};
|
|
54
|
+
if ("all" in filter && filter.id === TOP) return {
|
|
55
|
+
mode: "all",
|
|
56
|
+
children: filter.all.map((n) => childOf(n))
|
|
57
|
+
};
|
|
58
|
+
if ("any" in filter && filter.id === TOP) return {
|
|
59
|
+
mode: "any",
|
|
60
|
+
children: filter.any.map((n) => childOf(n))
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
mode: "all",
|
|
64
|
+
children: [childOf(filter)]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const leafNode = (c) => ({
|
|
68
|
+
id: c.id,
|
|
69
|
+
member: c.member,
|
|
70
|
+
op: c.op,
|
|
71
|
+
values: [...c.values]
|
|
72
|
+
});
|
|
73
|
+
function nodeOf(child) {
|
|
74
|
+
if (child.kind === "condition") return leafNode(child.node);
|
|
75
|
+
if (child.kind === "kept") return child.node;
|
|
76
|
+
const leaves = child.conditions.map(leafNode);
|
|
77
|
+
if (child.mode === "none") return {
|
|
78
|
+
id: child.id,
|
|
79
|
+
not: {
|
|
80
|
+
id: `${child.id}-any`,
|
|
81
|
+
any: leaves
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return child.mode === "all" ? {
|
|
85
|
+
id: child.id,
|
|
86
|
+
all: leaves
|
|
87
|
+
} : {
|
|
88
|
+
id: child.id,
|
|
89
|
+
any: leaves
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** The stored filter of a tree; none when it has no children. Empty groups are dropped. */
|
|
93
|
+
function storedOf(tree) {
|
|
94
|
+
const children = tree.children.filter((c) => c.kind !== "group" || c.conditions.length > 0);
|
|
95
|
+
if (children.length === 0) return void 0;
|
|
96
|
+
const nodes = children.map((c) => nodeOf(c));
|
|
97
|
+
return tree.mode === "all" ? {
|
|
98
|
+
id: TOP,
|
|
99
|
+
all: nodes
|
|
100
|
+
} : {
|
|
101
|
+
id: TOP,
|
|
102
|
+
any: nodes
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function ids(node, out) {
|
|
106
|
+
out.add(node.id);
|
|
107
|
+
const kids = "all" in node ? node.all : "any" in node ? node.any : "not" in node ? [node.not] : [];
|
|
108
|
+
for (const k of kids) ids(k, out);
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/** An id no node of the filter has: f1, f2, … (or g1, … for a group). */
|
|
112
|
+
function freeId(filter, prefix) {
|
|
113
|
+
const taken = filter === void 0 ? /* @__PURE__ */ new Set() : ids(filter, /* @__PURE__ */ new Set());
|
|
114
|
+
let n = 1;
|
|
115
|
+
while (taken.has(`${prefix}${String(n)}`) || taken.has(`${prefix}${String(n)}-any`)) n += 1;
|
|
116
|
+
return `${prefix}${String(n)}`;
|
|
117
|
+
}
|
|
118
|
+
/** Adds a condition at the top, to a group, or (with `group: "new"`) as a new group of one. */
|
|
119
|
+
function addCondition(filter, condition, group) {
|
|
120
|
+
const tree = treeOf(filter);
|
|
121
|
+
const node = {
|
|
122
|
+
...condition,
|
|
123
|
+
id: freeId(filter, "f")
|
|
124
|
+
};
|
|
125
|
+
if (group === "new") {
|
|
126
|
+
const id = freeId(filter, "g");
|
|
127
|
+
return storedOf({
|
|
128
|
+
...tree,
|
|
129
|
+
children: [...tree.children, {
|
|
130
|
+
kind: "group",
|
|
131
|
+
id,
|
|
132
|
+
mode: "any",
|
|
133
|
+
conditions: [node]
|
|
134
|
+
}]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (group === void 0) return storedOf({
|
|
138
|
+
...tree,
|
|
139
|
+
children: [...tree.children, {
|
|
140
|
+
kind: "condition",
|
|
141
|
+
node
|
|
142
|
+
}]
|
|
143
|
+
});
|
|
144
|
+
const children = tree.children.map((c) => c.kind === "group" && c.id === group ? {
|
|
145
|
+
...c,
|
|
146
|
+
conditions: [...c.conditions, node]
|
|
147
|
+
} : c);
|
|
148
|
+
return storedOf({
|
|
149
|
+
...tree,
|
|
150
|
+
children
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** Removes a condition, a group or a kept part, wherever it is. */
|
|
154
|
+
function removeNode(filter, id) {
|
|
155
|
+
const tree = treeOf(filter);
|
|
156
|
+
const children = tree.children.flatMap((c) => {
|
|
157
|
+
if (c.kind === "condition") return c.node.id === id ? [] : [c];
|
|
158
|
+
if (c.kind === "kept") return c.node.id === id ? [] : [c];
|
|
159
|
+
if (c.id === id) return [];
|
|
160
|
+
return [{
|
|
161
|
+
...c,
|
|
162
|
+
conditions: c.conditions.filter((k) => k.id !== id)
|
|
163
|
+
}];
|
|
164
|
+
});
|
|
165
|
+
return storedOf({
|
|
166
|
+
...tree,
|
|
167
|
+
children
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/** Sets how the top matches its children, or how one group matches its conditions. */
|
|
171
|
+
function setMode(filter, mode, group) {
|
|
172
|
+
const tree = treeOf(filter);
|
|
173
|
+
if (group === void 0) return mode === "none" ? filter : storedOf({
|
|
174
|
+
...tree,
|
|
175
|
+
mode
|
|
176
|
+
});
|
|
177
|
+
const children = tree.children.map((c) => c.kind === "group" && c.id === group ? {
|
|
178
|
+
...c,
|
|
179
|
+
mode
|
|
180
|
+
} : c);
|
|
181
|
+
return storedOf({
|
|
182
|
+
...tree,
|
|
183
|
+
children
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
export { addCondition, removeNode, setMode, storedOf, treeOf };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "derive-dashboards/core";
|
|
2
|
+
/** What went wrong, and where: `at` is the 1-based character it was found at. */
|
|
3
|
+
export type FormulaProblem = {
|
|
4
|
+
kind: "empty";
|
|
5
|
+
} | {
|
|
6
|
+
kind: "expected";
|
|
7
|
+
at: number;
|
|
8
|
+
} | {
|
|
9
|
+
kind: "unknown";
|
|
10
|
+
at: number;
|
|
11
|
+
text: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "unclosed";
|
|
14
|
+
at: number;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "unopened";
|
|
17
|
+
at: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/builder/formula-parse.ts
|
|
2
|
+
/** An error that carries the problem, so the reader can stop where it found it. */
|
|
3
|
+
const fail = (problem) => Object.assign(new Error(problem.kind), { problem });
|
|
4
|
+
const isFailed = (error) => error instanceof Error && "problem" in error;
|
|
5
|
+
/** One pass over a formula's text: `at` is where it has read to. */
|
|
6
|
+
var Reader = class {
|
|
7
|
+
text;
|
|
8
|
+
names;
|
|
9
|
+
at = 0;
|
|
10
|
+
uses = /* @__PURE__ */ new Set();
|
|
11
|
+
constructor(text, names) {
|
|
12
|
+
this.text = text;
|
|
13
|
+
this.names = names;
|
|
14
|
+
}
|
|
15
|
+
peek() {
|
|
16
|
+
while (this.text[this.at] === " ") this.at += 1;
|
|
17
|
+
return this.text[this.at];
|
|
18
|
+
}
|
|
19
|
+
sum() {
|
|
20
|
+
return this.chain(["+", "-"], () => this.product());
|
|
21
|
+
}
|
|
22
|
+
product() {
|
|
23
|
+
return this.chain(["*", "/"], () => this.factor());
|
|
24
|
+
}
|
|
25
|
+
chain(ops, next) {
|
|
26
|
+
let left = next();
|
|
27
|
+
for (let op = this.opAt(ops); op !== void 0; op = this.opAt(ops)) {
|
|
28
|
+
this.at += 1;
|
|
29
|
+
left = {
|
|
30
|
+
op,
|
|
31
|
+
args: [left, next()]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return left;
|
|
35
|
+
}
|
|
36
|
+
/** The operator next in the text, when it is one of `ops`. */
|
|
37
|
+
opAt(ops) {
|
|
38
|
+
const c = this.peek();
|
|
39
|
+
return ops.find((o) => o === c);
|
|
40
|
+
}
|
|
41
|
+
factor() {
|
|
42
|
+
const c = this.peek();
|
|
43
|
+
const at = this.at + 1;
|
|
44
|
+
if (c === void 0) throw fail({
|
|
45
|
+
kind: "expected",
|
|
46
|
+
at
|
|
47
|
+
});
|
|
48
|
+
if (c === "-") {
|
|
49
|
+
this.at += 1;
|
|
50
|
+
return {
|
|
51
|
+
op: "-",
|
|
52
|
+
args: [{ lit: 0 }, this.factor()]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (c === "(") return this.bracketed(at);
|
|
56
|
+
if (this.text.slice(this.at, this.at + 4).toLowerCase() === "abs(") {
|
|
57
|
+
this.at += 3;
|
|
58
|
+
return {
|
|
59
|
+
op: "abs",
|
|
60
|
+
args: [this.bracketed(this.at + 1)]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return this.atom(c, at);
|
|
64
|
+
}
|
|
65
|
+
/** A number or a name; anything else is a problem at `at`. */
|
|
66
|
+
atom(c, at) {
|
|
67
|
+
const rest = this.text.slice(this.at);
|
|
68
|
+
const number = /^\d+(\.\d+)?/u.exec(rest);
|
|
69
|
+
if (number !== null) {
|
|
70
|
+
this.at += number[0].length;
|
|
71
|
+
return { lit: Number(number[0]) };
|
|
72
|
+
}
|
|
73
|
+
const hit = this.names.find((n) => rest.toLowerCase().startsWith(n.label.toLowerCase()));
|
|
74
|
+
if (hit !== void 0) {
|
|
75
|
+
this.at += hit.label.length;
|
|
76
|
+
this.uses.add(hit.id);
|
|
77
|
+
return { ref: hit.id };
|
|
78
|
+
}
|
|
79
|
+
if (c === ")") throw fail({
|
|
80
|
+
kind: "unopened",
|
|
81
|
+
at
|
|
82
|
+
});
|
|
83
|
+
const word = /^[^+\-*/()]+/u.exec(rest)?.[0].trim() ?? c;
|
|
84
|
+
throw fail({
|
|
85
|
+
kind: "unknown",
|
|
86
|
+
at,
|
|
87
|
+
text: word
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
bracketed(at) {
|
|
91
|
+
this.at += 1;
|
|
92
|
+
const inside = this.sum();
|
|
93
|
+
if (this.peek() !== ")") throw fail({
|
|
94
|
+
kind: "unclosed",
|
|
95
|
+
at
|
|
96
|
+
});
|
|
97
|
+
this.at += 1;
|
|
98
|
+
return inside;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Reads a formula as people write it: the widget's measure and calc names, numbers, + - * /,
|
|
103
|
+
* brackets and abs(…). Names match without case, the longest first, so "Hours logged" wins over
|
|
104
|
+
* "Hours". Precedence is the usual one; a leading minus is 0 minus the value.
|
|
105
|
+
*/
|
|
106
|
+
function parseFormula(text, names) {
|
|
107
|
+
if (text.trim() === "") return {
|
|
108
|
+
ok: false,
|
|
109
|
+
problem: { kind: "empty" }
|
|
110
|
+
};
|
|
111
|
+
const r = new Reader(text, names.toSorted((a, b) => b.label.length - a.label.length));
|
|
112
|
+
try {
|
|
113
|
+
const formula = r.sum();
|
|
114
|
+
const next = r.peek();
|
|
115
|
+
if (next === ")") throw fail({
|
|
116
|
+
kind: "unopened",
|
|
117
|
+
at: r.at + 1
|
|
118
|
+
});
|
|
119
|
+
if (next !== void 0) throw fail({
|
|
120
|
+
kind: "expected",
|
|
121
|
+
at: r.at + 1
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
ok: true,
|
|
125
|
+
formula,
|
|
126
|
+
uses: [...r.uses]
|
|
127
|
+
};
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (isFailed(error)) return {
|
|
130
|
+
ok: false,
|
|
131
|
+
problem: error.problem
|
|
132
|
+
};
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export { parseFormula };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import { StoredQuery } from "derive-dashboards/core";
|
|
1
|
+
import { MetaResponse, StoredQuery } from "derive-dashboards/core";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "./base.mjs";
|
|
2
|
+
import "./filter-tree.mjs";
|
|
2
3
|
import "./labels.mjs";
|
|
3
|
-
import { DateRange, Grain, StoredQuery } from "derive-dashboards/core";
|
|
4
|
+
import { DateRange, Grain, Op, Primitive, StoredQuery } from "derive-dashboards/core";
|
|
4
5
|
type Time = NonNullable<StoredQuery["time"]>;
|
|
5
6
|
/** A change to the time part. A grain of "total" is one total; a compare of "none" drops it. */
|
|
6
7
|
export type TimeChange = {
|