@malloy-publisher/sdk 0.3.1 → 0.4.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.
- package/README.md +14 -9
- package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorageProvider-CyOJ0hqf.es.js} +7114 -6939
- package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
- package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-BnPzJ9Jf.es.js} +64 -57
- package/dist/{RenderedResult-CPi6uQWq.cjs.js → RenderedResult-Dp22kZsQ.cjs.js} +2 -2
- package/dist/{ServerProvider-X2Ma0HRs.es.js → ServerProvider-BWOEKg0O.es.js} +1217 -1244
- package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
- package/dist/builder/index.cjs.js +41 -41
- package/dist/builder/index.es.js +2752 -2831
- package/dist/client/api.d.ts +100 -42
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/AppDialog.d.ts +30 -0
- package/dist/components/BackLink.d.ts +32 -0
- package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
- package/dist/components/Dashboard/telemetry.d.ts +10 -5
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +8 -2
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +8 -10
- package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
- package/dist/components/ItemRow.d.ts +38 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +1 -2
- package/dist/components/Materializations/MaterializationRunsList.d.ts +1 -5
- package/dist/components/Materializations/Materializations.d.ts +7 -3
- package/dist/components/Materializations/ScopeButton.d.ts +18 -0
- package/dist/components/Materializations/SectionLabel.d.ts +7 -4
- package/dist/components/Materializations/TriggerLabel.d.ts +14 -0
- package/dist/components/Materializations/index.d.ts +0 -1
- package/dist/components/Package/ContentTypeIcon.d.ts +3 -5
- package/dist/components/Package/NewDashboardDialog.d.ts +18 -0
- package/dist/components/Package/index.d.ts +0 -1
- package/dist/components/PackageSection.d.ts +23 -0
- package/dist/components/buttons.d.ts +53 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/styles.d.ts +49 -40
- package/dist/hooks/useCrudMutation.d.ts +42 -0
- package/dist/index.cjs.js +22 -26
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +17425 -20672
- package/dist/telemetry/consoleEvents.d.ts +60 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/AppDialog.tsx +115 -0
- package/src/components/BackLink.tsx +83 -0
- package/src/components/Connections/AddConnectionDialog.tsx +50 -70
- package/src/components/Connections/DeleteConnectionDialog.tsx +23 -50
- package/src/components/Connections/EditConnectionDialog.tsx +54 -73
- package/src/components/Dashboard/DashboardBar.tsx +88 -0
- package/src/components/Dashboard/telemetry.ts +10 -3
- package/src/components/DashboardBuilder/AddTileDialog.tsx +141 -143
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +110 -218
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +5 -11
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +184 -171
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +2 -25
- package/src/components/DashboardBuilder/DashboardEditor.tsx +135 -61
- package/src/components/DashboardBuilder/DiffDialog.tsx +75 -82
- package/src/components/DashboardBuilder/DrillDialog.tsx +144 -156
- package/src/components/DashboardBuilder/FilterDialog.tsx +276 -295
- package/src/components/DashboardBuilder/FilterStrip.tsx +11 -10
- package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
- package/src/components/DashboardBuilder/newDashboard.ts +48 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +53 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +45 -8
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +56 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +12 -4
- package/src/components/Environment/About.tsx +14 -28
- package/src/components/Environment/AddPackageDialog.tsx +85 -154
- package/src/components/Environment/Connections.tsx +125 -205
- package/src/components/Environment/DeletePackageDialog.tsx +32 -77
- package/src/components/Environment/EditPackageDialog.tsx +46 -58
- package/src/components/Environment/Environment.tsx +34 -36
- package/src/components/Environment/Packages.tsx +63 -128
- package/src/components/Home/AddEnvironmentDialog.tsx +47 -70
- package/src/components/Home/DeleteEnvironmentDialog.tsx +32 -77
- package/src/components/Home/EditEnvironmentDialog.tsx +47 -61
- package/src/components/Home/Home.tsx +101 -214
- package/src/components/ItemRow.tsx +165 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +34 -51
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +31 -53
- package/src/components/Materializations/MaterializationDetailDialog.tsx +60 -69
- package/src/components/Materializations/MaterializationRunsList.tsx +29 -42
- package/src/components/Materializations/Materializations.tsx +137 -140
- package/src/components/Materializations/ScopeButton.tsx +85 -0
- package/src/components/Materializations/SectionLabel.tsx +7 -4
- package/src/components/Materializations/SetScheduleDialog.tsx +48 -89
- package/src/components/Materializations/TriggerLabel.tsx +36 -0
- package/src/components/Materializations/cron.spec.ts +113 -0
- package/src/components/Materializations/index.ts +0 -1
- package/src/components/Materializations/utils.spec.ts +182 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +22 -37
- package/src/components/Package/ContentTypeIcon.tsx +10 -12
- package/src/components/Package/NewDashboardDialog.spec.tsx +129 -0
- package/src/components/Package/NewDashboardDialog.tsx +265 -0
- package/src/components/Package/Package.tsx +179 -238
- package/src/components/Package/index.ts +0 -1
- package/src/components/PackageSection.tsx +85 -0
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
- package/src/components/RenderedResult/RenderedResult.tsx +22 -8
- package/src/components/ResultsDialog.tsx +8 -32
- package/src/components/buttons.tsx +114 -0
- package/src/components/designSystem.spec.tsx +316 -0
- package/src/components/given/paramCodec.spec.ts +1 -1
- package/src/components/index.ts +10 -0
- package/src/components/styles.ts +49 -85
- package/src/hooks/useCrudMutation.spec.tsx +119 -0
- package/src/hooks/useCrudMutation.tsx +85 -0
- package/src/index.ts +9 -0
- package/src/telemetry/consoleEvents.spec.ts +130 -0
- package/src/telemetry/consoleEvents.ts +124 -0
- package/src/theme/defaults.ts +34 -23
- package/src/theme/resolveTheme.spec.ts +9 -4
- package/src/theme/resolveTheme.ts +12 -8
- package/src/utils/sha256.ts +13 -0
- package/test/README.md +1 -1
- package/test/serverProvider.tsx +5 -2
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +0 -134
- package/dist/ServerProvider-CH71GsoL.cjs.js +0 -1
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +0 -14
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +0 -7
- package/dist/components/Materializations/ScheduleCard.d.ts +0 -20
- package/dist/components/Materializations/TriggerChip.d.ts +0 -10
- package/dist/components/Package/Models.d.ts +0 -6
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +0 -179
- package/src/components/Materializations/EnvironmentMaterializations.tsx +0 -267
- package/src/components/Materializations/ScheduleCard.tsx +0 -231
- package/src/components/Materializations/TriggerChip.tsx +0 -44
- package/src/components/Package/Models.tsx +0 -71
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import CheckIcon from "@mui/icons-material/Check";
|
|
5
5
|
import { Alert, Box, Button, Stack, Typography } from "@mui/material";
|
|
6
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
6
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
8
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
8
9
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
type DocumentLocator,
|
|
15
16
|
} from "../DocumentStorage";
|
|
16
17
|
import { GivensPanel } from "../given";
|
|
18
|
+
import { SecondaryButton } from "../buttons";
|
|
19
|
+
import { DashboardBar } from "../Dashboard/DashboardBar";
|
|
17
20
|
import { Loading } from "../Loading";
|
|
18
21
|
import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
19
22
|
import { useServer } from "../ServerProvider";
|
|
@@ -22,7 +25,7 @@ import { DashboardBuilder } from "./DashboardBuilder";
|
|
|
22
25
|
import type { DashboardDocument } from "./document";
|
|
23
26
|
import { previewGivens, previewTileQuery } from "./preview";
|
|
24
27
|
import { readDashboardDocument, readFailed } from "./readDocument";
|
|
25
|
-
import {
|
|
28
|
+
import { sha256Hex } from "../../utils/sha256";
|
|
26
29
|
|
|
27
30
|
/**
|
|
28
31
|
* The builder, opened on a package dashboard, with everything a host has to
|
|
@@ -30,27 +33,25 @@ import { spliceDashboardDocument, spliceFailed } from "./spliceDocument";
|
|
|
30
33
|
* control row and live tiles that follow the document, a catalog for the
|
|
31
34
|
* filter window's field search, and saving.
|
|
32
35
|
*
|
|
33
|
-
* SAVING
|
|
34
|
-
*
|
|
35
|
-
* copy is
|
|
36
|
-
*
|
|
37
|
-
* That is the plan's copy-and-export model, and it needs no server write path.
|
|
38
|
-
* A host with no storage still gets the editor, without Save.
|
|
36
|
+
* SAVING goes to the package on a server that takes writes, and otherwise to
|
|
37
|
+
* the host's {@link DocumentStorage} — the Console's default is this browser,
|
|
38
|
+
* where the copy is offered back on the next visit. A host with neither still
|
|
39
|
+
* gets the editor, without Save.
|
|
39
40
|
*
|
|
40
41
|
* What that costs is stated in the toolbar: a control added here is live in the
|
|
41
42
|
* editor (its value is written into each tile's query) but reaches the package
|
|
42
|
-
* only when the
|
|
43
|
+
* only when the file is saved into it.
|
|
43
44
|
*/
|
|
44
45
|
export interface DashboardEditorProps {
|
|
45
46
|
environmentName: string;
|
|
46
47
|
packageName: string;
|
|
47
48
|
/** The dashboard's slug: `overview`, not `dashboards/overview.malloy`. */
|
|
48
49
|
dashboardName: string;
|
|
49
|
-
/** Leave the editor: the host's "Done". Absent, no
|
|
50
|
+
/** Leave the editor: the host's "Done editing". Absent, no such button. */
|
|
50
51
|
onExit?: () => void;
|
|
51
52
|
/**
|
|
52
|
-
* What the editor does — opened, saved,
|
|
53
|
-
*
|
|
53
|
+
* What the editor does — opened, saved, refused — for the host to log or
|
|
54
|
+
* count; see `DashboardEvent`.
|
|
54
55
|
*/
|
|
55
56
|
onEvent?: DashboardEventHandler;
|
|
56
57
|
}
|
|
@@ -74,7 +75,8 @@ export function DashboardEditor({
|
|
|
74
75
|
onExit,
|
|
75
76
|
onEvent,
|
|
76
77
|
}: DashboardEditorProps) {
|
|
77
|
-
const { apiClients } = useServer();
|
|
78
|
+
const { apiClients, mutable } = useServer();
|
|
79
|
+
const queryClient = useQueryClient();
|
|
78
80
|
// When the editor was asked for — or the reader chose what to open — so
|
|
79
81
|
// "opened" can say how long it took. Read through refs by the open effect,
|
|
80
82
|
// so a host's handler changing identity does not re-open the document.
|
|
@@ -98,6 +100,22 @@ export function DashboardEditor({
|
|
|
98
100
|
const packageText = (
|
|
99
101
|
modelQuery.data?.data as { sourceText?: string } | undefined
|
|
100
102
|
)?.sourceText;
|
|
103
|
+
// The hash of the package file as opened: what a save into the package
|
|
104
|
+
// hands back as `expectedHash`, so a copy someone else changed in the
|
|
105
|
+
// meantime is refused rather than overwritten.
|
|
106
|
+
const [packageHash, setPackageHash] = useState<string | undefined>(
|
|
107
|
+
undefined,
|
|
108
|
+
);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (packageText === undefined) return;
|
|
111
|
+
let stale = false;
|
|
112
|
+
void sha256Hex(packageText).then((hash) => {
|
|
113
|
+
if (!stale) setPackageHash(hash);
|
|
114
|
+
});
|
|
115
|
+
return () => {
|
|
116
|
+
stale = true;
|
|
117
|
+
};
|
|
118
|
+
}, [packageText]);
|
|
101
119
|
|
|
102
120
|
// The host's copy, if one was saved earlier: offered, never assumed.
|
|
103
121
|
const [workspace, setWorkspace] = useState<string | undefined>(undefined);
|
|
@@ -147,8 +165,12 @@ export function DashboardEditor({
|
|
|
147
165
|
| undefined
|
|
148
166
|
>(undefined);
|
|
149
167
|
const [openError, setOpenError] = useState<string | undefined>(undefined);
|
|
168
|
+
// The text the builder last saved into the package. When that text comes
|
|
169
|
+
// back from the server it is not a new document to open — the builder
|
|
170
|
+
// already holds it, with its history — so the open effect leaves it be.
|
|
171
|
+
const savedRef = useRef<string | undefined>(undefined);
|
|
150
172
|
useEffect(() => {
|
|
151
|
-
if (opening === undefined) return;
|
|
173
|
+
if (opening === undefined || opening === savedRef.current) return;
|
|
152
174
|
let stale = false;
|
|
153
175
|
void readDashboardDocument(opening).then((result) => {
|
|
154
176
|
if (stale) return;
|
|
@@ -178,27 +200,82 @@ export function DashboardEditor({
|
|
|
178
200
|
};
|
|
179
201
|
}, [opening]);
|
|
180
202
|
|
|
181
|
-
const
|
|
203
|
+
const locator =
|
|
204
|
+
workspace === undefined
|
|
205
|
+
? undefined
|
|
206
|
+
: dashboardLocator(workspace, environmentName, packageName, modelPath);
|
|
207
|
+
const saveToBrowser = useCallback(
|
|
182
208
|
async (source: string) => {
|
|
183
|
-
if (!storage ||
|
|
209
|
+
if (!storage || !locator)
|
|
184
210
|
throw new Error(
|
|
185
211
|
"This host keeps no documents, so there is nowhere to save.",
|
|
186
212
|
);
|
|
187
|
-
await storage.saveDocument(
|
|
188
|
-
|
|
189
|
-
|
|
213
|
+
await storage.saveDocument(locator, source);
|
|
214
|
+
setDraft(source);
|
|
215
|
+
// Saving without choosing is choosing the package file.
|
|
216
|
+
setResume((chosen) => chosen ?? false);
|
|
217
|
+
},
|
|
218
|
+
[storage, locator],
|
|
219
|
+
);
|
|
220
|
+
// Into the package itself, when the server takes writes: compile-checked,
|
|
221
|
+
// written atomically and reloaded there, refused if the file changed since
|
|
222
|
+
// it was opened. A browser draft of the same file is superseded by it.
|
|
223
|
+
const saveToPackage = useCallback(
|
|
224
|
+
async (source: string) => {
|
|
225
|
+
if (packageHash === undefined)
|
|
226
|
+
throw new Error("The package file is still loading; try again.");
|
|
227
|
+
let result;
|
|
228
|
+
try {
|
|
229
|
+
result = await apiClients.models.updateModelSource(
|
|
190
230
|
environmentName,
|
|
191
231
|
packageName,
|
|
192
232
|
modelPath,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
233
|
+
{ source, expectedHash: packageHash },
|
|
234
|
+
);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
throw new Error(apiErrorMessage(error));
|
|
237
|
+
}
|
|
238
|
+
savedRef.current = source;
|
|
239
|
+
setPackageHash(result.data.contentHash);
|
|
240
|
+
if (storage && locator) {
|
|
241
|
+
await storage.deleteDocument(locator).catch(() => undefined);
|
|
242
|
+
setDraft(undefined);
|
|
243
|
+
setOffered(false);
|
|
244
|
+
}
|
|
198
245
|
setResume((chosen) => chosen ?? false);
|
|
246
|
+
// The package changed: the file, the manifest the live view reads,
|
|
247
|
+
// the package's dashboards list, and the dashboard the reader sees.
|
|
248
|
+
await queryClient.invalidateQueries({
|
|
249
|
+
queryKey: [
|
|
250
|
+
"dashboard-editor-model",
|
|
251
|
+
environmentName,
|
|
252
|
+
packageName,
|
|
253
|
+
modelPath,
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
for (const key of [
|
|
257
|
+
"dashboard-editor-manifest",
|
|
258
|
+
"dashboards",
|
|
259
|
+
"dashboard",
|
|
260
|
+
])
|
|
261
|
+
void queryClient.invalidateQueries({ queryKey: [key] });
|
|
199
262
|
},
|
|
200
|
-
[
|
|
263
|
+
[
|
|
264
|
+
apiClients,
|
|
265
|
+
environmentName,
|
|
266
|
+
packageName,
|
|
267
|
+
modelPath,
|
|
268
|
+
packageHash,
|
|
269
|
+
storage,
|
|
270
|
+
locator,
|
|
271
|
+
queryClient,
|
|
272
|
+
],
|
|
201
273
|
);
|
|
274
|
+
const save = mutable
|
|
275
|
+
? saveToPackage
|
|
276
|
+
: storage && locator
|
|
277
|
+
? saveToBrowser
|
|
278
|
+
: undefined;
|
|
202
279
|
const choose = (resumeDraft: boolean) => {
|
|
203
280
|
startedAt.current = now();
|
|
204
281
|
setResume(resumeDraft);
|
|
@@ -212,7 +289,15 @@ export function DashboardEditor({
|
|
|
212
289
|
/>
|
|
213
290
|
);
|
|
214
291
|
if (!packageText || !draftChecked)
|
|
215
|
-
|
|
292
|
+
// The bar first, so the page it is opening into is already the right
|
|
293
|
+
// shape: the reader's view had a bar in this spot, and a spinner where
|
|
294
|
+
// the bar was made the switch look like a page reload.
|
|
295
|
+
return (
|
|
296
|
+
<Stack sx={{ gap: 2 }}>
|
|
297
|
+
<DashboardBar />
|
|
298
|
+
<Loading text="Opening the dashboard…" />
|
|
299
|
+
</Stack>
|
|
300
|
+
);
|
|
216
301
|
if (openError)
|
|
217
302
|
return (
|
|
218
303
|
<Alert severity="error" sx={{ m: 2 }}>
|
|
@@ -249,19 +334,24 @@ export function DashboardEditor({
|
|
|
249
334
|
modelPath={modelPath}
|
|
250
335
|
slug={dashboardName}
|
|
251
336
|
opened={opened}
|
|
252
|
-
onSave={
|
|
337
|
+
onSave={save}
|
|
338
|
+
savesTo={mutable ? "package" : "browser"}
|
|
253
339
|
{...(onEvent ? { onEvent } : {})}
|
|
254
340
|
toolbar={
|
|
255
341
|
onExit && (
|
|
256
|
-
<
|
|
257
|
-
Done
|
|
258
|
-
|
|
342
|
+
<SecondaryButton
|
|
343
|
+
label="Done editing"
|
|
344
|
+
icon={<CheckIcon />}
|
|
345
|
+
onClick={onExit}
|
|
346
|
+
/>
|
|
259
347
|
)
|
|
260
348
|
}
|
|
261
349
|
note={
|
|
262
|
-
|
|
263
|
-
? "
|
|
264
|
-
:
|
|
350
|
+
mutable
|
|
351
|
+
? "Save writes the file into the package."
|
|
352
|
+
: storage
|
|
353
|
+
? "Saved in this browser: this server does not take writes."
|
|
354
|
+
: "This server does not take writes."
|
|
265
355
|
}
|
|
266
356
|
/>
|
|
267
357
|
)}
|
|
@@ -288,6 +378,7 @@ function Surface({
|
|
|
288
378
|
opened,
|
|
289
379
|
onSave,
|
|
290
380
|
onEvent,
|
|
381
|
+
savesTo,
|
|
291
382
|
toolbar,
|
|
292
383
|
note,
|
|
293
384
|
}: {
|
|
@@ -298,6 +389,7 @@ function Surface({
|
|
|
298
389
|
opened: { source: string; document: DashboardDocument; generation: number };
|
|
299
390
|
onSave?: (source: string) => Promise<void>;
|
|
300
391
|
onEvent?: DashboardEventHandler;
|
|
392
|
+
savesTo: "package" | "browser";
|
|
301
393
|
toolbar: React.ReactNode;
|
|
302
394
|
note: string;
|
|
303
395
|
}) {
|
|
@@ -371,22 +463,6 @@ function Surface({
|
|
|
371
463
|
|
|
372
464
|
const [doc, setDoc] = useState(opened.document);
|
|
373
465
|
useEffect(() => setDoc(opened.document), [opened.document]);
|
|
374
|
-
// Export: the file a save would write for the document as it stands —
|
|
375
|
-
// spliced when asked for, so an edit costs nothing until then. Refused
|
|
376
|
-
// (which the builder has already reported), the file as opened goes out.
|
|
377
|
-
const exportFile = useCallback(async () => {
|
|
378
|
-
const result = await spliceDashboardDocument(opened.source, doc);
|
|
379
|
-
const text = spliceFailed(result) ? opened.source : result.source;
|
|
380
|
-
onEvent?.({ type: "dashboard.exported", bytes: text.length });
|
|
381
|
-
const blob = new Blob([text], { type: "text/plain;charset=utf-8" });
|
|
382
|
-
const url = URL.createObjectURL(blob);
|
|
383
|
-
const anchor = document.createElement("a");
|
|
384
|
-
anchor.href = url;
|
|
385
|
-
anchor.download = `${slug}.malloy`;
|
|
386
|
-
anchor.click();
|
|
387
|
-
URL.revokeObjectURL(url);
|
|
388
|
-
}, [opened.source, doc, slug, onEvent]);
|
|
389
|
-
|
|
390
466
|
const modelSpecs = useMemo(() => manifest?.givens ?? [], [manifest]);
|
|
391
467
|
const runnable = useMemo(
|
|
392
468
|
() =>
|
|
@@ -466,22 +542,12 @@ function Surface({
|
|
|
466
542
|
{...(catalog ? { catalog } : {})}
|
|
467
543
|
dashboards={otherDashboards}
|
|
468
544
|
{...(onEvent ? { onEvent } : {})}
|
|
469
|
-
toolbar={
|
|
470
|
-
<>
|
|
471
|
-
<Button
|
|
472
|
-
size="small"
|
|
473
|
-
startIcon={<DownloadIcon fontSize="small" />}
|
|
474
|
-
onClick={() => void exportFile()}
|
|
475
|
-
>
|
|
476
|
-
Export
|
|
477
|
-
</Button>
|
|
478
|
-
{toolbar}
|
|
479
|
-
</>
|
|
480
|
-
}
|
|
545
|
+
toolbar={toolbar}
|
|
481
546
|
controls={
|
|
482
547
|
isSuccess ? <GivensPanel {...panel} layout="bar" /> : undefined
|
|
483
548
|
}
|
|
484
549
|
{...(onSave ? { onSave } : {})}
|
|
550
|
+
savesTo={savesTo}
|
|
485
551
|
/>
|
|
486
552
|
<Box sx={{ px: 0.5 }}>
|
|
487
553
|
<Typography variant="caption" sx={{ opacity: 0.7 }}>
|
|
@@ -491,3 +557,11 @@ function Surface({
|
|
|
491
557
|
</Stack>
|
|
492
558
|
);
|
|
493
559
|
}
|
|
560
|
+
|
|
561
|
+
/** The server's own reason for a refused write, when it gave one. */
|
|
562
|
+
function apiErrorMessage(error: unknown): string {
|
|
563
|
+
const data = (error as { response?: { data?: { message?: string } } })
|
|
564
|
+
.response?.data;
|
|
565
|
+
if (data?.message) return data.message;
|
|
566
|
+
return error instanceof Error ? error.message : String(error);
|
|
567
|
+
}
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
Box,
|
|
6
|
-
Button,
|
|
7
|
-
Dialog,
|
|
8
|
-
DialogActions,
|
|
9
|
-
DialogContent,
|
|
10
|
-
DialogTitle,
|
|
11
|
-
Typography,
|
|
12
|
-
} from "@mui/material";
|
|
4
|
+
import { Box, Button } from "@mui/material";
|
|
13
5
|
import { useMemo } from "react";
|
|
14
6
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
15
7
|
import { foldUnchanged, lineDiff } from "./diff";
|
|
8
|
+
import { AppDialog } from "../AppDialog";
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* What a save will do to the file, before it does it.
|
|
@@ -43,14 +36,13 @@ export function DiffDialog({
|
|
|
43
36
|
const added = lines.filter((l) => l.kind === "add").length;
|
|
44
37
|
const removed = lines.filter((l) => l.kind === "del").length;
|
|
45
38
|
return (
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
>
|
|
39
|
+
<AppDialog
|
|
40
|
+
open={open}
|
|
41
|
+
onClose={onClose}
|
|
42
|
+
maxWidth="md"
|
|
43
|
+
title="Review the change to the file"
|
|
44
|
+
description={
|
|
45
|
+
<>
|
|
54
46
|
A tile was added or removed, which moves declarations. Lines the
|
|
55
47
|
builder does not own — comments, other Malloy — are left where
|
|
56
48
|
they were; check they still read right.{" "}
|
|
@@ -60,70 +52,71 @@ export function DiffDialog({
|
|
|
60
52
|
>
|
|
61
53
|
+{added} −{removed}
|
|
62
54
|
</Box>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
55
|
+
</>
|
|
56
|
+
}
|
|
57
|
+
actions={
|
|
58
|
+
<>
|
|
59
|
+
<Button onClick={onClose}>Keep editing</Button>
|
|
60
|
+
<Button variant="contained" onClick={onConfirm}>
|
|
61
|
+
Save this
|
|
62
|
+
</Button>
|
|
63
|
+
</>
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
<Box
|
|
67
|
+
component="pre"
|
|
68
|
+
aria-label="File changes"
|
|
69
|
+
sx={{
|
|
70
|
+
m: 0,
|
|
71
|
+
px: 2,
|
|
72
|
+
py: 1,
|
|
73
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
74
|
+
fontSize: 12,
|
|
75
|
+
lineHeight: 1.6,
|
|
76
|
+
overflowX: "auto",
|
|
77
|
+
bgcolor: theme.background,
|
|
78
|
+
color: theme.foreground,
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
{lines.map((line, index) =>
|
|
82
|
+
line.kind === "fold" ? (
|
|
83
|
+
<Box
|
|
84
|
+
key={index}
|
|
85
|
+
component="span"
|
|
86
|
+
sx={{ display: "block", opacity: 0.55, py: 0.25 }}
|
|
87
|
+
>
|
|
88
|
+
{`⋯ ${line.count} unchanged line${line.count === 1 ? "" : "s"}`}
|
|
89
|
+
</Box>
|
|
90
|
+
) : (
|
|
91
|
+
<Box
|
|
92
|
+
key={index}
|
|
93
|
+
component="span"
|
|
94
|
+
sx={{
|
|
95
|
+
display: "block",
|
|
96
|
+
mx: -2,
|
|
97
|
+
px: 2,
|
|
98
|
+
whiteSpace: "pre",
|
|
99
|
+
bgcolor:
|
|
100
|
+
line.kind === "add"
|
|
101
|
+
? "rgba(46, 125, 91, 0.16)"
|
|
102
|
+
: line.kind === "del"
|
|
103
|
+
? "rgba(168, 41, 31, 0.14)"
|
|
104
|
+
: "transparent",
|
|
105
|
+
textDecoration:
|
|
106
|
+
line.kind === "del" ? "line-through" : "none",
|
|
107
|
+
opacity: line.kind === "del" ? 0.8 : 1,
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
{line.kind === "add"
|
|
111
|
+
? "+ "
|
|
112
|
+
: line.kind === "del"
|
|
113
|
+
? "− "
|
|
114
|
+
: " "}
|
|
115
|
+
{line.text}
|
|
116
|
+
</Box>
|
|
117
|
+
),
|
|
118
|
+
)}
|
|
119
|
+
</Box>
|
|
120
|
+
</AppDialog>
|
|
128
121
|
);
|
|
129
122
|
}
|