@malloy-publisher/sdk 0.3.1 → 0.4.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.
- package/README.md +33 -9
- package/dist/{DocumentStorageProvider-tGvodI8f.es.js → DocumentStorage-BiFqO15i.es.js} +7126 -6943
- package/dist/DocumentStorage-CMyLifsz.cjs.js +134 -0
- package/dist/RenderedResult-CZzE8wv-.cjs.js +115 -0
- package/dist/{RenderedResult-mDE-4u8S.es.js → RenderedResult-CvrmYyr5.es.js} +64 -57
- 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 +52 -52
- package/dist/builder/index.es.js +3961 -3960
- 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 +24 -7
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +12 -10
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +20 -2
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +21 -11
- package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +10 -1
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
- package/dist/components/DocumentStorage/index.d.ts +1 -0
- 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 +17431 -20676
- 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 +24 -5
- 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 +202 -171
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
- 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 +442 -94
- 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/DocumentStorage/BrowserDocumentStorage.ts +7 -6
- package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
- package/src/components/DocumentStorage/index.ts +1 -0
- 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 +184 -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/RenderedResult-CPi6uQWq.cjs.js +0 -115
- 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
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import AddIcon from "@mui/icons-material/Add";
|
|
5
5
|
import FilterListIcon from "@mui/icons-material/FilterList";
|
|
6
|
-
import {
|
|
6
|
+
import { Box, Chip, Stack, Tooltip, Typography } from "@mui/material";
|
|
7
7
|
import type { ReactNode } from "react";
|
|
8
|
+
import { SecondaryButton } from "../buttons";
|
|
8
9
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
9
10
|
import type { BuilderControl } from "./controls";
|
|
10
11
|
|
|
@@ -107,15 +108,15 @@ export function FilterStrip({
|
|
|
107
108
|
</Tooltip>
|
|
108
109
|
);
|
|
109
110
|
})}
|
|
110
|
-
<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
</
|
|
111
|
+
<Box sx={{ ml: "auto" }}>
|
|
112
|
+
<SecondaryButton
|
|
113
|
+
label="Filter"
|
|
114
|
+
icon={<AddIcon />}
|
|
115
|
+
onClick={() => onAdd()}
|
|
116
|
+
ariaLabel="Add filter"
|
|
117
|
+
ariaHasPopup="dialog"
|
|
118
|
+
/>
|
|
119
|
+
</Box>
|
|
119
120
|
</Stack>
|
|
120
121
|
|
|
121
122
|
{children}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { newDashboardSource, slugFor } from "./newDashboard";
|
|
6
|
+
import { openDocument } from "./testing/fixtures";
|
|
7
|
+
|
|
8
|
+
describe("a new dashboard", () => {
|
|
9
|
+
it("names its file after its title", () => {
|
|
10
|
+
expect(slugFor("Sales by Region")).toBe("sales-by-region");
|
|
11
|
+
expect(slugFor(" Q3 — West (draft) ")).toBe("q3-west-draft");
|
|
12
|
+
expect(slugFor("***")).toBe("");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("is a file the builder opens, with the picked view as its first tile", async () => {
|
|
16
|
+
const text = newDashboardSource({
|
|
17
|
+
title: 'Sales "West"',
|
|
18
|
+
modelPath: "models/storefront.malloy",
|
|
19
|
+
source: "order_items",
|
|
20
|
+
view: "by_category",
|
|
21
|
+
});
|
|
22
|
+
expect(text).toContain('title="Sales \\"West\\""');
|
|
23
|
+
expect(text).toContain(
|
|
24
|
+
'import { order_items } from "../models/storefront.malloy"',
|
|
25
|
+
);
|
|
26
|
+
const document = await openDocument(text);
|
|
27
|
+
expect(document.title).toBe('Sales "West"');
|
|
28
|
+
expect(document.sources).toEqual([
|
|
29
|
+
{ name: "order_items_tiles", base: "order_items" },
|
|
30
|
+
]);
|
|
31
|
+
expect(document.tiles.map((tile) => tile.name)).toEqual([
|
|
32
|
+
"by_category_tile",
|
|
33
|
+
]);
|
|
34
|
+
expect(document.tiles[0].declaration).toEqual({
|
|
35
|
+
kind: "reference",
|
|
36
|
+
from: "by_category",
|
|
37
|
+
});
|
|
38
|
+
expect(document.tiles[0].colspan).toBe(6);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A new dashboard file, the way the builder would have written it: the
|
|
6
|
+
* dashboard-declared-givens convention with no givens yet, one extension of
|
|
7
|
+
* the chosen source named the way the builder names one (`<source>_tiles`),
|
|
8
|
+
* and one tile on it — the reader needs a tile to lay out, and a first view
|
|
9
|
+
* is what the author picked anyway.
|
|
10
|
+
*/
|
|
11
|
+
export interface NewDashboard {
|
|
12
|
+
title: string;
|
|
13
|
+
/** The model that declares the source, relative to the package root. */
|
|
14
|
+
modelPath: string;
|
|
15
|
+
source: string;
|
|
16
|
+
view: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** `Sales by region` → `sales-by-region`: the file name, and so the slug. */
|
|
20
|
+
export function slugFor(title: string): string {
|
|
21
|
+
return title
|
|
22
|
+
.toLowerCase()
|
|
23
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
24
|
+
.replace(/^-+|-+$/g, "")
|
|
25
|
+
.slice(0, 80);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function newDashboardSource({
|
|
29
|
+
title,
|
|
30
|
+
modelPath,
|
|
31
|
+
source,
|
|
32
|
+
view,
|
|
33
|
+
}: NewDashboard): string {
|
|
34
|
+
const extension = `${source}_tiles`;
|
|
35
|
+
const tile = `${view}_tile`;
|
|
36
|
+
const quoted = `"${title.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
37
|
+
return [
|
|
38
|
+
"##! experimental.givens",
|
|
39
|
+
`## artifact { title=${quoted} tiles=["${extension} -> ${tile}"] } dashboard { columns=12 }`,
|
|
40
|
+
`import { ${source} } from "../${modelPath}"`,
|
|
41
|
+
"",
|
|
42
|
+
`source: ${extension} is ${source} extend {`,
|
|
43
|
+
" # colspan=6",
|
|
44
|
+
` view: ${tile} is ${view}`,
|
|
45
|
+
"}",
|
|
46
|
+
"",
|
|
47
|
+
].join("\n");
|
|
48
|
+
}
|
|
@@ -1106,3 +1106,56 @@ source: a is one extend {
|
|
|
1106
1106
|
);
|
|
1107
1107
|
});
|
|
1108
1108
|
});
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* A view name is unique within a source, not within a file. Two sources on one
|
|
1112
|
+
* dashboard may each declare the same view, and the writer has to patch the
|
|
1113
|
+
* one belonging to the tile it is editing.
|
|
1114
|
+
*/
|
|
1115
|
+
describe("spliceDashboardDocument: two sources, one view name", () => {
|
|
1116
|
+
const SHARED = `##! experimental.givens
|
|
1117
|
+
|
|
1118
|
+
## artifact { title="Shared" tiles=["a -> by_month", "b -> by_month"] } dashboard { columns=12 }
|
|
1119
|
+
import "../data_app.malloy"
|
|
1120
|
+
|
|
1121
|
+
source: a is scoped_orders extend {
|
|
1122
|
+
# colspan=6
|
|
1123
|
+
view: by_month is by_month_view
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
source: b is scoped_orders extend {
|
|
1127
|
+
# colspan=6
|
|
1128
|
+
view: by_month is by_month_view
|
|
1129
|
+
}`;
|
|
1130
|
+
|
|
1131
|
+
it("retags the second source's view without touching the first's", async () => {
|
|
1132
|
+
const out = await spliced(SHARED, (d) => {
|
|
1133
|
+
const tile = d.tiles.find((t) => t.source === "b");
|
|
1134
|
+
if (!tile) throw new Error("no tile on b");
|
|
1135
|
+
tile.label = "B by month";
|
|
1136
|
+
});
|
|
1137
|
+
// The label landed inside `source: b`, and `source: a` is byte-identical
|
|
1138
|
+
// to how it went in. Before the lookup was scoped to the source, the
|
|
1139
|
+
// file-wide search found `a`'s declaration first and retagged a tile the
|
|
1140
|
+
// author never touched.
|
|
1141
|
+
const a = out.slice(out.indexOf("source: a"), out.indexOf("source: b"));
|
|
1142
|
+
const b = out.slice(out.indexOf("source: b"));
|
|
1143
|
+
expect(a).not.toContain("B by month");
|
|
1144
|
+
expect(b).toContain('# label="B by month"');
|
|
1145
|
+
expect(a).toBe(
|
|
1146
|
+
SHARED.slice(SHARED.indexOf("source: a"), SHARED.indexOf("source: b")),
|
|
1147
|
+
);
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
it("edits the first source's view when that is the tile", async () => {
|
|
1151
|
+
const out = await spliced(SHARED, (d) => {
|
|
1152
|
+
const tile = d.tiles.find((t) => t.source === "a");
|
|
1153
|
+
if (!tile) throw new Error("no tile on a");
|
|
1154
|
+
tile.label = "A by month";
|
|
1155
|
+
});
|
|
1156
|
+
const a = out.slice(out.indexOf("source: a"), out.indexOf("source: b"));
|
|
1157
|
+
const b = out.slice(out.indexOf("source: b"));
|
|
1158
|
+
expect(a).toContain('# label="A by month"');
|
|
1159
|
+
expect(b).not.toContain("A by month");
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
@@ -222,6 +222,39 @@ function declarationEnd(lines: string[], line: number): number {
|
|
|
222
222
|
return lines.length - 1;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
/** A name as a regex literal: view and source names are identifiers, but the
|
|
226
|
+
* pattern is built from document data and should not be able to mean anything
|
|
227
|
+
* else. */
|
|
228
|
+
const literal = (name: string) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The line where `<source>` declares `view: <view>`, or -1.
|
|
232
|
+
*
|
|
233
|
+
* Scoped to that source's own `extend { … }` block, because a view name is
|
|
234
|
+
* only unique WITHIN a source: two sources in one dashboard may each declare
|
|
235
|
+
* `by_month`, and a file-wide search finds whichever comes first and then
|
|
236
|
+
* rewrites its tags — silently retagging a tile the author never touched.
|
|
237
|
+
*
|
|
238
|
+
* A source this file does not extend has nothing here to patch, so -1 is the
|
|
239
|
+
* honest answer; the caller refuses rather than reaching for another source's
|
|
240
|
+
* view. Tiles whose view lives on the model are `inherited` and never get
|
|
241
|
+
* this far.
|
|
242
|
+
*/
|
|
243
|
+
function viewDeclarationLine(
|
|
244
|
+
lines: string[],
|
|
245
|
+
sourceName: string,
|
|
246
|
+
viewName: string,
|
|
247
|
+
): number {
|
|
248
|
+
const sourceLine = lines.findIndex((line) =>
|
|
249
|
+
new RegExp(`\\bsource:\\s*${literal(sourceName)}\\s+is\\b`).test(line),
|
|
250
|
+
);
|
|
251
|
+
if (sourceLine < 0) return -1;
|
|
252
|
+
const end = declarationEnd(lines, sourceLine);
|
|
253
|
+
const wanted = new RegExp(`\\bview:\\s*${literal(viewName)}\\s+is\\b`);
|
|
254
|
+
for (let i = sourceLine; i <= end; i++) if (wanted.test(lines[i])) return i;
|
|
255
|
+
return -1;
|
|
256
|
+
}
|
|
257
|
+
|
|
225
258
|
/** `# drill { to=… given=… }`, one line, as the reader spells it back. */
|
|
226
259
|
function drillTagLine(drill: DashboardDrill): string {
|
|
227
260
|
const to =
|
|
@@ -238,12 +271,16 @@ const quoted = (text: string) =>
|
|
|
238
271
|
`"${text.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
239
272
|
|
|
240
273
|
/**
|
|
241
|
-
* One tile's identity, ignoring presentation and position — but
|
|
242
|
-
* declaration: a tile redeclared from another view is a different tile
|
|
243
|
-
* the file, removed and added, which `document.tileKey` does not say.
|
|
274
|
+
* One tile's identity TO THE FILE, ignoring presentation and position — but
|
|
275
|
+
* not its declaration: a tile redeclared from another view is a different tile
|
|
276
|
+
* to the file, removed and added, which `document.tileKey` does not say.
|
|
277
|
+
* `document.tileKey` is the grid's identity, which a drag names and React keys
|
|
278
|
+
* on; this one decides what gets written. Anything asking "will this save
|
|
279
|
+
* rewrite declarations?" wants THIS key.
|
|
244
280
|
*/
|
|
245
|
-
const
|
|
281
|
+
export const tileFileKey = (t: DashboardTile) =>
|
|
246
282
|
canonical([t.name, t.source, t.declaration]);
|
|
283
|
+
const tileKey = tileFileKey;
|
|
247
284
|
|
|
248
285
|
/** The tile list as identities, IN ORDER. Differs under a reorder. */
|
|
249
286
|
const tileIdentity = (document: DashboardDocument) =>
|
|
@@ -902,13 +939,13 @@ function planTilePresentation(ctx: SpliceContext): SpliceFailure | undefined {
|
|
|
902
939
|
};
|
|
903
940
|
}
|
|
904
941
|
|
|
905
|
-
const declLine = lines.
|
|
906
|
-
new RegExp(`view:\\s*${tile.name}\\s+is\\b`).test(l),
|
|
907
|
-
);
|
|
942
|
+
const declLine = viewDeclarationLine(lines, tile.source, tile.name);
|
|
908
943
|
if (declLine < 0) {
|
|
909
944
|
return {
|
|
910
945
|
ok: false,
|
|
911
|
-
reason:
|
|
946
|
+
reason:
|
|
947
|
+
`Could not find where \`${tile.name}\` is declared inside ` +
|
|
948
|
+
`\`${tile.source}\`.`,
|
|
912
949
|
};
|
|
913
950
|
}
|
|
914
951
|
|
|
@@ -253,3 +253,59 @@ describe("useDashboardEditor: saving", () => {
|
|
|
253
253
|
expect(view.result.current.error).toBeUndefined();
|
|
254
254
|
});
|
|
255
255
|
});
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* `structural` decides whether the builder shows the author a diff before it
|
|
259
|
+
* saves, so it has to mean what the WRITER means by a changed tile — not what
|
|
260
|
+
* the grid means.
|
|
261
|
+
*/
|
|
262
|
+
describe("useDashboardEditor: structural", () => {
|
|
263
|
+
it("is false for presentation and layout edits", async () => {
|
|
264
|
+
const view = await editor();
|
|
265
|
+
act(() => {
|
|
266
|
+
view.result.current.update((d) => {
|
|
267
|
+
d.tiles[0].label = "Categories";
|
|
268
|
+
d.tiles[0].colspan = 4;
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
expect(view.result.current.dirty).toBe(true);
|
|
272
|
+
expect(view.result.current.structural).toBe(false);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("is false for a reorder, which moves no declaration", async () => {
|
|
276
|
+
const view = await editor();
|
|
277
|
+
act(() => {
|
|
278
|
+
view.result.current.update((d) => {
|
|
279
|
+
d.tiles.reverse();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
expect(view.result.current.structural).toBe(false);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("is true when a tile is removed", async () => {
|
|
286
|
+
const view = await editor();
|
|
287
|
+
act(() => {
|
|
288
|
+
view.result.current.update((d) => {
|
|
289
|
+
d.tiles.pop();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
expect(view.result.current.structural).toBe(true);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("is true when a tile is redeclared, though the grid's key is unchanged", async () => {
|
|
296
|
+
// The regression: `document.tileKey` is `source.name`, which this edit
|
|
297
|
+
// leaves alone, so keying `structural` on it reported a save that
|
|
298
|
+
// rewrites the declaration as a plain presentation change — and the
|
|
299
|
+
// builder skipped the diff on exactly the edit that most needs one.
|
|
300
|
+
const view = await editor();
|
|
301
|
+
const before = view.result.current.document.tiles[0];
|
|
302
|
+
act(() => {
|
|
303
|
+
view.result.current.update((d) => {
|
|
304
|
+
d.tiles[0].declaration = { kind: "inline" };
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
const after = view.result.current.document.tiles[0];
|
|
308
|
+
expect([after.source, after.name]).toEqual([before.source, before.name]);
|
|
309
|
+
expect(view.result.current.structural).toBe(true);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { useCallback, useMemo, useState } from "react";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { type DashboardDocument } from "./document";
|
|
6
|
+
import {
|
|
7
|
+
spliceDashboardDocument,
|
|
8
|
+
spliceFailed,
|
|
9
|
+
tileFileKey,
|
|
10
|
+
} from "./spliceDocument";
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* The editor's state: the document being edited, its history, and saving.
|
|
@@ -162,8 +166,12 @@ export function useDashboardEditor(options: {
|
|
|
162
166
|
[document, saved],
|
|
163
167
|
);
|
|
164
168
|
const structural = useMemo(() => {
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
// The FILE's identity for a tile, not the grid's: `document.tileKey` is
|
|
170
|
+
// `source.name`, so a tile redeclared from another view keeps its key
|
|
171
|
+
// and a save that rewrites its declaration would not be reported as
|
|
172
|
+
// structural — the one case where the author most wants the diff.
|
|
173
|
+
const before = new Set(saved.tiles.map(tileFileKey));
|
|
174
|
+
const after = new Set(document.tiles.map(tileFileKey));
|
|
167
175
|
return (
|
|
168
176
|
[...before].some((k) => !after.has(k)) ||
|
|
169
177
|
[...after].some((k) => !before.has(k))
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import {
|
|
5
|
+
DocumentNotFoundError,
|
|
6
|
+
type DocumentLocator,
|
|
7
|
+
type DocumentStorage,
|
|
8
|
+
type DocumentType,
|
|
9
|
+
type Workspace,
|
|
9
10
|
} from "./DocumentStorage";
|
|
10
11
|
|
|
11
12
|
const LOCAL_WORKSPACE: Workspace = {
|
|
@@ -99,7 +100,7 @@ function locatorOf(key: string): DocumentLocator | undefined {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function missing(locator: DocumentLocator): Error {
|
|
102
|
-
return new
|
|
103
|
+
return new DocumentNotFoundError(
|
|
103
104
|
`No ${locator.type} at ${locator.workspace}/${locator.path}`,
|
|
104
105
|
);
|
|
105
106
|
}
|
|
@@ -19,10 +19,39 @@
|
|
|
19
19
|
* ask for one kind. Everything else a backend may know about a document, who
|
|
20
20
|
* changed it and when, who may see it, stays with the backend.
|
|
21
21
|
*
|
|
22
|
+
* A host hands the SDK ONE storage and keeps handing it the same one. What a
|
|
23
|
+
* storage says about its workspaces decides how the editor routes a save, and
|
|
24
|
+
* the editor asks once, when it opens; a host that re-creates its storage mid
|
|
25
|
+
* session leaves the editor routing by the old answer until the new list
|
|
26
|
+
* resolves.
|
|
27
|
+
*
|
|
22
28
|
* Every method rejects rather than returning a sentinel when the document is
|
|
23
|
-
* not there, so a caller can tell "missing" from "empty".
|
|
29
|
+
* not there, so a caller can tell "missing" from "empty". Absence rejects with
|
|
30
|
+
* a {@link DocumentNotFoundError} specifically, so a caller can tell either of
|
|
31
|
+
* those from a backend that could not be reached: a failed read answered with
|
|
32
|
+
* "there is no document" reads as "the package is the only copy", and saving
|
|
33
|
+
* on that belief overwrites the copy that was actually there.
|
|
24
34
|
*/
|
|
25
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Absence, and only absence: the document is not at that locator. Every other
|
|
38
|
+
* rejection means the backend could not answer, which is not the same thing and
|
|
39
|
+
* must not be treated as one.
|
|
40
|
+
*/
|
|
41
|
+
export class DocumentNotFoundError extends Error {
|
|
42
|
+
constructor(message: string) {
|
|
43
|
+
super(message);
|
|
44
|
+
// Not `instanceof`: the `es` and `cjs` builds carry their own copy of
|
|
45
|
+
// this class, so an error thrown by one fails the check in the other.
|
|
46
|
+
this.name = "DocumentNotFoundError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Whether a rejection means absence rather than a backend that could not answer. */
|
|
51
|
+
export const isDocumentNotFound = (error: unknown): boolean =>
|
|
52
|
+
error instanceof DocumentNotFoundError ||
|
|
53
|
+
(error instanceof Error && error.name === "DocumentNotFoundError");
|
|
54
|
+
|
|
26
55
|
/**
|
|
27
56
|
* The kinds of document the SDK authors. A `dashboard` is a
|
|
28
57
|
* `dashboards/<slug>.malloy` file; a `notebook` is a `.malloynb`.
|
|
@@ -34,7 +63,33 @@ export interface Workspace {
|
|
|
34
63
|
name: string;
|
|
35
64
|
/** False for a workspace this reader may list and open but not save into. */
|
|
36
65
|
writeable: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* What this place is, in the backend's own words, for the editor to show a
|
|
68
|
+
* reader rather than guessing on their behalf.
|
|
69
|
+
*/
|
|
37
70
|
description: string;
|
|
71
|
+
/**
|
|
72
|
+
* This workspace holds the package's system of record: what it keeps for a
|
|
73
|
+
* document IS that document, and the package file is a copy of it or a
|
|
74
|
+
* deploy behind it.
|
|
75
|
+
*
|
|
76
|
+
* Left out, the workspace is a place a reader's work is kept beside the
|
|
77
|
+
* package — the Console's browser copy, a scratch space — and the package
|
|
78
|
+
* file is the record.
|
|
79
|
+
*
|
|
80
|
+
* The contract, which the editor relies on and does not police:
|
|
81
|
+
*
|
|
82
|
+
* - At most one workspace of a storage declares itself authoritative. The
|
|
83
|
+
* editor takes the first it is given and does not arbitrate between two.
|
|
84
|
+
* - It is orthogonal to {@link Workspace.writeable} and to the server's
|
|
85
|
+
* `mutable`. A workspace can be the record and still be read-only to this
|
|
86
|
+
* reader, and a server that refuses writes to its own package says
|
|
87
|
+
* nothing about where the record lives.
|
|
88
|
+
* - A host whose authority differs per package mounts one storage per
|
|
89
|
+
* context rather than flipping this between renders; the editor reads it
|
|
90
|
+
* once, when it opens.
|
|
91
|
+
*/
|
|
92
|
+
authoritative?: boolean;
|
|
38
93
|
}
|
|
39
94
|
|
|
40
95
|
/** One document's address: which workspace, which kind, and its path there. */
|
|
@@ -59,15 +114,33 @@ export interface DocumentStorage {
|
|
|
59
114
|
type?: DocumentType,
|
|
60
115
|
): Promise<DocumentLocator[]>;
|
|
61
116
|
|
|
62
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* The document's content. Rejects with a {@link DocumentNotFoundError} when
|
|
119
|
+
* there is no document there, and with anything else when the backend could
|
|
120
|
+
* not be asked.
|
|
121
|
+
*/
|
|
63
122
|
getDocument(locator: DocumentLocator): Promise<string>;
|
|
64
123
|
|
|
65
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* Write the content, creating the document or replacing it.
|
|
126
|
+
*
|
|
127
|
+
* There is no expected-version slot, so this is last writer wins and a
|
|
128
|
+
* caller cannot tell that it overwrote someone. A backend that has to stop
|
|
129
|
+
* two authors clobbering each other enforces that itself, in the backend.
|
|
130
|
+
*/
|
|
66
131
|
saveDocument(locator: DocumentLocator, content: string): Promise<void>;
|
|
67
132
|
|
|
68
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Remove the document. Rejects with a {@link DocumentNotFoundError} when
|
|
135
|
+
* there is no document there, and with anything else when the backend could
|
|
136
|
+
* not be asked — a caller must not read the second as the first and report
|
|
137
|
+
* the document gone.
|
|
138
|
+
*/
|
|
69
139
|
deleteDocument(locator: DocumentLocator): Promise<void>;
|
|
70
140
|
|
|
71
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Rename or relocate a document, keeping its content. Rejects with a
|
|
143
|
+
* {@link DocumentNotFoundError} when `from` is missing.
|
|
144
|
+
*/
|
|
72
145
|
moveDocument(from: DocumentLocator, to: DocumentLocator): Promise<void>;
|
|
73
146
|
}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import { Box
|
|
4
|
+
import { Box } from "@mui/material";
|
|
5
5
|
import { useState } from "react";
|
|
6
6
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
7
7
|
import { parseResourceUri } from "../../utils/formatting";
|
|
8
8
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
9
9
|
import { Loading } from "../Loading";
|
|
10
|
+
import { PackageSection } from "../PackageSection";
|
|
10
11
|
import { Prose } from "../Prose";
|
|
12
|
+
import { SecondaryButton } from "../buttons";
|
|
11
13
|
import { useServer } from "../ServerProvider";
|
|
12
|
-
import {
|
|
13
|
-
PackageCard,
|
|
14
|
-
PackageCardContent,
|
|
15
|
-
PackageSectionTitle,
|
|
16
|
-
} from "../styles";
|
|
17
14
|
interface AboutProps {
|
|
18
15
|
resourceUri: string;
|
|
19
16
|
}
|
|
@@ -39,30 +36,19 @@ export default function About({ resourceUri }: AboutProps) {
|
|
|
39
36
|
<>
|
|
40
37
|
{!isSuccess && !isError && <Loading text="Fetching About..." />}
|
|
41
38
|
{isSuccess && readmeContent && (
|
|
42
|
-
<
|
|
43
|
-
<
|
|
44
|
-
|
|
39
|
+
<PackageSection title="Readme">
|
|
40
|
+
<Prose variant="caption">
|
|
41
|
+
{expanded || !shouldTruncate ? readmeContent : preview}
|
|
42
|
+
</Prose>
|
|
43
|
+
{shouldTruncate && (
|
|
45
44
|
<Box sx={{ mt: 1 }}>
|
|
46
|
-
<
|
|
47
|
-
{expanded
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{shouldTruncate && (
|
|
51
|
-
<Box sx={{ mt: 1 }}>
|
|
52
|
-
{" "}
|
|
53
|
-
{/* separate line */}
|
|
54
|
-
<Button
|
|
55
|
-
variant="text"
|
|
56
|
-
size="small"
|
|
57
|
-
onClick={() => setExpanded(!expanded)}
|
|
58
|
-
>
|
|
59
|
-
{expanded ? "Read less" : "Read more"}
|
|
60
|
-
</Button>
|
|
61
|
-
</Box>
|
|
62
|
-
)}
|
|
45
|
+
<SecondaryButton
|
|
46
|
+
label={expanded ? "Read less" : "Read more"}
|
|
47
|
+
onClick={() => setExpanded(!expanded)}
|
|
48
|
+
/>
|
|
63
49
|
</Box>
|
|
64
|
-
|
|
65
|
-
</
|
|
50
|
+
)}
|
|
51
|
+
</PackageSection>
|
|
66
52
|
)}
|
|
67
53
|
{isError && (
|
|
68
54
|
<ApiErrorDisplay
|