@malloy-publisher/sdk 0.3.0 → 0.4.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.
Files changed (244) hide show
  1. package/README.md +22 -9
  2. package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
  3. package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
  4. package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
  5. package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
  6. package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
  7. package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9482 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +100 -42
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/AppDialog.d.ts +30 -0
  16. package/dist/components/BackLink.d.ts +32 -0
  17. package/dist/components/Dashboard/Dashboard.d.ts +19 -14
  18. package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
  19. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  20. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  21. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  22. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  23. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  24. package/dist/components/Dashboard/index.d.ts +2 -0
  25. package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
  26. package/dist/components/Dashboard/telemetry.d.ts +48 -0
  27. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  28. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
  29. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
  30. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -0
  31. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  32. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  33. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  34. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  36. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  37. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  38. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  39. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  40. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  41. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  42. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  43. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  44. package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
  45. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  46. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  47. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  48. package/dist/components/DashboardBuilder/spliceDocument.d.ts +53 -0
  49. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  50. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  51. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  52. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  53. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  54. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  55. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  56. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
  57. package/dist/components/DocumentStorage/index.d.ts +1 -1
  58. package/dist/components/FloatingIconButton.d.ts +16 -0
  59. package/dist/components/ItemRow.d.ts +38 -0
  60. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
  61. package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
  62. package/dist/components/Materializations/Materializations.d.ts +7 -3
  63. package/dist/components/Materializations/ScopeButton.d.ts +18 -0
  64. package/dist/components/Materializations/SectionLabel.d.ts +7 -4
  65. package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
  66. package/dist/components/Materializations/index.d.ts +0 -1
  67. package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
  68. package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
  69. package/dist/components/Package/index.d.ts +0 -1
  70. package/dist/components/PackageSection.d.ts +23 -0
  71. package/dist/components/Prose.d.ts +46 -0
  72. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  73. package/dist/components/RenderedResult/index.d.ts +1 -0
  74. package/dist/components/buttons.d.ts +53 -0
  75. package/dist/components/drill/index.d.ts +1 -1
  76. package/dist/components/drill/resolveDrill.d.ts +22 -0
  77. package/dist/components/drill/useDrill.d.ts +11 -2
  78. package/dist/components/index.d.ts +6 -0
  79. package/dist/components/styles.d.ts +49 -44
  80. package/dist/hooks/index.d.ts +2 -0
  81. package/dist/hooks/useCrudMutation.d.ts +42 -0
  82. package/dist/hooks/useDocumentControls.d.ts +70 -0
  83. package/dist/hooks/useQueryResult.d.ts +40 -0
  84. package/dist/index.cjs.js +22 -273
  85. package/dist/index.d.ts +1 -0
  86. package/dist/index.es.js +16888 -44451
  87. package/dist/telemetry/consoleEvents.d.ts +60 -0
  88. package/dist/utils/malloyLiteral.d.ts +11 -0
  89. package/dist/utils/sha256.d.ts +2 -0
  90. package/package.json +24 -9
  91. package/src/builder-entry.ts +55 -0
  92. package/src/components/AppDialog.tsx +115 -0
  93. package/src/components/BackLink.tsx +83 -0
  94. package/src/components/Connections/AddConnectionDialog.tsx +50 -70
  95. package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
  96. package/src/components/Connections/EditConnectionDialog.tsx +54 -73
  97. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  98. package/src/components/Dashboard/Dashboard.tsx +165 -175
  99. package/src/components/Dashboard/DashboardBar.tsx +88 -0
  100. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  101. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  102. package/src/components/Dashboard/DashboardTile.tsx +66 -123
  103. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  104. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  105. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  106. package/src/components/Dashboard/TileCard.tsx +120 -0
  107. package/src/components/Dashboard/index.ts +2 -0
  108. package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
  109. package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
  110. package/src/components/Dashboard/telemetry.ts +51 -0
  111. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  112. package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
  113. package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
  114. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
  115. package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
  116. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
  117. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
  118. package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
  119. package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
  120. package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
  121. package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
  122. package/src/components/DashboardBuilder/FilterStrip.tsx +126 -0
  123. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  124. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  125. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  126. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  127. package/src/components/DashboardBuilder/catalog.ts +225 -0
  128. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  129. package/src/components/DashboardBuilder/controls.ts +398 -0
  130. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  131. package/src/components/DashboardBuilder/diff.ts +93 -0
  132. package/src/components/DashboardBuilder/document.ts +209 -0
  133. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  134. package/src/components/DashboardBuilder/layout.ts +143 -0
  135. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  136. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  137. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  138. package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
  139. package/src/components/DashboardBuilder/newDashboard.ts +48 -0
  140. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  141. package/src/components/DashboardBuilder/preview.ts +172 -0
  142. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  143. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  144. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  145. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1161 -0
  146. package/src/components/DashboardBuilder/spliceDocument.ts +1135 -0
  147. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  148. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  149. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +311 -0
  150. package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -0
  151. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  152. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  153. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  154. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  155. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  156. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  157. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  158. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  159. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
  160. package/src/components/DocumentStorage/index.ts +1 -0
  161. package/src/components/Environment/About.tsx +16 -62
  162. package/src/components/Environment/AddPackageDialog.tsx +85 -154
  163. package/src/components/Environment/Connections.tsx +125 -205
  164. package/src/components/Environment/DeletePackageDialog.tsx +32 -77
  165. package/src/components/Environment/EditPackageDialog.tsx +46 -58
  166. package/src/components/Environment/Environment.tsx +34 -36
  167. package/src/components/Environment/Packages.tsx +63 -128
  168. package/src/components/FloatingIconButton.tsx +41 -0
  169. package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
  170. package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
  171. package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
  172. package/src/components/Home/Home.tsx +101 -214
  173. package/src/components/ItemRow.tsx +165 -0
  174. package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
  175. package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
  176. package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
  177. package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
  178. package/src/components/Materializations/Materializations.tsx +137 -140
  179. package/src/components/Materializations/ScopeButton.tsx +85 -0
  180. package/src/components/Materializations/SectionLabel.tsx +7 -4
  181. package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
  182. package/src/components/Materializations/TriggerLabel.tsx +36 -0
  183. package/src/components/Materializations/cron.spec.ts +113 -0
  184. package/src/components/Materializations/index.ts +0 -1
  185. package/src/components/Materializations/utils.spec.ts +182 -0
  186. package/src/components/Model/Model.tsx +6 -23
  187. package/src/components/Model/ModelCell.tsx +33 -72
  188. package/src/components/Notebook/Notebook.tsx +25 -88
  189. package/src/components/Notebook/NotebookCell.tsx +35 -183
  190. package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
  191. package/src/components/Package/ContentTypeIcon.tsx +10 -12
  192. package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
  193. package/src/components/Package/NewDashboardDialog.tsx +265 -0
  194. package/src/components/Package/Package.tsx +179 -238
  195. package/src/components/Package/index.ts +0 -1
  196. package/src/components/PackageSection.tsx +85 -0
  197. package/src/components/Prose.spec.tsx +85 -0
  198. package/src/components/Prose.tsx +179 -0
  199. package/src/components/QueryResult/QueryResult.tsx +15 -43
  200. package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
  201. package/src/components/RenderedResult/RenderedResult.tsx +22 -8
  202. package/src/components/RenderedResult/ResultContainer.tsx +4 -12
  203. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  204. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  205. package/src/components/RenderedResult/index.ts +1 -0
  206. package/src/components/ResultsDialog.tsx +8 -32
  207. package/src/components/buttons.tsx +114 -0
  208. package/src/components/designSystem.spec.tsx +316 -0
  209. package/src/components/drill/index.ts +1 -0
  210. package/src/components/drill/resolveDrill.ts +22 -1
  211. package/src/components/drill/useDrill.spec.tsx +94 -0
  212. package/src/components/drill/useDrill.tsx +52 -12
  213. package/src/components/given/GivensPanel.tsx +1 -1
  214. package/src/components/given/paramCodec.spec.ts +1 -1
  215. package/src/components/index.ts +16 -0
  216. package/src/components/styles.ts +49 -122
  217. package/src/hooks/index.ts +13 -0
  218. package/src/hooks/useCrudMutation.spec.tsx +119 -0
  219. package/src/hooks/useCrudMutation.tsx +85 -0
  220. package/src/hooks/useDocumentControls.ts +170 -0
  221. package/src/hooks/useQueryResult.ts +82 -0
  222. package/src/index.ts +9 -0
  223. package/src/telemetry/consoleEvents.spec.ts +130 -0
  224. package/src/telemetry/consoleEvents.ts +124 -0
  225. package/src/theme/defaults.ts +34 -23
  226. package/src/theme/resolveTheme.spec.ts +9 -4
  227. package/src/theme/resolveTheme.ts +12 -8
  228. package/src/utils/malloyLiteral.spec.ts +43 -0
  229. package/src/utils/malloyLiteral.ts +76 -0
  230. package/src/utils/sha256.ts +13 -0
  231. package/test/README.md +1 -1
  232. package/test/serverProvider.tsx +5 -2
  233. package/vite.config.ts +5 -0
  234. package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
  235. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
  236. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
  237. package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
  238. package/dist/components/Materializations/TriggerChip.d.ts +0 -10
  239. package/dist/components/Package/Models.d.ts +0 -6
  240. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
  241. package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
  242. package/src/components/Materializations/ScheduleCard.tsx +0 -231
  243. package/src/components/Materializations/TriggerChip.tsx +0 -44
  244. package/src/components/Package/Models.tsx +0 -71
@@ -2,20 +2,34 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Alert, Box, Stack, Typography } from "@mui/material";
5
- import Markdown from "markdown-to-jsx";
6
- import { useCallback, useMemo } from "react";
5
+ import { useCallback, useMemo, useState } from "react";
7
6
  import type { DashboardManifest } from "../../client";
8
- import { useGivensState } from "../../hooks/useGivensState";
7
+ import { useDocumentControls } from "../../hooks/useDocumentControls";
9
8
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
10
- import { useSuggestOptions } from "../../hooks/useSuggestOptions";
11
9
  import { parseResourceUri } from "../../utils/formatting";
12
10
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
13
- import { useDrill, useDrillSelf, type DrillNavigation } from "../drill";
11
+ import {
12
+ useDrill,
13
+ type DrillBinding,
14
+ type DrillClickPayload,
15
+ type DrillNavigation,
16
+ type DrillRowsRequest,
17
+ } from "../drill";
14
18
  import { GivensPanel } from "../given";
19
+ import { Prose } from "../Prose";
20
+ import { givensToRequest } from "../given/paramCodec";
15
21
  import { Loading } from "../Loading";
16
22
  import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
17
23
  import { useServer } from "../ServerProvider";
24
+ import { DashboardGrid, DEFAULT_COLUMNS } from "./DashboardGrid";
18
25
  import { DashboardTile } from "./DashboardTile";
26
+ import { ExploreDialog } from "./ExploreDialog";
27
+ import { RowsDialog, stepsOf, type RowsRequest } from "./RowsDialog";
28
+ import type { DashboardEventHandler } from "./telemetry";
29
+
30
+ // The grid rule moved to `DashboardGrid`, which the builder shares.
31
+ // Re-exported so existing importers of it are unaffected.
32
+ export { DEFAULT_COLUMNS, tileGridColumn } from "./DashboardGrid";
19
33
 
20
34
  export interface DashboardProps {
21
35
  /** `publisher://environments/{env}/packages/{pkg}`, optionally `?versionId=`. */
@@ -58,26 +72,8 @@ export interface DashboardProps {
58
72
  */
59
73
  height?: number;
60
74
  maxResultSize?: number;
61
- }
62
-
63
- /** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
64
- const DEFAULT_COLUMNS = 2;
65
-
66
- /**
67
- * The `grid-column` one tile occupies: its `# colspan`, and a `# break` forcing
68
- * it to start a fresh row.
69
- *
70
- * Clamped to the grid width the same way @malloydata/render clamps it, so one
71
- * view laid out as a composite tile and as a `nest:` under `# dashboard` lands
72
- * in the same place. A break is `1 / span N` — an explicit start line, which is
73
- * what pushes the tile down to the next row; the renderer's grid does the same.
74
- */
75
- export function tileGridColumn(
76
- tile: { colspan?: number; break?: boolean },
77
- columns: number,
78
- ): string {
79
- const span = Math.min(tile.colspan ?? 1, columns);
80
- return tile.break ? `1 / span ${span}` : `span ${span}`;
75
+ /** The rows shown and tiles explored, for the host to log or count. */
76
+ onEvent?: DashboardEventHandler;
81
77
  }
82
78
 
83
79
  /**
@@ -97,6 +93,7 @@ export function Dashboard({
97
93
  onNavigate,
98
94
  height,
99
95
  maxResultSize,
96
+ onEvent,
100
97
  }: DashboardProps) {
101
98
  const parsed = parseResourceUri(resourceUri);
102
99
  const { apiClients } = useServer();
@@ -143,85 +140,72 @@ export function Dashboard({
143
140
  const manifest = manifestResponse?.data;
144
141
 
145
142
  const specs = useMemo(() => manifest?.givens ?? [], [manifest]);
146
- const declaredTypes = useMemo(
147
- () =>
148
- new Map(
149
- specs
150
- .filter((spec) => spec.name !== undefined)
151
- .map((spec) => [spec.name as string, spec.type]),
152
- ),
153
- [specs],
154
- );
155
143
 
156
- // Hands the host the names this dashboard MANAGES alongside the values, so it
157
- // can merge into a shared query string instead of replacing it. Guarded on
158
- // `isSuccess` as well as at the call site, since an empty declared set before
159
- // the manifest lands is the absence of an answer rather than the answer.
160
- const reportGivens = useCallback(
161
- (next: Record<string, string>) => {
162
- if (!isSuccess) return;
163
- onGivensChange?.(next, Array.from(declaredTypes.keys()));
164
- },
165
- [isSuccess, onGivensChange, declaredTypes],
166
- );
167
-
168
- const { draft, applied, setGiven, reset, apply, pending } = useGivensState({
169
- declaredTypes,
144
+ // The control row's state, options and `to=self` drill: the same hook the
145
+ // notebook uses, so a control behaves identically on both surfaces.
146
+ const controls = useDocumentControls({
147
+ specs,
148
+ loaded: isSuccess,
170
149
  startingValues: manifest?.startingGivens,
171
150
  params: givens,
172
- // Withheld until the manifest has loaded, for the same reason the notebook
173
- // withholds it. Changing `dashboard` changes the query key, so `data` is
174
- // undefined for one commit and `declaredTypes` is empty; `applied` prunes
175
- // to nothing and the hook reports "no values, and I manage nothing". This
176
- // component is reconciled rather than remounted on a dashboard-to-dashboard
177
- // drill, so the hook's record of what it last reported still holds the
178
- // PREVIOUS dashboard's values and does not suppress that report as a
179
- // repeat. The host reasonably clears its query string, which is exactly the
180
- // givens the drill just seeded for the dashboard now arriving.
181
- onParamsChange: isSuccess ? reportGivens : undefined,
182
- // Which document these edits belong to. Without it the edits are keyed by
183
- // their starting VALUES alone, so two dashboards whose starting values
184
- // coincide (the common case: both empty) look like one document, and the
185
- // one you came from keeps filtering the one you drilled into.
186
- // The version belongs in that identity too, so a swap between versions
187
- // drops the edits a reader made to the one they came from. Only the
188
- // EDITS: `initial` is `startingValues` merged with `params`, so a host
189
- // that round-trips givens through its own URL hands them straight back
190
- // and they still apply across the swap. That one is the host's call, and
191
- // this key neither can nor should overrule it.
151
+ onGivensChange,
152
+ // Which document these edits belong to, version included: two
153
+ // dashboards whose starting values coincide (both empty, usually)
154
+ // would otherwise look like one document, and the one you came from
155
+ // would keep filtering the one you drilled into. Only the EDITS: a host
156
+ // that round-trips givens through its own URL hands them straight back,
157
+ // and they still apply across the swap.
192
158
  documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${dashboard}`,
193
159
  // Absent means autorun; only an explicit `autorun=false` batches.
194
160
  autorun: manifest?.autorun !== false,
195
- });
196
-
197
- const {
198
- options,
199
- isLoading: optionsLoading,
200
- failed: optionsFailed,
201
- } = useSuggestOptions(
202
161
  environmentName,
203
162
  packageName,
204
- manifest?.path,
205
- specs,
163
+ modelPath: manifest?.path,
206
164
  versionId,
207
- // So a suggest over a gated or scoped source carries the givens it needs.
208
- { values: applied, declaredTypes },
209
- );
210
-
211
- // `to=self` filters in place. Which givens a tag may set, and setting one
212
- // from a clicked cell, is the same on both surfaces, so it is shared.
213
- const { canSelf, onSelf } = useDrillSelf({
214
- declaredTypes,
215
- setGiven,
216
165
  documentName: dashboard,
217
166
  });
167
+ const { applied, declaredTypes, canSelf, onSelf } = controls;
168
+
169
+ // The rows behind a clicked value, and a tile's query in the explorer —
170
+ // the two ways past a number. Composite tiles only: each names its
171
+ // source, which is what the rows are of and what the explorer opens on.
172
+ const [rows, setRows] = useState<RowsRequest | undefined>(undefined);
173
+ const [exploring, setExploring] = useState<string | undefined>(undefined);
174
+ const onRows = useCallback((request: DrillRowsRequest) => {
175
+ const steps = stepsOf(request.context);
176
+ if (steps === undefined) return;
177
+ setRows({
178
+ ...steps,
179
+ field: request.field,
180
+ rawValue: request.rawValue,
181
+ label: request.label,
182
+ });
183
+ }, []);
184
+
185
+ // The whole applied row: a source's own `where:` may read any of it, and a
186
+ // given the rows query does not reference is ignored by the server.
187
+ const rowsGivens = useMemo(
188
+ () => givensToRequest(applied, declaredTypes),
189
+ [applied, declaredTypes],
190
+ );
218
191
 
219
192
  const { drill, drillMenu } = useDrill({
220
193
  onNavigate,
221
194
  onSelf,
222
195
  canSelf,
223
196
  selfLabel: "Filter this dashboard",
197
+ onRows,
224
198
  });
199
+ // Each tile's clicks carry the tile they came from, so the rows behind a
200
+ // value know which source to run against.
201
+ const drillFor = useCallback(
202
+ (tile: string): DrillBinding => ({
203
+ canDrill: drill.canDrill,
204
+ onClick: (payload: DrillClickPayload) =>
205
+ drill.onClick({ ...payload, context: tile }),
206
+ }),
207
+ [drill],
208
+ );
225
209
 
226
210
  // After every hook, so the hook order does not depend on the URI.
227
211
  if (!uriNamesBoth) {
@@ -271,21 +255,7 @@ export function Dashboard({
271
255
  <Stack spacing={2}>
272
256
  <DashboardHeader manifest={manifest} />
273
257
 
274
- <GivensPanel
275
- givens={specs}
276
- values={draft}
277
- onChange={setGiven}
278
- onReset={reset}
279
- layout="bar"
280
- options={options}
281
- optionsLoading={optionsLoading}
282
- optionsFailed={optionsFailed}
283
- apply={
284
- manifest.autorun === false
285
- ? { onApply: apply, pending }
286
- : undefined
287
- }
288
- />
258
+ <GivensPanel {...controls.panel} layout="bar" />
289
259
 
290
260
  {modelPath === undefined ? (
291
261
  <Alert severity="error">
@@ -311,50 +281,40 @@ export function Dashboard({
311
281
  // Composite form: each tile runs on its own and the results are
312
282
  // combined into one grid here, since no single Malloy result spans
313
283
  // them.
314
- <Box
315
- sx={{
316
- display: "grid",
317
- gridTemplateColumns: {
318
- xs: "1fr",
319
- md: `repeat(${columns}, minmax(0, 1fr))`,
320
- },
321
- gap: 2,
322
- }}
323
- >
324
- {tiles.map((tile, index) => (
325
- <Box
326
- // Position too, not the expression alone: `tiles=[…]` can
327
- // repeat one, which is a typo rather than a request for two
328
- // identical panels, and keying on the expression made the
329
- // duplicate warn and reconcile onto its twin.
330
- key={`${index}:${tile.query}`}
331
- sx={{
332
- display: "grid",
333
- // Only above `md`: the narrow breakpoint is one column,
334
- // where a span would overflow the grid rather than widen
335
- // anything.
336
- gridColumn: { md: tileGridColumn(tile, columns) },
284
+ <DashboardGrid
285
+ tiles={tiles}
286
+ columns={columns}
287
+ // Position too, not the expression alone: `tiles=[…]` can repeat
288
+ // one, which is a typo rather than a request for two identical
289
+ // panels, and keying on the expression made the duplicate warn
290
+ // and reconcile onto its twin.
291
+ keyOf={(tile, index) => `${index}:${tile.query}`}
292
+ renderTile={(tile) => (
293
+ <DashboardTile
294
+ environmentName={environmentName}
295
+ packageName={packageName}
296
+ versionId={versionId}
297
+ modelPath={modelPath}
298
+ tile={tile.query}
299
+ label={tile.label}
300
+ subtitle={tile.subtitle}
301
+ borderless={tile.borderless}
302
+ givens={applied}
303
+ declaredTypes={declaredTypes}
304
+ givenNames={tile.givenNames}
305
+ height={height ?? TILE_MAX_HEIGHT}
306
+ maxResultSize={maxResultSize}
307
+ drill={drillFor(tile.query)}
308
+ onExplore={() => {
309
+ setExploring(tile.query);
310
+ onEvent?.({
311
+ type: "dashboard.explored",
312
+ tile: tile.query,
313
+ });
337
314
  }}
338
- >
339
- <DashboardTile
340
- environmentName={environmentName}
341
- packageName={packageName}
342
- versionId={versionId}
343
- modelPath={modelPath}
344
- tile={tile.query}
345
- label={tile.label}
346
- subtitle={tile.subtitle}
347
- borderless={tile.borderless}
348
- givens={applied}
349
- declaredTypes={declaredTypes}
350
- givenNames={tile.givenNames}
351
- height={height ?? TILE_MAX_HEIGHT}
352
- maxResultSize={maxResultSize}
353
- drill={drill}
354
- />
355
- </Box>
356
- ))}
357
- </Box>
315
+ />
316
+ )}
317
+ />
358
318
  ) : (
359
319
  <Alert severity="warning">
360
320
  This dashboard names neither a query nor any tiles.
@@ -362,6 +322,38 @@ export function Dashboard({
362
322
  )}
363
323
 
364
324
  {drillMenu}
325
+ {modelPath !== undefined && (
326
+ <>
327
+ <RowsDialog
328
+ request={rows}
329
+ environmentName={environmentName}
330
+ packageName={packageName}
331
+ {...(versionId === undefined ? {} : { versionId })}
332
+ modelPath={modelPath}
333
+ givens={rowsGivens}
334
+ onClose={() => setRows(undefined)}
335
+ onDone={(ok, durationMs) => {
336
+ if (rows)
337
+ onEvent?.({
338
+ type: "dashboard.rows_shown",
339
+ source: rows.source,
340
+ view: rows.view,
341
+ field: rows.field,
342
+ ok,
343
+ durationMs,
344
+ });
345
+ }}
346
+ />
347
+ <ExploreDialog
348
+ tile={exploring}
349
+ environmentName={environmentName}
350
+ packageName={packageName}
351
+ {...(versionId === undefined ? {} : { versionId })}
352
+ modelPath={modelPath}
353
+ onClose={() => setExploring(undefined)}
354
+ />
355
+ </>
356
+ )}
365
357
  </Stack>
366
358
  );
367
359
  }
@@ -381,41 +373,39 @@ export function Dashboard({
381
373
  * format cannot express yet. This is the half that needs nothing new.
382
374
  */
383
375
  function DashboardHeader({ manifest }: { manifest: DashboardManifest }) {
376
+ return (
377
+ <DashboardProse
378
+ title={manifest.title ?? manifest.name}
379
+ {...(manifest.description
380
+ ? { description: manifest.description }
381
+ : {})}
382
+ />
383
+ );
384
+ }
385
+
386
+ /**
387
+ * The prose header itself, over the two fields it actually needs.
388
+ *
389
+ * Separate from {@link DashboardHeader} so the BUILDER can render the same
390
+ * header over a `DashboardDocument` — which carries `title` and `description`
391
+ * but is not a manifest. Same argument as {@link tileGridColumn}: what the
392
+ * builder shows a author is the thing a reader will see, and one component is
393
+ * what stops the two drifting. A builder that restated this markdown block
394
+ * would be one edit away from showing a different header than it writes.
395
+ */
396
+ export function DashboardProse({
397
+ title,
398
+ description,
399
+ }: {
400
+ title: string;
401
+ description?: string;
402
+ }) {
384
403
  return (
385
404
  <Box>
386
405
  <Typography variant="h5" sx={{ fontWeight: 600 }}>
387
- {manifest.title ?? manifest.name}
406
+ {title}
388
407
  </Typography>
389
- {manifest.description && (
390
- <Box
391
- sx={{
392
- color: "text.secondary",
393
- typography: "body2",
394
- // The block starts flush under the title and ends flush
395
- // against the controls, so a one-line description sits
396
- // exactly where the old `Typography` put it and a longer one
397
- // grows downward rather than pushing the title around.
398
- "& > :first-of-type": { mt: 0 },
399
- "& > :last-child": { mb: 0 },
400
- // Headings in a description are section labels within the
401
- // page, not competitors to its title, so they stay at body
402
- // weight and size rather than MUI's h1..h6 scale.
403
- "& h1, & h2, & h3, & h4, & h5, & h6": {
404
- fontSize: "inherit",
405
- fontWeight: 600,
406
- m: "0.5em 0 0.25em",
407
- },
408
- "& p": { m: "0.5em 0" },
409
- "& ul, & ol": { m: "0.5em 0", pl: 3 },
410
- "& code": {
411
- fontFamily: "monospace",
412
- fontSize: "0.9em",
413
- },
414
- }}
415
- >
416
- <Markdown>{manifest.description}</Markdown>
417
- </Box>
418
- )}
408
+ {description && <Prose variant="caption">{description}</Prose>}
419
409
  </Box>
420
410
  );
421
411
  }
@@ -0,0 +1,88 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Stack } from "@mui/material";
5
+ import type { ReactNode } from "react";
6
+ import { usePublisherTheme } from "../../theme/ThemeContext";
7
+
8
+ /**
9
+ * The bar above a dashboard, in the one shape both the reader's view and the
10
+ * builder use.
11
+ *
12
+ * Reading and editing are the same page in two states, so the bar that carries
13
+ * the switch is the same bar: same height, same ground, same edge, and the
14
+ * same left and right margins as the dashboard under it — the state on the
15
+ * left, the way out of it on the right. The fixed height is the load-bearing
16
+ * part: it is what makes switching modes move nothing on the page.
17
+ *
18
+ * No horizontal padding of its own: it is laid out inside whatever insets the
19
+ * dashboard, so the left item lines up with the title below it and the right
20
+ * item with the right edge of the grid.
21
+ */
22
+ export function DashboardBar({
23
+ left,
24
+ children,
25
+ }: {
26
+ /** The page's state, at the left edge: a chip, or nothing while reading. */
27
+ left?: ReactNode;
28
+ /** What can be done about it, at the right edge. */
29
+ children?: ReactNode;
30
+ }) {
31
+ const { theme } = usePublisherTheme();
32
+ return (
33
+ <Stack
34
+ direction="row"
35
+ sx={{
36
+ position: "sticky",
37
+ top: 0,
38
+ zIndex: 5,
39
+ alignItems: "center",
40
+ justifyContent: "space-between",
41
+ gap: 1,
42
+ // One height whether or not the bar has anything on the left, so
43
+ // switching modes moves nothing.
44
+ minHeight: 48,
45
+ py: 0.5,
46
+ // The rule is the bar's own edge, not the page's underline: the
47
+ // title below needs room to read as a heading rather than as the
48
+ // bar's caption.
49
+ mb: 3,
50
+ // Its own ground, so the tiles scrolling under it do not show
51
+ // through, and an edge so it reads as a bar rather than a row. The
52
+ // Publisher theme's ground and edge, like every other surface here
53
+ // — MUI's own palette would not follow an instance theme or its
54
+ // dark mode.
55
+ bgcolor: theme.background,
56
+ borderBottom: theme.border,
57
+ }}
58
+ >
59
+ <Stack
60
+ direction="row"
61
+ sx={{
62
+ alignItems: "center",
63
+ gap: 1,
64
+ // The side that gives way: without a zero min-width a hint that
65
+ // will not wrap makes the whole bar wider than the page, and the
66
+ // controls on the right end up past the fold.
67
+ minWidth: 0,
68
+ overflow: "hidden",
69
+ }}
70
+ >
71
+ {left}
72
+ </Stack>
73
+ <Stack
74
+ direction="row"
75
+ sx={{
76
+ alignItems: "center",
77
+ gap: 0.5,
78
+ // A button's label never wraps onto a second line; anything
79
+ // beside them gives way first.
80
+ flexShrink: 0,
81
+ "& .MuiButton-root": { whiteSpace: "nowrap" },
82
+ }}
83
+ >
84
+ {children}
85
+ </Stack>
86
+ </Stack>
87
+ );
88
+ }
@@ -0,0 +1,124 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box } from "@mui/material";
5
+ import type { ReactNode } from "react";
6
+
7
+ /** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
8
+ export const DEFAULT_COLUMNS = 2;
9
+
10
+ /**
11
+ * The gutter between tiles, in px.
12
+ *
13
+ * A number rather than a `gap: 2` spacing unit because the BUILDER has to do
14
+ * arithmetic with it: turning a dragged edge into a column count means solving
15
+ * for the track width, and that needs the gutter in the same units as a
16
+ * `getBoundingClientRect`. Exported so the value the grid paints and the value
17
+ * the drag solves with cannot drift apart.
18
+ */
19
+ export const GRID_GAP_PX = 16;
20
+
21
+ /**
22
+ * The `grid-column` one tile occupies: its `# colspan`, and a `# break` forcing
23
+ * it to start a fresh row.
24
+ *
25
+ * Clamped to the grid width the same way @malloydata/render clamps it, so one
26
+ * view laid out as a composite tile and as a `nest:` under `# dashboard` lands
27
+ * in the same place. A break is `1 / span N` — an explicit start line, which is
28
+ * what pushes the tile down to the next row; the renderer's grid does the same.
29
+ */
30
+ export function tileGridColumn(
31
+ tile: { colspan?: number; break?: boolean },
32
+ columns: number,
33
+ ): string {
34
+ const span = Math.min(tile.colspan ?? 1, columns);
35
+ return tile.break ? `1 / span ${span}` : `span ${span}`;
36
+ }
37
+
38
+ /** The layout a tile carries, whatever else its own shape holds. */
39
+ export interface GridTile {
40
+ colspan?: number;
41
+ break?: boolean;
42
+ }
43
+
44
+ /**
45
+ * The composite dashboard's grid: the column track, and each tile's place on
46
+ * it.
47
+ *
48
+ * Shared by the READER ({@link Dashboard}) and the BUILDER, which is the whole
49
+ * point of it being a component rather than a rule each surface applies. An
50
+ * author arranging a dashboard is arranging the thing a reader will open, so
51
+ * the two cannot be allowed to lay tiles out even slightly differently; a
52
+ * restated track without the grid item's own `display: grid` ends rows at
53
+ * ragged heights on one surface and level on the other.
54
+ *
55
+ * **Why the item is a grid and not a block.** A grid item stretches to its row,
56
+ * but a block CHILD of one does not — it keeps its content height. Results
57
+ * divide on exactly that line (see `resultSizing`): a table, a map or a
58
+ * `# big_value` sizes to its content, while a plotted chart fills whatever box
59
+ * it is handed. So a block item put a short table beside a tall chart and let
60
+ * the row end twice. Making the item a grid passes the row's height down to the
61
+ * tile, and every card in a row ends level.
62
+ *
63
+ * The tile itself is the caller's: the reader renders a `DashboardTile`, the
64
+ * builder wraps one in its selection outline. Anything this component rendered
65
+ * on their behalf would be a third opinion about what a tile looks like.
66
+ */
67
+ export function DashboardGrid<T extends GridTile>({
68
+ tiles,
69
+ columns,
70
+ keyOf,
71
+ renderTile,
72
+ }: {
73
+ tiles: readonly T[];
74
+ /** Track count — `# dashboard { columns=N }`, or {@link DEFAULT_COLUMNS}. */
75
+ columns: number;
76
+ /**
77
+ * This tile's React key. Taken from the caller because the two surfaces
78
+ * identify a tile differently and both are right: the manifest's `tiles=[…]`
79
+ * can repeat one expression (a typo, not a request for two identical
80
+ * panels), so the reader keys on position as well.
81
+ */
82
+ keyOf: (tile: T, index: number) => string;
83
+ renderTile: (tile: T, index: number) => ReactNode;
84
+ }) {
85
+ return (
86
+ <Box
87
+ sx={{
88
+ display: "grid",
89
+ gridTemplateColumns: {
90
+ xs: "1fr",
91
+ md: `repeat(${columns}, minmax(0, 1fr))`,
92
+ },
93
+ gap: `${GRID_GAP_PX}px`,
94
+ }}
95
+ >
96
+ {tiles.map((tile, index) => (
97
+ <Box
98
+ key={keyOf(tile, index)}
99
+ sx={{
100
+ // Load-bearing — see the note above.
101
+ display: "grid",
102
+ // A tile follows its TRACK, whatever it holds. A grid item's
103
+ // minimum width is `auto` — its content's minimum — and a
104
+ // chart's content is an SVG drawn at the width the tile had
105
+ // when it rendered. So without this, narrowing a tile did not
106
+ // narrow it: the item stayed as wide as the old chart, ran
107
+ // under its neighbour, and the renderer's own size observer
108
+ // never saw a change to redraw for. Widening worked, which is
109
+ // what made it look like the chart filled in one direction
110
+ // only. With the minimum at zero the item takes the track's
111
+ // width, the chart's box shrinks with it, and the renderer
112
+ // redraws to fit — the same way it already did on growth.
113
+ minWidth: 0,
114
+ // Only above `md`: the narrow breakpoint is one column, where
115
+ // a span would overflow the grid rather than widen anything.
116
+ gridColumn: { md: tileGridColumn(tile, columns) },
117
+ }}
118
+ >
119
+ {renderTile(tile, index)}
120
+ </Box>
121
+ ))}
122
+ </Box>
123
+ );
124
+ }