@malloy-publisher/sdk 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +180 -204
  2. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
  3. package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
  4. package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
  5. package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
  6. package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
  7. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
  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 +9561 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +13 -1
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  16. package/dist/components/Dashboard/Dashboard.d.ts +23 -16
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  18. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  19. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  20. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  21. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  22. package/dist/components/Dashboard/index.d.ts +2 -0
  23. package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
  24. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  25. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  26. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  27. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  28. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  29. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  30. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  31. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  32. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  33. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  34. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  35. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  36. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  37. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  38. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  39. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  40. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  41. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  42. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  43. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  44. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  45. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  46. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  47. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  48. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  49. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  50. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  51. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  52. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  53. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  54. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  55. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
  56. package/dist/components/DocumentStorage/index.d.ts +3 -0
  57. package/dist/components/FloatingIconButton.d.ts +16 -0
  58. package/dist/components/Model/index.d.ts +0 -1
  59. package/dist/components/Prose.d.ts +46 -0
  60. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  61. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  62. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  63. package/dist/components/RenderedResult/index.d.ts +2 -0
  64. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  65. package/dist/components/drill/index.d.ts +2 -1
  66. package/dist/components/drill/resolveDrill.d.ts +22 -0
  67. package/dist/components/drill/useDrill.d.ts +11 -2
  68. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  69. package/dist/components/given/filterValue.d.ts +63 -0
  70. package/dist/components/given/index.d.ts +1 -0
  71. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  72. package/dist/components/index.d.ts +3 -3
  73. package/dist/components/styles.d.ts +3 -7
  74. package/dist/core-8NVBCLZh.cjs.js +148 -0
  75. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  76. package/dist/hooks/index.d.ts +3 -1
  77. package/dist/hooks/useDocumentControls.d.ts +70 -0
  78. package/dist/hooks/useQueryResult.d.ts +40 -0
  79. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  80. package/dist/index.cjs.js +34 -1
  81. package/dist/index.es.js +21487 -79
  82. package/dist/sdk.css +1 -1
  83. package/dist/styles.css +0 -1
  84. package/dist/utils/malloyLiteral.d.ts +11 -0
  85. package/package.json +25 -14
  86. package/src/builder-entry.ts +55 -0
  87. package/src/components/ApiErrorDisplay.tsx +1 -1
  88. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  89. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  90. package/src/components/Dashboard/Dashboard.tsx +184 -229
  91. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  92. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  93. package/src/components/Dashboard/DashboardTile.tsx +67 -101
  94. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  95. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  96. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  97. package/src/components/Dashboard/TileCard.tsx +120 -0
  98. package/src/components/Dashboard/index.ts +2 -0
  99. package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
  100. package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
  101. package/src/components/Dashboard/telemetry.ts +44 -0
  102. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  103. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  104. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  105. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  106. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  107. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  108. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  109. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  110. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  111. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  112. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  113. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  114. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  115. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  116. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  117. package/src/components/DashboardBuilder/catalog.ts +225 -0
  118. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  119. package/src/components/DashboardBuilder/controls.ts +398 -0
  120. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  121. package/src/components/DashboardBuilder/diff.ts +93 -0
  122. package/src/components/DashboardBuilder/document.ts +209 -0
  123. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  124. package/src/components/DashboardBuilder/layout.ts +143 -0
  125. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  126. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  127. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  128. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  129. package/src/components/DashboardBuilder/preview.ts +172 -0
  130. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  131. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  132. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  133. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  134. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  135. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  136. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  137. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  138. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  139. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  140. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  141. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  142. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  143. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  144. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  145. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  146. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  147. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  148. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  149. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  150. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
  151. package/src/components/DocumentStorage/index.ts +16 -0
  152. package/src/components/Environment/About.tsx +4 -36
  153. package/src/components/FloatingIconButton.tsx +41 -0
  154. package/src/components/Model/Model.tsx +6 -23
  155. package/src/components/Model/ModelCell.tsx +34 -72
  156. package/src/components/Model/index.ts +0 -1
  157. package/src/components/Notebook/Notebook.tsx +27 -156
  158. package/src/components/Notebook/NotebookCell.tsx +37 -191
  159. package/src/components/Prose.spec.tsx +85 -0
  160. package/src/components/Prose.tsx +179 -0
  161. package/src/components/QueryResult/QueryResult.tsx +15 -43
  162. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  163. package/src/components/RenderedResult/ResultContainer.tsx +25 -36
  164. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  165. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  166. package/src/components/RenderedResult/index.ts +16 -0
  167. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  168. package/src/components/RenderedResult/resultSizing.ts +308 -0
  169. package/src/components/ResultsDialog.tsx +2 -1
  170. package/src/components/drill/index.ts +6 -0
  171. package/src/components/drill/resolveDrill.ts +22 -1
  172. package/src/components/drill/useDrill.spec.tsx +94 -0
  173. package/src/components/drill/useDrill.tsx +52 -12
  174. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  175. package/src/components/drill/useDrillSelf.ts +110 -0
  176. package/src/components/given/GivenInput.spec.tsx +196 -2
  177. package/src/components/given/GivenInput.tsx +300 -25
  178. package/src/components/given/GivensPanel.tsx +1 -1
  179. package/src/components/given/filterValue.spec.ts +112 -0
  180. package/src/components/given/filterValue.ts +188 -0
  181. package/src/components/given/index.ts +4 -0
  182. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  183. package/src/components/given/useGivenUrlParams.ts +87 -0
  184. package/src/components/index.ts +11 -3
  185. package/src/components/styles.ts +0 -37
  186. package/src/hooks/index.ts +13 -1
  187. package/src/hooks/useDocumentControls.ts +170 -0
  188. package/src/hooks/useGivensState.spec.ts +158 -0
  189. package/src/hooks/useGivensState.ts +114 -23
  190. package/src/hooks/useQueryResult.ts +82 -0
  191. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  192. package/src/hooks/useSuggestOptions.ts +94 -51
  193. package/src/utils/malloyLiteral.spec.ts +43 -0
  194. package/src/utils/malloyLiteral.ts +76 -0
  195. package/vite.config.ts +5 -1
  196. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  197. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  198. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  199. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  200. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  201. package/dist/components/Workbook/Workbook.d.ts +0 -7
  202. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  203. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  204. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  205. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  206. package/dist/components/Workbook/index.d.ts +0 -7
  207. package/dist/core-CWKmWEg2.cjs.js +0 -148
  208. package/dist/index-B0WyZAUA.es.js +0 -66412
  209. package/dist/index-kxVD1RjY.cjs.js +0 -356
  210. package/dist/markdown-editor.css +0 -341
  211. package/src/components/AnalyzePackageButton.tsx +0 -319
  212. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  213. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  214. package/src/components/Workbook/ModelPicker.tsx +0 -134
  215. package/src/components/Workbook/MutableCell.tsx +0 -458
  216. package/src/components/Workbook/Workbook.tsx +0 -501
  217. package/src/components/Workbook/WorkbookList.tsx +0 -110
  218. package/src/components/Workbook/WorkbookManager.ts +0 -214
  219. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  220. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  221. package/src/components/Workbook/index.ts +0 -10
@@ -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,18 +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 { DASHBOARD_CARD_PADDING_PX } from "../../theme/buildTableCssVars";
4
+ import ExploreOutlinedIcon from "@mui/icons-material/ExploreOutlined";
5
+ import { IconButton, Tooltip } from "@mui/material";
6
6
  import { usePublisherTheme } from "../../theme/ThemeContext";
7
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
7
+ import { useQueryResult } from "../../hooks/useQueryResult";
8
8
  import type { GivenValue } from "../../hooks/givenValue";
9
- import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
10
- import { ApiErrorDisplay } from "../ApiErrorDisplay";
11
9
  import { humanizeSlug, type DrillBinding } from "../drill";
12
10
  import { givensToRequest } from "../given/paramCodec";
13
- import { Loading } from "../Loading";
14
- import ResultContainer from "../RenderedResult/ResultContainer";
15
- import { useServer } from "../ServerProvider";
11
+ import { ResultPanel } from "../RenderedResult/ResultPanel";
12
+ import { promoteMeasureRowToKpis } from "./promoteMeasureRow";
13
+ import { TileCard, TileHeading } from "./TileCard";
16
14
 
17
15
  export interface DashboardTileProps {
18
16
  environmentName: string;
@@ -49,6 +47,11 @@ export interface DashboardTileProps {
49
47
  maxResultSize?: number;
50
48
  /** Cell clicks and their affordance, for the dashboard's `# drill`. */
51
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;
52
55
  }
53
56
 
54
57
  /**
@@ -91,109 +94,72 @@ export function DashboardTile({
91
94
  height,
92
95
  maxResultSize,
93
96
  drill,
97
+ onExplore,
94
98
  }: DashboardTileProps) {
95
- const { apiClients } = useServer();
96
99
  const { theme } = usePublisherTheme();
97
- const requestGivens = givensToRequest(givens, declaredTypes, givenNames);
98
-
99
- const { data, isSuccess, isError, error } = useQueryWithApiError({
100
- queryKey: [
101
- "dashboardTile",
102
- environmentName,
103
- packageName,
104
- versionId,
105
- modelPath,
106
- queryName,
107
- tile,
108
- // Re-runs when the applied values change, which is the whole point of
109
- // the control row.
110
- JSON.stringify(requestGivens),
111
- ],
112
- queryFn: () =>
113
- apiClients.models.executeQueryModel(
114
- environmentName,
115
- packageName,
116
- modelPath,
117
- {
118
- queryName,
119
- query: tile !== undefined ? `run: ${tile}` : undefined,
120
- givens: requestGivens,
121
- versionId,
122
- },
123
- ),
124
- ...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),
125
109
  });
126
110
 
127
111
  return (
128
- <Paper
129
- elevation={0}
112
+ <TileCard
113
+ borderless={borderless}
130
114
  sx={{
131
- // The instance theme's border, not MUI's `divider`: the renderer
132
- // card's edge is this same value, and a card that agrees with the
133
- // theme everywhere except its outline still reads as a different
134
- // card. Radius stays on the host's `shape.borderRadius`, which the
135
- // renderer card is now pointed at too.
136
- //
137
- // `# borderless` asks for the result with no card, which the renderer
138
- // honours by dropping background, border, radius and most padding on
139
- // its own `.dashboard-item`. Same here, so the tag reads the same on
140
- // both forms.
141
- border: borderless ? "none" : theme.border,
142
- borderRadius: borderless ? 0 : 1,
143
- background: borderless ? "none" : undefined,
144
- overflow: "hidden",
145
- minHeight: 120,
146
- 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 },
147
124
  }}
148
125
  >
149
126
  {tile !== undefined && (
150
- <Box sx={{ pb: 1.5 }}>
151
- <Typography
152
- variant="subtitle2"
153
- sx={{
154
- fontWeight: 500,
155
- color: theme.tileTitle,
156
- fontFamily: theme.font.family,
157
- }}
158
- // The expression is what actually ran, so it stays reachable
159
- // as a tooltip rather than as the heading.
160
- title={tile}
161
- >
162
- {label ?? tileTitle(tile)}
163
- </Typography>
164
- {subtitle !== undefined && (
165
- <Typography
166
- variant="caption"
167
- sx={{
168
- display: "block",
169
- color: theme.tileTitle,
170
- fontFamily: theme.font.family,
171
- opacity: 0.8,
172
- }}
173
- >
174
- {subtitle}
175
- </Typography>
176
- )}
177
- </Box>
178
- )}
179
- {!isSuccess && !isError && <Loading text="Running…" />}
180
- {isSuccess && (
181
- <ResultContainer
182
- result={data.data.result}
183
- maxHeight={height}
184
- maxResultSize={maxResultSize}
185
- renderLogs={data.data.renderLogs}
186
- 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
+ }
187
148
  />
188
149
  )}
189
- {isError && (
190
- <Box sx={{ p: 2 }}>
191
- <ApiErrorDisplay
192
- context={tile ?? queryName ?? modelPath}
193
- error={error}
194
- />
195
- </Box>
196
- )}
197
- </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>
198
164
  );
199
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
+ }