@malloy-publisher/sdk 0.9.2 → 0.9.4
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/{RenderedResult-CBLHr32C.es.js → RenderedResult-DwB0-9Yx.es.js} +118 -119
- package/dist/{RenderedResult-B48wAjM8.cjs.js → RenderedResult-hKjFEqaN.cjs.js} +2 -2
- package/dist/{ServerProvider-DCV8BUWD.es.js → ServerProvider-CcSrGaRN.es.js} +1281 -1142
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +112 -115
- package/dist/builder/index.es.js +11766 -11502
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +170 -9
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +93 -89
- package/dist/client-entry.d.ts +2 -0
- package/dist/components/ApiErrorDisplay.d.ts +11 -0
- package/dist/components/AppDialog.d.ts +6 -6
- package/dist/components/Dashboard/DashboardGrid.d.ts +18 -3
- package/dist/components/Dashboard/DashboardTile.d.ts +12 -2
- package/dist/components/Dashboard/DashboardView.d.ts +38 -3
- package/dist/components/Dashboard/TileCard.d.ts +16 -2
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +3 -2
- package/dist/components/Dashboard/telemetry.d.ts +2 -1
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +7 -8
- package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
- package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
- package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +14 -17
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +3 -1
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +15 -7
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +28 -2
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +6 -4
- package/dist/components/DashboardBuilder/InlineText.d.ts +1 -1
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +4 -1
- package/dist/components/DashboardBuilder/TileFrame.d.ts +43 -6
- package/dist/components/DashboardBuilder/TileMenu.d.ts +6 -8
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +0 -18
- package/dist/components/DashboardBuilder/documentSession.d.ts +2 -2
- package/dist/components/DashboardBuilder/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +3 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +1 -1
- package/dist/components/DashboardBuilder/sortable.d.ts +2 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +2 -0
- package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
- package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
- package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +4 -7
- package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
- package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +2 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
- package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
- package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
- package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +32 -0
- package/dist/components/Loading.d.ts +13 -0
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/Package.d.ts +16 -1
- package/dist/components/Package/index.d.ts +1 -1
- package/dist/components/Prose.d.ts +1 -1
- package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
- package/dist/components/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +1 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +14 -14
- package/dist/index.es.js +9760 -10363
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-CbbBcZl8.es.js → text-entry-CA0LZ1xL.es.js} +8 -8
- package/dist/text-entry.d.ts +1 -1
- package/dist/theme/accent.d.ts +29 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/keys.d.ts +1 -1
- package/dist/theme/motion.d.ts +31 -0
- package/dist/theme/readChartAnnotations.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +4 -4
- package/dist/theme/types.d.ts +33 -5
- package/dist/{DashboardTile-BFcxdv7R.es.js → useCompiledDocument-BU6d8FPp.es.js} +6978 -6289
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/package.json +11 -11
- package/src/builder-entry.ts +1 -0
- package/src/client-entry.ts +8 -0
- package/src/clientEntry.spec.ts +17 -0
- package/src/components/ApiErrorDisplay.tsx +37 -18
- package/src/components/AppDialog.tsx +8 -7
- package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
- package/src/components/Dashboard/Dashboard.tsx +2 -2
- package/src/components/Dashboard/DashboardGrid.tsx +23 -5
- package/src/components/Dashboard/DashboardTile.spec.tsx +97 -2
- package/src/components/Dashboard/DashboardTile.tsx +95 -31
- package/src/components/Dashboard/DashboardView.spec.tsx +156 -0
- package/src/components/Dashboard/DashboardView.tsx +165 -89
- package/src/components/Dashboard/RowsDialog.tsx +3 -2
- package/src/components/Dashboard/TileCard.tsx +17 -2
- package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +11 -2
- package/src/components/Dashboard/telemetry.ts +2 -1
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +16 -56
- package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
- package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
- package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +86 -113
- package/src/components/DashboardBuilder/ChartPicker.tsx +4 -1
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +5 -5
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +74 -83
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +62 -18
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +55 -108
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +10 -62
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +50 -57
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +53 -40
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +10 -8
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +227 -704
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +32 -52
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +1 -50
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +12 -18
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +4 -24
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +4 -4
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +8 -13
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +142 -820
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +13 -8
- package/src/components/DashboardBuilder/FilterStrip.tsx +117 -79
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +7 -9
- package/src/components/DashboardBuilder/InlineText.tsx +23 -17
- package/src/components/DashboardBuilder/NotebookEditor.tsx +3 -3
- package/src/components/DashboardBuilder/TextTileBody.tsx +5 -2
- package/src/components/DashboardBuilder/TileFrame.tsx +255 -90
- package/src/components/DashboardBuilder/TileMenu.tsx +41 -91
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +1 -1
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +9 -4
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +0 -44
- package/src/components/DashboardBuilder/catalog.ts +0 -36
- package/src/components/DashboardBuilder/controls.spec.ts +1 -1
- package/src/components/DashboardBuilder/controls.ts +1 -1
- package/src/components/DashboardBuilder/documentSession.ts +3 -2
- package/src/components/DashboardBuilder/imports.spec.ts +61 -0
- package/src/components/DashboardBuilder/imports.ts +93 -0
- package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1 -1
- package/src/components/DashboardBuilder/malloyTree.ts +5 -1
- package/src/components/DashboardBuilder/newDashboard.ts +1 -1
- package/src/components/DashboardBuilder/preview.ts +1 -1
- package/src/components/DashboardBuilder/readDocument.spec.ts +36 -0
- package/src/components/DashboardBuilder/readDocument.ts +10 -4
- package/src/components/DashboardBuilder/readForEditor.ts +7 -2
- package/src/components/DashboardBuilder/sortable.spec.ts +25 -1
- package/src/components/DashboardBuilder/sortable.tsx +11 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +8 -3
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +62 -6
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/inline.ts +1 -1
- package/src/components/DashboardBuilder/testing/resize.ts +48 -0
- package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +43 -1
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +0 -85
- package/src/components/DashboardBuilder/useBuilderSession.ts +6 -43
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +32 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +11 -1
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +5 -2
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
- package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
- package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
- package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
- package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +146 -0
- package/src/components/DashboardBuilder/useTileResize.ts +133 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- package/src/components/DocumentCreate/guards.ts +1 -1
- package/src/components/Environment/Environment.tsx +0 -10
- package/src/components/Loading.tsx +14 -0
- package/src/components/Model/Model.tsx +16 -9
- package/src/components/Model/ModelExplorer.tsx +2 -2
- package/src/components/Notebook/Notebook.tsx +6 -2
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- package/src/components/Package/Package.artifacts.spec.tsx +8 -12
- package/src/components/Package/Package.create.spec.tsx +22 -1
- package/src/components/Package/Package.tsx +51 -27
- package/src/components/Package/index.ts +1 -1
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +5 -7
- package/src/components/RenderedResult/ResultContainer.tsx +7 -2
- package/src/components/RenderedResult/ResultPanel.tsx +20 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -0
- package/src/components/given/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.tsx +2 -8
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +1 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useCompiledDocument.spec.tsx +86 -0
- package/src/hooks/useCompiledDocument.ts +59 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
- package/src/hooks/useDocumentControls.ts +13 -1
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +7 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/text-entry.ts +1 -1
- package/src/textEntry.spec.ts +2 -8
- package/src/theme/accent.spec.ts +116 -0
- package/src/theme/accent.ts +148 -0
- package/src/theme/buildTableCssVars.spec.ts +24 -0
- package/src/theme/buildTableCssVars.ts +1 -2
- package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
- package/src/theme/buildVegaThemeOverride.ts +5 -5
- package/src/theme/defaults.ts +34 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/keys.ts +6 -0
- package/src/theme/motion.ts +44 -0
- package/src/theme/readChartAnnotations.spec.ts +18 -0
- package/src/theme/readChartAnnotations.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +73 -0
- package/src/theme/resolveTheme.ts +61 -20
- package/src/theme/types.ts +30 -5
- package/src/utils/queryClient.ts +8 -0
- package/dist/DashboardTile-sg8LjUk8.cjs.js +0 -137
- package/dist/ServerProvider-HRqT3w1C.cjs.js +0 -1
- package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -7
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +0 -27
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -32
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +0 -194
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +0 -25
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -103
- package/src/components/DashboardBuilder/SaveNotice.tsx +0 -113
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +0 -87
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -326
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- /package/dist/{components/DashboardBuilder → utils}/malloyText.d.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +0 -0
- /package/src/{components/DashboardBuilder → utils}/malloyText.ts +0 -0
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
act,
|
|
6
|
-
cleanup,
|
|
7
|
-
fireEvent,
|
|
8
|
-
render,
|
|
9
|
-
screen,
|
|
10
|
-
waitFor,
|
|
11
|
-
within,
|
|
12
|
-
} from "@testing-library/react";
|
|
13
|
-
import { afterEach, describe, expect, it, mock } from "bun:test";
|
|
14
|
-
import { DashboardBuilder } from "./DashboardBuilder";
|
|
15
|
-
import type { SaveContext } from "./useDocumentEditor";
|
|
16
|
-
import { openDocument } from "./testing/fixtures";
|
|
17
|
-
import { editInline } from "./testing/inline";
|
|
18
|
-
|
|
19
|
-
const SOURCE = `## artifact { title="Storefront" tiles=["a -> by_cat", "a -> by_brand"] } dashboard { columns=12 }
|
|
20
|
-
import "../data_app.malloy"
|
|
21
|
-
|
|
22
|
-
source: a is scoped_orders extend {
|
|
23
|
-
# colspan=6
|
|
24
|
-
# label="By category"
|
|
25
|
-
view: by_cat is by_category
|
|
26
|
-
|
|
27
|
-
# colspan=6
|
|
28
|
-
view: by_brand is by_brand_view
|
|
29
|
-
}`;
|
|
30
|
-
|
|
31
|
-
type Write = { source: string; context: SaveContext<unknown> };
|
|
32
|
-
|
|
33
|
-
const mount = async (
|
|
34
|
-
onSave: (source: string, context: SaveContext<unknown>) => Promise<void>,
|
|
35
|
-
) => {
|
|
36
|
-
const document = await openDocument(SOURCE);
|
|
37
|
-
return render(
|
|
38
|
-
<DashboardBuilder source={SOURCE} document={document} onSave={onSave} />,
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const writes: Write[] = [];
|
|
43
|
-
const recording = (fail?: () => Error | undefined) =>
|
|
44
|
-
mock(async (source: string, context: SaveContext<unknown>) => {
|
|
45
|
-
if (context.purpose === "undo") {
|
|
46
|
-
const failure = fail?.();
|
|
47
|
-
if (failure) throw failure;
|
|
48
|
-
}
|
|
49
|
-
writes.push({ source, context });
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const button = (name: string) =>
|
|
53
|
-
screen.getByRole("button", { name, hidden: true });
|
|
54
|
-
const noButton = (name: string) =>
|
|
55
|
-
screen.queryByRole("button", { name, hidden: true });
|
|
56
|
-
|
|
57
|
-
const retitle = (next: string) => {
|
|
58
|
-
editInline("By category", "Tile title", next);
|
|
59
|
-
};
|
|
60
|
-
const removeTile = () => {
|
|
61
|
-
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
62
|
-
fireEvent.click(screen.getByRole("button", { name: "Remove tile" }));
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/** The notice, which is the status region that offers Undo save. */
|
|
66
|
-
const notice = async () =>
|
|
67
|
-
(
|
|
68
|
-
await screen.findByRole("button", { name: "Undo save", hidden: true })
|
|
69
|
-
).closest('[role="status"]') as HTMLElement;
|
|
70
|
-
|
|
71
|
-
const press = (key: string, init: KeyboardEventInit = {}) =>
|
|
72
|
-
fireEvent.keyDown(window, { key, ctrlKey: true, metaKey: true, ...init });
|
|
73
|
-
|
|
74
|
-
afterEach(() => {
|
|
75
|
-
cleanup();
|
|
76
|
-
writes.length = 0;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("the save notice", () => {
|
|
80
|
-
it("appears after a save with what moved, View change and Undo save", async () => {
|
|
81
|
-
await mount(recording());
|
|
82
|
-
removeTile();
|
|
83
|
-
fireEvent.click(button("Save changes"));
|
|
84
|
-
const region = await notice();
|
|
85
|
-
expect(region.textContent).toContain("Removed 1 tile");
|
|
86
|
-
within(region).getByRole("button", { name: "View change", hidden: true });
|
|
87
|
-
// The toolbar's own Undo keeps its name; the notice never says a bare "Undo".
|
|
88
|
-
expect(
|
|
89
|
-
within(region).queryByRole("button", { name: "Undo", hidden: true }),
|
|
90
|
-
).toBeNull();
|
|
91
|
-
expect(writes).toHaveLength(1);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("withdraws on the first edit after the save", async () => {
|
|
95
|
-
await mount(recording());
|
|
96
|
-
retitle("Renamed");
|
|
97
|
-
fireEvent.click(button("Save changes"));
|
|
98
|
-
await notice();
|
|
99
|
-
editInline("Renamed", "Tile title", "Again");
|
|
100
|
-
await waitFor(() => expect(noButton("Undo save")).toBeNull());
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("stays through Escape, and Cmd-Z steps the editor back without writing the file", async () => {
|
|
104
|
-
await mount(recording());
|
|
105
|
-
retitle("Renamed");
|
|
106
|
-
fireEvent.click(button("Save changes"));
|
|
107
|
-
await notice();
|
|
108
|
-
|
|
109
|
-
fireEvent.keyDown(window, { key: "Escape" });
|
|
110
|
-
expect(noButton("Undo save")).not.toBeNull();
|
|
111
|
-
expect(writes).toHaveLength(1);
|
|
112
|
-
|
|
113
|
-
press("z");
|
|
114
|
-
// The shortcut is the editor's undo: it withdraws the offer, and never undoes the save.
|
|
115
|
-
await waitFor(() => expect(noButton("Undo save")).toBeNull());
|
|
116
|
-
expect(writes).toHaveLength(1);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("opens View change as a read-only viewer and pauses the shortcuts under it", async () => {
|
|
120
|
-
await mount(recording());
|
|
121
|
-
retitle("Renamed");
|
|
122
|
-
fireEvent.click(button("Save changes"));
|
|
123
|
-
await notice();
|
|
124
|
-
fireEvent.click(button("View change"));
|
|
125
|
-
const diff = (await screen.findByLabelText("File changes")).closest(
|
|
126
|
-
'[role="dialog"]',
|
|
127
|
-
) as HTMLElement;
|
|
128
|
-
expect(diff.textContent).toContain("Renamed");
|
|
129
|
-
expect(
|
|
130
|
-
within(diff).queryByRole("button", {
|
|
131
|
-
name: "Save this",
|
|
132
|
-
hidden: true,
|
|
133
|
-
}),
|
|
134
|
-
).toBeNull();
|
|
135
|
-
expect(
|
|
136
|
-
within(diff).queryByRole("button", {
|
|
137
|
-
name: "Keep editing",
|
|
138
|
-
hidden: true,
|
|
139
|
-
}),
|
|
140
|
-
).toBeNull();
|
|
141
|
-
|
|
142
|
-
press("z");
|
|
143
|
-
expect(noButton("Undo save")).not.toBeNull();
|
|
144
|
-
|
|
145
|
-
fireEvent.click(
|
|
146
|
-
within(diff).getByRole("button", { name: "Close", hidden: true }),
|
|
147
|
-
);
|
|
148
|
-
press("z");
|
|
149
|
-
await waitFor(() => expect(noButton("Undo save")).toBeNull());
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("Undo save writes the file back, restores the unsaved edit with its history, and says so", async () => {
|
|
153
|
-
await mount(recording());
|
|
154
|
-
retitle("Renamed");
|
|
155
|
-
fireEvent.click(button("Save changes"));
|
|
156
|
-
fireEvent.click(
|
|
157
|
-
await screen.findByRole("button", { name: "Undo save", hidden: true }),
|
|
158
|
-
);
|
|
159
|
-
await waitFor(() => expect(writes).toHaveLength(2));
|
|
160
|
-
expect(writes[1].source).toBe(SOURCE);
|
|
161
|
-
expect(writes[1].context.purpose).toBe("undo");
|
|
162
|
-
|
|
163
|
-
const status = await screen.findByText(
|
|
164
|
-
"Save undone. Your edits are back and unsaved.",
|
|
165
|
-
);
|
|
166
|
-
expect(status.closest('[role="status"]')).not.toBeNull();
|
|
167
|
-
expect(noButton("Undo save")).toBeNull();
|
|
168
|
-
// Dirty again, with the edit still on screen and its undo step intact.
|
|
169
|
-
await waitFor(() => expect(button("Save changes")).toBeDefined());
|
|
170
|
-
expect(screen.getByLabelText("Settings for Renamed")).toBeDefined();
|
|
171
|
-
expect(button("Undo").hasAttribute("disabled")).toBe(false);
|
|
172
|
-
await waitFor(() =>
|
|
173
|
-
expect(document.activeElement).toBe(button("Save changes")),
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
fireEvent.click(button("Undo"));
|
|
177
|
-
expect(screen.getByLabelText("Settings for By category")).toBeDefined();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it("keeps the notice and shows the failure when the undo is refused", async () => {
|
|
181
|
-
await mount(recording(() => new Error("the file changed")));
|
|
182
|
-
retitle("Renamed");
|
|
183
|
-
fireEvent.click(button("Save changes"));
|
|
184
|
-
fireEvent.click(
|
|
185
|
-
await screen.findByRole("button", { name: "Undo save", hidden: true }),
|
|
186
|
-
);
|
|
187
|
-
expect(
|
|
188
|
-
await screen.findByText(/Could not undo the save: the file changed/),
|
|
189
|
-
).toBeDefined();
|
|
190
|
-
expect(noButton("Undo save")).not.toBeNull();
|
|
191
|
-
expect(writes).toHaveLength(1);
|
|
192
|
-
await act(async () => {});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { render, screen } from "@testing-library/react";
|
|
5
|
-
import { describe, expect, it } from "bun:test";
|
|
6
|
-
import { DiffDialog } from "./DiffDialog";
|
|
7
|
-
|
|
8
|
-
describe("DiffDialog", () => {
|
|
9
|
-
it("marks a removed line with its sign and no strikethrough", () => {
|
|
10
|
-
render(
|
|
11
|
-
<DiffDialog
|
|
12
|
-
open
|
|
13
|
-
before={"keep\nold line\n"}
|
|
14
|
-
after={"keep\nnew line\n"}
|
|
15
|
-
onClose={() => {}}
|
|
16
|
-
/>,
|
|
17
|
-
);
|
|
18
|
-
const removed = screen.getByText(/old line/);
|
|
19
|
-
expect(removed.textContent).toContain("− old line");
|
|
20
|
-
expect(getComputedStyle(removed).textDecorationLine).not.toBe(
|
|
21
|
-
"line-through",
|
|
22
|
-
);
|
|
23
|
-
expect(screen.getByText(/new line/).textContent).toContain("+ new line");
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { Box, Button } from "@mui/material";
|
|
5
|
-
import { useMemo } from "react";
|
|
6
|
-
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
7
|
-
import { foldUnchanged, lineDiff } from "./diff";
|
|
8
|
-
import { AppDialog } from "../AppDialog";
|
|
9
|
-
|
|
10
|
-
/** What the last save changed in the file, read-only: the file is git-native, and a diff is the idiom its authors already read. */
|
|
11
|
-
export function DiffDialog({
|
|
12
|
-
open,
|
|
13
|
-
before,
|
|
14
|
-
after,
|
|
15
|
-
onClose,
|
|
16
|
-
}: {
|
|
17
|
-
open: boolean;
|
|
18
|
-
before: string;
|
|
19
|
-
after: string;
|
|
20
|
-
onClose: () => void;
|
|
21
|
-
}) {
|
|
22
|
-
const { theme } = usePublisherTheme();
|
|
23
|
-
const lines = useMemo(
|
|
24
|
-
() => (open ? foldUnchanged(lineDiff(before, after)) : []),
|
|
25
|
-
[open, before, after],
|
|
26
|
-
);
|
|
27
|
-
const added = lines.filter((l) => l.kind === "add").length;
|
|
28
|
-
const removed = lines.filter((l) => l.kind === "del").length;
|
|
29
|
-
return (
|
|
30
|
-
<AppDialog
|
|
31
|
-
open={open}
|
|
32
|
-
onClose={onClose}
|
|
33
|
-
maxWidth="md"
|
|
34
|
-
title="The change to the file"
|
|
35
|
-
description={
|
|
36
|
-
<>
|
|
37
|
-
What the last save wrote. Lines the builder does not own, such as
|
|
38
|
-
comments and other Malloy, are left where they were.{" "}
|
|
39
|
-
<Box
|
|
40
|
-
component="span"
|
|
41
|
-
sx={{ fontVariantNumeric: "tabular-nums" }}
|
|
42
|
-
>
|
|
43
|
-
+{added} −{removed}
|
|
44
|
-
</Box>
|
|
45
|
-
</>
|
|
46
|
-
}
|
|
47
|
-
actions={<Button onClick={onClose}>Close</Button>}
|
|
48
|
-
>
|
|
49
|
-
<Box
|
|
50
|
-
component="pre"
|
|
51
|
-
aria-label="File changes"
|
|
52
|
-
sx={{
|
|
53
|
-
m: 0,
|
|
54
|
-
px: 2,
|
|
55
|
-
py: 1,
|
|
56
|
-
fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
57
|
-
fontSize: 12,
|
|
58
|
-
lineHeight: 1.6,
|
|
59
|
-
overflowX: "auto",
|
|
60
|
-
bgcolor: theme.background,
|
|
61
|
-
color: theme.foreground,
|
|
62
|
-
}}
|
|
63
|
-
>
|
|
64
|
-
{lines.map((line, index) =>
|
|
65
|
-
line.kind === "fold" ? (
|
|
66
|
-
<Box
|
|
67
|
-
key={index}
|
|
68
|
-
component="span"
|
|
69
|
-
sx={{ display: "block", opacity: 0.55, py: 0.25 }}
|
|
70
|
-
>
|
|
71
|
-
{`⋯ ${line.count} unchanged line${line.count === 1 ? "" : "s"}`}
|
|
72
|
-
</Box>
|
|
73
|
-
) : (
|
|
74
|
-
<Box
|
|
75
|
-
key={index}
|
|
76
|
-
component="span"
|
|
77
|
-
sx={{
|
|
78
|
-
display: "block",
|
|
79
|
-
mx: -2,
|
|
80
|
-
px: 2,
|
|
81
|
-
whiteSpace: "pre",
|
|
82
|
-
bgcolor:
|
|
83
|
-
line.kind === "add"
|
|
84
|
-
? "rgba(46, 125, 91, 0.16)"
|
|
85
|
-
: line.kind === "del"
|
|
86
|
-
? "rgba(168, 41, 31, 0.14)"
|
|
87
|
-
: "transparent",
|
|
88
|
-
opacity: line.kind === "del" ? 0.8 : 1,
|
|
89
|
-
}}
|
|
90
|
-
>
|
|
91
|
-
{line.kind === "add"
|
|
92
|
-
? "+ "
|
|
93
|
-
: line.kind === "del"
|
|
94
|
-
? "− "
|
|
95
|
-
: " "}
|
|
96
|
-
{line.text}
|
|
97
|
-
</Box>
|
|
98
|
-
),
|
|
99
|
-
)}
|
|
100
|
-
</Box>
|
|
101
|
-
</AppDialog>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { Alert, Box, Button } from "@mui/material";
|
|
5
|
-
import { DiffDialog } from "./DiffDialog";
|
|
6
|
-
import type { LastSave } from "./useDocumentEditor";
|
|
7
|
-
|
|
8
|
-
export interface SaveNoticeProps {
|
|
9
|
-
/** The save the notice offers to take back; absent once that offer is withdrawn. */
|
|
10
|
-
lastSave?: LastSave & { removedComments?: string[] };
|
|
11
|
-
/** What the document's parts are called, singular: "tile" or "cell". */
|
|
12
|
-
unit: string;
|
|
13
|
-
/** How many parts the document had before the save and after it. */
|
|
14
|
-
moved: { before: number; after: number } | undefined;
|
|
15
|
-
canUndoSave: boolean;
|
|
16
|
-
/** An Undo save just landed and the offer is gone. */
|
|
17
|
-
undone: boolean;
|
|
18
|
-
/** The read-only viewer of the saved change is open. */
|
|
19
|
-
viewing: boolean;
|
|
20
|
-
onView: (open: boolean) => void;
|
|
21
|
-
onUndoSave: () => Promise<void> | void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const plural = (count: number, unit: string) =>
|
|
25
|
-
`${count} ${unit}${count === 1 ? "" : "s"}`;
|
|
26
|
-
|
|
27
|
-
/** What the save did to the file, as facts the author can check before moving on. */
|
|
28
|
-
function facts(
|
|
29
|
-
{ lastSave, unit, moved }: SaveNoticeProps,
|
|
30
|
-
comments: string[],
|
|
31
|
-
): string[] {
|
|
32
|
-
if (!lastSave) return [];
|
|
33
|
-
const lines: string[] = [];
|
|
34
|
-
const change = moved ? moved.after - moved.before : 0;
|
|
35
|
-
if (change === 1) lines.push(`Added a ${unit}`);
|
|
36
|
-
else if (change > 1) lines.push(`Added ${plural(change, unit)}`);
|
|
37
|
-
else if (change < 0) lines.push(`Removed ${plural(-change, unit)}`);
|
|
38
|
-
else if (lastSave.structural) lines.push(`Changed the ${unit}s in the file`);
|
|
39
|
-
else lines.push("Saved your edits");
|
|
40
|
-
if (comments.length > 0)
|
|
41
|
-
lines.push(
|
|
42
|
-
`Removed ${plural(comments.length, "comment")} with their ${unit}s`,
|
|
43
|
-
);
|
|
44
|
-
if (lastSave.clearsHistory) lines.push("Undo history was cleared");
|
|
45
|
-
return lines;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* What a save just did, with the way back: View change shows the file's diff
|
|
50
|
-
* read-only, Undo save writes the file back as it was. Stays until an edit
|
|
51
|
-
* withdraws the offer or the next save replaces it; nothing else hides it.
|
|
52
|
-
*/
|
|
53
|
-
export function SaveNotice(props: SaveNoticeProps) {
|
|
54
|
-
const { lastSave, canUndoSave, undone, viewing, onView, onUndoSave } = props;
|
|
55
|
-
if (undone)
|
|
56
|
-
return (
|
|
57
|
-
<Alert severity="info" role="status">
|
|
58
|
-
Save undone. Your edits are back and unsaved.
|
|
59
|
-
</Alert>
|
|
60
|
-
);
|
|
61
|
-
if (!lastSave) return null;
|
|
62
|
-
const comments = lastSave.removedComments ?? [];
|
|
63
|
-
return (
|
|
64
|
-
<>
|
|
65
|
-
<Alert
|
|
66
|
-
severity="success"
|
|
67
|
-
role="status"
|
|
68
|
-
action={
|
|
69
|
-
<>
|
|
70
|
-
<Button
|
|
71
|
-
color="inherit"
|
|
72
|
-
size="small"
|
|
73
|
-
onClick={() => onView(true)}
|
|
74
|
-
>
|
|
75
|
-
View change
|
|
76
|
-
</Button>
|
|
77
|
-
<Button
|
|
78
|
-
color="inherit"
|
|
79
|
-
size="small"
|
|
80
|
-
disabled={!canUndoSave}
|
|
81
|
-
onClick={() => void onUndoSave()}
|
|
82
|
-
>
|
|
83
|
-
Undo save
|
|
84
|
-
</Button>
|
|
85
|
-
</>
|
|
86
|
-
}
|
|
87
|
-
>
|
|
88
|
-
{facts(props, comments).join(". ")}.
|
|
89
|
-
{comments.length > 0 && (
|
|
90
|
-
<Box
|
|
91
|
-
component="span"
|
|
92
|
-
aria-label="Comments removed with their cell"
|
|
93
|
-
sx={{
|
|
94
|
-
display: "block",
|
|
95
|
-
whiteSpace: "pre",
|
|
96
|
-
fontFamily: "monospace",
|
|
97
|
-
fontSize: 12,
|
|
98
|
-
mt: 0.5,
|
|
99
|
-
}}
|
|
100
|
-
>
|
|
101
|
-
{comments.join("\n")}
|
|
102
|
-
</Box>
|
|
103
|
-
)}
|
|
104
|
-
</Alert>
|
|
105
|
-
<DiffDialog
|
|
106
|
-
open={viewing}
|
|
107
|
-
before={lastSave.before}
|
|
108
|
-
after={lastSave.after}
|
|
109
|
-
onClose={() => onView(false)}
|
|
110
|
-
/>
|
|
111
|
-
</>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
cleanup,
|
|
6
|
-
fireEvent,
|
|
7
|
-
render,
|
|
8
|
-
screen,
|
|
9
|
-
waitFor,
|
|
10
|
-
within,
|
|
11
|
-
} from "@testing-library/react";
|
|
12
|
-
import { afterEach, describe, expect, it } from "bun:test";
|
|
13
|
-
import {
|
|
14
|
-
MAX_COLUMNS,
|
|
15
|
-
nudgedSpan,
|
|
16
|
-
presetSpan,
|
|
17
|
-
} from "../Dashboard/DashboardGrid";
|
|
18
|
-
import { SettingsPopover, type PageSettings } from "./SettingsPopover";
|
|
19
|
-
|
|
20
|
-
afterEach(cleanup);
|
|
21
|
-
|
|
22
|
-
function open(settings: PageSettings, onCommit = (_: PageSettings) => {}) {
|
|
23
|
-
const anchor = document.body.appendChild(document.createElement("button"));
|
|
24
|
-
render(
|
|
25
|
-
<SettingsPopover
|
|
26
|
-
anchor={anchor}
|
|
27
|
-
settings={settings}
|
|
28
|
-
inUse={new Set()}
|
|
29
|
-
onClose={() => {}}
|
|
30
|
-
onCommit={onCommit}
|
|
31
|
-
/>,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const select = () => screen.getByLabelText("Grid width");
|
|
36
|
-
const options = async () => {
|
|
37
|
-
fireEvent.mouseDown(select());
|
|
38
|
-
const list = await screen.findByRole("listbox");
|
|
39
|
-
return within(list)
|
|
40
|
-
.getAllByRole("option")
|
|
41
|
-
.map((o) => o.textContent);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
describe("Grid width", () => {
|
|
45
|
-
it("shows 2 for an unset file, with no separate Default item", async () => {
|
|
46
|
-
open({ imports: [] });
|
|
47
|
-
expect(select().textContent).toBe("2");
|
|
48
|
-
const shown = await options();
|
|
49
|
-
expect(shown.filter((t) => t === "2")).toHaveLength(1);
|
|
50
|
-
expect(shown.some((t) => /default/i.test(t ?? ""))).toBe(false);
|
|
51
|
-
expect(shown.at(-1)).toBe(String(MAX_COLUMNS));
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("still lists a width the file wrote that is not a usual one", async () => {
|
|
55
|
-
open({ imports: [], columns: 10 });
|
|
56
|
-
expect(select().textContent).toBe("10");
|
|
57
|
-
expect(await options()).toContain("10");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("writes the picked width", async () => {
|
|
61
|
-
let next: PageSettings | undefined;
|
|
62
|
-
open({ imports: [] }, (s) => (next = s));
|
|
63
|
-
fireEvent.mouseDown(select());
|
|
64
|
-
const list = await screen.findByRole("listbox");
|
|
65
|
-
fireEvent.click(within(list).getByText("12"));
|
|
66
|
-
fireEvent.keyDown(list, { key: "Escape" });
|
|
67
|
-
await waitFor(() => expect(next?.columns).toBe(12));
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("nudgedSpan", () => {
|
|
72
|
-
it("stays within the grid and never passes the builder maximum", () => {
|
|
73
|
-
expect(nudgedSpan(1, -1, 12)).toBe(1);
|
|
74
|
-
expect(nudgedSpan(12, 1, 12)).toBe(12);
|
|
75
|
-
expect(nudgedSpan(5, 1, 12)).toBe(6);
|
|
76
|
-
expect(nudgedSpan(MAX_COLUMNS, 1, 36)).toBe(MAX_COLUMNS);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("presetSpan", () => {
|
|
81
|
-
it("takes a fraction of the grid and never passes the builder maximum", () => {
|
|
82
|
-
expect(presetSpan(12, 3)).toBe(4);
|
|
83
|
-
expect(presetSpan(2, 4)).toBe(1);
|
|
84
|
-
expect(presetSpan(36, 1)).toBe(MAX_COLUMNS);
|
|
85
|
-
expect(presetSpan(36, 2)).toBe(18);
|
|
86
|
-
});
|
|
87
|
-
});
|