@malloy-publisher/sdk 0.0.382-dev → 0.2.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 (277) 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-CTopDUWW.cjs.js +1 -0
  5. package/dist/ServerProvider-DUFPY6Rv.es.js +4072 -0
  6. package/dist/client/api.d.ts +3718 -1507
  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 +85 -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 +49 -0
  14. package/dist/components/Dashboard/DashboardTile.d.ts +48 -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-hLahnv0W.cjs.js} +1 -1
  66. package/dist/{core-CjeTkq8O.es.js → core-lb28vQkR.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-DvEanVgc.cjs.js +339 -0
  78. package/dist/{index-DRDu9kIV.es.js → index-txw04ZbN.es.js} +40531 -27964
  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 +25 -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 +30 -2
  104. package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
  105. package/src/components/Connections/EditConnectionDialog.tsx +33 -4
  106. package/src/components/Connections/common.ts +64 -1
  107. package/src/components/DOMElement/DOMElement.tsx +3 -0
  108. package/src/components/DOMElement/index.ts +3 -0
  109. package/src/components/Dashboard/Dashboard.tsx +398 -0
  110. package/src/components/Dashboard/DashboardTile.tsx +153 -0
  111. package/src/components/Dashboard/index.ts +5 -0
  112. package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
  113. package/src/components/DataAppViewer/index.ts +4 -0
  114. package/src/components/{Project → Environment}/About.tsx +11 -4
  115. package/src/components/Environment/AddPackageDialog.tsx +202 -0
  116. package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
  117. package/src/components/Environment/Connections.tsx +391 -0
  118. package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
  119. package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
  120. package/src/components/Environment/Environment.tsx +89 -0
  121. package/src/components/Environment/Packages.tsx +206 -0
  122. package/src/components/Environment/index.ts +5 -0
  123. package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
  124. package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
  125. package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
  126. package/src/components/Home/Home.tsx +386 -408
  127. package/src/components/Home/index.ts +3 -0
  128. package/src/components/Loading.tsx +3 -0
  129. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
  130. package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
  131. package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
  132. package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
  133. package/src/components/Materializations/ManifestView.tsx +87 -0
  134. package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
  135. package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
  136. package/src/components/Materializations/Materializations.tsx +355 -0
  137. package/src/components/Materializations/ScheduleCard.tsx +231 -0
  138. package/src/components/Materializations/SectionLabel.tsx +30 -0
  139. package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
  140. package/src/components/Materializations/TriggerChip.tsx +44 -0
  141. package/src/components/Materializations/cron.ts +124 -0
  142. package/src/components/Materializations/index.ts +5 -0
  143. package/src/components/Materializations/utils.ts +145 -0
  144. package/src/components/Model/Model.tsx +44 -2
  145. package/src/components/Model/ModelCell.tsx +14 -5
  146. package/src/components/Model/ModelExplorer.tsx +3 -0
  147. package/src/components/Model/ModelExplorerDialog.tsx +4 -1
  148. package/src/components/Model/SourcesExplorer.tsx +9 -6
  149. package/src/components/Model/index.ts +3 -0
  150. package/src/components/Model/useModelData.ts +6 -3
  151. package/src/components/Notebook/Notebook.tsx +475 -339
  152. package/src/components/Notebook/NotebookCell.tsx +264 -25
  153. package/src/components/Notebook/index.ts +3 -0
  154. package/src/components/Notebook/runPlan.spec.ts +155 -0
  155. package/src/components/Notebook/runPlan.ts +67 -0
  156. package/src/components/Notebook/types.ts +14 -0
  157. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  158. package/src/components/Package/ContentTypeIcon.tsx +177 -0
  159. package/src/components/Package/FileTreeView.tsx +3 -0
  160. package/src/components/Package/Models.tsx +7 -4
  161. package/src/components/Package/Package.tsx +666 -59
  162. package/src/components/Package/index.ts +3 -0
  163. package/src/components/QueryResult/QueryResult.tsx +17 -8
  164. package/src/components/QueryResult/index.ts +3 -0
  165. package/src/components/RenderedResult/RenderedResult.tsx +685 -67
  166. package/src/components/RenderedResult/ResultContainer.tsx +71 -2
  167. package/src/components/RenderedResult/index.ts +3 -0
  168. package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
  169. package/src/components/RenderedResult/renderLogs.ts +43 -0
  170. package/src/components/ResultsDialog.tsx +13 -1
  171. package/src/components/ServerProvider.tsx +175 -51
  172. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  173. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  174. package/src/components/Workbook/ModelPicker.tsx +7 -4
  175. package/src/components/Workbook/MutableCell.tsx +10 -5
  176. package/src/components/Workbook/Workbook.tsx +8 -5
  177. package/src/components/Workbook/WorkbookList.tsx +3 -0
  178. package/src/components/Workbook/WorkbookManager.ts +3 -0
  179. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  180. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  181. package/src/components/Workbook/index.ts +3 -0
  182. package/src/components/click_helper.ts +17 -1
  183. package/src/components/drill/index.ts +28 -0
  184. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  185. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  186. package/src/components/drill/markDrillableCells.ts +314 -0
  187. package/src/components/drill/resolveDrill.spec.ts +449 -0
  188. package/src/components/drill/resolveDrill.ts +375 -0
  189. package/src/components/drill/useDrill.tsx +203 -0
  190. package/src/components/filter/DimensionFilter.tsx +3 -0
  191. package/src/components/filter/index.ts +3 -0
  192. package/src/components/filter/utils.ts +16 -5
  193. package/src/components/given/GivenInput.spec.tsx +689 -0
  194. package/src/components/given/GivenInput.tsx +801 -0
  195. package/src/components/given/GivensPanel.spec.tsx +175 -0
  196. package/src/components/given/GivensPanel.tsx +195 -0
  197. package/src/components/given/filterValue.spec.ts +364 -0
  198. package/src/components/given/filterValue.ts +207 -0
  199. package/src/components/given/index.ts +9 -0
  200. package/src/components/given/paramCodec.spec.ts +857 -0
  201. package/src/components/given/paramCodec.ts +483 -0
  202. package/src/components/given/utils.spec.ts +60 -0
  203. package/src/components/given/utils.ts +79 -0
  204. package/src/components/highlighter.ts +22 -5
  205. package/src/components/index.ts +10 -2
  206. package/src/components/styles.ts +82 -33
  207. package/src/constants/docLinks.spec.ts +54 -0
  208. package/src/constants/docLinks.ts +46 -0
  209. package/src/hooks/givenValue.ts +13 -0
  210. package/src/hooks/index.ts +13 -0
  211. package/src/hooks/useDimensionFilters.ts +4 -7
  212. package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
  213. package/src/hooks/useDimensionFiltersQuery.ts +10 -13
  214. package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
  215. package/src/hooks/useGivensState.spec.ts +449 -0
  216. package/src/hooks/useGivensState.ts +340 -0
  217. package/src/hooks/useModelGivens.ts +29 -0
  218. package/src/hooks/useQueryWithApiError.ts +3 -0
  219. package/src/hooks/useRawQueryData.ts +6 -3
  220. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  221. package/src/hooks/useSuggestOptions.ts +263 -0
  222. package/src/index.ts +10 -1
  223. package/src/react-app-env.d.ts +3 -0
  224. package/src/theme/ThemeContext.tsx +86 -0
  225. package/src/theme/buildMalloyExplicitTheme.ts +61 -0
  226. package/src/theme/buildTableCssVars.spec.ts +67 -0
  227. package/src/theme/buildTableCssVars.ts +67 -0
  228. package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
  229. package/src/theme/buildVegaThemeOverride.ts +47 -0
  230. package/src/theme/defaults.ts +78 -0
  231. package/src/theme/index.ts +11 -0
  232. package/src/theme/keys.ts +32 -0
  233. package/src/theme/readChartAnnotations.spec.ts +58 -0
  234. package/src/theme/readChartAnnotations.ts +69 -0
  235. package/src/theme/resolveTheme.spec.ts +160 -0
  236. package/src/theme/resolveTheme.ts +121 -0
  237. package/src/theme/types.ts +79 -0
  238. package/src/utils/dataAppEmbed.spec.ts +63 -0
  239. package/src/utils/dataAppEmbed.ts +84 -0
  240. package/src/utils/formatting.spec.ts +25 -21
  241. package/src/utils/formatting.ts +11 -7
  242. package/src/utils/malloyString.spec.ts +24 -0
  243. package/src/utils/malloyString.ts +12 -0
  244. package/src/utils/parsing.spec.ts +26 -19
  245. package/src/utils/parsing.ts +11 -6
  246. package/src/utils/queryClient.ts +17 -0
  247. package/test/README.md +141 -0
  248. package/test/setup.ts +29 -0
  249. package/tsconfig.json +12 -1
  250. package/tsconfig.spec.json +22 -0
  251. package/vite.config.ts +3 -0
  252. package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
  253. package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
  254. package/dist/components/Home/AddProjectDialog.d.ts +0 -1
  255. package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
  256. package/dist/components/Home/EditProjectDialog.d.ts +0 -7
  257. package/dist/components/Package/Config.d.ts +0 -5
  258. package/dist/components/Package/Databases.d.ts +0 -5
  259. package/dist/components/Package/Notebooks.d.ts +0 -6
  260. package/dist/components/Project/Project.d.ts +0 -6
  261. package/dist/components/Project/index.d.ts +0 -2
  262. package/dist/index-BOLBP6_i.cjs.js +0 -233
  263. package/src/components/Package/Config.tsx +0 -97
  264. package/src/components/Package/Connections.tsx +0 -373
  265. package/src/components/Package/Databases.tsx +0 -228
  266. package/src/components/Package/Notebooks.tsx +0 -77
  267. package/src/components/Project/AddPackageDialog.tsx +0 -159
  268. package/src/components/Project/Packages.tsx +0 -191
  269. package/src/components/Project/Project.tsx +0 -52
  270. package/src/components/Project/index.ts +0 -2
  271. /package/dist/components/{Project → Environment}/About.d.ts +0 -0
  272. /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
  273. /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
  274. /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
  275. /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
  276. /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
  277. /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
@@ -1,82 +1,689 @@
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
+ Box,
9
+ Container,
10
+ Dialog,
11
+ DialogContent,
12
+ DialogTitle,
13
+ IconButton,
14
+ Link,
15
+ Stack,
16
+ Table,
17
+ TableBody,
18
+ TableCell,
19
+ TableHead,
20
+ TableRow,
21
+ Tooltip,
22
+ Typography,
23
+ } from "@mui/material";
24
+ import React, { useState } from "react";
25
+ import { Database } from "../../client";
26
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
27
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
28
+ import { Loading } from "../Loading";
29
+ import { Notebook } from "../Notebook";
30
+ import { useServer } from "../ServerProvider";
31
+ import { encodeResourceUri, parseResourceUri } from "../../utils/formatting";
32
+ import { serverBaseUrl } from "../../utils/dataAppEmbed";
33
+ import { MONO_FONT_FAMILY } from "../styles";
34
+ import ContentTypeIcon, {
35
+ CONTENT_TINT,
36
+ type ContentType,
37
+ } from "./ContentTypeIcon";
16
38
 
17
39
  const README_NOTEBOOK = "README.malloynb";
18
40
 
19
41
  interface PackageProps {
20
42
  onClickPackageFile?: (to: string, event?: React.MouseEvent) => void;
21
43
  resourceUri: string;
22
- /** Optional retrieval function for semantic search filters */
23
- retrievalFn?: RetrievalFunction;
24
44
  }
25
45
 
26
46
  export default function Package({
27
47
  onClickPackageFile,
28
48
  resourceUri,
29
- retrievalFn,
30
49
  }: PackageProps) {
31
- if (!onClickPackageFile) {
32
- onClickPackageFile = (to: string) => {
50
+ const { apiClients, server } = useServer();
51
+ const onClick =
52
+ onClickPackageFile ??
53
+ ((to: string) => {
33
54
  window.location.href = to;
34
- };
35
- }
55
+ });
56
+ const { environmentName, packageName, versionId } =
57
+ parseResourceUri(resourceUri);
58
+
59
+ const [schemaDatabase, setSchemaDatabase] = useState<Database | null>(null);
60
+
61
+ const pkgQuery = useQueryWithApiError({
62
+ queryKey: ["package", environmentName, packageName, versionId],
63
+ queryFn: () =>
64
+ apiClients.packages.getPackage(
65
+ environmentName,
66
+ packageName,
67
+ versionId,
68
+ false,
69
+ ),
70
+ });
71
+
72
+ const notebooksQuery = useQueryWithApiError({
73
+ queryKey: ["notebooks", environmentName, packageName, versionId],
74
+ queryFn: () =>
75
+ apiClients.notebooks.listNotebooks(
76
+ environmentName,
77
+ packageName,
78
+ versionId,
79
+ ),
80
+ });
81
+
82
+ const modelsQuery = useQueryWithApiError({
83
+ queryKey: ["models", environmentName, packageName, versionId],
84
+ queryFn: () =>
85
+ apiClients.models.listModels(environmentName, packageName, versionId),
86
+ });
87
+
88
+ const databasesQuery = useQueryWithApiError({
89
+ queryKey: ["databases", environmentName, packageName, versionId],
90
+ queryFn: () =>
91
+ apiClients.databases.listDatabases(
92
+ environmentName,
93
+ packageName,
94
+ versionId,
95
+ ),
96
+ });
97
+
98
+ // List of in-package HTML data apps bundled inside the package.
99
+ // Goes through the configured API client so consumers using a non-default
100
+ // baseURL or Bearer auth (via <ServerProvider>) get the same plumbing as
101
+ // every other endpoint.
102
+ // No versionId in the key: /data-apps serves static files, which aren't
103
+ // versioned (listDataApps takes only env + package), so keying on
104
+ // versionId would fragment the cache and prevent DataAppViewer's identical
105
+ // query from deduping.
106
+ const dataAppsQuery = useQueryWithApiError({
107
+ queryKey: ["data-apps", environmentName, packageName],
108
+ queryFn: async () => {
109
+ try {
110
+ return await apiClients.dataApps.listDataApps(
111
+ environmentName,
112
+ packageName,
113
+ );
114
+ } catch (e) {
115
+ // A 404 or transport-level failure (older Publisher without the
116
+ // /data-apps route, network blip) is non-fatal: render the package
117
+ // page without a Data Apps section. A genuinely missing package
118
+ // surfaces its own error via the package query above, so an empty
119
+ // list here can't hide it.
120
+ const status = (e as { response?: { status?: number } })?.response
121
+ ?.status;
122
+ if (status === 404 || status === undefined) {
123
+ return { data: [] } as Awaited<
124
+ ReturnType<typeof apiClients.dataApps.listDataApps>
125
+ >;
126
+ }
127
+ throw e;
128
+ }
129
+ },
130
+ });
131
+ const dataApps = dataAppsQuery.data?.data ?? [];
132
+
133
+ // No versionId, for the same reason as data apps: the dashboards endpoint
134
+ // takes only env + package.
135
+ const dashboardsQuery = useQueryWithApiError({
136
+ queryKey: ["dashboards", environmentName, packageName],
137
+ queryFn: async () => {
138
+ try {
139
+ return await apiClients.dashboards.listDashboards(
140
+ environmentName,
141
+ packageName,
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
+ {dashboards.length > 0 && (
291
+ <PackageSection title="Dashboards" count={dashboards.length}>
292
+ {dashboards.map((dashboard) => {
293
+ // A title equal to the slug is what the server falls
294
+ // back to when the file names itself neither way, so
295
+ // showing both would print the same word twice.
296
+ const hasTitle =
297
+ !!dashboard.title &&
298
+ dashboard.title !== dashboard.name;
299
+ return (
300
+ <PackageItemRow
301
+ key={dashboard.name}
302
+ type="dashboard"
303
+ label={
304
+ hasTitle ? dashboard.title! : dashboard.name!
305
+ }
306
+ rightLabel={hasTitle ? dashboard.name : undefined}
307
+ onClick={(event) =>
308
+ onClick(
309
+ `/${environmentName}/${packageName}/dashboards/` +
310
+ // The slug comes from a filename, which
311
+ // can hold characters that would read as
312
+ // structure in a path. The server encodes
313
+ // it in `resource` for the same reason.
314
+ encodeURIComponent(dashboard.name ?? ""),
315
+ event,
316
+ )
317
+ }
318
+ />
319
+ );
320
+ })}
321
+ </PackageSection>
322
+ )}
323
+
324
+ <PackageSection title="Notebooks" count={notebooks.length}>
325
+ {notebooks.map((notebook) => {
326
+ // Named the way dashboards and data apps are: a notebook
327
+ // that titles itself is listed by that title, with the
328
+ // filename kept as the secondary label so the path a
329
+ // reader needs to find the file is never lost.
330
+ const hasTitle =
331
+ !!notebook.title && notebook.title !== notebook.path;
332
+ return (
333
+ <PackageItemRow
334
+ key={notebook.path}
335
+ type="report"
336
+ label={hasTitle ? notebook.title! : notebook.path}
337
+ rightLabel={hasTitle ? notebook.path : undefined}
338
+ onClick={(event) =>
339
+ onClick(
340
+ `/${environmentName}/${packageName}/${notebook.path}`,
341
+ event,
342
+ )
343
+ }
74
344
  />
75
- </Box>
76
- </PackageCardContent>
77
- </PackageCard>
78
- </Grid>
79
- </Grid>
80
- </>
345
+ );
346
+ })}
347
+ {notebooks.length === 0 && <EmptyRow label="No notebooks" />}
348
+ </PackageSection>
349
+
350
+ {dataApps.length > 0 && (
351
+ <PackageSection title="Data Apps" count={dataApps.length}>
352
+ {dataApps.map((dataApp) => {
353
+ const hasTitle =
354
+ !!dataApp.title && dataApp.title !== dataApp.path;
355
+ // Standalone (raw) URL: the Publisher static-file route.
356
+ // dataApp.resource is the root-relative path; we join it
357
+ // with the data origin (the API base minus /api/v0),
358
+ // which may differ from the SPA origin when the SDK is
359
+ // embedded in a host app on another domain.
360
+ const standaloneUrl = `${serverBaseUrl(server)}${
361
+ dataApp.resource
362
+ }`;
363
+ return (
364
+ <PackageItemRow
365
+ key={dataApp.path}
366
+ type="dataApp"
367
+ label={hasTitle ? dataApp.title : dataApp.path}
368
+ rightLabel={hasTitle ? dataApp.path : undefined}
369
+ onClick={(event) => {
370
+ if (onClickPackageFile) {
371
+ // Host app routes within SPA to an embedded
372
+ // <DataAppViewer> that iframes the standalone
373
+ // URL. The `data-apps/` prefix lets the
374
+ // router branch off the existing model-path
375
+ // catch-all.
376
+ onClickPackageFile(
377
+ `/${environmentName}/${packageName}/data-apps/${dataApp.path}`,
378
+ event,
379
+ );
380
+ } else {
381
+ // No host app: navigate to standalone HTML.
382
+ if (
383
+ event &&
384
+ (event.metaKey || event.ctrlKey)
385
+ ) {
386
+ window.open(standaloneUrl, "_blank");
387
+ } else {
388
+ window.location.href = standaloneUrl;
389
+ }
390
+ }
391
+ }}
392
+ trailingAction={
393
+ <Tooltip title="Open standalone in new tab">
394
+ <IconButton
395
+ size="small"
396
+ href={standaloneUrl}
397
+ target="_blank"
398
+ rel="noopener noreferrer"
399
+ aria-label="Open standalone in new tab"
400
+ onClick={(event) =>
401
+ event.stopPropagation()
402
+ }
403
+ sx={{ color: "text.secondary" }}
404
+ >
405
+ <OpenInNewIcon fontSize="small" />
406
+ </IconButton>
407
+ </Tooltip>
408
+ }
409
+ />
410
+ );
411
+ })}
412
+ </PackageSection>
413
+ )}
414
+
415
+ <PackageSection title="Semantic Models" count={models.length}>
416
+ {models.map((model) => (
417
+ <PackageItemRow
418
+ key={model.path}
419
+ type="model"
420
+ label={model.path}
421
+ onClick={(event) =>
422
+ onClick(
423
+ `/${environmentName}/${packageName}/${model.path}`,
424
+ event,
425
+ )
426
+ }
427
+ />
428
+ ))}
429
+ {models.length === 0 && <EmptyRow label="No models" />}
430
+ </PackageSection>
431
+
432
+ <PackageSection title="Package Data" count={databases.length}>
433
+ {databases.map((database) => (
434
+ <PackageItemRow
435
+ key={database.path}
436
+ type="data"
437
+ label={database.path}
438
+ rightLabel={
439
+ // A file the server could not probe is listed with
440
+ // `error` and no `info`; show that instead of a
441
+ // row count rather than reading through undefined.
442
+ database.info
443
+ ? formatRowCount(database.info.rowCount)
444
+ : "Unreadable"
445
+ }
446
+ onClick={() => setSchemaDatabase(database)}
447
+ />
448
+ ))}
449
+ {databases.length === 0 && <EmptyRow label="No data files" />}
450
+ </PackageSection>
451
+
452
+ <PackageSection title="Materializations">
453
+ <PackageItemRow
454
+ type="materialization"
455
+ label="Materializations"
456
+ onClick={(event) =>
457
+ onClick(
458
+ `/${environmentName}/${packageName}/materializations`,
459
+ event,
460
+ )
461
+ }
462
+ />
463
+ </PackageSection>
464
+
465
+ {hasReadme && (
466
+ <Box sx={{ mt: 6 }}>
467
+ <Notebook
468
+ resourceUri={readmeResourceUri}
469
+ onNavigate={onClick}
470
+ />
471
+ </Box>
472
+ )}
473
+ </>
474
+ )}
475
+
476
+ <Dialog
477
+ open={schemaDatabase !== null}
478
+ onClose={() => setSchemaDatabase(null)}
479
+ maxWidth="sm"
480
+ fullWidth
481
+ >
482
+ <DialogTitle sx={{ pr: 6 }}>
483
+ {schemaDatabase?.path}
484
+ <IconButton
485
+ aria-label="close"
486
+ onClick={() => setSchemaDatabase(null)}
487
+ sx={{ position: "absolute", right: 8, top: 8 }}
488
+ >
489
+ <CloseIcon fontSize="small" />
490
+ </IconButton>
491
+ </DialogTitle>
492
+ <DialogContent>
493
+ {schemaDatabase?.error && (
494
+ <Typography variant="body2" color="error">
495
+ {schemaDatabase.error}
496
+ </Typography>
497
+ )}
498
+ {schemaDatabase?.info?.columns && (
499
+ <Table size="small">
500
+ <TableHead>
501
+ <TableRow>
502
+ <TableCell>Column</TableCell>
503
+ <TableCell>Type</TableCell>
504
+ </TableRow>
505
+ </TableHead>
506
+ <TableBody>
507
+ {schemaDatabase.info.columns.map((column) => (
508
+ <TableRow key={column.name}>
509
+ <TableCell component="th" scope="row">
510
+ {column.name}
511
+ </TableCell>
512
+ <TableCell>{column.type}</TableCell>
513
+ </TableRow>
514
+ ))}
515
+ </TableBody>
516
+ </Table>
517
+ )}
518
+ </DialogContent>
519
+ </Dialog>
520
+ </Container>
521
+ );
522
+ }
523
+
524
+ function PackageSection({
525
+ title,
526
+ count,
527
+ children,
528
+ }: {
529
+ title: string;
530
+ count?: number;
531
+ children: React.ReactNode;
532
+ }) {
533
+ return (
534
+ <Box sx={{ mb: 4 }}>
535
+ <Stack
536
+ direction="row"
537
+ alignItems="baseline"
538
+ spacing={1}
539
+ sx={{ mb: 1 }}
540
+ >
541
+ <Typography
542
+ variant="h6"
543
+ sx={{ fontWeight: 600, letterSpacing: "-0.025em" }}
544
+ >
545
+ {title}
546
+ </Typography>
547
+ {count !== undefined && (
548
+ <Typography variant="caption" color="text.secondary">
549
+ ({count})
550
+ </Typography>
551
+ )}
552
+ </Stack>
553
+ <Box>{children}</Box>
554
+ </Box>
555
+ );
556
+ }
557
+
558
+ /**
559
+ * A row names its content type once. The glyph and the color behind it are two
560
+ * halves of one signal, so the row derives both rather than letting a caller
561
+ * pair a dashboard's icon with a model's color.
562
+ *
563
+ * That is not hypothetical tidying: with the two passed separately, four of the
564
+ * six rows on this page had been handed the same teal, so color told a reader
565
+ * nothing about four of the kinds it was there to distinguish. A rule each call
566
+ * site has to remember is a rule some call sites will forget.
567
+ */
568
+ function PackageItemRow({
569
+ type,
570
+ label,
571
+ rightLabel,
572
+ onClick,
573
+ trailingAction,
574
+ }: {
575
+ type: ContentType;
576
+ label: string;
577
+ rightLabel?: string;
578
+ onClick?: (event: React.MouseEvent) => void;
579
+ /** Optional element rendered at the end of the row (e.g. an
580
+ * "open in new tab" icon button). Clicks on it should
581
+ * `event.stopPropagation()` so the row click doesn't also fire. */
582
+ trailingAction?: React.ReactNode;
583
+ }) {
584
+ const interactive = !!onClick;
585
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
586
+ if (!onClick) return;
587
+ if (event.key === "Enter" || event.key === " ") {
588
+ event.preventDefault();
589
+ onClick(event as unknown as React.MouseEvent);
590
+ }
591
+ };
592
+ return (
593
+ <Box
594
+ onClick={onClick}
595
+ onKeyDown={interactive ? handleKeyDown : undefined}
596
+ role={interactive ? "button" : undefined}
597
+ tabIndex={interactive ? 0 : undefined}
598
+ sx={(theme) => ({
599
+ display: "flex",
600
+ alignItems: "center",
601
+ gap: 1.5,
602
+ py: 1,
603
+ px: 1,
604
+ mx: -1,
605
+ cursor: interactive ? "pointer" : "default",
606
+ borderRadius: 1.5,
607
+ transition: "background-color 0.1s",
608
+ "&:hover": interactive
609
+ ? {
610
+ backgroundColor:
611
+ theme.palette.mode === "dark"
612
+ ? "rgba(255, 255, 255, 0.08)"
613
+ : "grey.100",
614
+ }
615
+ : undefined,
616
+ "&:focus-visible": interactive
617
+ ? {
618
+ outline: "2px solid",
619
+ outlineColor: "primary.main",
620
+ outlineOffset: 2,
621
+ }
622
+ : undefined,
623
+ })}
624
+ >
625
+ <Box
626
+ sx={{
627
+ width: 32,
628
+ height: 32,
629
+ borderRadius: 1,
630
+ bgcolor: CONTENT_TINT[type],
631
+ color: "#FFFFFF",
632
+ display: "flex",
633
+ alignItems: "center",
634
+ justifyContent: "center",
635
+ flexShrink: 0,
636
+ }}
637
+ >
638
+ <ContentTypeIcon type={type} />
639
+ </Box>
640
+ <Typography
641
+ variant="body2"
642
+ sx={{
643
+ fontFamily: MONO_FONT_FAMILY,
644
+ flex: 1,
645
+ minWidth: 0,
646
+ overflow: "hidden",
647
+ textOverflow: "ellipsis",
648
+ whiteSpace: "nowrap",
649
+ }}
650
+ >
651
+ {label}
652
+ </Typography>
653
+ {rightLabel && (
654
+ <Typography
655
+ variant="caption"
656
+ color="text.secondary"
657
+ sx={{ flexShrink: 0 }}
658
+ >
659
+ {rightLabel}
660
+ </Typography>
661
+ )}
662
+ {trailingAction && (
663
+ <Box sx={{ flexShrink: 0, display: "flex", alignItems: "center" }}>
664
+ {trailingAction}
665
+ </Box>
666
+ )}
667
+ </Box>
81
668
  );
82
669
  }
670
+
671
+ function EmptyRow({ label }: { label: string }) {
672
+ return (
673
+ <Typography
674
+ variant="body2"
675
+ color="text.secondary"
676
+ sx={{ py: 1, fontStyle: "italic" }}
677
+ >
678
+ {label}
679
+ </Typography>
680
+ );
681
+ }
682
+
683
+ function formatRowCount(rows: number): string {
684
+ if (rows >= 1_000_000_000)
685
+ return `${(rows / 1_000_000_000).toFixed(1)} B rows`;
686
+ if (rows >= 1_000_000) return `${(rows / 1_000_000).toFixed(1)} M rows`;
687
+ if (rows >= 1_000) return `${(rows / 1_000).toFixed(1)} K rows`;
688
+ return `${rows} rows`;
689
+ }