@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
|
@@ -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,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
|