@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
@@ -1,82 +1,715 @@
1
- import { Box, Grid } from "@mui/material";
2
- import React from "react";
3
- import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
4
- import { RetrievalFunction } from "../filter/DimensionFilter";
5
- import { Notebook } from "../Notebook";
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import ArrowBackIcon from "@mui/icons-material/ArrowBack";
5
+ import CloseIcon from "@mui/icons-material/Close";
6
+ import OpenInNewIcon from "@mui/icons-material/OpenInNew";
6
7
  import {
7
- PackageCard,
8
- PackageCardContent,
9
- PackageSectionTitle,
10
- } from "../styles";
11
- import Config from "./Config";
12
- import Connections from "./Connections";
13
- import Databases from "./Databases";
14
- import Models from "./Models";
15
- import Notebooks from "./Notebooks";
8
+ Alert,
9
+ Box,
10
+ Container,
11
+ Dialog,
12
+ DialogContent,
13
+ DialogTitle,
14
+ IconButton,
15
+ Link,
16
+ Stack,
17
+ Table,
18
+ TableBody,
19
+ TableCell,
20
+ TableHead,
21
+ TableRow,
22
+ Tooltip,
23
+ Typography,
24
+ } from "@mui/material";
25
+ import React, { useState } from "react";
26
+ import { Database } from "../../client";
27
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
28
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
29
+ import { Loading } from "../Loading";
30
+ import { Notebook } from "../Notebook";
31
+ import { useServer } from "../ServerProvider";
32
+ import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
33
+ import { serverBaseUrl } from "../../utils/dataAppEmbed";
34
+ import { MONO_FONT_FAMILY } from "../styles";
35
+ import ContentTypeIcon, {
36
+ CONTENT_TINT,
37
+ type ContentType,
38
+ } from "./ContentTypeIcon";
16
39
 
17
40
  const README_NOTEBOOK = "README.malloynb";
18
41
 
19
42
  interface PackageProps {
20
43
  onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
21
44
  resourceUri: string;
22
- /** Optional retrieval function for semantic search filters */
23
- retrievalFn?: RetrievalFunction;
24
45
  }
25
46
 
26
47
  export default function Package({
27
48
  onClickPackageFile,
28
49
  resourceUri,
29
- retrievalFn,
30
50
  }: PackageProps) {
31
- if (!onClickPackageFile) {
32
- onClickPackageFile = (to: string) => {
51
+ const { apiClients, server } = useServer();
52
+ const onClick =
53
+ onClickPackageFile ??
54
+ ((to: string) => {
33
55
  window.location.href = to;
34
- };
35
- }
56
+ });
57
+ const { environmentName, packageName, versionId } =
58
+ parseResourceUri(resourceUri);
59
+
60
+ const [schemaDatabase, setSchemaDatabase] = useState<Database | null>(null);
61
+
62
+ const pkgQuery = useQueryWithApiError({
63
+ queryKey: ["package", environmentName, packageName, versionId],
64
+ queryFn: () =>
65
+ apiClients.packages.getPackage(
66
+ environmentName,
67
+ packageName,
68
+ versionId,
69
+ false,
70
+ ),
71
+ });
72
+
73
+ const notebooksQuery = useQueryWithApiError({
74
+ queryKey: ["notebooks", environmentName, packageName, versionId],
75
+ queryFn: () =>
76
+ apiClients.notebooks.listNotebooks(
77
+ environmentName,
78
+ packageName,
79
+ versionId,
80
+ ),
81
+ });
82
+
83
+ const modelsQuery = useQueryWithApiError({
84
+ queryKey: ["models", environmentName, packageName, versionId],
85
+ queryFn: () =>
86
+ apiClients.models.listModels(environmentName, packageName, versionId),
87
+ });
88
+
89
+ const databasesQuery = useQueryWithApiError({
90
+ queryKey: ["databases", environmentName, packageName, versionId],
91
+ queryFn: () =>
92
+ apiClients.databases.listDatabases(
93
+ environmentName,
94
+ packageName,
95
+ versionId,
96
+ ),
97
+ });
98
+
99
+ // List of in-package HTML data apps bundled inside the package.
100
+ // Goes through the configured API client so consumers using a non-default
101
+ // baseURL or Bearer auth (via <ServerProvider>) get the same plumbing as
102
+ // every other endpoint.
103
+ // No versionId in the key: /data-apps serves static files, which aren't
104
+ // versioned (listDataApps takes only env + package), so keying on
105
+ // versionId would fragment the cache and prevent DataAppViewer's identical
106
+ // query from deduping.
107
+ const dataAppsQuery = useQueryWithApiError({
108
+ queryKey: ["data-apps", environmentName, packageName],
109
+ queryFn: async () => {
110
+ try {
111
+ return await apiClients.dataApps.listDataApps(
112
+ environmentName,
113
+ packageName,
114
+ );
115
+ } catch (e) {
116
+ // A 404 or transport-level failure (older Publisher without the
117
+ // /data-apps route, network blip) is non-fatal: render the package
118
+ // page without a Data Apps section. A genuinely missing package
119
+ // surfaces its own error via the package query above, so an empty
120
+ // list here can't hide it.
121
+ const status = (e as { response?: { status?: number } })?.response
122
+ ?.status;
123
+ if (status === 404 || status === undefined) {
124
+ return { data: [] } as Awaited<
125
+ ReturnType<typeof apiClients.dataApps.listDataApps>
126
+ >;
127
+ }
128
+ throw e;
129
+ }
130
+ },
131
+ });
132
+ const dataApps = dataAppsQuery.data?.data ?? [];
133
+
134
+ const dashboardsQuery = useQueryWithApiError({
135
+ queryKey: ["dashboards", environmentName, packageName, versionId],
136
+ queryFn: async () => {
137
+ try {
138
+ return await apiClients.dashboards.listDashboards(
139
+ environmentName,
140
+ packageName,
141
+ versionId,
142
+ );
143
+ } catch (e) {
144
+ // Non-fatal for the same reasons as the data-apps list above: an
145
+ // older Publisher without the route should render a package page
146
+ // without a Dashboards section, not an error.
147
+ const status = (e as { response?: { status?: number } })?.response
148
+ ?.status;
149
+ if (status === 404 || status === undefined) {
150
+ return { data: [] } as Awaited<
151
+ ReturnType<typeof apiClients.dashboards.listDashboards>
152
+ >;
153
+ }
154
+ throw e;
155
+ }
156
+ },
157
+ });
158
+ // Sorted by the string the row actually SHOWS, not by the slug or the path
159
+ // underneath it. A list labelled by title and ordered by filename reads as
160
+ // unsorted: `overview` titled "Business Overview" sorts ahead of `regions`
161
+ // titled "Regional Sales". Notebooks acquired that mismatch here too, when
162
+ // they started being listed by title while still being ordered by path.
163
+ const dashboardLabel = (dashboard: { name?: string; title?: string }) =>
164
+ dashboard.title && dashboard.title !== dashboard.name
165
+ ? dashboard.title
166
+ : (dashboard.name ?? "");
167
+ const notebookLabel = (notebook: { path?: string; title?: string }) =>
168
+ notebook.title && notebook.title !== notebook.path
169
+ ? notebook.title
170
+ : (notebook.path ?? "");
171
+
172
+ const dashboards = (dashboardsQuery.data?.data ?? [])
173
+ .slice()
174
+ .sort((a, b) => dashboardLabel(a).localeCompare(dashboardLabel(b)));
175
+
176
+ const notebooks = (notebooksQuery.data?.data ?? [])
177
+ .slice()
178
+ .sort((a, b) => notebookLabel(a).localeCompare(notebookLabel(b)));
179
+ // A dashboard is listed once, under Dashboards. Its file is a model like any
180
+ // other, so it would otherwise appear a second time under Semantic Models
181
+ // where clicking it opens the Explorer rather than the dashboard. Untagged
182
+ // shared includes in `dashboards/` are not dashboards and stay in the model
183
+ // list, which is where they belong.
184
+ const dashboardPaths = new Set(
185
+ dashboards
186
+ .map((dashboard) => dashboard.path)
187
+ .filter((path): path is string => path !== undefined),
188
+ );
189
+ const models = (modelsQuery.data?.data ?? [])
190
+ .slice()
191
+ .filter((model) => !dashboardPaths.has(model.path))
192
+ .sort((a, b) => a.path.localeCompare(b.path));
193
+ const databases = (databasesQuery.data?.data ?? [])
194
+ .slice()
195
+ .sort((a, b) => a.path.localeCompare(b.path));
36
196
 
197
+ const description = pkgQuery.data?.data?.description ?? "";
198
+ const hasReadme = notebooks.some((n) => n.path === README_NOTEBOOK);
37
199
  const readmeResourceUri = encodeResourceUri({
38
- ...parseResourceUri(resourceUri),
200
+ environmentName,
201
+ packageName,
202
+ versionId,
39
203
  modelPath: README_NOTEBOOK,
40
204
  });
41
205
 
206
+ // The dashboards list is part of the gate, not just the notebooks one,
207
+ // because the models list is FILTERED by it. Gated on notebooks alone, a
208
+ // dashboards call that resolves after the models call rendered the sections
209
+ // with an empty `dashboardPaths`, so `dashboards/overview.malloy` appeared
210
+ // under Semantic Models and then vanished: the double listing the filter
211
+ // exists to prevent, briefly on screen.
212
+ //
213
+ // What this covers and what it COSTS, since the two are different questions.
214
+ // It cannot hang the page on a FAILURE: the query above turns a 404 or a
215
+ // transport failure into an empty list. It does add LATENCY, and to every
216
+ // section rather than to the one that needs it: Notebooks, Semantic Models,
217
+ // Data Apps and Databases now wait on the dashboards call where they used to
218
+ // render as soon as notebooks resolved. The only thing that actually needs
219
+ // the gate is the `dashboardPaths` filter on the models list.
220
+ //
221
+ // Accepted rather than narrowed because the cost is bounded and small:
222
+ // `listDashboards` is a synchronous read off the already-loaded package
223
+ // (`service/package.ts`, reached with `getPackage(name, false)`, so no
224
+ // reload), which makes this one more parallel request and not a compile.
225
+ // Narrowing it means gating only the models section, which trades this
226
+ // whole-page wait for a models list that pops in after its neighbours.
227
+ const isLoading =
228
+ (!notebooksQuery.isSuccess && !notebooksQuery.isError) ||
229
+ (!dashboardsQuery.isSuccess && !dashboardsQuery.isError);
230
+
231
+ if (pkgQuery.isError) {
232
+ return (
233
+ <ApiErrorDisplay
234
+ error={pkgQuery.error}
235
+ context={`${environmentName} > ${packageName}`}
236
+ />
237
+ );
238
+ }
239
+
42
240
  return (
43
- <>
44
- <Grid container spacing={3} columns={12}>
45
- <Grid size={{ xs: 12, md: 4 }}>
46
- <Config resourceUri={resourceUri} />
47
- </Grid>
48
- <Grid size={{ xs: 12, md: 4 }}>
49
- <Notebooks
50
- onClickNotebookFile={onClickPackageFile}
51
- resourceUri={resourceUri}
52
- />
53
- </Grid>
54
- <Grid size={{ xs: 12, md: 4 }}>
55
- <Models
56
- onClickModelFile={onClickPackageFile}
57
- resourceUri={resourceUri}
58
- />
59
- </Grid>
60
- <Grid size={{ xs: 12, md: 6 }}>
61
- <Databases resourceUri={resourceUri} />
62
- </Grid>
63
- <Grid size={{ xs: 12, md: 6 }}>
64
- <Connections resourceUri={resourceUri} />
65
- </Grid>
66
- <Grid size={{ xs: 12, md: 12 }}>
67
- <PackageCard>
68
- <PackageCardContent>
69
- <PackageSectionTitle>README</PackageSectionTitle>
70
- <Box sx={{ mt: 1 }}>
71
- <Notebook
72
- resourceUri={readmeResourceUri}
73
- retrievalFn={retrievalFn}
241
+ <Container
242
+ maxWidth={false}
243
+ sx={{ maxWidth: 1024, mx: "auto", px: 3, py: 6 }}
244
+ >
245
+ <Box sx={{ mb: 4 }}>
246
+ <Link
247
+ onClick={(event: React.MouseEvent) =>
248
+ onClick(`/${environmentName}/`, event)
249
+ }
250
+ underline="none"
251
+ sx={{
252
+ display: "inline-flex",
253
+ alignItems: "center",
254
+ gap: 0.5,
255
+ cursor: "pointer",
256
+ color: "text.secondary",
257
+ fontSize: "0.875rem",
258
+ mb: 2,
259
+ "&:hover": { color: "primary.main" },
260
+ }}
261
+ >
262
+ <ArrowBackIcon sx={{ fontSize: 18 }} />
263
+ Back to {environmentName}
264
+ </Link>
265
+ <Typography
266
+ variant="h4"
267
+ component="h1"
268
+ sx={{
269
+ fontWeight: 600,
270
+ letterSpacing: "-0.025em",
271
+ mb: 0.5,
272
+ }}
273
+ >
274
+ {packageName}
275
+ </Typography>
276
+ {description && (
277
+ <Typography variant="body2" color="text.secondary">
278
+ {description}
279
+ </Typography>
280
+ )}
281
+ </Box>
282
+
283
+ {isLoading && <Loading text="Loading package..." />}
284
+
285
+ {!isLoading && (
286
+ <>
287
+ {/* First: the at-a-glance artifact a visitor most likely wants,
288
+ ahead of the notebooks and models it is built on. Hidden when
289
+ empty, like Data Apps. */}
290
+ {/* A listing that FAILED renders identically to a package with
291
+ no dashboards: `dashboards` falls back to `[]` and the
292
+ section hides itself. Only `pkgQuery` reaches the error page,
293
+ so nothing else here would say a word. Now that the listing
294
+ carries a `versionId`, a host that resolves it on some routes
295
+ and refuses it on others has a new way in, and "this package
296
+ has no dashboards" is the wrong thing to conclude from a
297
+ transport error. The 404 above stays swallowed: that one is
298
+ an older Publisher with no route, which genuinely has none. */}
299
+ {/* A listing that FAILED renders identically to a package with
300
+ no dashboards: `dashboards` falls back to `[]` and the
301
+ section hides itself. Only `pkgQuery` reaches the error page,
302
+ so nothing else here would say a word. Now that the listing
303
+ carries a `versionId`, a host that resolves it on some routes
304
+ and refuses it on others has a new way in, and "this package
305
+ has no dashboards" is the wrong thing to conclude from a
306
+ transport error. The 404 above stays swallowed: that one is
307
+ an older Publisher with no route, which genuinely has none. */}
308
+ {dashboardsQuery.isError && (
309
+ <Box sx={{ mb: 4 }}>
310
+ <Alert severity="warning">
311
+ Could not list this package&apos;s dashboards, so any it
312
+ has are missing from this page.
313
+ </Alert>
314
+ </Box>
315
+ )}
316
+ {dashboards.length > 0 && (
317
+ <PackageSection title="Dashboards" count={dashboards.length}>
318
+ {dashboards.map((dashboard) => {
319
+ // A title equal to the slug is what the server falls
320
+ // back to when the file names itself neither way, so
321
+ // showing both would print the same word twice.
322
+ const hasTitle =
323
+ !!dashboard.title &&
324
+ dashboard.title !== dashboard.name;
325
+ return (
326
+ <PackageItemRow
327
+ key={dashboard.name}
328
+ type="dashboard"
329
+ label={
330
+ hasTitle ? dashboard.title! : dashboard.name!
331
+ }
332
+ rightLabel={hasTitle ? dashboard.name : undefined}
333
+ onClick={(event) =>
334
+ onClick(
335
+ `/${environmentName}/${packageName}/dashboards/` +
336
+ // The slug comes from a filename, which
337
+ // can hold characters that would read as
338
+ // structure in a path. The server encodes
339
+ // it in `resource` for the same reason.
340
+ encodeURIComponent(dashboard.name ?? ""),
341
+ event,
342
+ )
343
+ }
344
+ />
345
+ );
346
+ })}
347
+ </PackageSection>
348
+ )}
349
+
350
+ <PackageSection title="Notebooks" count={notebooks.length}>
351
+ {notebooks.map((notebook) => {
352
+ // Named the way dashboards and data apps are: a notebook
353
+ // that titles itself is listed by that title, with the
354
+ // filename kept as the secondary label so the path a
355
+ // reader needs to find the file is never lost.
356
+ const hasTitle =
357
+ !!notebook.title && notebook.title !== notebook.path;
358
+ return (
359
+ <PackageItemRow
360
+ key={notebook.path}
361
+ type="report"
362
+ label={hasTitle ? notebook.title! : notebook.path}
363
+ rightLabel={hasTitle ? notebook.path : undefined}
364
+ onClick={(event) =>
365
+ onClick(
366
+ `/${environmentName}/${packageName}/${notebook.path}`,
367
+ event,
368
+ )
369
+ }
74
370
  />
75
- </Box>
76
- </PackageCardContent>
77
- </PackageCard>
78
- </Grid>
79
- </Grid>
80
- </>
371
+ );
372
+ })}
373
+ {notebooks.length === 0 && <EmptyRow label="No notebooks" />}
374
+ </PackageSection>
375
+
376
+ {dataApps.length > 0 && (
377
+ <PackageSection title="Data Apps" count={dataApps.length}>
378
+ {dataApps.map((dataApp) => {
379
+ const hasTitle =
380
+ !!dataApp.title && dataApp.title !== dataApp.path;
381
+ // Standalone (raw) URL: the Publisher static-file route.
382
+ // dataApp.resource is the root-relative path; we join it
383
+ // with the data origin (the API base minus /api/v0),
384
+ // which may differ from the SPA origin when the SDK is
385
+ // embedded in a host app on another domain.
386
+ const standaloneUrl = `${serverBaseUrl(server)}${
387
+ dataApp.resource
388
+ }`;
389
+ return (
390
+ <PackageItemRow
391
+ key={dataApp.path}
392
+ type="dataApp"
393
+ label={hasTitle ? dataApp.title : dataApp.path}
394
+ rightLabel={hasTitle ? dataApp.path : undefined}
395
+ onClick={(event) => {
396
+ if (onClickPackageFile) {
397
+ // Host app routes within SPA to an embedded
398
+ // <DataAppViewer> that iframes the standalone
399
+ // URL. The `data-apps/` prefix lets the
400
+ // router branch off the existing model-path
401
+ // catch-all.
402
+ onClickPackageFile(
403
+ `/${environmentName}/${packageName}/data-apps/${dataApp.path}`,
404
+ event,
405
+ );
406
+ } else {
407
+ // No host app: navigate to standalone HTML.
408
+ if (
409
+ event &&
410
+ (event.metaKey || event.ctrlKey)
411
+ ) {
412
+ window.open(standaloneUrl, "_blank");
413
+ } else {
414
+ window.location.href = standaloneUrl;
415
+ }
416
+ }
417
+ }}
418
+ trailingAction={
419
+ <Tooltip title="Open standalone in new tab">
420
+ <IconButton
421
+ size="small"
422
+ href={standaloneUrl}
423
+ target="_blank"
424
+ rel="noopener noreferrer"
425
+ aria-label="Open standalone in new tab"
426
+ onClick={(event) =>
427
+ event.stopPropagation()
428
+ }
429
+ sx={{ color: "text.secondary" }}
430
+ >
431
+ <OpenInNewIcon fontSize="small" />
432
+ </IconButton>
433
+ </Tooltip>
434
+ }
435
+ />
436
+ );
437
+ })}
438
+ </PackageSection>
439
+ )}
440
+
441
+ <PackageSection title="Semantic Models" count={models.length}>
442
+ {models.map((model) => (
443
+ <PackageItemRow
444
+ key={model.path}
445
+ type="model"
446
+ label={model.path}
447
+ onClick={(event) =>
448
+ onClick(
449
+ `/${environmentName}/${packageName}/${model.path}`,
450
+ event,
451
+ )
452
+ }
453
+ />
454
+ ))}
455
+ {models.length === 0 && <EmptyRow label="No models" />}
456
+ </PackageSection>
457
+
458
+ <PackageSection title="Package Data" count={databases.length}>
459
+ {databases.map((database) => (
460
+ <PackageItemRow
461
+ key={database.path}
462
+ type="data"
463
+ label={database.path}
464
+ rightLabel={
465
+ // A file the server could not probe is listed with
466
+ // `error` and no `info`; show that instead of a
467
+ // row count rather than reading through undefined.
468
+ database.info
469
+ ? formatRowCount(database.info.rowCount)
470
+ : "Unreadable"
471
+ }
472
+ onClick={() => setSchemaDatabase(database)}
473
+ />
474
+ ))}
475
+ {databases.length === 0 && <EmptyRow label="No data files" />}
476
+ </PackageSection>
477
+
478
+ <PackageSection title="Materializations">
479
+ <PackageItemRow
480
+ type="materialization"
481
+ label="Materializations"
482
+ onClick={(event) =>
483
+ onClick(
484
+ `/${environmentName}/${packageName}/materializations`,
485
+ event,
486
+ )
487
+ }
488
+ />
489
+ </PackageSection>
490
+
491
+ {hasReadme && (
492
+ <Box sx={{ mt: 6 }}>
493
+ <Notebook
494
+ resourceUri={readmeResourceUri}
495
+ onNavigate={onClick}
496
+ />
497
+ </Box>
498
+ )}
499
+ </>
500
+ )}
501
+
502
+ <Dialog
503
+ open={schemaDatabase !== null}
504
+ onClose={() => setSchemaDatabase(null)}
505
+ maxWidth="sm"
506
+ fullWidth
507
+ >
508
+ <DialogTitle sx={{ pr: 6 }}>
509
+ {schemaDatabase?.path}
510
+ <IconButton
511
+ aria-label="close"
512
+ onClick={() => setSchemaDatabase(null)}
513
+ sx={{ position: "absolute", right: 8, top: 8 }}
514
+ >
515
+ <CloseIcon fontSize="small" />
516
+ </IconButton>
517
+ </DialogTitle>
518
+ <DialogContent>
519
+ {schemaDatabase?.error && (
520
+ <Typography variant="body2" color="error">
521
+ {schemaDatabase.error}
522
+ </Typography>
523
+ )}
524
+ {schemaDatabase?.info?.columns && (
525
+ <Table size="small">
526
+ <TableHead>
527
+ <TableRow>
528
+ <TableCell>Column</TableCell>
529
+ <TableCell>Type</TableCell>
530
+ </TableRow>
531
+ </TableHead>
532
+ <TableBody>
533
+ {schemaDatabase.info.columns.map((column) => (
534
+ <TableRow key={column.name}>
535
+ <TableCell component="th" scope="row">
536
+ {column.name}
537
+ </TableCell>
538
+ <TableCell>{column.type}</TableCell>
539
+ </TableRow>
540
+ ))}
541
+ </TableBody>
542
+ </Table>
543
+ )}
544
+ </DialogContent>
545
+ </Dialog>
546
+ </Container>
547
+ );
548
+ }
549
+
550
+ function PackageSection({
551
+ title,
552
+ count,
553
+ children,
554
+ }: {
555
+ title: string;
556
+ count?: number;
557
+ children: React.ReactNode;
558
+ }) {
559
+ return (
560
+ <Box sx={{ mb: 4 }}>
561
+ <Stack
562
+ direction="row"
563
+ alignItems="baseline"
564
+ spacing={1}
565
+ sx={{ mb: 1 }}
566
+ >
567
+ <Typography
568
+ variant="h6"
569
+ sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
570
+ >
571
+ {title}
572
+ </Typography>
573
+ {count !== undefined && (
574
+ <Typography variant="caption" color="text.secondary">
575
+ ({count})
576
+ </Typography>
577
+ )}
578
+ </Stack>
579
+ <Box>{children}</Box>
580
+ </Box>
581
+ );
582
+ }
583
+
584
+ /**
585
+ * A row names its content type once. The glyph and the color behind it are two
586
+ * halves of one signal, so the row derives both rather than letting a caller
587
+ * pair a dashboard's icon with a model's color.
588
+ *
589
+ * That is not hypothetical tidying: with the two passed separately, four of the
590
+ * six rows on this page had been handed the same teal, so color told a reader
591
+ * nothing about four of the kinds it was there to distinguish. A rule each call
592
+ * site has to remember is a rule some call sites will forget.
593
+ */
594
+ function PackageItemRow({
595
+ type,
596
+ label,
597
+ rightLabel,
598
+ onClick,
599
+ trailingAction,
600
+ }: {
601
+ type: ContentType;
602
+ label: string;
603
+ rightLabel?: string;
604
+ onClick?: (event: React.MouseEvent) => void;
605
+ /** Optional element rendered at the end of the row (e.g. an
606
+ * "open in new tab" icon button). Clicks on it should
607
+ * `event.stopPropagation()` so the row click doesn't also fire. */
608
+ trailingAction?: React.ReactNode;
609
+ }) {
610
+ const interactive = !!onClick;
611
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
612
+ if (!onClick) return;
613
+ if (event.key === "Enter" || event.key === " ") {
614
+ event.preventDefault();
615
+ onClick(event as unknown as React.MouseEvent);
616
+ }
617
+ };
618
+ return (
619
+ <Box
620
+ onClick={onClick}
621
+ onKeyDown={interactive ? handleKeyDown : undefined}
622
+ role={interactive ? "button" : undefined}
623
+ tabIndex={interactive ? 0 : undefined}
624
+ sx={(theme) => ({
625
+ display: "flex",
626
+ alignItems: "center",
627
+ gap: 1.5,
628
+ py: 1,
629
+ px: 1,
630
+ mx: -1,
631
+ cursor: interactive ? "pointer" : "default",
632
+ borderRadius: 1.5,
633
+ transition: "background-color 0.1s",
634
+ "&:hover": interactive
635
+ ? {
636
+ backgroundColor:
637
+ theme.palette.mode === "dark"
638
+ ? "rgba(255, 255, 255, 0.08)"
639
+ : "grey.100",
640
+ }
641
+ : undefined,
642
+ "&:focus-visible": interactive
643
+ ? {
644
+ outline: "2px solid",
645
+ outlineColor: "primary.main",
646
+ outlineOffset: 2,
647
+ }
648
+ : undefined,
649
+ })}
650
+ >
651
+ <Box
652
+ sx={{
653
+ width: 32,
654
+ height: 32,
655
+ borderRadius: 1,
656
+ bgcolor: CONTENT_TINT[type],
657
+ color: "#FFFFFF",
658
+ display: "flex",
659
+ alignItems: "center",
660
+ justifyContent: "center",
661
+ flexShrink: 0,
662
+ }}
663
+ >
664
+ <ContentTypeIcon type={type} />
665
+ </Box>
666
+ <Typography
667
+ variant="body2"
668
+ sx={{
669
+ fontFamily: MONO_FONT_FAMILY,
670
+ flex: 1,
671
+ minWidth: 0,
672
+ overflow: "hidden",
673
+ textOverflow: "ellipsis",
674
+ whiteSpace: "nowrap",
675
+ }}
676
+ >
677
+ {label}
678
+ </Typography>
679
+ {rightLabel && (
680
+ <Typography
681
+ variant="caption"
682
+ color="text.secondary"
683
+ sx={{ flexShrink: 0 }}
684
+ >
685
+ {rightLabel}
686
+ </Typography>
687
+ )}
688
+ {trailingAction && (
689
+ <Box sx={{ flexShrink: 0, display: "flex", alignItems: "center" }}>
690
+ {trailingAction}
691
+ </Box>
692
+ )}
693
+ </Box>
81
694
  );
82
695
  }
696
+
697
+ function EmptyRow({ label }: { label: string }) {
698
+ return (
699
+ <Typography
700
+ variant="body2"
701
+ color="text.secondary"
702
+ sx={{ py: 1, fontStyle: "italic" }}
703
+ >
704
+ {label}
705
+ </Typography>
706
+ );
707
+ }
708
+
709
+ function formatRowCount(rows: number): string {
710
+ if (rows >= 1_000_000_000)
711
+ return `${(rows / 1_000_000_000).toFixed(1)} B rows`;
712
+ if (rows >= 1_000_000) return `${(rows / 1_000_000).toFixed(1)} M rows`;
713
+ if (rows >= 1_000) return `${(rows / 1_000).toFixed(1)} K rows`;
714
+ return `${rows} rows`;
715
+ }