@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
@@ -0,0 +1,67 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * What the notebook's run effect should do about the state it just observed.
6
+ *
7
+ * Pulled out as a pure function because the inline version produced two defects
8
+ * that no test could reach: it first lost the bound on concurrent runs
9
+ * entirely, then, once a settle delay put the bound back, it let an abandoned
10
+ * run fire. Both were reasoning errors about
11
+ * three interacting pieces of state, which is exactly what a table of cases
12
+ * pins and a component test does not.
13
+ */
14
+ export interface RunPlanInput {
15
+ /** Whether the notebook is loaded and runnable at all. */
16
+ ready: boolean;
17
+ /** Key of the run that has already been dispatched, or null before the first. */
18
+ lastRunKey: string | null;
19
+ /** Key of a run currently waiting out the settle delay, if any. */
20
+ pendingKey: string | undefined;
21
+ /** Key for the state the notebook is in now. */
22
+ runKey: string;
23
+ /** The `resourceUri|generation` prefix of {@link runKey}, without the parameters. */
24
+ documentKey: string;
25
+ }
26
+
27
+ export interface RunPlan {
28
+ /** Clear the pending timer, because what it would run is no longer current. */
29
+ cancelPending: boolean;
30
+ /** `now` skips the settle delay; `settle` waits it out; `none` does nothing. */
31
+ dispatch: "now" | "settle" | "none";
32
+ }
33
+
34
+ export function planRun({
35
+ ready,
36
+ lastRunKey,
37
+ pendingKey,
38
+ runKey,
39
+ documentKey,
40
+ }: RunPlanInput): RunPlan {
41
+ // A notebook that is not loaded still has to disarm. This is the reason the
42
+ // readiness check belongs here rather than as an early return in the effect:
43
+ // as an early return it skipped the cancellation below, so navigating away
44
+ // inside the settle window left a timer holding the PREVIOUS notebook's
45
+ // closure, which then ran a full wave of cells against the notebook the
46
+ // reader had just left and wrote them into the one now on screen.
47
+ if (!ready) {
48
+ return { cancelPending: pendingKey !== undefined, dispatch: "none" };
49
+ }
50
+
51
+ // A pending run for any other key is stale the moment the notebook moves on,
52
+ // INCLUDING when it moves back to a key that has already run. That last case
53
+ // is the one that bit: typing a value and deleting it again inside the
54
+ // window returns to an already-run key, and leaving the timer armed meant the
55
+ // abandoned value's results landed on screen with nothing to correct them.
56
+ const cancelPending = pendingKey !== undefined && pendingKey !== runKey;
57
+
58
+ if (lastRunKey === runKey) return { cancelPending, dispatch: "none" };
59
+ if (pendingKey === runKey) return { cancelPending, dispatch: "none" };
60
+
61
+ // Only a changed PARAMETER waits. A first run, a different notebook, and a
62
+ // package reload all change the document rather than a value, and none of
63
+ // them is a burst worth coalescing: delaying them is just a blank screen.
64
+ const changedDocument =
65
+ lastRunKey === null || !lastRunKey.startsWith(`${documentKey}|`);
66
+ return { cancelPending, dispatch: changedDocument ? "now" : "settle" };
67
+ }
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { NotebookCell as ClientNotebookCell } from "../../client";
2
5
 
3
6
  /**
@@ -21,4 +24,15 @@ export interface EnhancedNotebookCell extends ClientNotebookCell {
21
24
  * that become available in this cell (e.g., from imports or source definitions)
22
25
  */
23
26
  newSources?: string[];
27
+
28
+ /**
29
+ * Why this cell has no result, when the server refused to run it.
30
+ *
31
+ * A cell that throws used to be logged to the console and nothing else, so
32
+ * the reader got an empty space with no indication anything had happened.
33
+ * That was survivable while the only way to reach it was a server fault; it
34
+ * stopped being survivable once a model with a required `#(filter)` began
35
+ * failing every cell by design.
36
+ */
37
+ error?: string;
24
38
  }
@@ -0,0 +1,91 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { MALLOY_ACCENT } from "../styles";
6
+ import { CONTENT_TINT, type ContentType } from "./ContentTypeIcon";
7
+
8
+ /** Relative luminance, WCAG 2.x definition. */
9
+ function luminance(hex: string): number {
10
+ const channels = [1, 3, 5].map(
11
+ (i) => parseInt(hex.slice(i, i + 2), 16) / 255,
12
+ );
13
+ const [r, g, b] = channels.map((c) =>
14
+ c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4,
15
+ );
16
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
17
+ }
18
+
19
+ function contrastWithWhite(hex: string): number {
20
+ return (1 + 0.05) / (luminance(hex) + 0.05);
21
+ }
22
+
23
+ describe("CONTENT_TINT", () => {
24
+ /**
25
+ * The whole point of the map. Before the package row derived its color from
26
+ * its type, four of the six rows were handed the same teal by four separate
27
+ * call sites, so color distinguished two kinds out of six. A repeat here is
28
+ * that regression arriving again, and nothing renders differently enough for
29
+ * a person to notice it in review.
30
+ */
31
+ it("gives every content type its own color", () => {
32
+ const values = Object.values(CONTENT_TINT);
33
+ expect(new Set(values).size).toBe(values.length);
34
+ });
35
+ });
36
+
37
+ /**
38
+ * Content types whose colour predates this bar. `report` is backed by
39
+ * `MALLOY_BRAND.teal` at 2.5:1, which is below it; that is inherited from the
40
+ * logo and is a brand decision rather than a component one.
41
+ *
42
+ * Keyed by content TYPE rather than by colour, which is the whole point. A new
43
+ * type handed teal is not grandfathered and fails, and fixing teal one day
44
+ * leaves this entry merely unused rather than turning a correct fix into a red
45
+ * suite.
46
+ */
47
+ const GRANDFATHERED: ContentType[] = ["report"];
48
+
49
+ describe("CONTENT_TINT contrast", () => {
50
+ /**
51
+ * Every tint fills a 32px backplate behind an 18px white glyph, so it has to
52
+ * clear 3:1
53
+ * against white, WCAG's minimum for a graphical object. Asserted rather than
54
+ * written down, because the failure is invisible: a lighter colour looks fine
55
+ * in a screenshot and the icon simply stops being readable.
56
+ *
57
+ * Over `CONTENT_TINT` rather than over `MALLOY_ACCENT`, because the tints are
58
+ * what actually get painted. Asserting the accent palette alone left three of
59
+ * the six painted values unchecked.
60
+ */
61
+ it.each(
62
+ Object.entries(CONTENT_TINT).filter(
63
+ ([type]) => !GRANDFATHERED.includes(type as ContentType),
64
+ ),
65
+ )("%s clears 3:1 against white", (_type, hex) => {
66
+ expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
67
+ });
68
+
69
+ // Guards the exception list against drift: a grandfathered name that no
70
+ // longer matches a `ContentType` fails here rather than silently exempting
71
+ // nothing. It does NOT catch the list being emptied, which passes
72
+ // vacuously; that case is caught instead by the contrast assertion for the
73
+ // type that stops being skipped, and an empty list is the desired end state
74
+ // anyway.
75
+ it("grandfathers only types that exist", () => {
76
+ for (const type of GRANDFATHERED) {
77
+ expect(CONTENT_TINT).toHaveProperty(type);
78
+ }
79
+ });
80
+ });
81
+
82
+ describe("MALLOY_ACCENT", () => {
83
+ // The accents were chosen against this bar, so they hold it even before any
84
+ // of them is assigned to a content type.
85
+ it.each(Object.entries(MALLOY_ACCENT))(
86
+ "%s clears 3:1 against white",
87
+ (_name, hex) => {
88
+ expect(contrastWithWhite(hex)).toBeGreaterThanOrEqual(3);
89
+ },
90
+ );
91
+ });
@@ -0,0 +1,177 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import SvgIcon, { SvgIconProps } from "@mui/material/SvgIcon";
5
+ import { MALLOY_ACCENT, MALLOY_BRAND } from "../styles";
6
+
7
+ export type ContentType =
8
+ | "report"
9
+ | "model"
10
+ | "data"
11
+ | "materialization"
12
+ | "dataApp"
13
+ | "dashboard";
14
+
15
+ /**
16
+ * The backplate color behind each icon. One per content type and no repeats: on
17
+ * a page that lists all six, a shared color reads as a shared kind, and the
18
+ * glyphs are small enough that color does most of the telling apart.
19
+ *
20
+ * The logo's three go to the three artifacts a reader opens to look at data,
21
+ * dashboards and notebooks and the models under them, and the accents to the
22
+ * rest, so the brand leads on the things the page is mostly for. Not a
23
+ * seniority ranking: dashboards are the newest thing a package can hold, and
24
+ * Package Data is among the oldest and takes an accent.
25
+ *
26
+ * Exhaustive by type rather than by a default, so adding a `ContentType` is a
27
+ * compile error here instead of a row that silently paints itself the same as
28
+ * its neighbour.
29
+ */
30
+ export const CONTENT_TINT: Record<ContentType, string> = {
31
+ dashboard: MALLOY_BRAND.orange,
32
+ report: MALLOY_BRAND.teal,
33
+ model: MALLOY_BRAND.darkBlue,
34
+ dataApp: MALLOY_ACCENT.violet,
35
+ data: MALLOY_ACCENT.moss,
36
+ materialization: MALLOY_ACCENT.magenta,
37
+ };
38
+
39
+ interface ContentTypeIconProps extends Omit<SvgIconProps, "fontSize"> {
40
+ type: ContentType;
41
+ /** Pixel size of the rendered icon. */
42
+ size?: number;
43
+ }
44
+
45
+ /**
46
+ * Inline SVGs that visually match Central Icons'
47
+ * round-outlined-radius-2-stroke-1 family
48
+ * (IconFileChart, Icon3dBoxTop, IconTable). Reimplemented as plain SVG
49
+ * so the SDK does not pick up the paid @central-icons-react dependency.
50
+ */
51
+ export default function ContentTypeIcon({
52
+ type,
53
+ size = 18,
54
+ sx,
55
+ ...rest
56
+ }: ContentTypeIconProps) {
57
+ return (
58
+ <SvgIcon
59
+ {...rest}
60
+ viewBox="0 0 24 24"
61
+ sx={{
62
+ width: size,
63
+ height: size,
64
+ fill: "none",
65
+ stroke: "currentColor",
66
+ strokeWidth: 1.5,
67
+ strokeLinecap: "round",
68
+ strokeLinejoin: "round",
69
+ ...sx,
70
+ }}
71
+ >
72
+ {CONTENT_GLYPH[type]()}
73
+ </SvgIcon>
74
+ );
75
+ }
76
+
77
+ /**
78
+ * The glyph for each content type, a `Record` for the same reason
79
+ * `CONTENT_TINT` is one. This was a chain of `type === "x" && <Path />`, which
80
+ * type-checks with no arm for a new content type and renders an empty `<svg>`
81
+ * on a coloured backplate: the colour half of the signal failed loudly at
82
+ * compile time and the glyph half failed silently at runtime. Two halves of one
83
+ * signal should fail the same way. The failure mode differs at runtime as well
84
+ * as at compile time: an unknown type throws here, where the old chain rendered
85
+ * an empty `<svg>`. Unreachable today, since every call site passes a literal,
86
+ * and a crash is the better of the two if it ever is reachable.
87
+ */
88
+ const CONTENT_GLYPH: Record<ContentType, () => React.ReactElement> = {
89
+ report: FileChartPath,
90
+ model: BoxTopPath,
91
+ data: TablePath,
92
+ materialization: StackPath,
93
+ dataApp: BrowserWindowPath,
94
+ dashboard: DashboardGridPath,
95
+ };
96
+
97
+ /** File outline with a folded top-right corner and three chart bars inside. */
98
+ function FileChartPath() {
99
+ return (
100
+ <>
101
+ <path d="M14 3 H6 a2 2 0 0 0 -2 2 v14 a2 2 0 0 0 2 2 h12 a2 2 0 0 0 2 -2 V9 z" />
102
+ <path d="M14 3 v4 a2 2 0 0 0 2 2 h4" />
103
+ <path d="M8 17 v-3" />
104
+ <path d="M12 17 v-6" />
105
+ <path d="M16 17 v-4" />
106
+ </>
107
+ );
108
+ }
109
+
110
+ /** Cube viewed from above with visible top face — matches Icon3dBoxTop. */
111
+ function BoxTopPath() {
112
+ return (
113
+ <>
114
+ <path d="M12 3 L4 7 v10 l8 4 l8 -4 V7 z" />
115
+ <path d="M4 7 l8 4 l8 -4" />
116
+ <path d="M12 11 v10" />
117
+ </>
118
+ );
119
+ }
120
+
121
+ /** Rounded grid icon — matches IconTable. */
122
+ function TablePath() {
123
+ return (
124
+ <>
125
+ <rect x="3.5" y="3.5" width="17" height="17" rx="2" />
126
+ <path d="M3.5 9.5 H20.5" />
127
+ <path d="M9.5 3.5 V20.5" />
128
+ </>
129
+ );
130
+ }
131
+
132
+ /** Stacked layers icon for materialized output tables. */
133
+ function StackPath() {
134
+ return (
135
+ <>
136
+ <path d="M12 3 L21 7.5 L12 12 L3 7.5 Z" />
137
+ <path d="M3 12 L12 16.5 L21 12" />
138
+ <path d="M3 16.5 L12 21 L21 16.5" />
139
+ </>
140
+ );
141
+ }
142
+
143
+ /**
144
+ * Panels of unequal size in one frame: the grid of tiles a dashboard lays out.
145
+ *
146
+ * The neighbour to stay distinct from is the TABLE glyph, not the data app's
147
+ * browser window. Both this and the table are a rounded rect with the same
148
+ * `M3.5 9.5` divider, so before the second divider the whole difference between
149
+ * them was one vertical stroke: `M12 9.5 V20.5` here against the table's
150
+ * `M9.5 3.5 V20.5`: shifted 2.5 across, and starting at the divider rather
151
+ * than at the top of the frame. That read as the
152
+ * same icon at 18px, with the Dashboards and Databases sections on one page.
153
+ * The second divider is what makes this one read as a grid rather than as
154
+ * columns.
155
+ */
156
+ function DashboardGridPath() {
157
+ return (
158
+ <>
159
+ <rect x="3.5" y="3.5" width="17" height="17" rx="2" />
160
+ <path d="M3.5 9.5 H20.5" />
161
+ <path d="M12 9.5 V20.5" />
162
+ <path d="M12 15 H20.5" />
163
+ </>
164
+ );
165
+ }
166
+
167
+ /** Browser-window outline with an address-bar separator and content lines. */
168
+ function BrowserWindowPath() {
169
+ return (
170
+ <>
171
+ <rect x="3.5" y="4.5" width="17" height="15" rx="2" />
172
+ <path d="M3.5 9.5 H20.5" />
173
+ <path d="M7 13.5 H17" />
174
+ <path d="M7 16.5 H13" />
175
+ </>
176
+ );
177
+ }
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import * as React from "react";
2
5
  import {
3
6
  TreeItem2Content,
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { Box, Typography } from "@mui/material";
2
5
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
3
6
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
@@ -20,16 +23,16 @@ interface ModelsProps {
20
23
 
21
24
  export default function Models({ onClickModelFile, resourceUri }: ModelsProps) {
22
25
  const {
23
- projectName: projectName,
26
+ environmentName: environmentName,
24
27
  packageName: packageName,
25
28
  versionId: versionId,
26
29
  } = parseResourceUri(resourceUri);
27
30
  const { apiClients } = useServer();
28
31
 
29
32
  const { data, isError, error, isSuccess } = useQueryWithApiError({
30
- queryKey: ["models", projectName, packageName, versionId],
33
+ queryKey: ["models", environmentName, packageName, versionId],
31
34
  queryFn: () =>
32
- apiClients.models.listModels(projectName, packageName, versionId),
35
+ apiClients.models.listModels(environmentName, packageName, versionId),
33
36
  });
34
37
 
35
38
  return (
@@ -46,7 +49,7 @@ export default function Models({ onClickModelFile, resourceUri }: ModelsProps) {
46
49
  {isError && (
47
50
  <ApiErrorDisplay
48
51
  error={error}
49
- context={`${projectName} > ${packageName} > Models`}
52
+ context={`${environmentName} > ${packageName} > Models`}
50
53
  />
51
54
  )}
52
55
  {isSuccess && data.data.length > 0 && (