@malloy-publisher/sdk 0.0.86 → 0.0.88
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.
- package/dist/client/api.d.ts +167 -0
- package/dist/components/AnalyzePackageButton.d.ts +6 -1
- package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +6 -8
- package/dist/components/Workbook/Workbook.d.ts +3 -1
- package/dist/components/Workbook/WorkbookManager.d.ts +3 -6
- package/dist/components/Workbook/WorkbookStorage.d.ts +6 -7
- package/dist/index.cjs.js +75 -75
- package/dist/index.es.js +8902 -9166
- package/dist/malloy-explorer.css +18 -1
- package/dist/markdown-editor.css +0 -1
- package/dist/sdk.css +1 -1
- package/package.json +5 -5
- package/src/components/AnalyzePackageButton.tsx +32 -32
- package/src/components/Workbook/BrowserWorkbookStorage.ts +16 -54
- package/src/components/Workbook/Workbook.tsx +23 -29
- package/src/components/Workbook/WorkbookList.tsx +20 -24
- package/src/components/Workbook/WorkbookManager.ts +5 -24
- package/src/components/Workbook/WorkbookStorage.ts +6 -26
|
@@ -18,10 +18,8 @@ import {
|
|
|
18
18
|
import Stack from "@mui/material/Stack";
|
|
19
19
|
import React from "react";
|
|
20
20
|
import { Configuration, ModelsApi } from "../../client";
|
|
21
|
-
import { useRouterClickHandler } from "../click_helper";
|
|
22
21
|
import { SourceAndPath } from "../Model/SourcesExplorer";
|
|
23
22
|
import { WorkbookManager } from "./WorkbookManager";
|
|
24
|
-
import { usePackage } from "../Package";
|
|
25
23
|
import { useServer } from "../ServerProvider";
|
|
26
24
|
import { StyledCard, StyledCardContent, StyledCardMedia } from "../styles";
|
|
27
25
|
import { MutableCell } from "./MutableCell";
|
|
@@ -31,6 +29,7 @@ import * as Malloy from "@malloydata/malloy-interfaces";
|
|
|
31
29
|
import { ModelPicker } from "./ModelPicker";
|
|
32
30
|
import { getAxiosConfig } from "../../hooks";
|
|
33
31
|
import { WorkbookLocator } from "./WorkbookStorage";
|
|
32
|
+
import { useRouterClickHandler } from "../click_helper";
|
|
34
33
|
|
|
35
34
|
const modelsApi = new ModelsApi(new Configuration());
|
|
36
35
|
|
|
@@ -39,6 +38,8 @@ interface WorkbookProps {
|
|
|
39
38
|
expandCodeCells?: boolean;
|
|
40
39
|
expandEmbeddings?: boolean;
|
|
41
40
|
hideEmbeddingIcons?: boolean;
|
|
41
|
+
defaultProjectName?: string;
|
|
42
|
+
defaultPackageName?: string;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
interface PathToSources {
|
|
@@ -51,20 +52,15 @@ export default function Workbook({
|
|
|
51
52
|
expandCodeCells,
|
|
52
53
|
expandEmbeddings,
|
|
53
54
|
hideEmbeddingIcons,
|
|
55
|
+
defaultProjectName,
|
|
56
|
+
defaultPackageName,
|
|
54
57
|
}: WorkbookProps) {
|
|
55
58
|
const navigate = useRouterClickHandler();
|
|
56
|
-
const packageContext = usePackage();
|
|
57
|
-
const { projectName, packageName, versionId } = packageContext;
|
|
58
59
|
const { server, getAccessToken } = useServer();
|
|
59
60
|
const { workbookStorage } = useWorkbookStorage();
|
|
60
61
|
const [lastError, setLastError] = React.useState<string | undefined>(
|
|
61
62
|
undefined,
|
|
62
63
|
);
|
|
63
|
-
if (!projectName || !packageName) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
"Project and package must be provided via PubliserPackageProvider",
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
64
|
if (!workbookStorage) {
|
|
69
65
|
throw new Error(
|
|
70
66
|
"Workbook storage be provided via WorkbookStorageProvider",
|
|
@@ -110,10 +106,10 @@ export default function Workbook({
|
|
|
110
106
|
setDeleteDialogOpen(true);
|
|
111
107
|
};
|
|
112
108
|
|
|
113
|
-
const handleDeleteConfirm = async (
|
|
114
|
-
if (workbookPath && workbookStorage
|
|
109
|
+
const handleDeleteConfirm = async () => {
|
|
110
|
+
if (workbookPath && workbookStorage) {
|
|
115
111
|
await workbookStorage
|
|
116
|
-
.deleteWorkbook(
|
|
112
|
+
.deleteWorkbook(workbookPath)
|
|
117
113
|
.then(() => {
|
|
118
114
|
setLastError(undefined);
|
|
119
115
|
})
|
|
@@ -122,7 +118,8 @@ export default function Workbook({
|
|
|
122
118
|
});
|
|
123
119
|
}
|
|
124
120
|
setDeleteDialogOpen(false);
|
|
125
|
-
|
|
121
|
+
// TODO(jjs) - on delete event
|
|
122
|
+
navigate(`/${defaultProjectName}/${defaultPackageName}`);
|
|
126
123
|
};
|
|
127
124
|
|
|
128
125
|
const handleDeleteCancel = () => {
|
|
@@ -159,10 +156,10 @@ export default function Workbook({
|
|
|
159
156
|
promises.push(
|
|
160
157
|
modelsApi
|
|
161
158
|
.getModel(
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
defaultProjectName,
|
|
160
|
+
defaultPackageName,
|
|
164
161
|
model,
|
|
165
|
-
|
|
162
|
+
undefined,
|
|
166
163
|
await getAxiosConfig(server, getAccessToken),
|
|
167
164
|
)
|
|
168
165
|
.then((data) => ({
|
|
@@ -193,24 +190,21 @@ export default function Workbook({
|
|
|
193
190
|
// Work this cannot depend on sourceAndPaths because it will cause an infinite loop.
|
|
194
191
|
getAccessToken,
|
|
195
192
|
workbookData,
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
defaultPackageName,
|
|
194
|
+
defaultProjectName,
|
|
198
195
|
server,
|
|
199
|
-
versionId,
|
|
200
196
|
]);
|
|
201
197
|
|
|
202
198
|
React.useEffect(() => {
|
|
203
199
|
if (!workbookPath) {
|
|
204
200
|
return;
|
|
205
201
|
}
|
|
206
|
-
WorkbookManager.loadWorkbook(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
});
|
|
213
|
-
}, [workbookPath, workbookStorage, packageContext]);
|
|
202
|
+
WorkbookManager.loadWorkbook(workbookStorage, workbookPath).then(
|
|
203
|
+
(workbookData) => {
|
|
204
|
+
setWorkbookData(workbookData);
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
}, [workbookPath, workbookStorage]);
|
|
214
208
|
|
|
215
209
|
if (!workbookData) {
|
|
216
210
|
return <div>Loading...</div>;
|
|
@@ -305,7 +299,7 @@ export default function Workbook({
|
|
|
305
299
|
ml: 1,
|
|
306
300
|
}}
|
|
307
301
|
>
|
|
308
|
-
{`${
|
|
302
|
+
{`${workbookPath.workspace} > ${workbookPath.path}`}
|
|
309
303
|
</Typography>
|
|
310
304
|
</Stack>
|
|
311
305
|
<Stack sx={{ display: "flex", flexDirection: "row", gap: 1 }}>
|
|
@@ -416,7 +410,7 @@ export default function Workbook({
|
|
|
416
410
|
key={`${index}-${workbookData.getCells().length}`}
|
|
417
411
|
>
|
|
418
412
|
<MutableCell
|
|
419
|
-
key={`${index}-${cell.isMarkdown}-${workbookPath}-${
|
|
413
|
+
key={`${index}-${cell.isMarkdown}-${workbookPath.workspace}-${workbookPath.path}`}
|
|
420
414
|
cell={cell}
|
|
421
415
|
addButtonCallback={(isMarkdown) =>
|
|
422
416
|
plusButton(isMarkdown, index)
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
} from "@mui/material";
|
|
9
9
|
import React from "react";
|
|
10
10
|
import { useWorkbookStorage } from "./WorkbookStorageProvider";
|
|
11
|
-
import { usePackage } from "../Package";
|
|
12
11
|
import { WorkbookLocator } from "./WorkbookStorage";
|
|
13
12
|
|
|
14
13
|
interface WorkbookListProps {
|
|
@@ -20,7 +19,6 @@ interface WorkbookListProps {
|
|
|
20
19
|
|
|
21
20
|
export function WorkbookList({ onWorkbookClick }: WorkbookListProps) {
|
|
22
21
|
const { workbookStorage } = useWorkbookStorage();
|
|
23
|
-
const packageContext = usePackage();
|
|
24
22
|
const [workbooks, setWorkbooks] = React.useState<WorkbookLocator[]>([]);
|
|
25
23
|
const [lastError, setLastError] = React.useState<string | undefined>(
|
|
26
24
|
undefined,
|
|
@@ -28,30 +26,28 @@ export function WorkbookList({ onWorkbookClick }: WorkbookListProps) {
|
|
|
28
26
|
|
|
29
27
|
React.useEffect(() => {
|
|
30
28
|
if (workbookStorage) {
|
|
31
|
-
workbookStorage
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
setWorkbooks(allWorkbooks);
|
|
50
|
-
setLastError(undefined);
|
|
51
|
-
});
|
|
29
|
+
workbookStorage.listWorkspaces(false).then((workspaces) => {
|
|
30
|
+
const allWorkbooks: WorkbookLocator[] = [];
|
|
31
|
+
Promise.all(
|
|
32
|
+
workspaces.map(async (workspace) => {
|
|
33
|
+
await workbookStorage
|
|
34
|
+
.listWorkbooks(workspace)
|
|
35
|
+
.then((newWorkbooks) => {
|
|
36
|
+
allWorkbooks.push(...newWorkbooks);
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
setLastError(
|
|
40
|
+
`Error listing workbooks: ${error.message}`,
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}),
|
|
44
|
+
).then(() => {
|
|
45
|
+
setWorkbooks(allWorkbooks);
|
|
46
|
+
setLastError(undefined);
|
|
52
47
|
});
|
|
48
|
+
});
|
|
53
49
|
}
|
|
54
|
-
}, [workbookStorage
|
|
50
|
+
}, [workbookStorage]);
|
|
55
51
|
|
|
56
52
|
return (
|
|
57
53
|
<>
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PackageContextProps } from "../Package";
|
|
2
1
|
import type { WorkbookLocator, WorkbookStorage } from "./WorkbookStorage";
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -40,21 +39,17 @@ export interface WorkbookCellValue {
|
|
|
40
39
|
export class WorkbookManager {
|
|
41
40
|
private isSaved: boolean;
|
|
42
41
|
private workbookStorage: WorkbookStorage;
|
|
43
|
-
private packageContext: PackageContextProps;
|
|
44
42
|
|
|
45
43
|
/**
|
|
46
44
|
* Creates a new WorkbookManager instance
|
|
47
45
|
* @param {WorkbookStorage} workbookStorage - Storage implementation
|
|
48
|
-
* @param {PackageContextProps} packageContext - Package context for storage
|
|
49
46
|
* @param {WorkbookData} workbookData - Initial workbook data
|
|
50
47
|
*/
|
|
51
48
|
constructor(
|
|
52
49
|
workbookStorage: WorkbookStorage,
|
|
53
|
-
packageContext: PackageContextProps,
|
|
54
50
|
private workbookData: WorkbookData,
|
|
55
51
|
) {
|
|
56
52
|
this.workbookStorage = workbookStorage;
|
|
57
|
-
this.packageContext = packageContext;
|
|
58
53
|
if (this.workbookData) {
|
|
59
54
|
this.isSaved = true;
|
|
60
55
|
} else {
|
|
@@ -92,7 +87,6 @@ export class WorkbookManager {
|
|
|
92
87
|
if (this.workbookData.workbookPath.path !== workbookPath) {
|
|
93
88
|
try {
|
|
94
89
|
await this.workbookStorage.moveWorkbook(
|
|
95
|
-
this.packageContext,
|
|
96
90
|
this.workbookData.workbookPath,
|
|
97
91
|
{
|
|
98
92
|
path: workbookPath,
|
|
@@ -154,17 +148,12 @@ export class WorkbookManager {
|
|
|
154
148
|
throw new Error("Workbook path is not set");
|
|
155
149
|
}
|
|
156
150
|
await this.workbookStorage.saveWorkbook(
|
|
157
|
-
this.packageContext,
|
|
158
151
|
this.workbookData.workbookPath,
|
|
159
152
|
JSON.stringify(this.workbookData),
|
|
160
153
|
);
|
|
161
154
|
this.isSaved = true;
|
|
162
155
|
}
|
|
163
|
-
return new WorkbookManager(
|
|
164
|
-
this.workbookStorage,
|
|
165
|
-
this.packageContext,
|
|
166
|
-
this.workbookData,
|
|
167
|
-
);
|
|
156
|
+
return new WorkbookManager(this.workbookStorage, this.workbookData);
|
|
168
157
|
}
|
|
169
158
|
|
|
170
159
|
/**
|
|
@@ -188,11 +177,8 @@ export class WorkbookManager {
|
|
|
188
177
|
.join("\n");
|
|
189
178
|
}
|
|
190
179
|
|
|
191
|
-
static newWorkbook(
|
|
192
|
-
workbookStorage
|
|
193
|
-
packageContext: PackageContextProps,
|
|
194
|
-
): WorkbookManager {
|
|
195
|
-
return new WorkbookManager(workbookStorage, packageContext, undefined);
|
|
180
|
+
static newWorkbook(workbookStorage: WorkbookStorage): WorkbookManager {
|
|
181
|
+
return new WorkbookManager(workbookStorage, undefined);
|
|
196
182
|
}
|
|
197
183
|
|
|
198
184
|
/**
|
|
@@ -204,16 +190,11 @@ export class WorkbookManager {
|
|
|
204
190
|
*/
|
|
205
191
|
static async loadWorkbook(
|
|
206
192
|
workbookStorage: WorkbookStorage,
|
|
207
|
-
packageContext: PackageContextProps,
|
|
208
193
|
workbookPath: WorkbookLocator,
|
|
209
194
|
): Promise<WorkbookManager> {
|
|
210
195
|
let workbookData: WorkbookData | undefined = undefined;
|
|
211
|
-
console.log("loadWorkbook", workbookPath);
|
|
212
196
|
try {
|
|
213
|
-
const saved = await workbookStorage.getWorkbook(
|
|
214
|
-
packageContext,
|
|
215
|
-
workbookPath,
|
|
216
|
-
);
|
|
197
|
+
const saved = await workbookStorage.getWorkbook(workbookPath);
|
|
217
198
|
if (saved) {
|
|
218
199
|
workbookData = JSON.parse(saved);
|
|
219
200
|
}
|
|
@@ -225,6 +206,6 @@ export class WorkbookManager {
|
|
|
225
206
|
workbookPath: workbookPath,
|
|
226
207
|
};
|
|
227
208
|
}
|
|
228
|
-
return new WorkbookManager(workbookStorage,
|
|
209
|
+
return new WorkbookManager(workbookStorage, workbookData);
|
|
229
210
|
}
|
|
230
211
|
}
|
|
@@ -13,42 +13,22 @@ export interface WorkbookLocator {
|
|
|
13
13
|
|
|
14
14
|
export interface WorkbookStorage {
|
|
15
15
|
// Lists all available workspaces for the context.
|
|
16
|
-
listWorkspaces(
|
|
17
|
-
context: PackageContextProps,
|
|
18
|
-
writeableOnly: boolean,
|
|
19
|
-
): Promise<Workspace[]>;
|
|
16
|
+
listWorkspaces(writeableOnly: boolean): Promise<Workspace[]>;
|
|
20
17
|
|
|
21
18
|
// Lists all available workbooks for the context.
|
|
22
19
|
// Workbooks names are like S3 paths- / denote hierarchical
|
|
23
20
|
// folders, but otherwise folders are not "real" objects
|
|
24
|
-
listWorkbooks(
|
|
25
|
-
workspace: Workspace,
|
|
26
|
-
context: PackageContextProps,
|
|
27
|
-
): Promise<WorkbookLocator[]>;
|
|
21
|
+
listWorkbooks(workspace: Workspace): Promise<WorkbookLocator[]>;
|
|
28
22
|
|
|
29
23
|
// Returns the workbook at the specific path, throws an exception if no such workbook exists (or cannot be accessed)
|
|
30
|
-
getWorkbook(
|
|
31
|
-
context: PackageContextProps,
|
|
32
|
-
path: WorkbookLocator,
|
|
33
|
-
): Promise<string>;
|
|
24
|
+
getWorkbook(path: WorkbookLocator): Promise<string>;
|
|
34
25
|
|
|
35
26
|
// Deletes the workbook at the specified path, or throws an
|
|
36
27
|
// Exception on failure
|
|
37
|
-
deleteWorkbook(
|
|
38
|
-
context: PackageContextProps,
|
|
39
|
-
path: WorkbookLocator,
|
|
40
|
-
): Promise<void>;
|
|
28
|
+
deleteWorkbook(path: WorkbookLocator): Promise<void>;
|
|
41
29
|
|
|
42
|
-
saveWorkbook(
|
|
43
|
-
context: PackageContextProps,
|
|
44
|
-
path: WorkbookLocator,
|
|
45
|
-
workbook: string,
|
|
46
|
-
): Promise<void>;
|
|
30
|
+
saveWorkbook(path: WorkbookLocator, workbook: string): Promise<void>;
|
|
47
31
|
|
|
48
32
|
// Moves workbook from the "from" path to the "to" path
|
|
49
|
-
moveWorkbook(
|
|
50
|
-
context: PackageContextProps,
|
|
51
|
-
from: WorkbookLocator,
|
|
52
|
-
to: WorkbookLocator,
|
|
53
|
-
): Promise<void>;
|
|
33
|
+
moveWorkbook(from: WorkbookLocator, to: WorkbookLocator): Promise<void>;
|
|
54
34
|
}
|