@malloy-publisher/sdk 0.2.7 → 0.3.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 (221) hide show
  1. package/README.md +180 -204
  2. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
  3. package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
  4. package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
  5. package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
  6. package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
  7. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9561 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +13 -1
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  16. package/dist/components/Dashboard/Dashboard.d.ts +23 -16
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  18. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  19. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  20. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  21. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  22. package/dist/components/Dashboard/index.d.ts +2 -0
  23. package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
  24. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  25. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  26. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  27. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  28. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  29. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  30. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  31. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  32. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  33. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  34. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  35. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  36. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  37. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  38. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  39. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  40. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  41. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  42. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  43. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  44. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  45. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  46. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  47. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  48. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  49. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  50. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  51. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  52. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  53. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  54. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  55. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
  56. package/dist/components/DocumentStorage/index.d.ts +3 -0
  57. package/dist/components/FloatingIconButton.d.ts +16 -0
  58. package/dist/components/Model/index.d.ts +0 -1
  59. package/dist/components/Prose.d.ts +46 -0
  60. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  61. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  62. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  63. package/dist/components/RenderedResult/index.d.ts +2 -0
  64. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  65. package/dist/components/drill/index.d.ts +2 -1
  66. package/dist/components/drill/resolveDrill.d.ts +22 -0
  67. package/dist/components/drill/useDrill.d.ts +11 -2
  68. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  69. package/dist/components/given/filterValue.d.ts +63 -0
  70. package/dist/components/given/index.d.ts +1 -0
  71. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  72. package/dist/components/index.d.ts +3 -3
  73. package/dist/components/styles.d.ts +3 -7
  74. package/dist/core-8NVBCLZh.cjs.js +148 -0
  75. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  76. package/dist/hooks/index.d.ts +3 -1
  77. package/dist/hooks/useDocumentControls.d.ts +70 -0
  78. package/dist/hooks/useQueryResult.d.ts +40 -0
  79. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  80. package/dist/index.cjs.js +34 -1
  81. package/dist/index.es.js +21487 -79
  82. package/dist/sdk.css +1 -1
  83. package/dist/styles.css +0 -1
  84. package/dist/utils/malloyLiteral.d.ts +11 -0
  85. package/package.json +25 -14
  86. package/src/builder-entry.ts +55 -0
  87. package/src/components/ApiErrorDisplay.tsx +1 -1
  88. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  89. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  90. package/src/components/Dashboard/Dashboard.tsx +184 -229
  91. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  92. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  93. package/src/components/Dashboard/DashboardTile.tsx +67 -101
  94. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  95. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  96. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  97. package/src/components/Dashboard/TileCard.tsx +120 -0
  98. package/src/components/Dashboard/index.ts +2 -0
  99. package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
  100. package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
  101. package/src/components/Dashboard/telemetry.ts +44 -0
  102. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  103. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  104. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  105. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  106. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  107. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  108. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  109. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  110. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  111. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  112. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  113. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  114. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  115. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  116. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  117. package/src/components/DashboardBuilder/catalog.ts +225 -0
  118. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  119. package/src/components/DashboardBuilder/controls.ts +398 -0
  120. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  121. package/src/components/DashboardBuilder/diff.ts +93 -0
  122. package/src/components/DashboardBuilder/document.ts +209 -0
  123. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  124. package/src/components/DashboardBuilder/layout.ts +143 -0
  125. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  126. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  127. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  128. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  129. package/src/components/DashboardBuilder/preview.ts +172 -0
  130. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  131. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  132. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  133. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  134. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  135. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  136. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  137. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  138. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  139. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  140. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  141. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  142. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  143. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  144. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  145. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  146. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  147. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  148. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  149. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  150. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
  151. package/src/components/DocumentStorage/index.ts +16 -0
  152. package/src/components/Environment/About.tsx +4 -36
  153. package/src/components/FloatingIconButton.tsx +41 -0
  154. package/src/components/Model/Model.tsx +6 -23
  155. package/src/components/Model/ModelCell.tsx +34 -72
  156. package/src/components/Model/index.ts +0 -1
  157. package/src/components/Notebook/Notebook.tsx +27 -156
  158. package/src/components/Notebook/NotebookCell.tsx +37 -191
  159. package/src/components/Prose.spec.tsx +85 -0
  160. package/src/components/Prose.tsx +179 -0
  161. package/src/components/QueryResult/QueryResult.tsx +15 -43
  162. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  163. package/src/components/RenderedResult/ResultContainer.tsx +25 -36
  164. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  165. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  166. package/src/components/RenderedResult/index.ts +16 -0
  167. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  168. package/src/components/RenderedResult/resultSizing.ts +308 -0
  169. package/src/components/ResultsDialog.tsx +2 -1
  170. package/src/components/drill/index.ts +6 -0
  171. package/src/components/drill/resolveDrill.ts +22 -1
  172. package/src/components/drill/useDrill.spec.tsx +94 -0
  173. package/src/components/drill/useDrill.tsx +52 -12
  174. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  175. package/src/components/drill/useDrillSelf.ts +110 -0
  176. package/src/components/given/GivenInput.spec.tsx +196 -2
  177. package/src/components/given/GivenInput.tsx +300 -25
  178. package/src/components/given/GivensPanel.tsx +1 -1
  179. package/src/components/given/filterValue.spec.ts +112 -0
  180. package/src/components/given/filterValue.ts +188 -0
  181. package/src/components/given/index.ts +4 -0
  182. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  183. package/src/components/given/useGivenUrlParams.ts +87 -0
  184. package/src/components/index.ts +11 -3
  185. package/src/components/styles.ts +0 -37
  186. package/src/hooks/index.ts +13 -1
  187. package/src/hooks/useDocumentControls.ts +170 -0
  188. package/src/hooks/useGivensState.spec.ts +158 -0
  189. package/src/hooks/useGivensState.ts +114 -23
  190. package/src/hooks/useQueryResult.ts +82 -0
  191. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  192. package/src/hooks/useSuggestOptions.ts +94 -51
  193. package/src/utils/malloyLiteral.spec.ts +43 -0
  194. package/src/utils/malloyLiteral.ts +76 -0
  195. package/vite.config.ts +5 -1
  196. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  197. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  198. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  199. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  200. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  201. package/dist/components/Workbook/Workbook.d.ts +0 -7
  202. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  203. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  204. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  205. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  206. package/dist/components/Workbook/index.d.ts +0 -7
  207. package/dist/core-CWKmWEg2.cjs.js +0 -148
  208. package/dist/index-B0WyZAUA.es.js +0 -66412
  209. package/dist/index-kxVD1RjY.cjs.js +0 -356
  210. package/dist/markdown-editor.css +0 -341
  211. package/src/components/AnalyzePackageButton.tsx +0 -319
  212. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  213. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  214. package/src/components/Workbook/ModelPicker.tsx +0 -134
  215. package/src/components/Workbook/MutableCell.tsx +0 -458
  216. package/src/components/Workbook/Workbook.tsx +0 -501
  217. package/src/components/Workbook/WorkbookList.tsx +0 -110
  218. package/src/components/Workbook/WorkbookManager.ts +0 -214
  219. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  220. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  221. package/src/components/Workbook/index.ts +0 -10
@@ -0,0 +1,73 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * Where authored documents are kept, as an interface the host hands the SDK.
6
+ *
7
+ * The SDK renders dashboards and notebooks that a Publisher server serves out
8
+ * of a package, and it will author them too, but it does not decide where an
9
+ * authored document goes. That is the host's business: the Console keeps one
10
+ * in the browser, a platform keeps one in its own document store, a repo-backed
11
+ * host writes it to the package directory. So the SDK asks for a
12
+ * {@link DocumentStorage} through {@link DocumentStorageProvider} and calls it,
13
+ * and never touches a backend itself.
14
+ *
15
+ * A document is a string. The interface does not know whether it is a
16
+ * `dashboards/*.malloy` file, a `.malloynb`, or something else; the
17
+ * {@link DocumentLocator.type} says what kind it is so a backend can keep the
18
+ * kinds apart (a database column, a directory, a key prefix) and a listing can
19
+ * ask for one kind. Everything else a backend may know about a document, who
20
+ * changed it and when, who may see it, stays with the backend.
21
+ *
22
+ * Every method rejects rather than returning a sentinel when the document is
23
+ * not there, so a caller can tell "missing" from "empty".
24
+ */
25
+
26
+ /**
27
+ * The kinds of document the SDK authors. A `dashboard` is a
28
+ * `dashboards/<slug>.malloy` file; a `notebook` is a `.malloynb`.
29
+ */
30
+ export type DocumentType = "dashboard" | "notebook";
31
+
32
+ /** A place documents live, as the backend presents it to a reader. */
33
+ export interface Workspace {
34
+ name: string;
35
+ /** False for a workspace this reader may list and open but not save into. */
36
+ writeable: boolean;
37
+ description: string;
38
+ }
39
+
40
+ /** One document's address: which workspace, which kind, and its path there. */
41
+ export interface DocumentLocator {
42
+ workspace: string;
43
+ type: DocumentType;
44
+ /**
45
+ * The document's path within the workspace, spelled the way the backend
46
+ * spells it. For a repo-backed store that is the file path relative to the
47
+ * package (`dashboards/overview.malloy`); a database store may use a slug.
48
+ */
49
+ path: string;
50
+ }
51
+
52
+ export interface DocumentStorage {
53
+ /** The workspaces this reader can see; only the writeable ones when asked. */
54
+ listWorkspaces(writeableOnly: boolean): Promise<Workspace[]>;
55
+
56
+ /** Every document in a workspace, or only those of one kind. */
57
+ listDocuments(
58
+ workspace: Workspace,
59
+ type?: DocumentType,
60
+ ): Promise<DocumentLocator[]>;
61
+
62
+ /** The document's content. Rejects when there is no document there. */
63
+ getDocument(locator: DocumentLocator): Promise<string>;
64
+
65
+ /** Write the content, creating the document or replacing it. */
66
+ saveDocument(locator: DocumentLocator, content: string): Promise<void>;
67
+
68
+ /** Remove the document. Rejects when there is no document there. */
69
+ deleteDocument(locator: DocumentLocator): Promise<void>;
70
+
71
+ /** Rename or relocate a document, keeping its content. Rejects when `from` is missing. */
72
+ moveDocument(from: DocumentLocator, to: DocumentLocator): Promise<void>;
73
+ }
@@ -0,0 +1,58 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import React, { createContext, useContext, useMemo } from "react";
5
+ import type { DocumentStorage } from "./DocumentStorage";
6
+
7
+ export interface DocumentStorageProviderProps {
8
+ children: React.ReactNode;
9
+ documentStorage: DocumentStorage;
10
+ }
11
+
12
+ interface DocumentStorageContextValue {
13
+ documentStorage: DocumentStorage;
14
+ }
15
+
16
+ const DocumentStorageContext = createContext<
17
+ DocumentStorageContextValue | undefined
18
+ >(undefined);
19
+
20
+ /**
21
+ * Hands a {@link DocumentStorage} to every SDK component beneath it. The host
22
+ * constructs the storage; the SDK only ever reads it through
23
+ * {@link useDocumentStorage}.
24
+ */
25
+ export function DocumentStorageProvider({
26
+ children,
27
+ documentStorage,
28
+ }: DocumentStorageProviderProps) {
29
+ const value = useMemo(() => ({ documentStorage }), [documentStorage]);
30
+ return (
31
+ <DocumentStorageContext.Provider value={value}>
32
+ {children}
33
+ </DocumentStorageContext.Provider>
34
+ );
35
+ }
36
+
37
+ /** The host's storage, or a thrown error outside a provider: there is no default. */
38
+ export function useDocumentStorage(): DocumentStorageContextValue {
39
+ const context = useContext(DocumentStorageContext);
40
+ if (!context) {
41
+ throw new Error(
42
+ "useDocumentStorage must be used within a DocumentStorageProvider",
43
+ );
44
+ }
45
+ return context;
46
+ }
47
+
48
+ /**
49
+ * The host's storage, or undefined outside a provider. For a component that
50
+ * can do without one — the dashboard editor still edits and exports with no
51
+ * place to save — rather than the throwing form, which is for components that
52
+ * cannot.
53
+ */
54
+ export function useOptionalDocumentStorage():
55
+ | DocumentStorageContextValue
56
+ | undefined {
57
+ return useContext(DocumentStorageContext);
58
+ }
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ export type {
5
+ DocumentLocator,
6
+ DocumentStorage,
7
+ DocumentType,
8
+ Workspace,
9
+ } from "./DocumentStorage";
10
+ export {
11
+ DocumentStorageProvider,
12
+ useDocumentStorage,
13
+ useOptionalDocumentStorage,
14
+ type DocumentStorageProviderProps,
15
+ } from "./DocumentStorageProvider";
16
+ export { BrowserDocumentStorage } from "./BrowserDocumentStorage";
@@ -2,12 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Box, Button } from "@mui/material";
5
- import Markdown from "markdown-to-jsx";
6
5
  import { useState } from "react";
7
6
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
8
7
  import { parseResourceUri } from "../../utils/formatting";
9
8
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
10
9
  import { Loading } from "../Loading";
10
+ import { Prose } from "../Prose";
11
11
  import { useServer } from "../ServerProvider";
12
12
  import {
13
13
  PackageCard,
@@ -42,42 +42,10 @@ export default function About({ resourceUri }: AboutProps) {
42
42
  <PackageCard>
43
43
  <PackageCardContent>
44
44
  <PackageSectionTitle>Readme</PackageSectionTitle>
45
- <Box sx={{ mt: 1, fontSize: "0.875rem", lineHeight: 1.6 }}>
46
- <Markdown
47
- options={{
48
- overrides: {
49
- h1: {
50
- component: "p",
51
- props: {
52
- style: {
53
- fontSize: "inherit",
54
- fontWeight: "italic",
55
- },
56
- },
57
- },
58
- h2: {
59
- component: "p",
60
- props: {
61
- style: {
62
- fontSize: "inherit",
63
- fontWeight: "italic",
64
- },
65
- },
66
- },
67
- h3: {
68
- component: "p",
69
- props: {
70
- style: {
71
- fontSize: "inherit",
72
- fontWeight: "italic",
73
- },
74
- },
75
- },
76
- },
77
- }}
78
- >
45
+ <Box sx={{ mt: 1 }}>
46
+ <Prose variant="caption">
79
47
  {expanded || !shouldTruncate ? readmeContent : preview}
80
- </Markdown>
48
+ </Prose>
81
49
 
82
50
  {shouldTruncate && (
83
51
  <Box sx={{ mt: 1 }}>
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { IconButton, type IconButtonProps } from "@mui/material";
5
+ import { usePublisherTheme } from "../theme/ThemeContext";
6
+
7
+ /**
8
+ * A small round button that sits OVER content — a rendered result, an
9
+ * explorer, a chart — to open something about it: the code, the full result,
10
+ * a render warning.
11
+ *
12
+ * On the instance theme's tile colour, with its border, so it reads as a chip
13
+ * of the same card it floats on in both modes. Six of these were drawn by hand
14
+ * before, every one on a hardcoded white plate with a hardcoded dark icon,
15
+ * and the notebook's comment said why that was the only way: a white plate
16
+ * needs a dark icon whatever the mode. The plate follows the theme now, so
17
+ * the icon can too.
18
+ *
19
+ * Positioning is the caller's: it passes `sx` for where the button floats.
20
+ */
21
+ export function FloatingIconButton({ sx, ...props }: IconButtonProps) {
22
+ const { theme } = usePublisherTheme();
23
+ return (
24
+ <IconButton
25
+ size="small"
26
+ {...props}
27
+ sx={[
28
+ {
29
+ width: 32,
30
+ height: 32,
31
+ bgcolor: theme.tile,
32
+ border: theme.border,
33
+ color: theme.tileTitle,
34
+ "&:hover": { bgcolor: theme.tile, color: theme.drillLink },
35
+ "& .MuiSvgIcon-root": { fontSize: 18 },
36
+ },
37
+ ...(Array.isArray(sx) ? sx : [sx]),
38
+ ]}
39
+ />
40
+ );
41
+ }
@@ -4,17 +4,11 @@
4
4
  import "@malloydata/malloy-explorer/styles.css";
5
5
  import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
6
6
  import SearchIcon from "@mui/icons-material/Search";
7
- import {
8
- Box,
9
- IconButton,
10
- Snackbar,
11
- Stack,
12
- Tooltip,
13
- Typography,
14
- } from "@mui/material";
7
+ import { Box, Snackbar, Stack, Tooltip, Typography } from "@mui/material";
15
8
  import React, { useState } from "react";
16
9
  import { parseResourceUri } from "../../utils/formatting";
17
10
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
11
+ import { FloatingIconButton } from "../FloatingIconButton";
18
12
  import { Loading } from "../Loading";
19
13
  import { ModelCell } from "./ModelCell";
20
14
  import { ModelExplorer } from "./ModelExplorer";
@@ -151,29 +145,18 @@ export default function Model({
151
145
  />
152
146
 
153
147
  {/* Magnifying glass icon */}
154
- <IconButton
148
+ <FloatingIconButton
149
+ aria-label="Expand results"
155
150
  sx={{
156
151
  position: "absolute",
157
152
  top: "90px",
158
153
  right: "4px",
159
- backgroundColor: "rgba(255, 255, 255, 0.9)",
160
- "&:hover": {
161
- backgroundColor: "rgba(255, 255, 255, 1)",
162
- },
163
- width: "32px",
164
- height: "32px",
165
154
  zIndex: 2,
166
155
  }}
167
156
  onClick={() => setDialogOpen(true)}
168
157
  >
169
- <SearchIcon
170
- sx={{
171
- fontSize: "18px",
172
- color: "text.secondary",
173
- marginBottom: "5px",
174
- }}
175
- />
176
- </IconButton>
158
+ <SearchIcon />
159
+ </FloatingIconButton>
177
160
  </Stack>
178
161
  )}
179
162
 
@@ -3,17 +3,17 @@
3
3
 
4
4
  import PlayArrowIcon from "@mui/icons-material/PlayArrow";
5
5
  import SearchIcon from "@mui/icons-material/Search";
6
- import { Box, Button, IconButton, Typography } from "@mui/material";
6
+ import { Box, Button, Typography } from "@mui/material";
7
7
  import React, { useEffect } from "react";
8
- import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
8
+ import { useQueryResult } from "../../hooks/useQueryResult";
9
9
  import { usePublisherTheme } from "../../theme/ThemeContext";
10
10
  import { parseResourceUri } from "../../utils/formatting";
11
- import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
11
+ import { FloatingIconButton } from "../FloatingIconButton";
12
12
  import { highlight } from "../highlighter";
13
- import ResultContainer from "../RenderedResult/ResultContainer";
13
+ import { ResultPanel } from "../RenderedResult/ResultPanel";
14
+ import { MODEL_CELL_MAX_HEIGHT } from "../RenderedResult/resultSizing";
14
15
  import ResultsDialog from "../ResultsDialog";
15
- import { useServer } from "../ServerProvider";
16
- import { CleanMetricCard, CleanNotebookCell } from "../styles";
16
+ import { CleanMetricCard } from "../styles";
17
17
 
18
18
  interface ModelCellProps {
19
19
  sourceName?: string;
@@ -39,29 +39,13 @@ export function ModelCell({
39
39
 
40
40
  const { packageName, environmentName, versionId, modelPath } =
41
41
  parseResourceUri(resourceUri);
42
- const { apiClients } = useServer();
43
-
44
- const {
45
- data: queryData,
46
- isSuccess,
47
- isLoading,
48
- } = useQueryWithApiError({
49
- queryKey: ["namedQueryResult", resourceUri, queryName],
50
- queryFn: () =>
51
- apiClients.models.executeQueryModel(
52
- environmentName,
53
- packageName,
54
- modelPath,
55
- {
56
- query: undefined,
57
- sourceName: undefined,
58
- queryName: queryName,
59
- versionId: versionId,
60
- },
61
- ),
62
- enabled: runOnDemand ? hasRun : true, // Execute on demand or always
63
- ...CHART_RESULT_QUERY_OPTIONS,
64
- });
42
+ // Run on demand or always; a query not yet asked for is not fetched.
43
+ const shouldRun = !runOnDemand || hasRun;
44
+ const state = useQueryResult(
45
+ { environmentName, packageName, modelPath, versionId, queryName },
46
+ { enabled: shouldRun },
47
+ );
48
+ const queryData = state.data;
65
49
 
66
50
  const { mode } = usePublisherTheme();
67
51
  useEffect(() => {
@@ -76,7 +60,7 @@ export function ModelCell({
76
60
  }, [annotations, mode]);
77
61
 
78
62
  return (
79
- <CleanNotebookCell>
63
+ <Box>
80
64
  {highlightedAnnotations && (
81
65
  <Box sx={{ marginBottom: "16px" }}>
82
66
  <Typography
@@ -109,29 +93,24 @@ export function ModelCell({
109
93
  variant="body2"
110
94
  sx={{
111
95
  fontSize: "15px",
112
- fontWeight: "600",
113
- color: "#495057",
114
- padding: "8px 16px",
115
- backgroundColor: "#f8f9fa",
116
- borderRadius: "6px",
117
- border: "1px solid #e9ecef",
96
+ fontWeight: 600,
97
+ color: "text.primary",
98
+ px: 2,
99
+ py: 1,
100
+ bgcolor: "action.hover",
101
+ borderRadius: 1.5,
102
+ border: 1,
103
+ borderColor: "divider",
118
104
  }}
119
105
  >
120
106
  {queryName}
121
107
  </Typography>
122
- <IconButton
123
- sx={{
124
- backgroundColor: "rgba(255, 255, 255, 0.9)",
125
- "&:hover": {
126
- backgroundColor: "rgba(255, 255, 255, 1)",
127
- },
128
- width: "32px",
129
- height: "32px",
130
- }}
108
+ <FloatingIconButton
109
+ aria-label="Expand results"
131
110
  onClick={() => setResultsDialogOpen(true)}
132
111
  >
133
- <SearchIcon sx={{ fontSize: "18px", color: "text.secondary" }} />
134
- </IconButton>
112
+ <SearchIcon />
113
+ </FloatingIconButton>
135
114
  </Box>
136
115
 
137
116
  <CleanMetricCard
@@ -157,36 +136,19 @@ export function ModelCell({
157
136
  variant="contained"
158
137
  startIcon={<PlayArrowIcon />}
159
138
  onClick={() => setHasRun(true)}
160
- sx={{
161
- backgroundColor: "#1976d2",
162
- "&:hover": {
163
- backgroundColor: "#1565c0",
164
- },
165
- textTransform: "none",
166
- fontSize: "14px",
167
- fontWeight: 600,
168
- padding: "8px 24px",
169
- }}
170
139
  >
171
140
  Run Query
172
141
  </Button>
173
142
  </Box>
174
143
  )}
175
- {(!runOnDemand || hasRun) && isLoading && (
176
- <Box sx={{ padding: "20px", textAlign: "center" }}>
177
- <Typography>Loading results...</Typography>
178
- </Box>
144
+ {shouldRun && (
145
+ <ResultPanel
146
+ state={state}
147
+ context={queryName}
148
+ maxHeight={MODEL_CELL_MAX_HEIGHT}
149
+ maxResultSize={maxResultSize}
150
+ />
179
151
  )}
180
- {(!runOnDemand || hasRun) &&
181
- isSuccess &&
182
- queryData?.data?.result && (
183
- <ResultContainer
184
- result={queryData.data.result}
185
- maxHeight={600}
186
- maxResultSize={maxResultSize}
187
- renderLogs={queryData.data.renderLogs}
188
- />
189
- )}
190
152
  </CleanMetricCard>
191
153
 
192
154
  {/* Results Dialog */}
@@ -197,6 +159,6 @@ export function ModelCell({
197
159
  renderLogs={queryData?.data?.renderLogs}
198
160
  title={`Query: ${queryName}`}
199
161
  />
200
- </CleanNotebookCell>
162
+ </Box>
201
163
  );
202
164
  }
@@ -5,7 +5,6 @@ export { default as Model } from "./Model";
5
5
  export { ModelExplorer } from "./ModelExplorer";
6
6
  export { ModelExplorerDialog } from "./ModelExplorerDialog";
7
7
  export { SourcesExplorer } from "./SourcesExplorer";
8
- export { SourceExplorerComponent } from "./SourcesExplorer";
9
8
  export type { SourceAndPath, QueryExplorerResult } from "./SourcesExplorer";
10
9
  export { useModelData } from "./useModelData";
11
10
  export type { ModelExplorerProps } from "./ModelExplorer";