@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
@@ -1,501 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- // TODO(jjs) - Export to .malloynb
5
- // TOOD(jjs) - Import via Publisher API that parses whole NB
6
-
7
- import AddIcon from "@mui/icons-material/Add";
8
- import {
9
- Box,
10
- Button,
11
- Dialog,
12
- DialogActions,
13
- DialogContent,
14
- DialogContentText,
15
- DialogTitle,
16
- Divider,
17
- Menu,
18
- MenuItem,
19
- Typography,
20
- } from "@mui/material";
21
- import Stack from "@mui/material/Stack";
22
- import React from "react";
23
- import { SourceAndPath } from "../Model/SourcesExplorer";
24
- import { WorkbookManager } from "./WorkbookManager";
25
- import { useServer } from "../ServerProvider";
26
- import { StyledCard, StyledCardContent, StyledCardMedia } from "../styles";
27
- import { MutableCell } from "./MutableCell";
28
- import { useWorkbookStorage } from "./WorkbookStorageProvider";
29
-
30
- import * as Malloy from "@malloydata/malloy-interfaces";
31
- import { ModelPicker } from "./ModelPicker";
32
- import { WorkbookLocator } from "./WorkbookStorage";
33
- import { useRouterClickHandler } from "../click_helper";
34
- import { parseResourceUri } from "../../utils/formatting";
35
-
36
- interface WorkbookProps {
37
- workbookPath?: WorkbookLocator;
38
- resourceUri: string;
39
- }
40
-
41
- interface PathToSources {
42
- modelPath: string;
43
- sourceInfos: Malloy.SourceInfo[];
44
- }
45
-
46
- export default function Workbook({ workbookPath, resourceUri }: WorkbookProps) {
47
- const navigate = useRouterClickHandler();
48
- const { server, getAccessToken } = useServer();
49
- const { apiClients } = useServer();
50
- const { workbookStorage } = useWorkbookStorage();
51
- const { environmentName, packageName } = parseResourceUri(resourceUri);
52
- const [success, setSuccess] = React.useState<string | undefined>(undefined);
53
- const [lastError, setLastError] = React.useState<string | undefined>(
54
- undefined,
55
- );
56
- if (!workbookStorage) {
57
- throw new Error(
58
- "Workbook storage be provided via WorkbookStorageProvider",
59
- );
60
- }
61
- const [workbookData, setWorkbookData] = React.useState<
62
- WorkbookManager | undefined
63
- >();
64
- const [editingMalloyIndex, setEditingMalloyIndex] = React.useState<
65
- number | undefined
66
- >();
67
- const [editingMarkdownIndex, setEditingMarkdownIndex] = React.useState<
68
- number | undefined
69
- >();
70
- const [sourceAndPaths, setSourceAndPaths] = React.useState<PathToSources[]>(
71
- [],
72
- );
73
- const [menuAnchorEl, setMenuAnchorEl] = React.useState<null | HTMLElement>(
74
- null,
75
- );
76
- const [menuIndex, setMenuIndex] = React.useState<number | null>(null);
77
- const menuOpen = Boolean(menuAnchorEl);
78
- const handleMenuClose = () => {
79
- setMenuAnchorEl(null);
80
- setMenuIndex(null);
81
- };
82
- const handleAddCell = (isMarkdown: boolean, index: number) => {
83
- if (!workbookData) return;
84
- setWorkbookData(
85
- workbookData.insertCell(index, {
86
- isMarkdown,
87
- value: "",
88
- }),
89
- );
90
- if (isMarkdown) {
91
- setEditingMarkdownIndex(index);
92
- } else {
93
- setEditingMalloyIndex(index);
94
- }
95
- handleMenuClose();
96
- console.log("handleAddCell", isMarkdown, index);
97
- };
98
-
99
- const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
100
- const handleDeleteClick = () => {
101
- setDeleteDialogOpen(true);
102
- };
103
-
104
- const handleDeleteConfirm = async () => {
105
- if (workbookPath && workbookStorage) {
106
- await workbookStorage
107
- .deleteWorkbook(workbookPath)
108
- .then(() => {
109
- setLastError(undefined);
110
- setSuccess(undefined);
111
- })
112
- .catch((error) => {
113
- setLastError(`Error deleting workbook: ${error.message}`);
114
- setSuccess(undefined);
115
- });
116
- }
117
- setDeleteDialogOpen(false);
118
- // TODO(jjs) - on delete event
119
- navigate(`/${environmentName}/${packageName}`);
120
- };
121
-
122
- const handleDeleteCancel = () => {
123
- setDeleteDialogOpen(false);
124
- };
125
-
126
- const saveWorkbook = React.useCallback(async () => {
127
- if (!workbookData) {
128
- console.log("No workbook data ref");
129
- return;
130
- }
131
- try {
132
- setWorkbookData(await workbookData.saveWorkbook());
133
- setLastError(undefined);
134
- setSuccess("Workbook saved");
135
- } catch (error) {
136
- setLastError(`Error saving workbook: ${error.message}`);
137
- setSuccess(undefined);
138
- }
139
- }, [workbookData]);
140
- React.useEffect(() => {
141
- // Load SourceInfos from selected models and sync PathsToSources
142
- if (!workbookData) {
143
- return;
144
- }
145
-
146
- const fetchModels = async () => {
147
- const modelPathToSourceInfo = new Map(
148
- sourceAndPaths.map(({ modelPath, sourceInfos }) => [
149
- modelPath,
150
- sourceInfos,
151
- ]),
152
- );
153
- const newSourceAndPaths = [];
154
- const promises = [];
155
-
156
- for (const model of workbookData.getModels()) {
157
- if (!modelPathToSourceInfo.has(model)) {
158
- console.log("Fetching model from Publisher", model);
159
- promises.push(
160
- apiClients.models
161
- .getModel(environmentName, packageName, model, undefined)
162
- .then((data) => ({
163
- modelPath: model,
164
- sourceInfos: data.data.sourceInfos.map((source) =>
165
- JSON.parse(source),
166
- ),
167
- })),
168
- );
169
- } else {
170
- newSourceAndPaths.push({
171
- modelPath: model,
172
- sourceInfos: modelPathToSourceInfo.get(model),
173
- });
174
- }
175
- }
176
-
177
- if (promises.length > 0) {
178
- const loadedSourceAndPaths = await Promise.all(promises);
179
- setSourceAndPaths([...newSourceAndPaths, ...loadedSourceAndPaths]);
180
- } else {
181
- setSourceAndPaths(newSourceAndPaths);
182
- }
183
- };
184
-
185
- fetchModels();
186
- // This function cannot depend on sourceAndPaths because it would cause an infinite loop.
187
- // eslint-disable-next-line react-hooks/exhaustive-deps
188
- }, [getAccessToken, workbookData, packageName, environmentName, server]);
189
-
190
- React.useEffect(() => {
191
- if (!workbookPath) {
192
- return;
193
- }
194
- WorkbookManager.loadWorkbook(workbookStorage, workbookPath).then(
195
- (workbookData) => {
196
- setWorkbookData(workbookData);
197
- },
198
- );
199
- }, [workbookPath, workbookStorage]);
200
-
201
- if (!workbookData) {
202
- return <div>Loading...</div>;
203
- }
204
- const getSourceList = (sourceAndPaths: PathToSources[]): SourceAndPath[] => {
205
- const sourceAndPath = [];
206
- for (const sources of sourceAndPaths) {
207
- for (const sourceInfo of sources.sourceInfos) {
208
- sourceAndPath.push({
209
- modelPath: sources.modelPath,
210
- sourceInfo: sourceInfo,
211
- });
212
- }
213
- }
214
- return sourceAndPath;
215
- };
216
- const plusButton = (isMarkdown: boolean, index: number) => {
217
- return (
218
- <Button
219
- size="small"
220
- startIcon={<AddIcon />}
221
- onClick={() => handleAddCell(isMarkdown, index)}
222
- variant="contained"
223
- sx={{
224
- backgroundColor: (theme) => theme.palette.background.paper,
225
- color: (theme) =>
226
- theme.palette.mode === "dark"
227
- ? theme.palette.grey[100]
228
- : theme.palette.grey[700],
229
- boxShadow: "none",
230
- "&:hover": {
231
- backgroundColor: (theme) =>
232
- theme.palette.mode === "dark"
233
- ? theme.palette.grey[500]
234
- : theme.palette.grey[300],
235
- boxShadow: "none",
236
- },
237
- }}
238
- >
239
- {isMarkdown ? "Markdown" : "Explore"}
240
- </Button>
241
- );
242
- };
243
- const addButtonSet = (
244
- <Box
245
- sx={{
246
- display: "flex",
247
- gap: 1,
248
- justifyContent: "center",
249
- flex: 2,
250
- }}
251
- >
252
- {plusButton(false, workbookData.getCells().length)}
253
- {plusButton(true, workbookData.getCells().length)}
254
- </Box>
255
- );
256
-
257
- return (
258
- <StyledCard variant="outlined">
259
- <StyledCardContent>
260
- <Box sx={{ mb: 2 }}>
261
- <Box sx={{ minHeight: "24px" }}>
262
- {lastError ? (
263
- <Typography color="error" variant="body2">
264
- {lastError}
265
- </Typography>
266
- ) : success ? (
267
- <Typography color="success" variant="body2">
268
- {success}
269
- </Typography>
270
- ) : (
271
- <span>&nbsp;</span>
272
- )}
273
- </Box>
274
- </Box>
275
- <Stack
276
- sx={{
277
- flexDirection: "row",
278
- justifyContent: "space-between",
279
- alignItems: "center",
280
- }}
281
- >
282
- <Stack direction="row" spacing={1} alignItems="center">
283
- <Typography
284
- variant="overline"
285
- sx={{
286
- fontSize: "13px",
287
- fontWeight: "bold",
288
- verticalAlign: "middle",
289
- }}
290
- >
291
- Workbook
292
- </Typography>
293
- <Typography
294
- variant="subtitle2"
295
- sx={{
296
- fontSize: "13px",
297
- fontWeight: "normal",
298
- verticalAlign: "middle",
299
- ml: 1,
300
- }}
301
- >
302
- {`${workbookPath.workspace} > ${workbookPath.path}`}
303
- </Typography>
304
- </Stack>
305
- <Stack sx={{ display: "flex", flexDirection: "row", gap: 1 }}>
306
- <Box
307
- sx={{
308
- display: "flex",
309
- alignItems: "center",
310
- mt: 1,
311
- mb: 1,
312
- }}
313
- >
314
- <ExportMalloyButton workbookData={workbookData} />
315
- </Box>
316
- <Box
317
- sx={{
318
- display: "flex",
319
- alignItems: "center",
320
- mt: 1,
321
- mb: 1,
322
- }}
323
- >
324
- <Button
325
- color="error"
326
- onClick={handleDeleteClick}
327
- size="small"
328
- >
329
- Delete
330
- </Button>
331
- <Dialog
332
- open={deleteDialogOpen}
333
- onClose={handleDeleteCancel}
334
- >
335
- <DialogTitle>Delete Workbook</DialogTitle>
336
- <DialogContent>
337
- <DialogContentText>
338
- Are you sure you want to delete the workbook
339
- &quot;
340
- {workbookPath.path}&quot;? This action cannot be
341
- undone.
342
- </DialogContentText>
343
- </DialogContent>
344
- <DialogActions>
345
- <Button
346
- onClick={handleDeleteCancel}
347
- color="primary"
348
- size="small"
349
- >
350
- Cancel
351
- </Button>
352
- <Button
353
- onClick={handleDeleteConfirm}
354
- color="error"
355
- autoFocus
356
- size="small"
357
- >
358
- Delete
359
- </Button>
360
- </DialogActions>
361
- </Dialog>
362
- </Box>
363
- </Stack>
364
- </Stack>
365
- <Divider />
366
- <Stack
367
- sx={{
368
- display: "flex",
369
- flexDirection: "row",
370
- width: "100%",
371
- mt: 2,
372
- }}
373
- >
374
- <Box sx={{ flex: 1 }}>
375
- <ModelPicker
376
- initialSelectedModels={workbookData.getModels()}
377
- onModelChange={(models) => {
378
- setWorkbookData(workbookData.setModels(models));
379
- saveWorkbook();
380
- }}
381
- resourceUri={resourceUri}
382
- />
383
- </Box>
384
- <Box sx={{ flex: 1 }} />
385
- </Stack>
386
- </StyledCardContent>
387
- <StyledCardMedia>
388
- <Stack>
389
- {workbookData.getCells().length === 0 && (
390
- <>
391
- <Typography
392
- sx={{
393
- textAlign: "center",
394
- p: 2,
395
- variant: "subtitle2",
396
- fontWeight: "medium",
397
- }}
398
- >
399
- Workbook is empty
400
- </Typography>
401
- <Typography
402
- variant="body2"
403
- sx={{ textAlign: "center", mb: 2, variant: "body2" }}
404
- >
405
- Click the + buttons to add a markdown or code cell.
406
- </Typography>
407
- </>
408
- )}
409
- {workbookData.getCells().map((cell, index) => (
410
- <React.Fragment
411
- key={`${index}-${workbookData.getCells().length}`}
412
- >
413
- <MutableCell
414
- key={`${index}-${cell.isMarkdown}-${workbookPath.workspace}-${workbookPath.path}`}
415
- cell={cell}
416
- resourceUri={resourceUri}
417
- addButtonCallback={(isMarkdown) =>
418
- plusButton(isMarkdown, index)
419
- }
420
- sourceAndPaths={getSourceList(sourceAndPaths)}
421
- editingMarkdown={editingMarkdownIndex === index}
422
- editingMalloy={editingMalloyIndex === index}
423
- onDelete={() => {
424
- setWorkbookData(workbookData.deleteCell(index));
425
- saveWorkbook();
426
- }}
427
- onCellChange={(cell) => {
428
- setWorkbookData(workbookData.setCell(index, cell));
429
- }}
430
- onEdit={() => {
431
- if (cell.isMarkdown) {
432
- setEditingMarkdownIndex(index);
433
- } else {
434
- setEditingMalloyIndex(index);
435
- }
436
- }}
437
- onClose={() => {
438
- if (cell.isMarkdown) {
439
- setEditingMarkdownIndex(undefined);
440
- } else {
441
- setEditingMalloyIndex(undefined);
442
- }
443
- saveWorkbook();
444
- }}
445
- />
446
- </React.Fragment>
447
- ))}
448
- {addButtonSet}
449
- <Menu
450
- anchorEl={menuAnchorEl}
451
- open={menuOpen}
452
- onClose={handleMenuClose}
453
- anchorOrigin={{ vertical: "bottom", horizontal: "right" }}
454
- transformOrigin={{ vertical: "top", horizontal: "right" }}
455
- >
456
- <MenuItem onClick={() => handleAddCell(true, menuIndex ?? 0)}>
457
- Add Markdown
458
- </MenuItem>
459
- <MenuItem
460
- onClick={() => handleAddCell(false, menuIndex ?? 0)}
461
- >
462
- Add Malloy
463
- </MenuItem>
464
- </Menu>
465
- <Stack
466
- sx={{
467
- flexDirection: "row",
468
- justifyContent: "flex-end",
469
- p: 1,
470
- }}
471
- ></Stack>
472
- </Stack>
473
- </StyledCardMedia>
474
- </StyledCard>
475
- );
476
- }
477
-
478
- function ExportMalloyButton({
479
- workbookData,
480
- }: {
481
- workbookData: WorkbookManager;
482
- }) {
483
- const [copied, setCopied] = React.useState(false);
484
- const handleExport = async () => {
485
- if (!workbookData) return;
486
- const malloy = workbookData.toMalloyWorkbook();
487
- try {
488
- await navigator.clipboard.writeText(malloy);
489
- setCopied(true);
490
- setTimeout(() => setCopied(false), 1500);
491
- } catch {
492
- setCopied(false);
493
- alert("Failed to copy to clipboard");
494
- }
495
- };
496
- return (
497
- <Button color="primary" onClick={handleExport} size="small">
498
- {copied ? "Copied!" : "Export"}
499
- </Button>
500
- );
501
- }
@@ -1,110 +0,0 @@
1
- // Copyright (c) Credible Data Inc.
2
- // SPDX-License-Identifier: MIT
3
-
4
- import {
5
- Box,
6
- Divider,
7
- List,
8
- ListItem,
9
- ListItemText,
10
- Typography,
11
- } from "@mui/material";
12
- import React from "react";
13
- import { useWorkbookStorage } from "./WorkbookStorageProvider";
14
- import { WorkbookLocator } from "./WorkbookStorage";
15
-
16
- interface WorkbookListProps {
17
- onWorkbookClick: (
18
- workbook: WorkbookLocator,
19
- event: React.MouseEvent,
20
- ) => void;
21
- }
22
-
23
- export function WorkbookList({ onWorkbookClick }: WorkbookListProps) {
24
- const { workbookStorage } = useWorkbookStorage();
25
- const [workbooks, setWorkbooks] = React.useState<WorkbookLocator[]>([]);
26
- const [lastError, setLastError] = React.useState<string | undefined>(
27
- undefined,
28
- );
29
-
30
- React.useEffect(() => {
31
- if (workbookStorage) {
32
- workbookStorage.listWorkspaces(false).then((workspaces) => {
33
- const allWorkbooks: WorkbookLocator[] = [];
34
- Promise.all(
35
- workspaces.map(async (workspace) => {
36
- await workbookStorage
37
- .listWorkbooks(workspace)
38
- .then((newWorkbooks) => {
39
- allWorkbooks.push(...newWorkbooks);
40
- })
41
- .catch((error) => {
42
- setLastError(
43
- `Error listing workbooks: ${error.message}`,
44
- );
45
- });
46
- }),
47
- ).then(() => {
48
- setWorkbooks(allWorkbooks);
49
- setLastError(undefined);
50
- });
51
- });
52
- }
53
- }, [workbookStorage]);
54
-
55
- return (
56
- <>
57
- {lastError && (
58
- <Box sx={{ mb: 2 }}>
59
- <Typography color="error" variant="body2">
60
- {lastError}
61
- </Typography>
62
- </Box>
63
- )}
64
- <Divider />
65
- <Box
66
- sx={{
67
- maxHeight: "300px",
68
- overflow: "auto",
69
- "&::-webkit-scrollbar": {
70
- width: "8px",
71
- },
72
- "&::-webkit-scrollbar-track": {
73
- background: "transparent",
74
- },
75
- "&::-webkit-scrollbar-thumb": {
76
- background: "rgba(0,0,0,0.2)",
77
- borderRadius: "4px",
78
- },
79
- }}
80
- >
81
- <List dense>
82
- {workbooks.length === 0 && (
83
- <ListItem>
84
- <ListItemText
85
- primary="No workbooks found."
86
- sx={{ textAlign: "center" }}
87
- />
88
- </ListItem>
89
- )}
90
- {workbooks.map((workbook) => (
91
- <ListItem
92
- key={workbook.path}
93
- onClick={(event: React.MouseEvent) =>
94
- onWorkbookClick(workbook, event)
95
- }
96
- sx={{
97
- cursor: "pointer",
98
- "&:hover": {
99
- backgroundColor: "action.hover",
100
- },
101
- }}
102
- >
103
- <ListItemText primary={workbook.path} />
104
- </ListItem>
105
- ))}
106
- </List>
107
- </Box>
108
- </>
109
- );
110
- }