@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
@@ -0,0 +1,49 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { render, screen } from "@testing-library/react";
5
+ import { describe, expect, it } from "bun:test";
6
+ import type { QueryResultState } from "../../hooks/useQueryResult";
7
+ import { ResultPanel } from "./ResultPanel";
8
+
9
+ // The two states short of a result, which every query surface used to draw
10
+ // for itself — and one of them (the model cell) not at all. The result state
11
+ // goes through `ResultContainer`, which has its own coverage and lazy-loads
12
+ // the renderer, so it is not driven from here.
13
+
14
+ const stateOf = (partial: Partial<QueryResultState>) =>
15
+ ({ isSuccess: false, isError: false, ...partial }) as QueryResultState;
16
+
17
+ describe("ResultPanel", () => {
18
+ it("says it is running until the query answers", () => {
19
+ render(<ResultPanel state={stateOf({})} context="orders -> by_month" />);
20
+ expect(screen.getByText("Running…")).toBeDefined();
21
+ });
22
+
23
+ it("takes the caller's words for the wait", () => {
24
+ render(
25
+ <ResultPanel
26
+ state={stateOf({})}
27
+ context="orders -> by_month"
28
+ loadingText="Fetching…"
29
+ />,
30
+ );
31
+ expect(screen.getByText("Fetching…")).toBeDefined();
32
+ });
33
+
34
+ it("shows a refused query's reason, and what was asked", () => {
35
+ const error = Object.assign(new Error("refused"), {
36
+ status: 400,
37
+ data: { code: 400, message: "filter 'state' is required" },
38
+ });
39
+ render(
40
+ <ResultPanel
41
+ state={stateOf({ isError: true, error })}
42
+ context="orders -> by_month"
43
+ />,
44
+ );
45
+ expect(screen.getByText("filter 'state' is required")).toBeDefined();
46
+ expect(screen.getByText("orders -> by_month")).toBeDefined();
47
+ expect(screen.queryByText("Running…")).toBeNull();
48
+ });
49
+ });
@@ -0,0 +1,73 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box } from "@mui/material";
5
+ import { useMemo } from "react";
6
+ import type { QueryResultState } from "../../hooks/useQueryResult";
7
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
8
+ import type { DrillBinding } from "../drill/useDrill";
9
+ import { Loading } from "../Loading";
10
+ import ResultContainer from "./ResultContainer";
11
+
12
+ export interface ResultPanelProps {
13
+ /** From `useQueryResult`. */
14
+ state: QueryResultState;
15
+ /** Names the request in an error: the tile expression, the query name, the model path. */
16
+ context: string;
17
+ loadingText?: string;
18
+ maxHeight?: number;
19
+ maxResultSize?: number;
20
+ drill?: DrillBinding;
21
+ /**
22
+ * Rewrites the result before it is rendered — a dashboard tile promotes a
23
+ * one-row measure result to KPI cards this way. Memoized on the result
24
+ * string, so a large result is not re-parsed on every render around it.
25
+ */
26
+ transform?: (result: string) => string;
27
+ }
28
+
29
+ /**
30
+ * The three states of a running query, once: waiting, failed, and the result
31
+ * itself through `ResultContainer`.
32
+ *
33
+ * Every surface that runs a query goes through the same three, and each used
34
+ * to draw them itself with its own words ("Running…", "Loading results...",
35
+ * "Fetching Query Results...") and, in one case, without the failed state at
36
+ * all. A tile owning its own panel is still what lets a composite dashboard
37
+ * survive a bad tile: the broken one shows its error in place and the rest of
38
+ * the grid still renders.
39
+ */
40
+ export function ResultPanel({
41
+ state,
42
+ context,
43
+ loadingText = "Running…",
44
+ maxHeight,
45
+ maxResultSize,
46
+ drill,
47
+ transform,
48
+ }: ResultPanelProps) {
49
+ const { data, isSuccess, isError, error } = state;
50
+ const raw = data?.data.result;
51
+ const result = useMemo(
52
+ () => (raw !== undefined && transform ? transform(raw) : raw),
53
+ [raw, transform],
54
+ );
55
+
56
+ if (isError) {
57
+ return (
58
+ <Box sx={{ p: 2 }}>
59
+ <ApiErrorDisplay context={context} error={error} />
60
+ </Box>
61
+ );
62
+ }
63
+ if (!isSuccess) return <Loading text={loadingText} />;
64
+ return (
65
+ <ResultContainer
66
+ result={result}
67
+ maxHeight={maxHeight}
68
+ maxResultSize={maxResultSize}
69
+ renderLogs={data.data.renderLogs}
70
+ drill={drill}
71
+ />
72
+ );
73
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  export { default as RenderedResult } from "./RenderedResult";
5
5
  export { default as ResultContainer } from "./ResultContainer";
6
+ export { ResultPanel, type ResultPanelProps } from "./ResultPanel";
6
7
  export {
7
8
  contentNodeDepth,
8
9
  INITIAL_RENDER_HEIGHT,
@@ -1,12 +1,12 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import CloseIcon from "@mui/icons-material/Close";
5
- import { Dialog, DialogContent, DialogTitle, IconButton } from "@mui/material";
4
+ import { Box } from "@mui/material";
6
5
  import { LogMessage } from "../client";
7
6
  import type { DrillBinding } from "./drill";
8
7
  import ResultContainer from "./RenderedResult/ResultContainer";
9
8
  import { RESULTS_DIALOG_MAX_HEIGHT } from "./RenderedResult/resultSizing";
9
+ import { AppDialog } from "./AppDialog";
10
10
 
11
11
  interface ResultsDialogProps {
12
12
  open: boolean;
@@ -27,38 +27,14 @@ export default function ResultsDialog({
27
27
  drill,
28
28
  }: ResultsDialogProps) {
29
29
  return (
30
- <Dialog
30
+ <AppDialog
31
31
  open={open}
32
32
  onClose={onClose}
33
+ title={title}
33
34
  maxWidth={false}
34
- fullWidth
35
- sx={{
36
- "& .MuiDialog-paper": {
37
- width: "95vw",
38
- height: "95vh",
39
- maxWidth: "none",
40
- },
41
- }}
35
+ showClose
42
36
  >
43
- <DialogTitle
44
- sx={{
45
- display: "flex",
46
- justifyContent: "space-between",
47
- alignItems: "center",
48
- }}
49
- >
50
- {title}
51
- <IconButton onClick={onClose} sx={{ color: "text.secondary" }}>
52
- <CloseIcon />
53
- </IconButton>
54
- </DialogTitle>
55
- <DialogContent
56
- sx={{
57
- height: "calc(95vh - 120px)",
58
- overflow: "auto",
59
- padding: "0 16px",
60
- }}
61
- >
37
+ <Box sx={{ height: "70vh", overflow: "auto" }}>
62
38
  <ResultContainer
63
39
  result={result}
64
40
  maxHeight={RESULTS_DIALOG_MAX_HEIGHT}
@@ -66,7 +42,7 @@ export default function ResultsDialog({
66
42
  renderLogs={renderLogs}
67
43
  drill={drill}
68
44
  />
69
- </DialogContent>
70
- </Dialog>
45
+ </Box>
46
+ </AppDialog>
71
47
  );
72
48
  }
@@ -0,0 +1,114 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import AddIcon from "@mui/icons-material/Add";
5
+ import { Button, Tooltip } from "@mui/material";
6
+ import * as React from "react";
7
+
8
+ /**
9
+ * The Console's buttons, by the job they do. Four roles, and every button on
10
+ * every page is one of them:
11
+ *
12
+ * 1. **Primary** — the one thing a surface is for: adding a package, a
13
+ * dashboard, a materialization; the confirm in a dialog. A filled dark pill
14
+ * at the default size. {@link AddButton} is the section-heading form of it.
15
+ * 2. **Secondary** — a control beside the primary one, changing something that
16
+ * already exists: Scope, Schedule, Filter. An outlined pill, the same size
17
+ * as the primary, so a heading row reads as one set of controls rather than
18
+ * a big button and some small ones. {@link SecondaryButton}.
19
+ * 3. **Quiet** — a dense bar of equals, where an outline per item would draw a
20
+ * grid: the dashboard builder's toolbar, a dialog's Cancel. A small text
21
+ * button, written inline.
22
+ * 4. **Icon** — a row's overflow menu or a compact toggle. A small icon
23
+ * button, written inline.
24
+ *
25
+ * The roles are exhaustive on purpose. A button that is none of them is a new
26
+ * family of control on a page that already has four, so add it here — with the
27
+ * job it does — rather than inline at its one call site.
28
+ */
29
+
30
+ /**
31
+ * The control that adds one thing to a section: a filled pill with a plus,
32
+ * right of the section's heading.
33
+ *
34
+ * The LABEL names the thing alone — "Package", "Connection", "Dashboard" —
35
+ * because the plus already says add; the verb went back into the accessible
36
+ * name, where a control called "Package" would otherwise say nothing about
37
+ * what it does.
38
+ */
39
+ export function AddButton({
40
+ label,
41
+ onClick,
42
+ disabled,
43
+ }: {
44
+ /** The thing being added, as it should read on the button: "Package". */
45
+ label: string;
46
+ onClick: () => void;
47
+ disabled?: boolean;
48
+ }) {
49
+ return (
50
+ <Button
51
+ variant="contained"
52
+ color="primary"
53
+ // Always the plus. The glyph is half of what makes this role
54
+ // recognisable across pages, and a per-caller override is how a
55
+ // consistent control becomes an inconsistent one.
56
+ startIcon={<AddIcon />}
57
+ onClick={onClick}
58
+ disabled={disabled}
59
+ aria-label={`Add ${label.toLowerCase()}`}
60
+ sx={{ whiteSpace: "nowrap" }}
61
+ >
62
+ {label}
63
+ </Button>
64
+ );
65
+ }
66
+
67
+ /**
68
+ * A secondary control: outlined, and the same size as the primary it sits
69
+ * beside. Takes its own icon and, when it is disabled, the reason — a control
70
+ * that greys out without saying why is a control a reader has to guess at.
71
+ */
72
+ export function SecondaryButton({
73
+ label,
74
+ icon,
75
+ onClick,
76
+ disabled,
77
+ disabledReason,
78
+ ariaLabel,
79
+ ariaHasPopup,
80
+ }: {
81
+ label: string;
82
+ icon?: React.ReactNode;
83
+ onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
84
+ disabled?: boolean;
85
+ /** Shown on hover when disabled. */
86
+ disabledReason?: string;
87
+ /** Overrides the accessible name, which is otherwise the label. */
88
+ ariaLabel?: string;
89
+ ariaHasPopup?: "menu" | "dialog";
90
+ }) {
91
+ const button = (
92
+ // A disabled button fires no pointer events, so the tooltip needs a
93
+ // wrapper that does.
94
+ <span>
95
+ <Button
96
+ variant="outlined"
97
+ startIcon={icon}
98
+ onClick={onClick}
99
+ disabled={disabled}
100
+ aria-label={ariaLabel}
101
+ aria-haspopup={ariaHasPopup}
102
+ // A pill that wraps to two lines stops reading as a pill.
103
+ sx={{ whiteSpace: "nowrap" }}
104
+ >
105
+ {label}
106
+ </Button>
107
+ </span>
108
+ );
109
+ return disabled && disabledReason ? (
110
+ <Tooltip title={disabledReason}>{button}</Tooltip>
111
+ ) : (
112
+ button
113
+ );
114
+ }
@@ -0,0 +1,316 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { fireEvent, render, screen, within } from "@testing-library/react";
5
+ import { describe, expect, it, mock } from "bun:test";
6
+ import { AppDialog } from "./AppDialog";
7
+ import { BackLink } from "./BackLink";
8
+ import { ItemRow } from "./ItemRow";
9
+ import { PackageSection } from "./PackageSection";
10
+ import { AddButton, SecondaryButton } from "./buttons";
11
+
12
+ /**
13
+ * The five components every Console screen is built out of. They carry the
14
+ * contracts the rest of the app assumes and the Playwright suite selects on —
15
+ * accessible names, landmark roles, keyboard reachability — and none of it was
16
+ * covered. A screenshot cannot show any of it: a row that is not reachable by
17
+ * keyboard and a row that is look exactly alike.
18
+ */
19
+
20
+ describe("AddButton", () => {
21
+ it("announces the verb while showing only the noun", () => {
22
+ // The plus carries "add", so the label is the thing being added. The
23
+ // accessible name has to put the verb back, or every add button on the
24
+ // page announces as a bare noun.
25
+ render(<AddButton label="Package" onClick={() => {}} />);
26
+ const button = screen.getByRole("button", { name: "Add package" });
27
+ expect(button.textContent).toContain("Package");
28
+ expect(button.textContent).not.toContain("Add package");
29
+ });
30
+
31
+ it("calls back when clicked", () => {
32
+ const onClick = mock(() => {});
33
+ render(<AddButton label="Connection" onClick={onClick} />);
34
+ fireEvent.click(screen.getByRole("button", { name: "Add connection" }));
35
+ expect(onClick).toHaveBeenCalledTimes(1);
36
+ });
37
+ });
38
+
39
+ describe("SecondaryButton", () => {
40
+ it("uses the label as its name unless given another", () => {
41
+ render(<SecondaryButton label="Edit" onClick={() => {}} />);
42
+ expect(screen.getByRole("button", { name: "Edit" })).toBeTruthy();
43
+ });
44
+
45
+ it("takes an explicit accessible name for a label that is not unique", () => {
46
+ render(
47
+ <SecondaryButton
48
+ label="Settings"
49
+ ariaLabel="Settings for Orders"
50
+ onClick={() => {}}
51
+ />,
52
+ );
53
+ expect(
54
+ screen.getByRole("button", { name: "Settings for Orders" }),
55
+ ).toBeTruthy();
56
+ });
57
+
58
+ it("does not fire while disabled", () => {
59
+ const onClick = mock(() => {});
60
+ render(
61
+ <SecondaryButton
62
+ label="Save"
63
+ disabled
64
+ disabledReason="Nothing to save"
65
+ onClick={onClick}
66
+ />,
67
+ );
68
+ fireEvent.click(screen.getByRole("button", { name: "Save" }));
69
+ expect(onClick).not.toHaveBeenCalled();
70
+ });
71
+ });
72
+
73
+ describe("PackageSection", () => {
74
+ it("is a landmark named by its own heading", () => {
75
+ // What makes "Dashboards" addressable to a screen reader moving by
76
+ // region, and to a test that wants the dashboards list rather than
77
+ // every row on the page sharing a word with it.
78
+ render(
79
+ <PackageSection title="Dashboards" count={2}>
80
+ <div>a row</div>
81
+ </PackageSection>,
82
+ );
83
+ const region = screen.getByRole("region", { name: "Dashboards" });
84
+ expect(within(region).getByText("a row")).toBeTruthy();
85
+ expect(
86
+ within(region).getByRole("heading", { name: "Dashboards", level: 6 }),
87
+ ).toBeTruthy();
88
+ });
89
+
90
+ it("shows a count of zero rather than hiding it", () => {
91
+ render(
92
+ <PackageSection title="Notebooks" count={0}>
93
+ <div />
94
+ </PackageSection>,
95
+ );
96
+ expect(screen.getByText("(0)")).toBeTruthy();
97
+ });
98
+
99
+ it("omits the count entirely when none is given", () => {
100
+ render(
101
+ <PackageSection title="Readme">
102
+ <div />
103
+ </PackageSection>,
104
+ );
105
+ expect(screen.queryByText(/^\(\d+\)$/)).toBeNull();
106
+ });
107
+
108
+ it("puts the action inside the section, on the heading's row", () => {
109
+ render(
110
+ <PackageSection
111
+ title="Packages"
112
+ action={<AddButton label="Package" onClick={() => {}} />}
113
+ >
114
+ <div />
115
+ </PackageSection>,
116
+ );
117
+ const region = screen.getByRole("region", { name: "Packages" });
118
+ expect(
119
+ within(region).getByRole("button", { name: "Add package" }),
120
+ ).toBeTruthy();
121
+ });
122
+ });
123
+
124
+ describe("ItemRow", () => {
125
+ const row = (props: Partial<Parameters<typeof ItemRow>[0]> = {}) =>
126
+ render(
127
+ <ItemRow
128
+ label="storefront"
129
+ description="An ecommerce model"
130
+ tint="#2563eb"
131
+ icon={<span />}
132
+ onClick={props.onClick ?? (() => {})}
133
+ {...props}
134
+ />,
135
+ );
136
+
137
+ it("is operable by keyboard, not only by pointer", () => {
138
+ // It is a div wearing role=button, so Enter and Space are the component's
139
+ // own responsibility; a real button would get them from the platform.
140
+ const onClick = mock(() => {});
141
+ row({ onClick, ariaLabel: "storefront" });
142
+ const target = screen.getByRole("button", { name: "storefront" });
143
+ fireEvent.keyDown(target, { key: "Enter" });
144
+ fireEvent.keyDown(target, { key: " " });
145
+ expect(onClick).toHaveBeenCalledTimes(2);
146
+ });
147
+
148
+ it("ignores keys that are not activation keys", () => {
149
+ const onClick = mock(() => {});
150
+ row({ onClick, ariaLabel: "storefront" });
151
+ fireEvent.keyDown(screen.getByRole("button", { name: "storefront" }), {
152
+ key: "a",
153
+ });
154
+ expect(onClick).not.toHaveBeenCalled();
155
+ });
156
+
157
+ it("takes an explicit name so a lookup is not a guess at concatenated text", () => {
158
+ // Without it the accessible name is the row's whole text content, label
159
+ // and description run together, which makes every exact-name lookup a
160
+ // guess at someone's prose.
161
+ row({ ariaLabel: "storefront package" });
162
+ const target = screen.getByRole("button", { name: "storefront package" });
163
+ expect(target.textContent).toContain("An ecommerce model");
164
+ });
165
+
166
+ it("falls back to the row's text when given no explicit name", () => {
167
+ row();
168
+ expect(
169
+ screen.getByRole("button", { name: /storefront.*ecommerce model/ }),
170
+ ).toBeTruthy();
171
+ });
172
+
173
+ it("still shows the description it does not put in the name", () => {
174
+ row({ ariaLabel: "storefront" });
175
+ expect(screen.getByText("An ecommerce model")).toBeTruthy();
176
+ });
177
+ });
178
+
179
+ describe("AppDialog", () => {
180
+ it("is named by its own title", () => {
181
+ render(
182
+ <AppDialog open onClose={() => {}} title="New dashboard">
183
+ <div>body</div>
184
+ </AppDialog>,
185
+ );
186
+ expect(
187
+ screen.getByRole("dialog", { name: "New dashboard" }),
188
+ ).toBeTruthy();
189
+ });
190
+
191
+ it("renders nothing while closed", () => {
192
+ render(
193
+ <AppDialog open={false} onClose={() => {}} title="New dashboard">
194
+ <div>body</div>
195
+ </AppDialog>,
196
+ );
197
+ expect(screen.queryByRole("dialog")).toBeNull();
198
+ });
199
+
200
+ it("shows the description and the actions it is given", () => {
201
+ render(
202
+ <AppDialog
203
+ open
204
+ onClose={() => {}}
205
+ title="Delete package"
206
+ description="This cannot be undone."
207
+ actions={<button>Delete package</button>}
208
+ >
209
+ <div />
210
+ </AppDialog>,
211
+ );
212
+ expect(screen.getByText("This cannot be undone.")).toBeTruthy();
213
+ expect(
214
+ screen.getByRole("button", { name: "Delete package" }),
215
+ ).toBeTruthy();
216
+ });
217
+
218
+ it("offers a way out only when asked for one", () => {
219
+ const onClose = mock(() => {});
220
+ const { rerender } = render(
221
+ <AppDialog open onClose={onClose} title="Rows">
222
+ <div />
223
+ </AppDialog>,
224
+ );
225
+ expect(screen.queryByRole("button", { name: "Close" })).toBeNull();
226
+ rerender(
227
+ <AppDialog open onClose={onClose} title="Rows" showClose>
228
+ <div />
229
+ </AppDialog>,
230
+ );
231
+ fireEvent.click(screen.getByRole("button", { name: "Close" }));
232
+ expect(onClose).toHaveBeenCalledTimes(1);
233
+ });
234
+ });
235
+
236
+ describe("BackLink", () => {
237
+ it("names the parent it goes to", () => {
238
+ render(<BackLink label="storefront" onClick={() => {}} />);
239
+ expect(
240
+ screen.getByRole("button", { name: "Back to storefront" }),
241
+ ).toBeTruthy();
242
+ });
243
+
244
+ it("is a real link when there is a URL, so it can be opened in a new tab", () => {
245
+ // The regression: it used to render an `<a>` with no href, which is
246
+ // neither focusable nor announced as a link, and swallows a middle-click.
247
+ render(
248
+ <BackLink
249
+ label="storefront"
250
+ href="/examples/storefront"
251
+ onClick={() => {}}
252
+ />,
253
+ );
254
+ const link = screen.getByRole("link", { name: "Back to storefront" });
255
+ expect(link.getAttribute("href")).toBe("/examples/storefront");
256
+ });
257
+
258
+ it("is still focusable when there is no URL to point at", () => {
259
+ render(<BackLink label="Publisher" onClick={() => {}} />);
260
+ const control = screen.getByRole("button", { name: "Back to Publisher" });
261
+ control.focus();
262
+ expect(document.activeElement).toBe(control);
263
+ });
264
+
265
+ it("hands the host the click, with its event", () => {
266
+ const onClick = mock(() => {});
267
+ render(<BackLink label="Publisher" onClick={onClick} />);
268
+ fireEvent.click(
269
+ screen.getByRole("button", { name: "Back to Publisher" }),
270
+ );
271
+ expect(onClick).toHaveBeenCalledTimes(1);
272
+ });
273
+
274
+ it("suppresses the anchor's own navigation on a plain click", () => {
275
+ // The regression: with an href present and the default left alone, the
276
+ // page navigated twice — the host's router, and then a full document
277
+ // load that undid it.
278
+ const onClick = mock(() => {});
279
+ render(
280
+ <BackLink
281
+ label="storefront"
282
+ href="/examples/storefront"
283
+ onClick={onClick}
284
+ />,
285
+ );
286
+ const link = screen.getByRole("link", { name: "Back to storefront" });
287
+ const event = new MouseEvent("click", {
288
+ bubbles: true,
289
+ cancelable: true,
290
+ });
291
+ link.dispatchEvent(event);
292
+ expect(onClick).toHaveBeenCalledTimes(1);
293
+ expect(event.defaultPrevented).toBe(true);
294
+ });
295
+
296
+ it("leaves a modified click to the browser, so it opens a new tab", () => {
297
+ // The whole reason for the href. Handling this one would swallow it.
298
+ const onClick = mock(() => {});
299
+ render(
300
+ <BackLink
301
+ label="storefront"
302
+ href="/examples/storefront"
303
+ onClick={onClick}
304
+ />,
305
+ );
306
+ const link = screen.getByRole("link", { name: "Back to storefront" });
307
+ const event = new MouseEvent("click", {
308
+ bubbles: true,
309
+ cancelable: true,
310
+ metaKey: true,
311
+ });
312
+ link.dispatchEvent(event);
313
+ expect(onClick).not.toHaveBeenCalled();
314
+ expect(event.defaultPrevented).toBe(false);
315
+ });
316
+ });
@@ -18,6 +18,7 @@ export {
18
18
  type DrillField,
19
19
  type DrillIntent,
20
20
  type DrillNavigation,
21
+ type DrillRowsRequest,
21
22
  type DrillTagReader,
22
23
  } from "./resolveDrill";
23
24
  export {
@@ -72,6 +72,27 @@ export interface DrillClickPayload {
72
72
  * a modifier was held (cmd/ctrl to open in a new tab).
73
73
  */
74
74
  event?: MouseEvent;
75
+ /**
76
+ * Where the click came from, as the host names it — for a dashboard, the
77
+ * tile expression whose result was clicked. Set by the host when it wraps
78
+ * a binding per tile; the renderer never fills it. What "the rows behind
79
+ * this value" runs against is read from here.
80
+ */
81
+ context?: string;
82
+ }
83
+
84
+ /**
85
+ * A click asking for the rows behind a value, on a surface that offers them.
86
+ * No tag is involved: any grouped value has rows behind it.
87
+ */
88
+ export interface DrillRowsRequest {
89
+ /** The clicked field's name, as the result spells it. */
90
+ field: string;
91
+ rawValue: unknown;
92
+ /** The value as it read on screen. */
93
+ label: string;
94
+ /** {@link DrillClickPayload.context}, when the host set one. */
95
+ context?: string;
75
96
  }
76
97
 
77
98
  /** The literal `to=self`: filter the current view instead of leaving it. */
@@ -232,7 +253,7 @@ export function drillValueToFilter(value: unknown): string | undefined {
232
253
  }
233
254
 
234
255
  /** How the clicked value read on screen, for a menu label. */
235
- function drillValueLabel(value: unknown): string {
256
+ export function drillValueLabel(value: unknown): string {
236
257
  if (value instanceof Date) return drillValueToFilter(value) ?? "";
237
258
  return String(value);
238
259
  }