@malloy-publisher/sdk 0.2.7 → 0.3.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 (99) hide show
  1. package/README.md +172 -204
  2. package/dist/ServerProvider-CGnLjzag.cjs.js +1 -0
  3. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-DSK9rfSY.es.js} +245 -245
  4. package/dist/client/api.d.ts +13 -1
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +1 -1
  7. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  8. package/dist/components/Dashboard/Dashboard.d.ts +4 -2
  9. package/dist/components/Dashboard/promoteMeasureRow.d.ts +36 -0
  10. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  11. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  12. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +18 -0
  13. package/dist/components/DocumentStorage/index.d.ts +3 -0
  14. package/dist/components/Model/index.d.ts +0 -1
  15. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  16. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  17. package/dist/components/RenderedResult/index.d.ts +1 -0
  18. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  19. package/dist/components/drill/index.d.ts +1 -0
  20. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  21. package/dist/components/given/filterValue.d.ts +63 -0
  22. package/dist/components/given/index.d.ts +1 -0
  23. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  24. package/dist/components/index.d.ts +2 -3
  25. package/dist/components/styles.d.ts +3 -3
  26. package/dist/core-8NVBCLZh.cjs.js +148 -0
  27. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  28. package/dist/hooks/index.d.ts +1 -1
  29. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  30. package/dist/index.cjs.js +281 -1
  31. package/dist/index.es.js +45803 -79
  32. package/dist/sdk.css +1 -1
  33. package/dist/styles.css +0 -1
  34. package/package.json +2 -6
  35. package/src/components/ApiErrorDisplay.tsx +1 -1
  36. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  37. package/src/components/Dashboard/Dashboard.tsx +60 -95
  38. package/src/components/Dashboard/DashboardTile.tsx +25 -2
  39. package/src/components/Dashboard/promoteMeasureRow.spec.ts +137 -0
  40. package/src/components/Dashboard/promoteMeasureRow.ts +129 -0
  41. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  42. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  43. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  44. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +46 -0
  45. package/src/components/DocumentStorage/index.ts +15 -0
  46. package/src/components/Model/ModelCell.tsx +2 -1
  47. package/src/components/Model/index.ts +0 -1
  48. package/src/components/Notebook/Notebook.tsx +10 -76
  49. package/src/components/Notebook/NotebookCell.tsx +2 -8
  50. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  51. package/src/components/RenderedResult/ResultContainer.tsx +21 -24
  52. package/src/components/RenderedResult/index.ts +15 -0
  53. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  54. package/src/components/RenderedResult/resultSizing.ts +308 -0
  55. package/src/components/ResultsDialog.tsx +2 -1
  56. package/src/components/drill/index.ts +5 -0
  57. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  58. package/src/components/drill/useDrillSelf.ts +110 -0
  59. package/src/components/given/GivenInput.spec.tsx +196 -2
  60. package/src/components/given/GivenInput.tsx +300 -25
  61. package/src/components/given/filterValue.spec.ts +112 -0
  62. package/src/components/given/filterValue.ts +188 -0
  63. package/src/components/given/index.ts +4 -0
  64. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  65. package/src/components/given/useGivenUrlParams.ts +87 -0
  66. package/src/components/index.ts +5 -3
  67. package/src/hooks/index.ts +0 -1
  68. package/src/hooks/useGivensState.spec.ts +158 -0
  69. package/src/hooks/useGivensState.ts +114 -23
  70. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  71. package/src/hooks/useSuggestOptions.ts +94 -51
  72. package/vite.config.ts +0 -1
  73. package/dist/ServerProvider-xXW1HJOJ.cjs.js +0 -1
  74. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  75. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  76. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  77. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  78. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  79. package/dist/components/Workbook/Workbook.d.ts +0 -7
  80. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  81. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  82. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  83. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  84. package/dist/components/Workbook/index.d.ts +0 -7
  85. package/dist/core-CWKmWEg2.cjs.js +0 -148
  86. package/dist/index-B0WyZAUA.es.js +0 -66412
  87. package/dist/index-kxVD1RjY.cjs.js +0 -356
  88. package/dist/markdown-editor.css +0 -341
  89. package/src/components/AnalyzePackageButton.tsx +0 -319
  90. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  91. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  92. package/src/components/Workbook/ModelPicker.tsx +0 -134
  93. package/src/components/Workbook/MutableCell.tsx +0 -458
  94. package/src/components/Workbook/Workbook.tsx +0 -501
  95. package/src/components/Workbook/WorkbookList.tsx +0 -110
  96. package/src/components/Workbook/WorkbookManager.ts +0 -214
  97. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  98. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  99. 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
- }