@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,36 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Tooltip, Typography } from "@mui/material";
5
+ import { MaterializationMetadata, triggerLabel } from "./utils";
6
+
7
+ /**
8
+ * How a run was initiated — Scheduled (the standalone scheduler fired the
9
+ * package's cron) or Manual (an API or UI create) — with the tooltip that says
10
+ * which. One source of truth for the label, so the runs list and the detail
11
+ * dialog cannot drift.
12
+ *
13
+ * A word, like every other cell in the row. A two-value distinction needs no
14
+ * pictogram, and a bordered pill here made a value look like something to
15
+ * click.
16
+ */
17
+ export default function TriggerLabel({
18
+ meta,
19
+ }: {
20
+ meta: MaterializationMetadata;
21
+ }) {
22
+ const scheduled = meta.trigger === "SCHEDULER";
23
+ return (
24
+ <Tooltip
25
+ title={
26
+ scheduled
27
+ ? "Fired by the materialization schedule"
28
+ : "Triggered manually"
29
+ }
30
+ >
31
+ <Typography variant="body2" color="text.secondary">
32
+ {triggerLabel(meta)}
33
+ </Typography>
34
+ </Tooltip>
35
+ );
36
+ }
@@ -0,0 +1,113 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { describeCron, formatNextRun } from "./cron";
6
+
7
+ /**
8
+ * `describeCron` is the only thing standing between a typed cron and a
9
+ * schedule that publishes and then never fires. It drives four things at once
10
+ * in `SetScheduleDialog` — the error state, the helper text, whether Save is
11
+ * enabled, and the section's summary line — and its whole job is to agree with
12
+ * the server's `CronEvaluator` about what counts as a cron. Agreeing is not
13
+ * something a screenshot can show, which is why it is asserted here.
14
+ */
15
+ describe("describeCron: what it accepts", () => {
16
+ it("describes a valid five-field expression and says when it next fires", () => {
17
+ const info = describeCron("0 6 * * *");
18
+ expect(info.valid).toBe(true);
19
+ expect(info.description).toContain("06:00");
20
+ expect(info.nextRun).toBeInstanceOf(Date);
21
+ expect(info.error).toBeUndefined();
22
+ });
23
+
24
+ it("takes the three-letter month and day names UNIX cron defines", () => {
25
+ for (const expr of ["0 0 1 JAN *", "0 0 * * MON", "0 0 * * mon-fri"]) {
26
+ expect(describeCron(expr).valid).toBe(true);
27
+ }
28
+ });
29
+
30
+ it("takes lists, ranges and steps", () => {
31
+ for (const expr of ["0,30 * * * *", "0 9-17 * * *", "*/15 * * * *"]) {
32
+ expect(describeCron(expr).valid).toBe(true);
33
+ }
34
+ });
35
+
36
+ it("ignores surrounding and repeated whitespace", () => {
37
+ expect(describeCron(" 0 6 * * * ").valid).toBe(true);
38
+ });
39
+
40
+ it("computes the next run in UTC, not in the machine's zone", () => {
41
+ // A daily 06:00 job fires at 06:00 UTC wherever the browser is. Reading
42
+ // it back in UTC is the only way to assert that without the suite
43
+ // passing or failing by timezone.
44
+ const next = describeCron("0 6 * * *").nextRun;
45
+ expect(next?.getUTCHours()).toBe(6);
46
+ expect(next?.getUTCMinutes()).toBe(0);
47
+ });
48
+ });
49
+
50
+ describe("describeCron: what it refuses", () => {
51
+ it("refuses anything that is not five fields", () => {
52
+ // Six fields is the trap: cron-parser reads a leading SECONDS field, so
53
+ // "0 0 6 * * *" parses happily and means something else entirely. The
54
+ // manifest contract is five fields, so it has to be refused here rather
55
+ // than silently reinterpreted.
56
+ for (const expr of ["", " ", "0 6 * *", "0 0 6 * * *"]) {
57
+ const info = describeCron(expr);
58
+ expect(info.valid).toBe(false);
59
+ expect(info.error).toContain("5-field");
60
+ expect(info.nextRun).toBeNull();
61
+ expect(info.description).toBe("");
62
+ }
63
+ });
64
+
65
+ it("refuses the Quartz extensions the server does not implement", () => {
66
+ // Each of these parses in cron-parser and would describe itself
67
+ // plausibly, then never arm after publish.
68
+ for (const expr of [
69
+ "0 0 L * *",
70
+ "0 0 15W * *",
71
+ "0 0 * * 6#3",
72
+ "0 0 * * ?",
73
+ ]) {
74
+ const info = describeCron(expr);
75
+ expect(info.valid).toBe(false);
76
+ expect(info.error).toContain("Unsupported cron syntax");
77
+ }
78
+ });
79
+
80
+ it("refuses a word that is not a month or a day", () => {
81
+ const info = describeCron("0 0 * * FUNDAY");
82
+ expect(info.valid).toBe(false);
83
+ expect(info.error).toContain("Unsupported cron syntax");
84
+ });
85
+
86
+ it("refuses an out-of-range field with the parser's own reason", () => {
87
+ const info = describeCron("0 99 * * *");
88
+ expect(info.valid).toBe(false);
89
+ expect(info.error).toBeTruthy();
90
+ expect(info.nextRun).toBeNull();
91
+ });
92
+
93
+ it("treats a null or undefined expression as empty rather than throwing", () => {
94
+ for (const expr of [null, undefined]) {
95
+ const info = describeCron(expr as unknown as string);
96
+ expect(info.valid).toBe(false);
97
+ expect(info.error).toContain("5-field");
98
+ }
99
+ });
100
+ });
101
+
102
+ describe("formatNextRun", () => {
103
+ it("renders an instant in UTC and says so", () => {
104
+ const label = formatNextRun(new Date("2026-07-14T06:00:00Z"));
105
+ expect(label).toContain("2026");
106
+ expect(label).toContain("06:00");
107
+ expect(label.endsWith(" UTC")).toBe(true);
108
+ });
109
+
110
+ it("renders an em dash when there is no next run", () => {
111
+ expect(formatNextRun(null)).toBe("—");
112
+ });
113
+ });
@@ -2,4 +2,3 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  export { default as Materializations } from "./Materializations";
5
- export { default as EnvironmentMaterializations } from "./EnvironmentMaterializations";
@@ -0,0 +1,182 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { MaterializationStatus, type Materialization } from "../../client";
6
+ import {
7
+ formatDuration,
8
+ formatRelativeTime,
9
+ formatTimestamp,
10
+ isActiveStatus,
11
+ isTerminalStatus,
12
+ parseMetadata,
13
+ statusColor,
14
+ statusLabel,
15
+ triggerLabel,
16
+ } from "./utils";
17
+
18
+ /**
19
+ * The materializations table is entirely these functions: every cell it draws
20
+ * is one of them, and the polling loop that keeps it live is driven by the two
21
+ * predicates. None of it was covered, in either direction — a status the
22
+ * publisher adds later would fall through to "Unknown" and be polled forever,
23
+ * and nothing would say so.
24
+ */
25
+
26
+ const ALL = Object.values(MaterializationStatus);
27
+
28
+ describe("status predicates", () => {
29
+ it("treats the two in-flight phases as active", () => {
30
+ expect(isActiveStatus(MaterializationStatus.Pending)).toBe(true);
31
+ expect(isActiveStatus(MaterializationStatus.ManifestRowsReady)).toBe(
32
+ true,
33
+ );
34
+ });
35
+
36
+ it("treats the three settled phases as terminal", () => {
37
+ expect(isTerminalStatus(MaterializationStatus.ManifestFileReady)).toBe(
38
+ true,
39
+ );
40
+ expect(isTerminalStatus(MaterializationStatus.Failed)).toBe(true);
41
+ expect(isTerminalStatus(MaterializationStatus.Cancelled)).toBe(true);
42
+ });
43
+
44
+ /**
45
+ * The one that matters for the polling loop: every status the client knows
46
+ * is on exactly one side. A status that is neither is polled until the page
47
+ * is closed, because the loop stops on terminal and nothing else.
48
+ */
49
+ it("puts every known status on exactly one side", () => {
50
+ for (const status of ALL) {
51
+ expect([isActiveStatus(status), isTerminalStatus(status)]).toContain(
52
+ true,
53
+ );
54
+ expect(isActiveStatus(status) && isTerminalStatus(status)).toBe(false);
55
+ }
56
+ });
57
+
58
+ it("says an absent status is neither, so a half-loaded row is not polled", () => {
59
+ expect(isActiveStatus(undefined)).toBe(false);
60
+ expect(isTerminalStatus(undefined)).toBe(false);
61
+ });
62
+ });
63
+
64
+ describe("statusLabel", () => {
65
+ it("collapses both in-flight phases to one word", () => {
66
+ // The publisher drives the phases itself, so the distinction between
67
+ // them is not one a reader can act on.
68
+ expect(statusLabel(MaterializationStatus.Pending)).toBe("Pending");
69
+ expect(statusLabel(MaterializationStatus.ManifestRowsReady)).toBe(
70
+ "Pending",
71
+ );
72
+ });
73
+
74
+ it("names the settled phases apart", () => {
75
+ expect(statusLabel(MaterializationStatus.ManifestFileReady)).toBe("Done");
76
+ expect(statusLabel(MaterializationStatus.Failed)).toBe("Failed");
77
+ expect(statusLabel(MaterializationStatus.Cancelled)).toBe("Cancelled");
78
+ });
79
+
80
+ it("never renders a raw enum value at a reader", () => {
81
+ for (const status of ALL) {
82
+ expect(statusLabel(status)).not.toContain("_");
83
+ }
84
+ expect(statusLabel(undefined)).toBe("Unknown");
85
+ });
86
+ });
87
+
88
+ describe("statusColor", () => {
89
+ it("pairs failure with error and success with success", () => {
90
+ expect(statusColor(MaterializationStatus.Failed)).toBe("error");
91
+ expect(statusColor(MaterializationStatus.ManifestFileReady)).toBe(
92
+ "success",
93
+ );
94
+ expect(statusColor(MaterializationStatus.Cancelled)).toBe("warning");
95
+ });
96
+
97
+ it("gives every known status a colour the theme defines", () => {
98
+ const allowed = ["default", "info", "success", "error", "warning"];
99
+ for (const status of ALL) expect(allowed).toContain(statusColor(status));
100
+ expect(allowed).toContain(statusColor(undefined));
101
+ });
102
+ });
103
+
104
+ describe("parseMetadata and triggerLabel", () => {
105
+ const run = (metadata: unknown) =>
106
+ ({ metadata }) as unknown as Materialization;
107
+
108
+ it("reads the fields a run carries", () => {
109
+ const meta = parseMetadata(
110
+ run({ trigger: "SCHEDULER", sourcesBuilt: 3 }),
111
+ );
112
+ expect(meta.trigger).toBe("SCHEDULER");
113
+ expect(meta.sourcesBuilt).toBe(3);
114
+ });
115
+
116
+ it("hands back an empty object when there is no metadata", () => {
117
+ // The generated client types this as `object | null`, so every caller
118
+ // reads through here rather than risking a null dereference per cell.
119
+ expect(parseMetadata(run(null))).toEqual({});
120
+ expect(parseMetadata(run(undefined))).toEqual({});
121
+ });
122
+
123
+ it("calls a run manual unless the scheduler says otherwise", () => {
124
+ expect(triggerLabel({ trigger: "SCHEDULER" })).toBe("Scheduled");
125
+ expect(triggerLabel({ trigger: "ON_DEMAND" })).toBe("Manual");
126
+ expect(triggerLabel({})).toBe("Manual");
127
+ });
128
+ });
129
+
130
+ describe("formatDuration", () => {
131
+ const from = "2026-07-14T06:00:00.000Z";
132
+ const plus = (ms: number) => new Date(Date.parse(from) + ms).toISOString();
133
+
134
+ it("steps through the units as the run gets longer", () => {
135
+ expect(formatDuration(from, plus(250))).toBe("250ms");
136
+ expect(formatDuration(from, plus(4_000))).toBe("4s");
137
+ expect(formatDuration(from, plus(90_000))).toBe("1m 30s");
138
+ expect(formatDuration(from, plus(3_600_000 + 120_000))).toBe("1h 2m");
139
+ });
140
+
141
+ it("measures an open run against now rather than reporting nothing", () => {
142
+ const started = new Date(Date.now() - 5_000).toISOString();
143
+ expect(formatDuration(started, null)).toMatch(/^[45]s$/);
144
+ });
145
+
146
+ it("clamps a completion that precedes its start instead of going negative", () => {
147
+ expect(formatDuration(plus(5_000), from)).toBe("0ms");
148
+ });
149
+
150
+ it("renders a dash for a run that never started", () => {
151
+ expect(formatDuration(undefined, plus(1000))).toBe("-");
152
+ expect(formatDuration(null, null)).toBe("-");
153
+ });
154
+ });
155
+
156
+ describe("formatTimestamp", () => {
157
+ it("renders an instant", () => {
158
+ expect(formatTimestamp("2026-07-14T06:00:00Z")).toContain("2026");
159
+ });
160
+
161
+ it("renders an em dash rather than 'Invalid Date' for junk", () => {
162
+ expect(formatTimestamp("not a date")).toBe("—");
163
+ expect(formatTimestamp(null)).toBe("—");
164
+ expect(formatTimestamp(undefined)).toBe("—");
165
+ });
166
+ });
167
+
168
+ describe("formatRelativeTime", () => {
169
+ const ago = (ms: number) => new Date(Date.now() - ms).toISOString();
170
+
171
+ it("steps through the units as the instant recedes", () => {
172
+ expect(formatRelativeTime(ago(2_000))).toBe("just now");
173
+ expect(formatRelativeTime(ago(5 * 60_000))).toBe("5m ago");
174
+ expect(formatRelativeTime(ago(2 * 3_600_000))).toBe("2h ago");
175
+ expect(formatRelativeTime(ago(3 * 86_400_000))).toBe("3d ago");
176
+ });
177
+
178
+ it("renders a dash when there is no instant", () => {
179
+ expect(formatRelativeTime(null)).toBe("-");
180
+ expect(formatRelativeTime(undefined)).toBe("-");
181
+ });
182
+ });
@@ -4,17 +4,11 @@
4
4
  import "@malloydata/malloy-explorer/styles.css";
5
5
  import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
6
6
  import SearchIcon from "@mui/icons-material/Search";
7
- import {
8
- Box,
9
- IconButton,
10
- Snackbar,
11
- Stack,
12
- Tooltip,
13
- Typography,
14
- } from "@mui/material";
7
+ import { Box, Snackbar, Stack, Tooltip, Typography } from "@mui/material";
15
8
  import React, { useState } from "react";
16
9
  import { parseResourceUri } from "../../utils/formatting";
17
10
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
11
+ import { FloatingIconButton } from "../FloatingIconButton";
18
12
  import { Loading } from "../Loading";
19
13
  import { ModelCell } from "./ModelCell";
20
14
  import { ModelExplorer } from "./ModelExplorer";
@@ -151,29 +145,18 @@ export default function Model({
151
145
  />
152
146
 
153
147
  {/* Magnifying glass icon */}
154
- <IconButton
148
+ <FloatingIconButton
149
+ aria-label="Expand results"
155
150
  sx={{
156
151
  position: "absolute",
157
152
  top: "90px",
158
153
  right: "4px",
159
- backgroundColor: "rgba(255, 255, 255, 0.9)",
160
- "&:hover": {
161
- backgroundColor: "rgba(255, 255, 255, 1)",
162
- },
163
- width: "32px",
164
- height: "32px",
165
154
  zIndex: 2,
166
155
  }}
167
156
  onClick={() => setDialogOpen(true)}
168
157
  >
169
- <SearchIcon
170
- sx={{
171
- fontSize: "18px",
172
- color: "text.secondary",
173
- marginBottom: "5px",
174
- }}
175
- />
176
- </IconButton>
158
+ <SearchIcon />
159
+ </FloatingIconButton>
177
160
  </Stack>
178
161
  )}
179
162
 
@@ -3,18 +3,17 @@
3
3
 
4
4
  import PlayArrowIcon from "@mui/icons-material/PlayArrow";
5
5
  import SearchIcon from "@mui/icons-material/Search";
6
- import { Box, Button, IconButton, Typography } from "@mui/material";
6
+ import { Box, Button, Typography } from "@mui/material";
7
7
  import React, { useEffect } from "react";
8
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
8
+ import { useQueryResult } from "../../hooks/useQueryResult";
9
9
  import { usePublisherTheme } from "../../theme/ThemeContext";
10
10
  import { parseResourceUri } from "../../utils/formatting";
11
- import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
11
+ import { FloatingIconButton } from "../FloatingIconButton";
12
12
  import { highlight } from "../highlighter";
13
- import ResultContainer from "../RenderedResult/ResultContainer";
13
+ import { ResultPanel } from "../RenderedResult/ResultPanel";
14
14
  import { MODEL_CELL_MAX_HEIGHT } from "../RenderedResult/resultSizing";
15
15
  import ResultsDialog from "../ResultsDialog";
16
- import { useServer } from "../ServerProvider";
17
- import { CleanMetricCard, CleanNotebookCell } from "../styles";
16
+ import { CleanMetricCard } from "../styles";
18
17
 
19
18
  interface ModelCellProps {
20
19
  sourceName?: string;
@@ -40,29 +39,13 @@ export function ModelCell({
40
39
 
41
40
  const { packageName, environmentName, versionId, modelPath } =
42
41
  parseResourceUri(resourceUri);
43
- const { apiClients } = useServer();
44
-
45
- const {
46
- data: queryData,
47
- isSuccess,
48
- isLoading,
49
- } = useQueryWithApiError({
50
- queryKey: ["namedQueryResult", resourceUri, queryName],
51
- queryFn: () =>
52
- apiClients.models.executeQueryModel(
53
- environmentName,
54
- packageName,
55
- modelPath,
56
- {
57
- query: undefined,
58
- sourceName: undefined,
59
- queryName: queryName,
60
- versionId: versionId,
61
- },
62
- ),
63
- enabled: runOnDemand ? hasRun : true, // Execute on demand or always
64
- ...CHART_RESULT_QUERY_OPTIONS,
65
- });
42
+ // Run on demand or always; a query not yet asked for is not fetched.
43
+ const shouldRun = !runOnDemand || hasRun;
44
+ const state = useQueryResult(
45
+ { environmentName, packageName, modelPath, versionId, queryName },
46
+ { enabled: shouldRun },
47
+ );
48
+ const queryData = state.data;
66
49
 
67
50
  const { mode } = usePublisherTheme();
68
51
  useEffect(() => {
@@ -77,7 +60,7 @@ export function ModelCell({
77
60
  }, [annotations, mode]);
78
61
 
79
62
  return (
80
- <CleanNotebookCell>
63
+ <Box>
81
64
  {highlightedAnnotations && (
82
65
  <Box sx={{ marginBottom: "16px" }}>
83
66
  <Typography
@@ -110,29 +93,24 @@ export function ModelCell({
110
93
  variant="body2"
111
94
  sx={{
112
95
  fontSize: "15px",
113
- fontWeight: "600",
114
- color: "#495057",
115
- padding: "8px 16px",
116
- backgroundColor: "#f8f9fa",
117
- borderRadius: "6px",
118
- border: "1px solid #e9ecef",
96
+ fontWeight: 600,
97
+ color: "text.primary",
98
+ px: 2,
99
+ py: 1,
100
+ bgcolor: "action.hover",
101
+ borderRadius: 1.5,
102
+ border: 1,
103
+ borderColor: "divider",
119
104
  }}
120
105
  >
121
106
  {queryName}
122
107
  </Typography>
123
- <IconButton
124
- sx={{
125
- backgroundColor: "rgba(255, 255, 255, 0.9)",
126
- "&:hover": {
127
- backgroundColor: "rgba(255, 255, 255, 1)",
128
- },
129
- width: "32px",
130
- height: "32px",
131
- }}
108
+ <FloatingIconButton
109
+ aria-label="Expand results"
132
110
  onClick={() => setResultsDialogOpen(true)}
133
111
  >
134
- <SearchIcon sx={{ fontSize: "18px", color: "text.secondary" }} />
135
- </IconButton>
112
+ <SearchIcon />
113
+ </FloatingIconButton>
136
114
  </Box>
137
115
 
138
116
  <CleanMetricCard
@@ -158,36 +136,19 @@ export function ModelCell({
158
136
  variant="contained"
159
137
  startIcon={<PlayArrowIcon />}
160
138
  onClick={() => setHasRun(true)}
161
- sx={{
162
- backgroundColor: "#1976d2",
163
- "&:hover": {
164
- backgroundColor: "#1565c0",
165
- },
166
- textTransform: "none",
167
- fontSize: "14px",
168
- fontWeight: 600,
169
- padding: "8px 24px",
170
- }}
171
139
  >
172
140
  Run Query
173
141
  </Button>
174
142
  </Box>
175
143
  )}
176
- {(!runOnDemand || hasRun) && isLoading && (
177
- <Box sx={{ padding: "20px", textAlign: "center" }}>
178
- <Typography>Loading results...</Typography>
179
- </Box>
144
+ {shouldRun && (
145
+ <ResultPanel
146
+ state={state}
147
+ context={queryName}
148
+ maxHeight={MODEL_CELL_MAX_HEIGHT}
149
+ maxResultSize={maxResultSize}
150
+ />
180
151
  )}
181
- {(!runOnDemand || hasRun) &&
182
- isSuccess &&
183
- queryData?.data?.result && (
184
- <ResultContainer
185
- result={queryData.data.result}
186
- maxHeight={MODEL_CELL_MAX_HEIGHT}
187
- maxResultSize={maxResultSize}
188
- renderLogs={queryData.data.renderLogs}
189
- />
190
- )}
191
152
  </CleanMetricCard>
192
153
 
193
154
  {/* Results Dialog */}
@@ -198,6 +159,6 @@ export function ModelCell({
198
159
  renderLogs={queryData?.data?.renderLogs}
199
160
  title={`Query: ${queryName}`}
200
161
  />
201
- </CleanNotebookCell>
162
+ </Box>
202
163
  );
203
164
  }