@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
@@ -9,7 +9,7 @@
9
9
  * prop alone.
10
10
  */
11
11
  import { beforeEach, expect, it, mock } from "bun:test";
12
- import { render, waitFor } from "@testing-library/react";
12
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
13
13
  import {
14
14
  cacheKeys,
15
15
  clearCache,
@@ -54,7 +54,7 @@ it("puts the version in the request body and in the key", async () => {
54
54
 
55
55
  await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
56
56
  expect(executeQueryModel.mock.calls[0][3].versionId).toBe("v2");
57
- expect(cacheKeys("dashboardTile")[0]).toContain('"v2"');
57
+ expect(cacheKeys("queryResult")[0]).toContain('"v2"');
58
58
  });
59
59
 
60
60
  it("sends and keys nothing extra without one", async () => {
@@ -64,9 +64,9 @@ it("sends and keys nothing extra without one", async () => {
64
64
  expect(executeQueryModel.mock.calls[0][3].versionId).toBeUndefined();
65
65
  // The whole key: an empty slot rather than a literal "undefined", and
66
66
  // nothing else disturbed. The narrow assertion above cannot see either.
67
- expect(cacheKeys("dashboardTile")[0]).toBe(
68
- '["dashboardTile","env","pkg",null,"dashboards/ops.malloy",null,' +
69
- '"sales_by_month","{}","http://localhost/api/v0"]',
67
+ expect(cacheKeys("queryResult")[0]).toBe(
68
+ '["queryResult","env","pkg",null,"dashboards/ops.malloy",null,' +
69
+ '"run: sales_by_month",null,"{}","http://localhost/api/v0"]',
70
70
  );
71
71
  });
72
72
 
@@ -77,5 +77,29 @@ it("keeps two versions of one tile apart", async () => {
77
77
  rerender(tileAt("v2"));
78
78
 
79
79
  await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(2));
80
- expect(new Set(cacheKeys("dashboardTile")).size).toBe(2);
80
+ expect(new Set(cacheKeys("queryResult")).size).toBe(2);
81
+ });
82
+
83
+ it("offers to explore from the tile when the host can take it somewhere", () => {
84
+ const onExplore = mock(() => {});
85
+ render(
86
+ <DashboardTile
87
+ environmentName="env"
88
+ packageName="pkg"
89
+ modelPath="dashboards/ops.malloy"
90
+ tile="overview -> sales_by_month"
91
+ givens={new Map()}
92
+ declaredTypes={new Map()}
93
+ height={400}
94
+ onExplore={onExplore}
95
+ />,
96
+ { wrapper: serverWrapper },
97
+ );
98
+ fireEvent.click(screen.getByLabelText("Explore Sales by month"));
99
+ expect(onExplore).toHaveBeenCalledTimes(1);
100
+ });
101
+
102
+ it("has no explore button when the host offers nowhere to go", () => {
103
+ render(tileAt(), { wrapper: serverWrapper });
104
+ expect(screen.queryByLabelText(/^Explore /)).toBeNull();
81
105
  });
@@ -1,20 +1,16 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import { Box, Paper, Typography } from "@mui/material";
5
- import { useMemo } from "react";
6
- import { DASHBOARD_CARD_PADDING_PX } from "../../theme/buildTableCssVars";
4
+ import ExploreOutlinedIcon from "@mui/icons-material/ExploreOutlined";
5
+ import { IconButton, Tooltip } from "@mui/material";
7
6
  import { usePublisherTheme } from "../../theme/ThemeContext";
8
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
7
+ import { useQueryResult } from "../../hooks/useQueryResult";
9
8
  import type { GivenValue } from "../../hooks/givenValue";
10
- import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
11
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
12
9
  import { humanizeSlug, type DrillBinding } from "../drill";
13
10
  import { givensToRequest } from "../given/paramCodec";
14
- import { Loading } from "../Loading";
15
- import ResultContainer from "../RenderedResult/ResultContainer";
16
- import { useServer } from "../ServerProvider";
11
+ import { ResultPanel } from "../RenderedResult/ResultPanel";
17
12
  import { promoteMeasureRowToKpis } from "./promoteMeasureRow";
13
+ import { TileCard, TileHeading } from "./TileCard";
18
14
 
19
15
  export interface DashboardTileProps {
20
16
  environmentName: string;
@@ -51,6 +47,11 @@ export interface DashboardTileProps {
51
47
  maxResultSize?: number;
52
48
  /** Cell clicks and their affordance, for the dashboard's `# drill`. */
53
49
  drill?: DrillBinding;
50
+ /**
51
+ * Open this tile's query somewhere it can be changed. Shown as a button in
52
+ * the heading, on hover; absent, the heading has no button.
53
+ */
54
+ onExplore?: () => void;
54
55
  }
55
56
 
56
57
  /**
@@ -93,130 +94,72 @@ export function DashboardTile({
93
94
  height,
94
95
  maxResultSize,
95
96
  drill,
97
+ onExplore,
96
98
  }: DashboardTileProps) {
97
- const { apiClients } = useServer();
98
99
  const { theme } = usePublisherTheme();
99
- const requestGivens = givensToRequest(givens, declaredTypes, givenNames);
100
-
101
- const { data, isSuccess, isError, error } = useQueryWithApiError({
102
- queryKey: [
103
- "dashboardTile",
104
- environmentName,
105
- packageName,
106
- versionId,
107
- modelPath,
108
- queryName,
109
- tile,
110
- // Re-runs when the applied values change, which is the whole point of
111
- // the control row.
112
- JSON.stringify(requestGivens),
113
- ],
114
- queryFn: () =>
115
- apiClients.models.executeQueryModel(
116
- environmentName,
117
- packageName,
118
- modelPath,
119
- {
120
- queryName,
121
- query: tile !== undefined ? `run: ${tile}` : undefined,
122
- givens: requestGivens,
123
- versionId,
124
- },
125
- ),
126
- ...CHART_RESULT_QUERY_OPTIONS,
100
+ const state = useQueryResult({
101
+ environmentName,
102
+ packageName,
103
+ modelPath,
104
+ versionId,
105
+ queryName,
106
+ query: tile !== undefined ? `run: ${tile}` : undefined,
107
+ // Narrowed to the givens this tile references: see `givenNames`.
108
+ givens: givensToRequest(givens, declaredTypes, givenNames),
127
109
  });
128
110
 
129
- // A composite tile that is one row of measures draws as KPI cards, the way
130
- // Malloyyo splices the same tile into its grid, rather than as a one-row
131
- // table. Composite only: the single-query form is one result the renderer
132
- // lays out from the query's own tags, and its aggregates are already tiles.
133
- // Memoized on the result string so a large result is not re-parsed on every
134
- // render of the tile around it.
135
- const result = useMemo(() => {
136
- const raw = data?.data.result;
137
- if (raw === undefined || tile === undefined) return raw;
138
- return promoteMeasureRowToKpis(raw);
139
- }, [data, tile]);
140
-
141
111
  return (
142
- <Paper
143
- elevation={0}
112
+ <TileCard
113
+ borderless={borderless}
144
114
  sx={{
145
- // The instance theme's border, not MUI's `divider`: the renderer
146
- // card's edge is this same value, and a card that agrees with the
147
- // theme everywhere except its outline still reads as a different
148
- // card. Radius stays on the host's `shape.borderRadius`, which the
149
- // renderer card is now pointed at too.
150
- //
151
- // `# borderless` asks for the result with no card, which the renderer
152
- // honours by dropping background, border, radius and most padding on
153
- // its own `.dashboard-item`. Same here, so the tag reads the same on
154
- // both forms.
155
- //
156
- // The background is `theme.tile`, the same value the renderer card
157
- // paints, and NOT MUI's Paper default. Leaving it unset was the last
158
- // piece of the two cards' geometry that did not agree: measured on
159
- // the `grid`/`tiled` fixture pair, the renderer card came out
160
- // `#f5fafc` from the theme and this one plain white, so on a theme
161
- // whose page is also white the composite tiles lost the tint that
162
- // separates a card from the page while the single-query form kept
163
- // it. Radius, padding, border, shadow and gap already matched.
164
- border: borderless ? "none" : theme.border,
165
- borderRadius: borderless ? 0 : 1,
166
- background: borderless ? "none" : theme.tile,
167
- overflow: "hidden",
168
- minHeight: 120,
169
- p: borderless ? "12px 0" : `${DASHBOARD_CARD_PADDING_PX}px`,
115
+ // The heading's button shows on hover and keyboard focus, the way
116
+ // a tile's chrome does everywhere else; always-on it competes with
117
+ // the title on every card at once.
118
+ "& .publisher-tile-explore": {
119
+ opacity: 0,
120
+ transition: "opacity 120ms",
121
+ },
122
+ "&:hover .publisher-tile-explore, & .publisher-tile-explore:focus-visible":
123
+ { opacity: 1 },
170
124
  }}
171
125
  >
172
126
  {tile !== undefined && (
173
- <Box sx={{ pb: 1.5 }}>
174
- <Typography
175
- variant="subtitle2"
176
- sx={{
177
- fontWeight: 500,
178
- color: theme.tileTitle,
179
- fontFamily: theme.font.family,
180
- }}
181
- // The expression is what actually ran, so it stays reachable
182
- // as a tooltip rather than as the heading.
183
- title={tile}
184
- >
185
- {label ?? tileTitle(tile)}
186
- </Typography>
187
- {subtitle !== undefined && (
188
- <Typography
189
- variant="caption"
190
- sx={{
191
- display: "block",
192
- color: theme.tileTitle,
193
- fontFamily: theme.font.family,
194
- opacity: 0.8,
195
- }}
196
- >
197
- {subtitle}
198
- </Typography>
199
- )}
200
- </Box>
201
- )}
202
- {!isSuccess && !isError && <Loading text="Running…" />}
203
- {isSuccess && (
204
- <ResultContainer
205
- result={result}
206
- maxHeight={height}
207
- maxResultSize={maxResultSize}
208
- renderLogs={data.data.renderLogs}
209
- drill={drill}
127
+ <TileHeading
128
+ title={label ?? tileTitle(tile)}
129
+ subtitle={subtitle}
130
+ // The expression is what actually ran, so it stays reachable as
131
+ // a tooltip rather than as the heading.
132
+ tooltip={tile}
133
+ action={
134
+ onExplore && (
135
+ <Tooltip title="Explore from here">
136
+ <IconButton
137
+ className="publisher-tile-explore"
138
+ size="small"
139
+ aria-label={`Explore ${label ?? tileTitle(tile)}`}
140
+ onClick={onExplore}
141
+ sx={{ mt: -0.5, mr: -0.5, color: theme.tileTitle }}
142
+ >
143
+ <ExploreOutlinedIcon fontSize="small" />
144
+ </IconButton>
145
+ </Tooltip>
146
+ )
147
+ }
210
148
  />
211
149
  )}
212
- {isError && (
213
- <Box sx={{ p: 2 }}>
214
- <ApiErrorDisplay
215
- context={tile ?? queryName ?? modelPath}
216
- error={error}
217
- />
218
- </Box>
219
- )}
220
- </Paper>
150
+ <ResultPanel
151
+ state={state}
152
+ context={tile ?? queryName ?? modelPath}
153
+ maxHeight={height}
154
+ maxResultSize={maxResultSize}
155
+ drill={drill}
156
+ // A composite tile that is one row of measures draws as KPI cards,
157
+ // the way Malloyyo splices the same tile into its grid, rather than
158
+ // as a one-row table. Composite only: the single-query form is one
159
+ // result the renderer lays out from the query's own tags, and its
160
+ // aggregates are already tiles.
161
+ transform={tile !== undefined ? promoteMeasureRowToKpis : undefined}
162
+ />
163
+ </TileCard>
221
164
  );
222
165
  }
@@ -0,0 +1,84 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type * as Malloy from "@malloydata/malloy-interfaces";
5
+ import { useMemo } from "react";
6
+ import { encodeResourceUri } from "../../utils/formatting";
7
+ import { ModelExplorerDialog } from "../Model/ModelExplorerDialog";
8
+ import { useModelData } from "../Model/useModelData";
9
+ import { sourceOf, stepsOf } from "./RowsDialog";
10
+
11
+ /**
12
+ * "Explore from here": the tile's query, open in the model explorer on the
13
+ * tile's source, so the reader can change it rather than only look at it.
14
+ *
15
+ * The dashboard file is itself a model, so the explorer opens on that file:
16
+ * the tile's source is an extension declared there, and its query resolves
17
+ * as written. The model is fetched here rather than inside the explorer so
18
+ * the tile's source can be selected before it renders.
19
+ */
20
+ export function ExploreDialog({
21
+ tile,
22
+ environmentName,
23
+ packageName,
24
+ versionId,
25
+ modelPath,
26
+ onClose,
27
+ }: {
28
+ /** The tile expression to open, or undefined when closed. */
29
+ tile: string | undefined;
30
+ environmentName: string;
31
+ packageName: string;
32
+ versionId?: string;
33
+ modelPath: string;
34
+ onClose: () => void;
35
+ }) {
36
+ const resourceUri = encodeResourceUri({
37
+ environmentName,
38
+ packageName,
39
+ modelPath,
40
+ ...(versionId === undefined ? {} : { versionId }),
41
+ });
42
+ const { data } = useModelData(resourceUri, tile !== undefined);
43
+ const sourceIndex = useMemo(() => {
44
+ const source = sourceOf(tile);
45
+ if (!data || source === undefined) return 0;
46
+ const index = (data.sourceInfos ?? []).findIndex((info) => {
47
+ try {
48
+ return JSON.parse(info)?.name === source;
49
+ } catch {
50
+ return false;
51
+ }
52
+ });
53
+ return index < 0 ? 0 : index;
54
+ }, [data, tile]);
55
+ // As a query AST when the expression is `source -> view`, so the explorer's
56
+ // builder shows the view and its Run button works from the first render; a
57
+ // string otherwise, which the explorer runs as written but cannot show.
58
+ const existingQuery = useMemo(() => {
59
+ if (tile === undefined) return undefined;
60
+ const steps = stepsOf(tile);
61
+ const malloyQuery: Malloy.Query | string = steps
62
+ ? {
63
+ definition: {
64
+ kind: "arrow",
65
+ source: { kind: "source_reference", name: steps.source },
66
+ view: { kind: "view_reference", name: steps.view },
67
+ },
68
+ }
69
+ : `run: ${tile}`;
70
+ return { query: `run: ${tile}`, malloyQuery, malloyResult: undefined };
71
+ }, [tile]);
72
+ if (tile === undefined || !data) return null;
73
+ return (
74
+ <ModelExplorerDialog
75
+ open
76
+ onClose={onClose}
77
+ resourceUri={resourceUri}
78
+ data={data}
79
+ title={`Explore: ${tile}`}
80
+ existingQuery={existingQuery}
81
+ initialSelectedSourceIndex={sourceIndex}
82
+ />
83
+ );
84
+ }
@@ -0,0 +1,42 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { rowsQuery, sourceOf, stepsOf } from "./RowsDialog";
6
+
7
+ describe("the rows query", () => {
8
+ it("drills through the tile's view to the value's rows", () => {
9
+ expect(
10
+ rowsQuery({
11
+ source: "overview",
12
+ view: "best_sellers",
13
+ field: "name",
14
+ rawValue: "Loft Insulated Jacket",
15
+ label: "Loft Insulated Jacket",
16
+ }),
17
+ ).toBe(
18
+ "run: overview -> { drill: best_sellers.name = 'Loft Insulated Jacket'; select: *; limit: 200 }",
19
+ );
20
+ expect(
21
+ rowsQuery({
22
+ source: "a",
23
+ view: "v",
24
+ field: "f",
25
+ rawValue: {},
26
+ label: "",
27
+ }),
28
+ ).toBeUndefined();
29
+ });
30
+
31
+ it("reads the source and view off a tile expression, and nothing off any other shape", () => {
32
+ expect(stepsOf("overview -> revenue_trend")).toEqual({
33
+ source: "overview",
34
+ view: "revenue_trend",
35
+ });
36
+ expect(sourceOf("overview->kpis")).toBe("overview");
37
+ expect(stepsOf("{ group_by: x } -> y")).toBeUndefined();
38
+ expect(stepsOf("a -> b -> c")).toBeUndefined();
39
+ expect(stepsOf("a -> b + { limit: 2 }")).toBeUndefined();
40
+ expect(stepsOf(undefined)).toBeUndefined();
41
+ });
42
+ });
@@ -0,0 +1,234 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import CloseIcon from "@mui/icons-material/Close";
5
+ import {
6
+ Box,
7
+ Button,
8
+ Dialog,
9
+ DialogActions,
10
+ DialogContent,
11
+ DialogTitle,
12
+ IconButton,
13
+ Typography,
14
+ } from "@mui/material";
15
+ import { useEffect, useRef } from "react";
16
+ import { useQueryResult } from "../../hooks/useQueryResult";
17
+ import { malloyLiteral } from "../../utils/malloyLiteral";
18
+ import { isIdentifier, tileSteps } from "../DashboardBuilder/malloyText";
19
+ import { usePublisherTheme } from "../../theme/ThemeContext";
20
+ import { ResultPanel } from "../RenderedResult/ResultPanel";
21
+ import { now } from "./telemetry";
22
+
23
+ /**
24
+ * The rows behind a value: "show the rows" on a cell, as one query.
25
+ *
26
+ * A grouped value is an aggregate over rows of the tile's source, and Malloy's
27
+ * `drill:` names exactly those rows: `drill: <view>.<field> = <value>` applies
28
+ * the view's own `where:` — the tile's control bindings included — and the
29
+ * clicked value's, so what comes back is the rows the number was made of.
30
+ * Measured: `where: name = …` alone failed on a view that spelled the column
31
+ * `name is products.name`, because the output name is not a source field;
32
+ * `drill:` resolves it through the view, which is where the name lives.
33
+ */
34
+ export const ROW_LIMIT = 200;
35
+
36
+ export interface RowsRequest {
37
+ /** The source the rows are of: the tile expression's first step. */
38
+ source: string;
39
+ /** The view the value was grouped in: the expression's last step. */
40
+ view: string;
41
+ field: string;
42
+ rawValue: unknown;
43
+ label: string;
44
+ }
45
+
46
+ /** The query the dialog runs, or undefined when the value cannot be spelled. */
47
+ export function rowsQuery(request: RowsRequest): string | undefined {
48
+ const literal = malloyLiteral(request.rawValue);
49
+ if (literal === undefined) return undefined;
50
+ return `run: ${request.source} -> { drill: ${request.view}.${request.field} = ${literal}; select: *; limit: ${ROW_LIMIT} }`;
51
+ }
52
+
53
+ /**
54
+ * `overview -> revenue_trend` → its source and view; undefined for anything
55
+ * else — an inline stage has no view to drill through, a refined one carries
56
+ * filters `drill:` would not, and a longer pipeline has no one view its value
57
+ * came from.
58
+ */
59
+ export function stepsOf(
60
+ tileExpression: string | undefined,
61
+ ): { source: string; view: string } | undefined {
62
+ const steps = tileSteps(tileExpression);
63
+ if (
64
+ !steps ||
65
+ steps.refinement !== undefined ||
66
+ !isIdentifier(steps.source) ||
67
+ !isIdentifier(steps.view)
68
+ )
69
+ return undefined;
70
+ return { source: steps.source, view: steps.view };
71
+ }
72
+
73
+ /** The source alone, for opening the explorer on it. */
74
+ export const sourceOf = (tileExpression: string | undefined) =>
75
+ stepsOf(tileExpression)?.source;
76
+
77
+ export function RowsDialog({
78
+ request,
79
+ environmentName,
80
+ packageName,
81
+ versionId,
82
+ modelPath,
83
+ givens,
84
+ onClose,
85
+ onDone,
86
+ }: {
87
+ request: RowsRequest | undefined;
88
+ environmentName: string;
89
+ packageName: string;
90
+ versionId?: string;
91
+ modelPath: string;
92
+ /** The applied control row, which the source's own `where:` may read. */
93
+ givens: Record<string, unknown>;
94
+ onClose: () => void;
95
+ /** The query's outcome and how long it took, once per request. */
96
+ onDone?: (ok: boolean, durationMs: number) => void;
97
+ }) {
98
+ const { theme } = usePublisherTheme();
99
+ const query = request ? rowsQuery(request) : undefined;
100
+
101
+ return (
102
+ <Dialog
103
+ open={request !== undefined}
104
+ onClose={onClose}
105
+ maxWidth="lg"
106
+ fullWidth
107
+ >
108
+ <DialogTitle
109
+ sx={{
110
+ display: "flex",
111
+ alignItems: "flex-start",
112
+ justifyContent: "space-between",
113
+ pb: 0.5,
114
+ }}
115
+ >
116
+ <Box>
117
+ {request ? (
118
+ <>
119
+ Rows where{" "}
120
+ <Box component="code" sx={{ fontSize: "0.9em" }}>
121
+ {request.field}
122
+ </Box>{" "}
123
+ is {request.label}
124
+ </>
125
+ ) : (
126
+ "Rows"
127
+ )}
128
+ <Typography
129
+ component="div"
130
+ variant="caption"
131
+ sx={{ color: theme.tileTitle, mt: 0.25 }}
132
+ >
133
+ {request
134
+ ? `The first ${ROW_LIMIT} rows of ${request.source} behind this value, with the tile's own filters and the controls applied.`
135
+ : ""}
136
+ </Typography>
137
+ </Box>
138
+ <IconButton
139
+ onClick={onClose}
140
+ aria-label="Close"
141
+ size="small"
142
+ sx={{ color: "text.secondary", ml: 1 }}
143
+ >
144
+ <CloseIcon fontSize="small" />
145
+ </IconButton>
146
+ </DialogTitle>
147
+ <DialogContent dividers sx={{ p: 0, minHeight: 240 }}>
148
+ {query === undefined && request && (
149
+ <Typography variant="body2" sx={{ p: 2 }}>
150
+ This value cannot be written as a filter, so its rows cannot
151
+ be fetched.
152
+ </Typography>
153
+ )}
154
+ {query !== undefined && (
155
+ <RowsResult
156
+ query={query}
157
+ environmentName={environmentName}
158
+ packageName={packageName}
159
+ {...(versionId === undefined ? {} : { versionId })}
160
+ modelPath={modelPath}
161
+ givens={givens}
162
+ {...(onDone ? { onDone } : {})}
163
+ />
164
+ )}
165
+ </DialogContent>
166
+ <DialogActions sx={{ px: 3, py: 1.5 }}>
167
+ {query !== undefined && (
168
+ <Typography
169
+ variant="caption"
170
+ sx={{
171
+ mr: "auto",
172
+ color: theme.tileTitle,
173
+ fontFamily: "ui-monospace, monospace",
174
+ overflow: "hidden",
175
+ textOverflow: "ellipsis",
176
+ whiteSpace: "nowrap",
177
+ }}
178
+ title={query}
179
+ >
180
+ {query}
181
+ </Typography>
182
+ )}
183
+ <Button onClick={onClose}>Close</Button>
184
+ </DialogActions>
185
+ </Dialog>
186
+ );
187
+ }
188
+
189
+ /**
190
+ * The rows themselves. Its own component so the query exists only while a
191
+ * request does: a closed dialog holds nothing in the cache.
192
+ */
193
+ function RowsResult({
194
+ query,
195
+ environmentName,
196
+ packageName,
197
+ versionId,
198
+ modelPath,
199
+ givens,
200
+ onDone,
201
+ }: {
202
+ query: string;
203
+ environmentName: string;
204
+ packageName: string;
205
+ versionId?: string;
206
+ modelPath: string;
207
+ givens: Record<string, unknown>;
208
+ onDone?: (ok: boolean, durationMs: number) => void;
209
+ }) {
210
+ const state = useQueryResult({
211
+ environmentName,
212
+ packageName,
213
+ modelPath,
214
+ ...(versionId === undefined ? {} : { versionId }),
215
+ query,
216
+ givens,
217
+ });
218
+ const { isSuccess, isError } = state;
219
+ // Reported once per request, when the query settles.
220
+ const started = useRef<number | undefined>(undefined);
221
+ useEffect(() => {
222
+ started.current = now();
223
+ }, [query]);
224
+ useEffect(() => {
225
+ if (started.current === undefined || (!isSuccess && !isError)) return;
226
+ onDone?.(isSuccess, now() - started.current);
227
+ started.current = undefined;
228
+ }, [isSuccess, isError, onDone]);
229
+ return (
230
+ <Box sx={{ p: 1 }}>
231
+ <ResultPanel state={state} context={query} />
232
+ </Box>
233
+ );
234
+ }