@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,94 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { act, renderHook } from "@testing-library/react";
5
+ import { describe, expect, it, mock } from "bun:test";
6
+ import type { DrillField, DrillTagReader } from "./resolveDrill";
7
+ import { useDrill } from "./useDrill";
8
+
9
+ const tag = (drill?: { to: string[]; given?: string }): DrillTagReader => ({
10
+ tag: (...at: string[]) =>
11
+ drill && at[0] === "drill" ? tag(drill) : undefined,
12
+ text: (...at: string[]) =>
13
+ at[0] === "given"
14
+ ? drill?.given
15
+ : at[0] === "to"
16
+ ? drill?.to[0]
17
+ : undefined,
18
+ textArray: (...at: string[]) => (at[0] === "to" ? drill?.to : undefined),
19
+ });
20
+
21
+ const dimension = (
22
+ name: string,
23
+ drill?: { to: string[]; given?: string },
24
+ ): DrillField => ({ name, tag: tag(drill), wasDimension: () => true });
25
+ const measure = (name: string): DrillField => ({
26
+ name,
27
+ tag: tag(),
28
+ wasDimension: () => false,
29
+ });
30
+
31
+ describe("useDrill: the rows behind a value", () => {
32
+ it("opens the rows for a grouped value that has no drill, and marks it clickable", () => {
33
+ const onRows = mock(() => {});
34
+ const { result } = renderHook(() => useDrill({ onRows }));
35
+ expect(result.current.drill.canDrill(dimension("cat"))).toBe(true);
36
+ expect(result.current.drill.canDrill(measure("revenue"))).toBe(false);
37
+ act(() =>
38
+ result.current.drill.onClick({
39
+ field: dimension("cat"),
40
+ value: "Jeans",
41
+ context: "overview -> by_cat",
42
+ }),
43
+ );
44
+ expect(onRows).toHaveBeenCalledWith({
45
+ field: "cat",
46
+ rawValue: "Jeans",
47
+ label: "Jeans",
48
+ context: "overview -> by_cat",
49
+ });
50
+ });
51
+
52
+ it("does nothing for a header, a measure, or an empty cell", () => {
53
+ const onRows = mock(() => {});
54
+ const { result } = renderHook(() => useDrill({ onRows }));
55
+ act(() => {
56
+ result.current.drill.onClick({
57
+ field: dimension("cat"),
58
+ value: "Jeans",
59
+ isHeader: true,
60
+ });
61
+ result.current.drill.onClick({ field: measure("revenue"), value: 3 });
62
+ result.current.drill.onClick({ field: dimension("cat"), value: null });
63
+ });
64
+ expect(onRows).not.toHaveBeenCalled();
65
+ });
66
+
67
+ it("leaves a drilled value to its drill: one destination still navigates at once", () => {
68
+ const onRows = mock(() => {});
69
+ const onSelf = mock(() => {});
70
+ const { result } = renderHook(() => useDrill({ onRows, onSelf }));
71
+ act(() =>
72
+ result.current.drill.onClick({
73
+ field: dimension("cat", { to: ["self"], given: "CATEGORY" }),
74
+ value: "Jeans",
75
+ context: "overview -> by_cat",
76
+ }),
77
+ );
78
+ expect(onSelf).toHaveBeenCalledWith("CATEGORY", "Jeans");
79
+ expect(onRows).not.toHaveBeenCalled();
80
+ });
81
+
82
+ it("still navigates straight away when rows are not on offer", () => {
83
+ const onSelf = mock(() => {});
84
+ const { result } = renderHook(() => useDrill({ onSelf }));
85
+ expect(result.current.drill.canDrill(dimension("cat"))).toBe(false);
86
+ act(() =>
87
+ result.current.drill.onClick({
88
+ field: dimension("cat", { to: ["self"], given: "CATEGORY" }),
89
+ value: "Jeans",
90
+ }),
91
+ );
92
+ expect(onSelf).toHaveBeenCalledWith("CATEGORY", "Jeans");
93
+ });
94
+ });
@@ -8,11 +8,14 @@ import {
8
8
  DRILL_SELF,
9
9
  drillDestinations,
10
10
  drillGivenName,
11
+ drillValueLabel,
12
+ drillValueToFilter,
11
13
  humanizeSlug,
12
14
  resolveDrill,
13
15
  type DrillClickPayload,
14
16
  type DrillIntent,
15
17
  type DrillNavigation,
18
+ type DrillRowsRequest,
16
19
  } from "./resolveDrill";
17
20
 
18
21
  export interface UseDrillOptions {
@@ -43,6 +46,15 @@ export interface UseDrillOptions {
43
46
  * cannot know which document the reader is in, so the surface names itself.
44
47
  */
45
48
  selfLabel?: string;
49
+ /**
50
+ * Show the rows behind a grouped value. With it, EVERY dimension cell is
51
+ * clickable: one with no `# drill` this surface can honour opens the rows;
52
+ * one with a drill behaves exactly as it does without this option, since a
53
+ * drill is the author's own instruction for that value. Omitted on a
54
+ * surface with nowhere to show them, and cells then click only where a tag
55
+ * says so.
56
+ */
57
+ onRows?: (request: DrillRowsRequest) => void;
46
58
  }
47
59
 
48
60
  /**
@@ -70,11 +82,12 @@ export interface UseDrillResult {
70
82
  }
71
83
 
72
84
  interface DrillMenuState {
73
- intent: DrillIntent;
85
+ intent?: DrillIntent;
74
86
  destinations: string[];
75
87
  event?: MouseEvent;
76
88
  top: number;
77
89
  left: number;
90
+ label: string;
78
91
  }
79
92
 
80
93
  /**
@@ -91,6 +104,7 @@ export function useDrill({
91
104
  onSelf,
92
105
  selfLabel = "Filter this view",
93
106
  canSelf,
107
+ onRows,
94
108
  }: UseDrillOptions): UseDrillResult {
95
109
  // A cell inside the renderer's own DOM is the anchor, and this component
96
110
  // holds no ref to it, so the menu is positioned from the click coordinates.
@@ -128,35 +142,60 @@ export function useDrill({
128
142
  [onNavigate, onSelf],
129
143
  );
130
144
 
145
+ // The rows behind this click, when the surface shows rows and the click is
146
+ // on a grouped value. A header names the field and has no value; a measure
147
+ // has no rows of its own; an empty cell is more likely a misclick.
148
+ const rowsBehind = useCallback(
149
+ (payload: DrillClickPayload): DrillRowsRequest | undefined => {
150
+ if (!onRows || payload.isHeader || !payload.field) return undefined;
151
+ if (!(payload.field.wasDimension?.() ?? false)) return undefined;
152
+ if (drillValueToFilter(payload.value) === undefined) return undefined;
153
+ return {
154
+ field: payload.field.name,
155
+ rawValue: payload.value,
156
+ label: drillValueLabel(payload.value),
157
+ ...(payload.context === undefined
158
+ ? {}
159
+ : { context: payload.context }),
160
+ };
161
+ },
162
+ [onRows],
163
+ );
164
+
131
165
  const onClick = useCallback(
132
166
  (payload: DrillClickPayload) => {
133
167
  // Runs on every cell click, so "not a drill" is the ordinary answer.
134
168
  const intent = resolveDrill(payload);
135
- if (!intent) return;
136
-
169
+ const rows = rowsBehind(payload);
137
170
  // Offer only what this surface can actually do, so a menu never lists a
138
171
  // destination that would be a no-op when picked.
139
- const destinations = honorable(intent.to, intent.given);
140
- if (destinations.length === 0) return;
141
- if (destinations.length === 1) {
172
+ const destinations = intent ? honorable(intent.to, intent.given) : [];
173
+ if (destinations.length === 0) {
174
+ if (rows) onRows?.(rows);
175
+ return;
176
+ }
177
+ if (destinations.length === 1 && intent) {
142
178
  go(intent, destinations[0], payload.event);
143
179
  return;
144
180
  }
145
181
  setMenu({
146
- intent,
182
+ ...(intent ? { intent } : {}),
147
183
  destinations,
148
184
  event: payload.event,
149
185
  top: payload.event?.clientY ?? 0,
150
186
  left: payload.event?.clientX ?? 0,
187
+ label: intent?.label ?? rows?.label ?? "",
151
188
  });
152
189
  },
153
- [go, honorable],
190
+ [go, honorable, onRows, rowsBehind],
154
191
  );
155
192
 
156
193
  const canDrill = useCallback(
157
194
  (field: DrillField) =>
158
- honorable(drillDestinations(field), drillGivenName(field)).length > 0,
159
- [honorable],
195
+ honorable(drillDestinations(field), drillGivenName(field)).length >
196
+ 0 ||
197
+ (onRows !== undefined && (field.wasDimension?.() ?? false)),
198
+ [honorable, onRows],
160
199
  );
161
200
 
162
201
  const drill = useMemo<DrillBinding>(
@@ -176,7 +215,7 @@ export function useDrill({
176
215
  anchorPosition={{ top: menu?.top ?? 0, left: menu?.left ?? 0 }}
177
216
  >
178
217
  <ListSubheader sx={{ lineHeight: "32px" }}>
179
- {menu ? `${menu.intent.label} →` : ""}
218
+ {menu ? `${menu.label} →` : ""}
180
219
  </ListSubheader>
181
220
  {/* Deduplicated: `# drill { to=[overview, overview] }` is a typo
182
221
  rather than a request for two identical rows, and React keys
@@ -188,7 +227,8 @@ export function useDrill({
188
227
  key={destination}
189
228
  onClick={() => {
190
229
  close();
191
- if (menu) go(menu.intent, destination, menu.event);
230
+ if (menu?.intent)
231
+ go(menu.intent, destination, menu.event);
192
232
  }}
193
233
  >
194
234
  {destination === DRILL_SELF
@@ -166,7 +166,7 @@ export function GivensPanel({
166
166
  >
167
167
  <Typography
168
168
  variant="subtitle2"
169
- sx={{ fontWeight: 600, color: "#333" }}
169
+ sx={{ fontWeight: 600, color: "text.primary" }}
170
170
  >
171
171
  {title ?? "Parameters"}
172
172
  </Typography>
@@ -510,7 +510,7 @@ describe("a naive timestamp is read as UTC, in any timezone", () => {
510
510
  // these assertions only bite when the suite runs outside UTC, and a UTC CI
511
511
  // cannot catch a regression here. Verified by hand across UTC,
512
512
  // America/New_York, Asia/Kolkata and Pacific/Auckland; to exercise it:
513
- // TZ=America/New_York bun test src/components/given/paramCodec.spec.ts
513
+ // TZ=America/New_York bun test ./src/components/given/paramCodec.spec.ts
514
514
  // Running one suite under a non-UTC zone in CI would close that gap.
515
515
  //
516
516
  // Each assertion below names its expected value outright rather than
@@ -5,6 +5,16 @@
5
5
  // failures through it; a host composing those needs the same presentation for
6
6
  // its own.
7
7
  export { ApiErrorDisplay, type ApiErrorDisplayProps } from "./ApiErrorDisplay";
8
+ // The Console's button roles; see `buttons.tsx`. Exported so a host — the
9
+ // Publisher app included — builds its own screens out of the same four.
10
+ export { AddButton, SecondaryButton } from "./buttons";
11
+ export { AppDialog } from "./AppDialog";
12
+ export { BackLink } from "./BackLink";
13
+ export { DashboardBar } from "./Dashboard/DashboardBar";
14
+ // The Console's palette, and the two maps drawn from it. Exported so a host
15
+ // paints its own chrome — the Publisher app's theme included — from the same
16
+ // hues rather than picking a near-miss beside them.
17
+ export { PALETTE, SURFACE_TINT } from "./styles";
8
18
  export { useRouterClickHandler, type NavigationClick } from "./click_helper";
9
19
  export * from "./Dashboard";
10
20
  export * from "./DataAppViewer";
@@ -18,6 +28,12 @@ export * from "./Materializations";
18
28
  export * from "./Model";
19
29
  export * from "./Notebook";
20
30
  export * from "./Package";
31
+ export {
32
+ Prose,
33
+ type ProseLinkContext,
34
+ type ProseProps,
35
+ type ProseVariant,
36
+ } from "./Prose";
21
37
  export * from "./QueryResult";
22
38
  export * from "./RenderedResult";
23
39
  export { ServerProvider, useServer } from "./ServerProvider";
@@ -4,51 +4,66 @@
4
4
  import { Card, CardContent, CardMedia, styled } from "@mui/material";
5
5
 
6
6
  /**
7
- * Malloy brand colors — exact hex values from
8
- * `publisher/packages/app/public/logo.svg`. Use these instead of hardcoding
9
- * the hex values inline so the brand can be retuned in one place.
7
+ * The Console's palette: one set of hues, used everywhere a colour carries
8
+ * meaning.
9
+ *
10
+ * These are the register data tools encode categories in — saturated, mid-dark,
11
+ * evenly spaced around the wheel — rather than colours lifted from a logo. A
12
+ * logo is drawn to be recognised at one size in one place; a palette has to
13
+ * distinguish a dozen kinds of thing in a list, behind a glyph, and along a
14
+ * chart's series, and the two jobs pull in different directions. The previous
15
+ * palette was the logo's three plus two families invented to extend it, which
16
+ * is how one screen ended up with three unrelated colour systems on it.
17
+ *
18
+ * **Every value clears 3:1 against white**, WCAG's minimum for a graphical
19
+ * object, because these are painted as small solid backplates behind white
20
+ * glyphs where the glyph has to stay readable. That is a hard constraint on
21
+ * anything added here, asserted in `ContentTypeIcon.spec.ts` rather than left
22
+ * to review: a too-light plate looks perfectly fine in a screenshot and simply
23
+ * stops being legible. Measured against white, lowest first: emerald 3.8:1,
24
+ * red 4.8:1, lime 5.0:1, amber 5.0:1, blue 5.2:1, orange 5.2:1, cyan 5.4:1,
25
+ * teal 5.5:1, violet 5.7:1, pink 6.0:1, indigo 6.3:1, slate 7.6:1.
10
26
  */
11
- export const MALLOY_BRAND = {
12
- teal: "#14b3cb", // light wing of the M
13
- orange: "#e47404", // right wing of the M
14
- darkBlue: "#1474a4", // deep shadow of the M
27
+ export const PALETTE = {
28
+ blue: "#2563eb",
29
+ indigo: "#4f46e5",
30
+ violet: "#7c3aed",
31
+ pink: "#be185d",
32
+ red: "#dc2626",
33
+ orange: "#c2410c",
34
+ amber: "#b45309",
35
+ lime: "#4d7c0f",
36
+ emerald: "#059669",
37
+ teal: "#0f766e",
38
+ cyan: "#0e7490",
39
+ slate: "#475569",
15
40
  } as const;
16
41
 
17
42
  /**
18
- * Accents that extend the logo's three, for the places that need more colors
19
- * than the brand supplies. The package page gives every kind of content its
20
- * own, and three kinds became six.
21
- *
22
- * Their own family rather than borrowings from the chart series
23
- * (`theme/defaults.ts`), because the two have opposite constraints. A series
24
- * color fills a large area and can be light; these sit behind a white icon as a
25
- * small solid backplate, where the icon has to stay legible. Measured against
26
- * white: violet 5.5:1, magenta 4.6:1, moss 3.9:1, so all three clear 3:1, the
27
- * WCAG minimum for a graphical object. The nearest series hues do not: `#aacd85`
28
- * sage is 1.8:1, `#ec72b8` pink 2.7:1, `#b87ced` violet 2.9:1.
43
+ * The tints for what a SERVER holds, as against what a package holds. Three
44
+ * kinds — an environment, a package, a connection — listed on the home and
45
+ * environment pages.
29
46
  *
30
- * These three were picked against the bar, but they are not the only colors it
31
- * now binds. `CONTENT_TINT` in `Package/ContentTypeIcon.tsx` paints all three of
32
- * `MALLOY_BRAND` behind glyphs as well, and `ContentTypeIcon.spec.ts` holds two
33
- * of them to the same 3:1: orange at 3.09:1 and darkBlue at 5.17:1. Orange
34
- * clears it by 0.09, so retuning it lighter turns that suite red, in a file a
35
- * brand change would not otherwise open. For those two the bar is a component
36
- * constraint, not only a brand decision.
47
+ * Kept clear of the hues `CONTENT_TINT` uses, so a colour means one kind of
48
+ * thing across the whole Console rather than one kind per page. All three are
49
+ * real colours rather than near-neutrals: a grey plate reads as chrome instead
50
+ * of as one of the coloured kinds, which is the plate's whole job.
37
51
  *
38
- * Teal is the exception at 2.5:1, below the bar and inherited from the logo, so
39
- * the row it backs carries a white-on-teal glyph that does not meet the
40
- * standard. Pre-existing, not introduced here. The spec grandfathers it by
41
- * content type rather than by color, so a new type handed teal still fails.
52
+ * Also kept clear of the primary. Packages were indigo, which sat a few degrees
53
+ * from the blue of the "Package" button on the same row and read as a failed
54
+ * attempt at the same colour. Teal is the furthest hue from blue still open,
55
+ * and packages and connections — the pair that actually share a screen — now
56
+ * sit on opposite sides of the wheel. Environments never appear beside either.
42
57
  */
43
- export const MALLOY_ACCENT = {
44
- violet: "#7c4dcc",
45
- magenta: "#c2478f",
46
- moss: "#5c8f3f",
58
+ export const SURFACE_TINT = {
59
+ environment: PALETTE.emerald,
60
+ package: PALETTE.teal,
61
+ connection: PALETTE.orange,
47
62
  } as const;
48
63
 
49
64
  /**
50
65
  * Monospace font stack used by code-like surfaces inside the SDK
51
- * (file-path labels in PackageItemRow, code blocks, etc.). Matches the
66
+ * (file-path labels in `ItemRow`, code blocks, etc.). Matches the
52
67
  * `MONO_FONT_FAMILY` defined in the publisher app's theme.
53
68
  */
54
69
  export const MONO_FONT_FAMILY =
@@ -85,12 +100,6 @@ export const CleanNotebookContainer = styled("div")(({ theme }) => ({
85
100
  margin: "0 auto",
86
101
  }));
87
102
 
88
- export const CleanNotebookHeader = styled("div")(({ theme }) => ({
89
- marginBottom: "40px",
90
- paddingBottom: "24px",
91
- borderBottom: `1px solid ${theme.palette.divider}`,
92
- }));
93
-
94
103
  export const CleanNotebookSection = styled("div")({
95
104
  marginBottom: "48px",
96
105
  padding: "0",
@@ -99,14 +108,6 @@ export const CleanNotebookSection = styled("div")({
99
108
  boxShadow: "none",
100
109
  });
101
110
 
102
- export const CleanNotebookCell = styled("div")({
103
- marginBottom: "0",
104
- padding: "0",
105
- backgroundColor: "transparent",
106
- border: "none",
107
- boxShadow: "none",
108
- });
109
-
110
111
  export const CleanMetricCard = styled("div")({
111
112
  backgroundColor: "transparent",
112
113
  paddingTop: "12px",
@@ -117,86 +118,12 @@ export const CleanMetricCard = styled("div")({
117
118
  marginBottom: "0",
118
119
  });
119
120
 
120
- export const CleanCodeBlock = styled("div")(({ theme }) => ({
121
- backgroundColor: theme.palette.mode === "dark" ? "#1e293b" : "#f8f9fa",
122
- padding: "16px",
123
- borderRadius: "8px",
124
- border: `1px solid ${theme.palette.divider}`,
125
- fontFamily: "'Monaco', 'Menlo', 'Ubuntu Mono', monospace",
126
- fontSize: "13px",
127
- lineHeight: "1.5",
128
- overflowX: "auto",
129
- color: theme.palette.text.primary,
130
- }));
131
-
132
- export const CleanActionBar = styled("div")(({ theme }) => ({
133
- backgroundColor: theme.palette.mode === "dark" ? "#1e293b" : "#f8f9fa",
134
- padding: "12px 16px",
135
- borderRadius: "8px",
136
- border: `1px solid ${theme.palette.divider}`,
137
- marginBottom: "16px",
138
- display: "flex",
139
- justifyContent: "space-between",
140
- alignItems: "center",
141
- }));
142
-
143
121
  export const StyledExplorerPage = styled("div")({
144
122
  height: "100%",
145
123
  });
146
124
 
147
- export const StyledExplorerBanner = styled("div")({
148
- height: "30px",
149
- backgroundColor: "rgba(225, 240, 255, 1)",
150
- display: "flex",
151
- padding: "4px",
152
- alignItems: "center",
153
- });
154
-
155
125
  export const StyledExplorerContent = styled("div")({
156
126
  height: "75vh",
157
127
  width: "100%",
158
128
  overflowY: "auto",
159
129
  });
160
-
161
- export const StyledExplorerPanel = styled("div")({
162
- position: "relative",
163
- height: "100%",
164
- flex: "0 0 auto",
165
- });
166
-
167
- // Package page styles
168
- export const PackageCard = styled(Card)(({ theme }) => ({
169
- backgroundColor: theme.palette.background.paper,
170
- padding: "24px",
171
- borderRadius: "8px",
172
- border: `1px solid ${theme.palette.divider}`,
173
- boxShadow: "0 1px 3px rgba(0, 0, 0, 0.04)",
174
- height: "100%",
175
- transition: "box-shadow 0.2s ease-in-out",
176
- "&:hover": {
177
- boxShadow: "0 2px 6px rgba(0, 0, 0, 0.08)",
178
- },
179
- }));
180
-
181
- export const PackageCardContent = styled(CardContent)({
182
- padding: "0",
183
- "&:last-child": {
184
- paddingBottom: "0",
185
- },
186
- });
187
-
188
- export const PackageSectionTitle = styled("div")(({ theme }) => ({
189
- fontSize: "0.875rem",
190
- fontWeight: 500,
191
- color: theme.palette.text.secondary,
192
- marginBottom: "16px",
193
- paddingBottom: "8px",
194
- borderBottom: `1px solid ${theme.palette.divider}`,
195
- }));
196
-
197
- export const PackageContainer = styled("div")({
198
- padding: "32px",
199
- maxWidth: "1400px",
200
- margin: "0 auto",
201
- minHeight: "100vh",
202
- });
@@ -43,3 +43,16 @@ export {
43
43
  type UseGivensStateResult,
44
44
  } from "./useGivensState";
45
45
  export { useSuggestOptions } from "./useSuggestOptions";
46
+
47
+ // One query, and one control row, as every surface asks for them
48
+ export {
49
+ queryResultKey,
50
+ useQueryResult,
51
+ type QueryRequestSpec,
52
+ type QueryResultState,
53
+ } from "./useQueryResult";
54
+ export {
55
+ useDocumentControls,
56
+ type DocumentControls,
57
+ type UseDocumentControlsOptions,
58
+ } from "./useDocumentControls";
@@ -0,0 +1,119 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { act, renderHook, waitFor } from "@testing-library/react";
5
+ import { afterEach, describe, expect, it, mock } from "bun:test";
6
+ import { QueryClientProvider } from "@tanstack/react-query";
7
+ import type { ReactNode } from "react";
8
+ import { globalQueryClient } from "../utils/queryClient";
9
+ import {
10
+ setConsoleEventHandler,
11
+ type ConsoleEvent,
12
+ } from "../telemetry/consoleEvents";
13
+ import { useCrudMutation } from "./useCrudMutation";
14
+
15
+ /**
16
+ * The shape every create, edit and delete dialog in the Console now runs
17
+ * through. Its job is four things in one order — run the write, close the
18
+ * dialog, refetch what changed, and say what happened — and the fourth used
19
+ * to be written out per file in two different ways.
20
+ */
21
+
22
+ const wrapper = ({ children }: { children: ReactNode }) => (
23
+ <QueryClientProvider client={globalQueryClient}>
24
+ {children}
25
+ </QueryClientProvider>
26
+ );
27
+
28
+ const mount = (
29
+ mutationFn: () => Promise<unknown>,
30
+ closeDialog = () => {},
31
+ invalidates: string[][] = [["packages", "examples"]],
32
+ ) =>
33
+ renderHook(
34
+ () =>
35
+ useCrudMutation({
36
+ mutationFn,
37
+ success: "Package deleted",
38
+ invalidates,
39
+ closeDialog,
40
+ resource: "package",
41
+ action: "delete",
42
+ }),
43
+ { wrapper },
44
+ );
45
+
46
+ describe("useCrudMutation", () => {
47
+ afterEach(() => setConsoleEventHandler(undefined));
48
+
49
+ it("closes the dialog and reports success once the write lands", async () => {
50
+ const events: ConsoleEvent[] = [];
51
+ setConsoleEventHandler((e) => events.push(e));
52
+ const closeDialog = mock(() => {});
53
+ const view = mount(() => Promise.resolve({ ok: true }), closeDialog);
54
+
55
+ act(() => view.result.current.mutate());
56
+ await waitFor(() => expect(closeDialog).toHaveBeenCalledTimes(1));
57
+ await waitFor(() => expect(events).toHaveLength(1));
58
+ expect(events[0]).toMatchObject({
59
+ type: "console.mutation",
60
+ resource: "package",
61
+ action: "delete",
62
+ ok: true,
63
+ });
64
+ expect(events[0].reason).toBeUndefined();
65
+ });
66
+
67
+ it("reports a failure with the reason the operator was shown", async () => {
68
+ // The gap this closes: a delete that failed left no trace at all once
69
+ // its six-second snackbar had gone.
70
+ const events: ConsoleEvent[] = [];
71
+ setConsoleEventHandler((e) => events.push(e));
72
+ const view = mount(() => Promise.reject(new Error("Package is in use")));
73
+
74
+ act(() => view.result.current.mutate());
75
+ await waitFor(() => expect(events).toHaveLength(1));
76
+ expect(events[0]).toMatchObject({
77
+ ok: false,
78
+ reason: "Package is in use",
79
+ });
80
+ });
81
+
82
+ it("does not close the dialog when the write fails", async () => {
83
+ // There is something to correct and retry, so the form has to stay.
84
+ const closeDialog = mock(() => {});
85
+ const view = mount(() => Promise.reject(new Error("nope")), closeDialog);
86
+ act(() => view.result.current.mutate());
87
+ await waitFor(() => expect(view.result.current.isPending).toBe(false));
88
+ expect(closeDialog).not.toHaveBeenCalled();
89
+ });
90
+
91
+ it("falls back to a sentence for a rejection that is not an Error", async () => {
92
+ // Every dialog had its own copy of this, and two of them did not have
93
+ // it at all — they read `error.message` off whatever was thrown.
94
+ const events: ConsoleEvent[] = [];
95
+ setConsoleEventHandler((e) => events.push(e));
96
+ const view = mount(() => Promise.reject("a bare string"));
97
+ act(() => view.result.current.mutate());
98
+ await waitFor(() => expect(events).toHaveLength(1));
99
+ expect(events[0].reason).toBe("An unknown error occurred");
100
+ });
101
+
102
+ it("invalidates the keys it was given", async () => {
103
+ const invalidate = mock(() => Promise.resolve());
104
+ const original = globalQueryClient.invalidateQueries;
105
+ globalQueryClient.invalidateQueries =
106
+ invalidate as unknown as typeof original;
107
+ try {
108
+ const view = mount(
109
+ () => Promise.resolve({}),
110
+ () => {},
111
+ [["packages", "examples"], ["environments"]],
112
+ );
113
+ act(() => view.result.current.mutate());
114
+ await waitFor(() => expect(invalidate).toHaveBeenCalledTimes(2));
115
+ } finally {
116
+ globalQueryClient.invalidateQueries = original;
117
+ }
118
+ });
119
+ });