@malloy-publisher/sdk 0.0.382-dev → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/README.md +115 -95
  2. package/TREE_SHAKING.md +16 -11
  3. package/bunfig.toml +7 -0
  4. package/dist/ServerProvider-Cn_LhKda.cjs.js +1 -0
  5. package/dist/ServerProvider-sfabtriY.es.js +4076 -0
  6. package/dist/client/api.d.ts +3773 -1515
  7. package/dist/client/configuration.d.ts +1 -1
  8. package/dist/client/index.cjs.js +1 -1
  9. package/dist/client/index.d.ts +1 -1
  10. package/dist/client/index.es.js +86 -59
  11. package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
  12. package/dist/components/Connections/common.d.ts +8 -2
  13. package/dist/components/Dashboard/Dashboard.d.ts +62 -0
  14. package/dist/components/Dashboard/DashboardTile.d.ts +57 -0
  15. package/dist/components/Dashboard/index.d.ts +2 -0
  16. package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
  17. package/dist/components/DataAppViewer/index.d.ts +1 -0
  18. package/dist/components/Environment/Environment.d.ts +6 -0
  19. package/dist/components/Environment/index.d.ts +2 -0
  20. package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
  21. package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
  22. package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
  23. package/dist/components/Home/Home.d.ts +2 -2
  24. package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
  25. package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
  26. package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
  27. package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
  28. package/dist/components/Materializations/ManifestView.d.ts +13 -0
  29. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
  30. package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
  31. package/dist/components/Materializations/Materializations.d.ts +7 -0
  32. package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
  33. package/dist/components/Materializations/SectionLabel.d.ts +10 -0
  34. package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
  35. package/dist/components/Materializations/TriggerChip.d.ts +10 -0
  36. package/dist/components/Materializations/cron.d.ts +23 -0
  37. package/dist/components/Materializations/index.d.ts +2 -0
  38. package/dist/components/Materializations/utils.d.ts +46 -0
  39. package/dist/components/Notebook/Notebook.d.ts +47 -4
  40. package/dist/components/Notebook/NotebookCell.d.ts +37 -1
  41. package/dist/components/Notebook/runPlan.d.ts +29 -0
  42. package/dist/components/Notebook/types.d.ts +10 -0
  43. package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
  44. package/dist/components/Package/Package.d.ts +1 -4
  45. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  46. package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
  47. package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
  48. package/dist/components/ResultsDialog.d.ts +6 -1
  49. package/dist/components/ServerProvider.d.ts +28 -4
  50. package/dist/components/click_helper.d.ts +10 -1
  51. package/dist/components/drill/index.d.ts +3 -0
  52. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  53. package/dist/components/drill/resolveDrill.d.ts +139 -0
  54. package/dist/components/drill/useDrill.d.ts +63 -0
  55. package/dist/components/given/GivenInput.d.ts +52 -0
  56. package/dist/components/given/GivensPanel.d.ts +47 -0
  57. package/dist/components/given/filterValue.d.ts +97 -0
  58. package/dist/components/given/index.d.ts +2 -0
  59. package/dist/components/given/paramCodec.d.ts +60 -0
  60. package/dist/components/given/utils.d.ts +17 -0
  61. package/dist/components/highlighter.d.ts +6 -1
  62. package/dist/components/index.d.ts +7 -2
  63. package/dist/components/styles.d.ts +47 -0
  64. package/dist/constants/docLinks.d.ts +12 -0
  65. package/dist/{core-YNpOLuB1.cjs.js → core-CqRKhtoy.cjs.js} +1 -1
  66. package/dist/{core-CjeTkq8O.es.js → core-DyU47reh.es.js} +1 -1
  67. package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
  68. package/dist/github-dark-DenFmJkN.es.js +4 -0
  69. package/dist/hooks/givenValue.d.ts +10 -0
  70. package/dist/hooks/index.d.ts +4 -0
  71. package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
  72. package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
  73. package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
  74. package/dist/hooks/useGivensState.d.ts +64 -0
  75. package/dist/hooks/useModelGivens.d.ts +10 -0
  76. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  77. package/dist/{index-DRDu9kIV.es.js → index-CAkFE4Ol.es.js} +41278 -28504
  78. package/dist/index-DD4b_bt0.cjs.js +356 -0
  79. package/dist/index.cjs.js +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.es.js +79 -48
  82. package/dist/malloy-explorer.css +12 -1
  83. package/dist/sdk.css +1 -1
  84. package/dist/theme/ThemeContext.d.ts +45 -0
  85. package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
  86. package/dist/theme/buildTableCssVars.d.ts +41 -0
  87. package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
  88. package/dist/theme/defaults.d.ts +7 -0
  89. package/dist/theme/index.d.ts +8 -0
  90. package/dist/theme/keys.d.ts +20 -0
  91. package/dist/theme/readChartAnnotations.d.ts +23 -0
  92. package/dist/theme/resolveTheme.d.ts +22 -0
  93. package/dist/theme/types.d.ts +70 -0
  94. package/dist/utils/dataAppEmbed.d.ts +44 -0
  95. package/dist/utils/formatting.d.ts +1 -1
  96. package/dist/utils/malloyString.d.ts +7 -0
  97. package/dist/utils/parsing.d.ts +2 -2
  98. package/dist/utils/queryClient.d.ts +5 -0
  99. package/package.json +19 -8
  100. package/src/client-entry.ts +3 -0
  101. package/src/components/AnalyzePackageButton.tsx +9 -3
  102. package/src/components/ApiErrorDisplay.tsx +3 -0
  103. package/src/components/Connections/AddConnectionDialog.tsx +132 -25
  104. package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
  105. package/src/components/Connections/EditConnectionDialog.tsx +167 -37
  106. package/src/components/Connections/common.ts +94 -3
  107. package/src/components/DOMElement/DOMElement.tsx +3 -0
  108. package/src/components/DOMElement/index.ts +3 -0
  109. package/src/components/Dashboard/Dashboard.spec.tsx +216 -0
  110. package/src/components/Dashboard/Dashboard.tsx +458 -0
  111. package/src/components/Dashboard/DashboardTile.spec.tsx +81 -0
  112. package/src/components/Dashboard/DashboardTile.tsx +199 -0
  113. package/src/components/Dashboard/index.ts +5 -0
  114. package/src/components/Dashboard/tileGridColumn.spec.ts +35 -0
  115. package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
  116. package/src/components/DataAppViewer/index.ts +4 -0
  117. package/src/components/{Project → Environment}/About.tsx +11 -4
  118. package/src/components/Environment/AddPackageDialog.tsx +202 -0
  119. package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
  120. package/src/components/Environment/Connections.tsx +391 -0
  121. package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
  122. package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
  123. package/src/components/Environment/Environment.tsx +89 -0
  124. package/src/components/Environment/Packages.tsx +206 -0
  125. package/src/components/Environment/index.ts +5 -0
  126. package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
  127. package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
  128. package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
  129. package/src/components/Home/Home.tsx +386 -408
  130. package/src/components/Home/index.ts +3 -0
  131. package/src/components/Loading.tsx +3 -0
  132. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
  133. package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
  134. package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
  135. package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
  136. package/src/components/Materializations/ManifestView.tsx +87 -0
  137. package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
  138. package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
  139. package/src/components/Materializations/Materializations.tsx +355 -0
  140. package/src/components/Materializations/ScheduleCard.tsx +231 -0
  141. package/src/components/Materializations/SectionLabel.tsx +30 -0
  142. package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
  143. package/src/components/Materializations/TriggerChip.tsx +44 -0
  144. package/src/components/Materializations/cron.ts +124 -0
  145. package/src/components/Materializations/index.ts +5 -0
  146. package/src/components/Materializations/utils.ts +145 -0
  147. package/src/components/Model/Model.tsx +44 -2
  148. package/src/components/Model/ModelCell.tsx +14 -5
  149. package/src/components/Model/ModelExplorer.tsx +3 -0
  150. package/src/components/Model/ModelExplorerDialog.tsx +4 -1
  151. package/src/components/Model/SourcesExplorer.tsx +9 -6
  152. package/src/components/Model/index.ts +3 -0
  153. package/src/components/Model/useModelData.ts +6 -3
  154. package/src/components/Notebook/Notebook.spec.tsx +88 -0
  155. package/src/components/Notebook/Notebook.tsx +476 -339
  156. package/src/components/Notebook/NotebookCell.tsx +264 -25
  157. package/src/components/Notebook/index.ts +3 -0
  158. package/src/components/Notebook/runPlan.spec.ts +155 -0
  159. package/src/components/Notebook/runPlan.ts +67 -0
  160. package/src/components/Notebook/types.ts +14 -0
  161. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  162. package/src/components/Package/ContentTypeIcon.tsx +177 -0
  163. package/src/components/Package/FileTreeView.tsx +3 -0
  164. package/src/components/Package/Models.tsx +7 -4
  165. package/src/components/Package/Package.spec.tsx +113 -0
  166. package/src/components/Package/Package.tsx +692 -59
  167. package/src/components/Package/index.ts +3 -0
  168. package/src/components/QueryResult/QueryResult.tsx +17 -8
  169. package/src/components/QueryResult/index.ts +3 -0
  170. package/src/components/RenderedResult/RenderedResult.tsx +725 -67
  171. package/src/components/RenderedResult/ResultContainer.tsx +71 -2
  172. package/src/components/RenderedResult/index.ts +3 -0
  173. package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
  174. package/src/components/RenderedResult/renderLogs.ts +43 -0
  175. package/src/components/ResultsDialog.tsx +13 -1
  176. package/src/components/ServerProvider.tsx +175 -51
  177. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  178. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  179. package/src/components/Workbook/ModelPicker.tsx +7 -4
  180. package/src/components/Workbook/MutableCell.tsx +10 -5
  181. package/src/components/Workbook/Workbook.tsx +8 -5
  182. package/src/components/Workbook/WorkbookList.tsx +3 -0
  183. package/src/components/Workbook/WorkbookManager.ts +3 -0
  184. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  185. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  186. package/src/components/Workbook/index.ts +3 -0
  187. package/src/components/click_helper.ts +17 -1
  188. package/src/components/drill/index.ts +28 -0
  189. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  190. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  191. package/src/components/drill/markDrillableCells.ts +314 -0
  192. package/src/components/drill/resolveDrill.spec.ts +449 -0
  193. package/src/components/drill/resolveDrill.ts +375 -0
  194. package/src/components/drill/useDrill.tsx +203 -0
  195. package/src/components/filter/DimensionFilter.tsx +3 -0
  196. package/src/components/filter/index.ts +3 -0
  197. package/src/components/filter/utils.ts +16 -5
  198. package/src/components/given/GivenInput.spec.tsx +689 -0
  199. package/src/components/given/GivenInput.tsx +801 -0
  200. package/src/components/given/GivensPanel.spec.tsx +175 -0
  201. package/src/components/given/GivensPanel.tsx +195 -0
  202. package/src/components/given/filterValue.spec.ts +364 -0
  203. package/src/components/given/filterValue.ts +207 -0
  204. package/src/components/given/index.ts +9 -0
  205. package/src/components/given/paramCodec.spec.ts +857 -0
  206. package/src/components/given/paramCodec.ts +483 -0
  207. package/src/components/given/utils.spec.ts +60 -0
  208. package/src/components/given/utils.ts +79 -0
  209. package/src/components/highlighter.ts +22 -5
  210. package/src/components/index.ts +10 -2
  211. package/src/components/styles.ts +82 -33
  212. package/src/constants/docLinks.spec.ts +54 -0
  213. package/src/constants/docLinks.ts +46 -0
  214. package/src/hooks/givenValue.ts +13 -0
  215. package/src/hooks/index.ts +13 -0
  216. package/src/hooks/useDimensionFilters.ts +4 -7
  217. package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
  218. package/src/hooks/useDimensionFiltersQuery.ts +10 -13
  219. package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
  220. package/src/hooks/useGivensState.spec.ts +449 -0
  221. package/src/hooks/useGivensState.ts +340 -0
  222. package/src/hooks/useModelGivens.ts +29 -0
  223. package/src/hooks/useQueryWithApiError.ts +3 -0
  224. package/src/hooks/useRawQueryData.ts +6 -3
  225. package/src/hooks/useSuggestOptions.dom.spec.ts +91 -0
  226. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  227. package/src/hooks/useSuggestOptions.ts +268 -0
  228. package/src/index.ts +10 -1
  229. package/src/react-app-env.d.ts +3 -0
  230. package/src/theme/ThemeContext.tsx +86 -0
  231. package/src/theme/buildMalloyExplicitTheme.ts +61 -0
  232. package/src/theme/buildTableCssVars.spec.ts +86 -0
  233. package/src/theme/buildTableCssVars.ts +98 -0
  234. package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
  235. package/src/theme/buildVegaThemeOverride.ts +47 -0
  236. package/src/theme/defaults.ts +78 -0
  237. package/src/theme/index.ts +11 -0
  238. package/src/theme/keys.ts +32 -0
  239. package/src/theme/readChartAnnotations.spec.ts +58 -0
  240. package/src/theme/readChartAnnotations.ts +69 -0
  241. package/src/theme/resolveTheme.spec.ts +160 -0
  242. package/src/theme/resolveTheme.ts +121 -0
  243. package/src/theme/types.ts +79 -0
  244. package/src/utils/dataAppEmbed.spec.ts +63 -0
  245. package/src/utils/dataAppEmbed.ts +84 -0
  246. package/src/utils/formatting.spec.ts +25 -21
  247. package/src/utils/formatting.ts +11 -7
  248. package/src/utils/malloyString.spec.ts +24 -0
  249. package/src/utils/malloyString.ts +12 -0
  250. package/src/utils/parsing.spec.ts +26 -19
  251. package/src/utils/parsing.ts +11 -6
  252. package/src/utils/queryClient.ts +17 -0
  253. package/test/README.md +185 -0
  254. package/test/serverProvider.tsx +72 -0
  255. package/test/setup.ts +29 -0
  256. package/tsconfig.json +12 -1
  257. package/tsconfig.spec.json +22 -0
  258. package/vite.config.ts +3 -0
  259. package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
  260. package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
  261. package/dist/components/Home/AddProjectDialog.d.ts +0 -1
  262. package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
  263. package/dist/components/Home/EditProjectDialog.d.ts +0 -7
  264. package/dist/components/Package/Config.d.ts +0 -5
  265. package/dist/components/Package/Databases.d.ts +0 -5
  266. package/dist/components/Package/Notebooks.d.ts +0 -6
  267. package/dist/components/Project/Project.d.ts +0 -6
  268. package/dist/components/Project/index.d.ts +0 -2
  269. package/dist/index-BOLBP6_i.cjs.js +0 -233
  270. package/src/components/Package/Config.tsx +0 -97
  271. package/src/components/Package/Connections.tsx +0 -373
  272. package/src/components/Package/Databases.tsx +0 -228
  273. package/src/components/Package/Notebooks.tsx +0 -77
  274. package/src/components/Project/AddPackageDialog.tsx +0 -159
  275. package/src/components/Project/Packages.tsx +0 -191
  276. package/src/components/Project/Project.tsx +0 -52
  277. package/src/components/Project/index.ts +0 -2
  278. /package/dist/components/{Project → Environment}/About.d.ts +0 -0
  279. /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
  280. /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
  281. /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
  282. /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
  283. /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
  284. /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
@@ -0,0 +1,81 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * The tile's own query key, asserted directly rather than through `Dashboard`.
6
+ *
7
+ * `DashboardTile` is exported from the package root, so a host can mount one
8
+ * itself, and `versionId` has to land in both the request and the key from the
9
+ * prop alone.
10
+ */
11
+ import { beforeEach, expect, it, mock } from "bun:test";
12
+ import { render, waitFor } from "@testing-library/react";
13
+ import {
14
+ cacheKeys,
15
+ clearCache,
16
+ mockServerProvider,
17
+ pending,
18
+ serverWrapper,
19
+ } from "../../../test/serverProvider";
20
+
21
+ const executeQueryModel = mock(
22
+ (
23
+ _environmentName: string,
24
+ _packageName: string,
25
+ _modelPath: string,
26
+ _request: { versionId?: string },
27
+ ) => pending(),
28
+ );
29
+
30
+ mockServerProvider({ models: { executeQueryModel } });
31
+
32
+ const { DashboardTile } = await import("./DashboardTile");
33
+
34
+ const tileAt = (versionId?: string) => (
35
+ <DashboardTile
36
+ environmentName="env"
37
+ packageName="pkg"
38
+ versionId={versionId}
39
+ modelPath="dashboards/ops.malloy"
40
+ tile="sales_by_month"
41
+ givens={new Map()}
42
+ declaredTypes={new Map()}
43
+ height={400}
44
+ />
45
+ );
46
+
47
+ beforeEach(() => {
48
+ clearCache();
49
+ executeQueryModel.mockClear();
50
+ });
51
+
52
+ it("puts the version in the request body and in the key", async () => {
53
+ render(tileAt("v2"), { wrapper: serverWrapper });
54
+
55
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
56
+ expect(executeQueryModel.mock.calls[0][3].versionId).toBe("v2");
57
+ expect(cacheKeys("dashboardTile")[0]).toContain('"v2"');
58
+ });
59
+
60
+ it("sends and keys nothing extra without one", async () => {
61
+ render(tileAt(), { wrapper: serverWrapper });
62
+
63
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
64
+ expect(executeQueryModel.mock.calls[0][3].versionId).toBeUndefined();
65
+ // The whole key: an empty slot rather than a literal "undefined", and
66
+ // nothing else disturbed. The narrow assertion above cannot see either.
67
+ expect(cacheKeys("dashboardTile")[0]).toBe(
68
+ '["dashboardTile","env","pkg",null,"dashboards/ops.malloy",null,' +
69
+ '"sales_by_month","{}","http://localhost/api/v0"]',
70
+ );
71
+ });
72
+
73
+ it("keeps two versions of one tile apart", async () => {
74
+ const { rerender } = render(tileAt("v1"), { wrapper: serverWrapper });
75
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(1));
76
+
77
+ rerender(tileAt("v2"));
78
+
79
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(2));
80
+ expect(new Set(cacheKeys("dashboardTile")).size).toBe(2);
81
+ });
@@ -0,0 +1,199 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box, Paper, Typography } from "@mui/material";
5
+ import { DASHBOARD_CARD_PADDING_PX } from "../../theme/buildTableCssVars";
6
+ import { usePublisherTheme } from "../../theme/ThemeContext";
7
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
8
+ import type { GivenValue } from "../../hooks/givenValue";
9
+ import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
10
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
11
+ import { humanizeSlug, type DrillBinding } from "../drill";
12
+ import { givensToRequest } from "../given/paramCodec";
13
+ import { Loading } from "../Loading";
14
+ import ResultContainer from "../RenderedResult/ResultContainer";
15
+ import { useServer } from "../ServerProvider";
16
+
17
+ export interface DashboardTileProps {
18
+ environmentName: string;
19
+ packageName: string;
20
+ /** The package version the dashboard's URI named, when it named one. */
21
+ versionId?: string;
22
+ modelPath: string;
23
+ /** A named query (the single-query form). */
24
+ queryName?: string;
25
+ /** A run expression (a composite tile). */
26
+ tile?: string;
27
+ /** `# label` on the view the tile names, when it has one. */
28
+ label?: string;
29
+ /** `# subtitle` on it: a second line under the heading. */
30
+ subtitle?: string;
31
+ /** `# borderless` on it: no card around the result. */
32
+ borderless?: boolean;
33
+ /**
34
+ * The whole applied control row, NOT this tile's share of it. The narrowing
35
+ * happens here, in `givensToRequest` below, using {@link givenNames}: the
36
+ * caller does not know which givens a tile references and this component
37
+ * does.
38
+ */
39
+ givens: Map<string, GivenValue>;
40
+ /** Declared type per given name, which decides how a value is encoded. */
41
+ declaredTypes: ReadonlyMap<string, string | undefined>;
42
+ /**
43
+ * Given names this tile references, or undefined when discovery could not
44
+ * resolve the tile. Undefined means "send the whole control row", which the
45
+ * server accepts: a surfaced given a query does not reference is ignored.
46
+ */
47
+ givenNames?: string[];
48
+ height: number;
49
+ maxResultSize?: number;
50
+ /** Cell clicks and their affordance, for the dashboard's `# drill`. */
51
+ drill?: DrillBinding;
52
+ }
53
+
54
+ /**
55
+ * A composite tile's heading when the view it names carries no `# label`: the
56
+ * last step's name as a sentence, so `scoped_sales -> sales_by_month` is titled
57
+ * "Sales by month".
58
+ *
59
+ * The label itself is the same `# label` a nest gets in the single-query form,
60
+ * read off the view server-side, so one view is titled identically whichever way
61
+ * it is consumed. This derivation is the fallback for an untitled view, so a
62
+ * tile shows a heading rather than code.
63
+ */
64
+ export function tileTitle(tile: string): string {
65
+ const lastStep = tile.split("->").at(-1)?.trim() ?? tile;
66
+ // Anything that is not a bare name (an inline `{ … }` stage, say) has no
67
+ // sensible title to derive, so it keeps the expression as written.
68
+ return /^[A-Za-z_][\w-]*$/.test(lastStep) ? humanizeSlug(lastStep) : tile;
69
+ }
70
+
71
+ /**
72
+ * One result panel: run it, render it, and keep its failure to itself.
73
+ *
74
+ * A tile owning its own query is what lets a composite dashboard survive a bad
75
+ * tile: the broken one shows its error in place and the rest of the grid still
76
+ * renders, rather than one failure blanking the page.
77
+ */
78
+ export function DashboardTile({
79
+ environmentName,
80
+ packageName,
81
+ versionId,
82
+ modelPath,
83
+ queryName,
84
+ tile,
85
+ label,
86
+ subtitle,
87
+ borderless,
88
+ givens,
89
+ declaredTypes,
90
+ givenNames,
91
+ height,
92
+ maxResultSize,
93
+ drill,
94
+ }: DashboardTileProps) {
95
+ const { apiClients } = useServer();
96
+ const { theme } = usePublisherTheme();
97
+ const requestGivens = givensToRequest(givens, declaredTypes, givenNames);
98
+
99
+ const { data, isSuccess, isError, error } = useQueryWithApiError({
100
+ queryKey: [
101
+ "dashboardTile",
102
+ environmentName,
103
+ packageName,
104
+ versionId,
105
+ modelPath,
106
+ queryName,
107
+ tile,
108
+ // Re-runs when the applied values change, which is the whole point of
109
+ // the control row.
110
+ JSON.stringify(requestGivens),
111
+ ],
112
+ queryFn: () =>
113
+ apiClients.models.executeQueryModel(
114
+ environmentName,
115
+ packageName,
116
+ modelPath,
117
+ {
118
+ queryName,
119
+ query: tile !== undefined ? `run: ${tile}` : undefined,
120
+ givens: requestGivens,
121
+ versionId,
122
+ },
123
+ ),
124
+ ...CHART_RESULT_QUERY_OPTIONS,
125
+ });
126
+
127
+ return (
128
+ <Paper
129
+ elevation={0}
130
+ sx={{
131
+ // The instance theme's border, not MUI's `divider`: the renderer
132
+ // card's edge is this same value, and a card that agrees with the
133
+ // theme everywhere except its outline still reads as a different
134
+ // card. Radius stays on the host's `shape.borderRadius`, which the
135
+ // renderer card is now pointed at too.
136
+ //
137
+ // `# borderless` asks for the result with no card, which the renderer
138
+ // honours by dropping background, border, radius and most padding on
139
+ // its own `.dashboard-item`. Same here, so the tag reads the same on
140
+ // both forms.
141
+ border: borderless ? "none" : theme.border,
142
+ borderRadius: borderless ? 0 : 1,
143
+ background: borderless ? "none" : undefined,
144
+ overflow: "hidden",
145
+ minHeight: 120,
146
+ p: borderless ? "12px 0" : `${DASHBOARD_CARD_PADDING_PX}px`,
147
+ }}
148
+ >
149
+ {tile !== undefined && (
150
+ <Box sx={{ pb: 1.5 }}>
151
+ <Typography
152
+ variant="subtitle2"
153
+ sx={{
154
+ fontWeight: 500,
155
+ color: theme.tileTitle,
156
+ fontFamily: theme.font.family,
157
+ }}
158
+ // The expression is what actually ran, so it stays reachable
159
+ // as a tooltip rather than as the heading.
160
+ title={tile}
161
+ >
162
+ {label ?? tileTitle(tile)}
163
+ </Typography>
164
+ {subtitle !== undefined && (
165
+ <Typography
166
+ variant="caption"
167
+ sx={{
168
+ display: "block",
169
+ color: theme.tileTitle,
170
+ fontFamily: theme.font.family,
171
+ opacity: 0.8,
172
+ }}
173
+ >
174
+ {subtitle}
175
+ </Typography>
176
+ )}
177
+ </Box>
178
+ )}
179
+ {!isSuccess && !isError && <Loading text="Running…" />}
180
+ {isSuccess && (
181
+ <ResultContainer
182
+ result={data.data.result}
183
+ maxHeight={height}
184
+ maxResultSize={maxResultSize}
185
+ renderLogs={data.data.renderLogs}
186
+ drill={drill}
187
+ />
188
+ )}
189
+ {isError && (
190
+ <Box sx={{ p: 2 }}>
191
+ <ApiErrorDisplay
192
+ context={tile ?? queryName ?? modelPath}
193
+ error={error}
194
+ />
195
+ </Box>
196
+ )}
197
+ </Paper>
198
+ );
199
+ }
@@ -0,0 +1,5 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ export { Dashboard, type DashboardProps } from "./Dashboard";
5
+ export { DashboardTile, type DashboardTileProps } from "./DashboardTile";
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { tileGridColumn } from "./Dashboard";
6
+
7
+ describe("tileGridColumn", () => {
8
+ it("spans one column when the view carries no colspan", () => {
9
+ expect(tileGridColumn({}, 12)).toBe("span 1");
10
+ });
11
+
12
+ it("spans the colspan the view asked for", () => {
13
+ expect(tileGridColumn({ colspan: 8 }, 12)).toBe("span 8");
14
+ });
15
+
16
+ // Clamped rather than allowed to overflow the grid, matching how
17
+ // @malloydata/render clamps the same tag on a `# dashboard` nest child. The
18
+ // whole point of reading the tag off the view is that one view lays out the
19
+ // same either way, which a different overflow rule would break.
20
+ it("clamps a colspan wider than the grid", () => {
21
+ expect(tileGridColumn({ colspan: 20 }, 4)).toBe("span 4");
22
+ });
23
+
24
+ // An explicit start line is what pushes the tile onto a fresh row; `span N`
25
+ // alone would let it flow into whatever columns are left beside its sibling.
26
+ it("starts a new row for a break", () => {
27
+ expect(tileGridColumn({ colspan: 6, break: true }, 12)).toBe(
28
+ "1 / span 6",
29
+ );
30
+ });
31
+
32
+ it("breaks with no colspan too", () => {
33
+ expect(tileGridColumn({ break: true }, 12)).toBe("1 / span 1");
34
+ });
35
+ });
@@ -0,0 +1,214 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import OpenInNewIcon from "@mui/icons-material/OpenInNew";
5
+ import { Box, IconButton, Stack, Tooltip, Typography } from "@mui/material";
6
+ import { useEffect, useMemo, useRef, useState } from "react";
7
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
8
+ import { useServer } from "../ServerProvider";
9
+ import { MONO_FONT_FAMILY } from "../styles";
10
+ import { parseResourceUri } from "../../utils/formatting";
11
+ import {
12
+ isPublisherResizeMessage,
13
+ packageFileUrl,
14
+ } from "../../utils/dataAppEmbed";
15
+
16
+ interface DataAppViewerProps {
17
+ resourceUri: string;
18
+ }
19
+
20
+ function parseDataAppResource(resourceUri: string) {
21
+ try {
22
+ const { environmentName, packageName, modelPath } =
23
+ parseResourceUri(resourceUri);
24
+ if (!environmentName || !packageName || !modelPath) return null;
25
+ return { environmentName, packageName, dataAppPath: modelPath };
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Renders an in-package HTML data app (from the Publisher static-file route)
33
+ * inside an iframe, wrapped in light SPA chrome — title, breadcrumb-ish
34
+ * label, and an "open standalone" escape hatch.
35
+ *
36
+ * The iframe `src` points at the Publisher worker's standalone URL on the
37
+ * data origin (derived from `useServer().server`, which may differ from
38
+ * the SPA origin in multi-host deployments). The app's `publisher.js`
39
+ * runtime postMessages `{ type: "publisher:resize", height }` as content
40
+ * height changes; we listen and resize the iframe to match so embedded
41
+ * dashboards don't get a nested scrollbar.
42
+ *
43
+ * Full-screen apps (e.g. slide decks) can opt out of content-height sizing
44
+ * with `<meta name="publisher:fit" content="viewport">`, surfaced as
45
+ * `DataApp.fit === "viewport"`. The iframe then fills the available viewport
46
+ * height (matching the standalone view) instead of collapsing to the app's
47
+ * near-zero reported content height.
48
+ */
49
+ export default function DataAppViewer({ resourceUri }: DataAppViewerProps) {
50
+ const { server, apiClients } = useServer();
51
+ const parsed = parseDataAppResource(resourceUri);
52
+ const environmentName = parsed?.environmentName ?? "";
53
+ const packageName = parsed?.packageName ?? "";
54
+ const dataAppPath = parsed?.dataAppPath ?? "";
55
+
56
+ const standaloneUrl = useMemo(
57
+ () =>
58
+ packageFileUrl({
59
+ server,
60
+ environmentName,
61
+ packageName,
62
+ path: dataAppPath,
63
+ }),
64
+ [server, environmentName, packageName, dataAppPath],
65
+ );
66
+
67
+ // Use the /data-apps endpoint to grab the <title> for the header. Any error
68
+ // here (older Publisher without /data-apps, transient network blip, 5xx) is
69
+ // non-fatal — `title` falls back to `dataAppPath` and the iframe still
70
+ // renders. The app itself is loaded via the iframe `src`, not from this
71
+ // query, so blocking the viewer on a metadata lookup would be wrong.
72
+ const dataAppsQuery = useQueryWithApiError({
73
+ queryKey: ["data-apps", environmentName, packageName],
74
+ queryFn: () =>
75
+ apiClients.dataApps.listDataApps(environmentName, packageName),
76
+ enabled: !!parsed,
77
+ });
78
+ const dataAppMeta = dataAppsQuery.data?.data?.find(
79
+ (a) => a.path === dataAppPath,
80
+ );
81
+ const title = dataAppMeta?.title ?? dataAppPath;
82
+ // Full-screen apps opt in via <meta name="publisher:fit" content="viewport">
83
+ // (surfaced as DataApp.fit by the /data-apps listing). In fill mode the
84
+ // iframe fills the available viewport height instead of being sized to the
85
+ // app's reported content height: a viewport-filling deck has ~no content
86
+ // height to report, so the default auto-size would clip it. An ordinary
87
+ // content-driven app keeps auto-sizing.
88
+ const fillViewport = dataAppMeta?.fit === "viewport";
89
+
90
+ const iframeRef = useRef<HTMLIFrameElement | null>(null);
91
+ // Start small so the iframe doesn't pre-commit space before the first
92
+ // resize message; the runtime postMessages the real content height
93
+ // within a frame of load.
94
+ const [iframeHeight, setIframeHeight] = useState<number>(120);
95
+
96
+ useEffect(() => {
97
+ // Fill mode pins the iframe to 100%, so content-height resize messages are
98
+ // irrelevant; skip subscribing (and the per-message re-renders) until the
99
+ // app is in content-height mode.
100
+ if (fillViewport) return;
101
+ function onMessage(e: MessageEvent) {
102
+ if (!isPublisherResizeMessage(e.data)) return;
103
+ if (e.source !== iframeRef.current?.contentWindow) return;
104
+ if (e.data.height > 0) {
105
+ setIframeHeight(Math.ceil(e.data.height));
106
+ }
107
+ }
108
+ window.addEventListener("message", onMessage);
109
+ return () => window.removeEventListener("message", onMessage);
110
+ }, [fillViewport]);
111
+
112
+ if (!parsed) {
113
+ return (
114
+ <Box sx={{ p: 3, maxWidth: 1200, mx: "auto" }}>
115
+ <Typography variant="h6" sx={{ fontWeight: 600 }}>
116
+ Can&apos;t open data app
117
+ </Typography>
118
+ <Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
119
+ This data app link is missing an environment, package, or path:
120
+ <Box
121
+ component="span"
122
+ sx={{ fontFamily: MONO_FONT_FAMILY, ml: 1 }}
123
+ >
124
+ {resourceUri}
125
+ </Box>
126
+ </Typography>
127
+ </Box>
128
+ );
129
+ }
130
+
131
+ return (
132
+ <Box
133
+ sx={{
134
+ p: 3,
135
+ // Fill mode fills the available height of DataAppViewer's ancestor,
136
+ // so it must render inside a height-constrained container. The
137
+ // Publisher app provides one (MainPage's 100dvh flex chain); an SDK
138
+ // consumer embedding DataAppViewer should give it a bounded-height
139
+ // parent.
140
+ ...(fillViewport
141
+ ? { height: "100%", display: "flex", flexDirection: "column" }
142
+ : { maxWidth: 1200, mx: "auto" }),
143
+ }}
144
+ >
145
+ <Stack
146
+ direction="row"
147
+ alignItems="baseline"
148
+ spacing={1}
149
+ sx={{ mb: 1, flexShrink: 0 }}
150
+ >
151
+ <Typography
152
+ variant="h6"
153
+ sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
154
+ >
155
+ {title}
156
+ </Typography>
157
+ <Typography
158
+ variant="caption"
159
+ color="text.secondary"
160
+ sx={{ fontFamily: MONO_FONT_FAMILY }}
161
+ >
162
+ {dataAppPath}
163
+ </Typography>
164
+ <Box sx={{ flex: 1 }} />
165
+ <Tooltip title="Open standalone in new tab">
166
+ <IconButton
167
+ size="small"
168
+ href={standaloneUrl}
169
+ target="_blank"
170
+ rel="noopener noreferrer"
171
+ aria-label="Open standalone in new tab"
172
+ sx={{ color: "text.secondary" }}
173
+ >
174
+ <OpenInNewIcon fontSize="small" />
175
+ </IconButton>
176
+ </Tooltip>
177
+ </Stack>
178
+ <Box
179
+ sx={{
180
+ border: "1px solid",
181
+ borderColor: "divider",
182
+ borderRadius: 1.5,
183
+ overflow: "hidden",
184
+ backgroundColor: "background.paper",
185
+ // Fill mode: grow to consume the remaining viewport height (the
186
+ // SPA gives DataAppViewer a 100dvh flex ancestor) so the iframe
187
+ // below can be 100% tall. minHeight:0 lets this flex child
188
+ // actually shrink/grow instead of overflowing its parent.
189
+ ...(fillViewport ? { flex: 1, minHeight: 0 } : {}),
190
+ }}
191
+ >
192
+ <iframe
193
+ ref={iframeRef}
194
+ src={standaloneUrl}
195
+ title={title}
196
+ // allow-same-origin so the iframe can use cookies for the
197
+ // Publisher API. allow-scripts so the dashboard's JS runs.
198
+ // allow-forms so dropdown/filter forms work. Intentionally
199
+ // NOT allowing top-navigation or popups.
200
+ sandbox="allow-scripts allow-same-origin allow-forms"
201
+ style={{
202
+ display: "block",
203
+ width: "100%",
204
+ // Fill mode pins the iframe to the available height so the
205
+ // deck's own 100vh resolves against a real viewport. Otherwise
206
+ // track the content height reported via publisher:resize.
207
+ height: fillViewport ? "100%" : iframeHeight,
208
+ border: 0,
209
+ }}
210
+ />
211
+ </Box>
212
+ </Box>
213
+ );
214
+ }
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ export { default as DataAppViewer } from "./DataAppViewer";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { Box, Button } from "@mui/material";
2
5
  import Markdown from "markdown-to-jsx";
3
6
  import { useState } from "react";
@@ -16,14 +19,15 @@ interface AboutProps {
16
19
  }
17
20
 
18
21
  export default function About({ resourceUri }: AboutProps) {
19
- const { projectName } = parseResourceUri(resourceUri);
22
+ const { environmentName } = parseResourceUri(resourceUri);
20
23
  const { apiClients } = useServer();
21
24
  const [expanded, setExpanded] = useState(false);
22
25
  const wordLimit = 90;
23
26
 
24
27
  const { data, isSuccess, isError, error } = useQueryWithApiError({
25
- queryKey: ["about", projectName],
26
- queryFn: () => apiClients.projects.getProject(projectName, false),
28
+ queryKey: ["about", environmentName],
29
+ queryFn: () =>
30
+ apiClients.environments.getEnvironment(environmentName, false),
27
31
  });
28
32
 
29
33
  const readmeContent = data?.data?.readme || "";
@@ -93,7 +97,10 @@ export default function About({ resourceUri }: AboutProps) {
93
97
  </PackageCard>
94
98
  )}
95
99
  {isError && (
96
- <ApiErrorDisplay error={error} context={`${projectName} > About`} />
100
+ <ApiErrorDisplay
101
+ error={error}
102
+ context={`${environmentName} > About`}
103
+ />
97
104
  )}
98
105
  </>
99
106
  );