@malloy-publisher/sdk 0.3.0 → 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 +22 -9
- package/dist/DocumentStorageProvider-CyOJ0hqf.es.js +24443 -0
- package/dist/DocumentStorageProvider-DGPQEd_l.cjs.js +134 -0
- package/dist/RenderedResult-BnPzJ9Jf.es.js +549 -0
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +115 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-BWOEKg0O.es.js} +1256 -1318
- package/dist/ServerProvider-Cc489A3f.cjs.js +1 -0
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9482 -0
- package/dist/builder-entry.d.ts +8 -0
- 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/Dashboard.d.ts +19 -14
- package/dist/components/Dashboard/DashboardBar.d.ts +21 -0
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +48 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +118 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +30 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +17 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +53 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
- package/dist/components/DocumentStorage/index.d.ts +1 -1
- package/dist/components/FloatingIconButton.d.ts +16 -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/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +1 -0
- package/dist/components/buttons.d.ts +53 -0
- package/dist/components/drill/index.d.ts +1 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/index.d.ts +6 -0
- package/dist/components/styles.d.ts +49 -44
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCrudMutation.d.ts +42 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +22 -273
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +16888 -44451
- package/dist/telemetry/consoleEvents.d.ts +60 -0
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/dist/utils/sha256.d.ts +2 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- 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/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardBar.tsx +88 -0
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +66 -123
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
- package/src/components/Dashboard/telemetry.ts +51 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +247 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +852 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +666 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +163 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +188 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +567 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +122 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +269 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +562 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +126 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/newDashboard.spec.ts +40 -0
- package/src/components/DashboardBuilder/newDashboard.ts +48 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1161 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1135 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +311 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +201 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Environment/About.tsx +16 -62
- 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/FloatingIconButton.tsx +41 -0
- 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/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +33 -72
- package/src/components/Notebook/Notebook.tsx +25 -88
- package/src/components/Notebook/NotebookCell.tsx +35 -183
- 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/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +198 -0
- package/src/components/RenderedResult/RenderedResult.tsx +22 -8
- package/src/components/RenderedResult/ResultContainer.tsx +4 -12
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +1 -0
- 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/drill/index.ts +1 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/given/paramCodec.spec.ts +1 -1
- package/src/components/index.ts +16 -0
- package/src/components/styles.ts +49 -122
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useCrudMutation.spec.tsx +119 -0
- package/src/hooks/useCrudMutation.tsx +85 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -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/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/src/utils/sha256.ts +13 -0
- package/test/README.md +1 -1
- package/test/serverProvider.tsx +5 -2
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.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
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import { sha256Hex } from "../../utils/sha256";
|
|
13
|
+
import { BrowserDocumentStorage } from "../DocumentStorage/BrowserDocumentStorage";
|
|
14
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The editor against a server that takes writes: Save goes into the package,
|
|
18
|
+
* carrying the hash of the text that was opened, and a browser draft of the
|
|
19
|
+
* same file is superseded by it.
|
|
20
|
+
*/
|
|
21
|
+
const PACKAGE_FILE = `## artifact { title="Storefront" tiles=["a -> by_cat"] } dashboard { columns=12 }
|
|
22
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
23
|
+
|
|
24
|
+
source: a is scoped_orders extend {
|
|
25
|
+
# colspan=6
|
|
26
|
+
# label="By category"
|
|
27
|
+
view: by_cat is by_category
|
|
28
|
+
}`;
|
|
29
|
+
|
|
30
|
+
const getModel = mock((_env: string, _pkg: string, path: string) =>
|
|
31
|
+
Promise.resolve({
|
|
32
|
+
data:
|
|
33
|
+
path === "dashboards/overview.malloy"
|
|
34
|
+
? { modelPath: path, sourceText: PACKAGE_FILE }
|
|
35
|
+
: { modelPath: path, sources: [], sourceInfos: [] },
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
const updateModelSource = mock(
|
|
39
|
+
(_env: string, _pkg: string, path: string, body: { source: string }) =>
|
|
40
|
+
Promise.resolve({
|
|
41
|
+
data: {
|
|
42
|
+
path,
|
|
43
|
+
contentHash: `hash-of-${body.source.length}`,
|
|
44
|
+
created: false,
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
mockServerProvider(
|
|
49
|
+
{
|
|
50
|
+
models: {
|
|
51
|
+
getModel,
|
|
52
|
+
executeQueryModel: mock(() => pending()),
|
|
53
|
+
updateModelSource,
|
|
54
|
+
},
|
|
55
|
+
dashboards: {
|
|
56
|
+
getDashboard: mock(() =>
|
|
57
|
+
Promise.resolve({
|
|
58
|
+
data: {
|
|
59
|
+
path: "dashboards/overview.malloy",
|
|
60
|
+
givens: [],
|
|
61
|
+
tiles: [],
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
listDashboards: mock(() =>
|
|
66
|
+
Promise.resolve({ data: [{ name: "overview" }] }),
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{ mutable: true },
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const { DashboardEditor } = await import("./DashboardEditor");
|
|
74
|
+
|
|
75
|
+
const DRAFT = {
|
|
76
|
+
workspace: "Local",
|
|
77
|
+
type: "dashboard" as const,
|
|
78
|
+
path: "env/pkg/dashboards/overview.malloy",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const mount = () => {
|
|
82
|
+
const storage = new BrowserDocumentStorage();
|
|
83
|
+
render(
|
|
84
|
+
<DocumentStorageProvider documentStorage={storage}>
|
|
85
|
+
<DashboardEditor
|
|
86
|
+
environmentName="env"
|
|
87
|
+
packageName="pkg"
|
|
88
|
+
dashboardName="overview"
|
|
89
|
+
/>
|
|
90
|
+
</DocumentStorageProvider>,
|
|
91
|
+
{ wrapper: serverWrapper },
|
|
92
|
+
);
|
|
93
|
+
return storage;
|
|
94
|
+
};
|
|
95
|
+
const button = (name: string) =>
|
|
96
|
+
screen.getByRole("button", { name, hidden: true });
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
clearCache();
|
|
100
|
+
localStorage.clear();
|
|
101
|
+
updateModelSource.mockClear();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("DashboardEditor, when the server takes writes", () => {
|
|
105
|
+
it("saves into the package with the hash of the text it opened, and supersedes the browser draft", async () => {
|
|
106
|
+
const storage = mount();
|
|
107
|
+
await new BrowserDocumentStorage().saveDocument(DRAFT, "stale draft");
|
|
108
|
+
await screen.findByText("Storefront");
|
|
109
|
+
expect(
|
|
110
|
+
screen.getByText("Save writes the file into the package."),
|
|
111
|
+
).toBeDefined();
|
|
112
|
+
|
|
113
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
114
|
+
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
115
|
+
target: { value: "Categories" },
|
|
116
|
+
});
|
|
117
|
+
fireEvent.keyDown(screen.getByLabelText("Tile title"), { key: "Escape" });
|
|
118
|
+
fireEvent.click(button("Save changes"));
|
|
119
|
+
|
|
120
|
+
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
121
|
+
const [env, pkg, path, body] = updateModelSource.mock.calls[0];
|
|
122
|
+
expect([env, pkg, path]).toEqual([
|
|
123
|
+
"env",
|
|
124
|
+
"pkg",
|
|
125
|
+
"dashboards/overview.malloy",
|
|
126
|
+
]);
|
|
127
|
+
expect(body.source).toContain('# label="Categories"');
|
|
128
|
+
expect((body as { expectedHash?: string }).expectedHash).toBe(
|
|
129
|
+
await sha256Hex(PACKAGE_FILE),
|
|
130
|
+
);
|
|
131
|
+
await waitFor(() => expect(button("Saved")).toBeDefined());
|
|
132
|
+
await expect(storage.getDocument(DRAFT)).rejects.toBeDefined();
|
|
133
|
+
// No offer to resume a draft over what was just written.
|
|
134
|
+
expect(screen.queryByText(/saved in this browser/)).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("keeps the edit and shows the server's reason when the package refuses the write", async () => {
|
|
138
|
+
updateModelSource.mockImplementationOnce(() =>
|
|
139
|
+
Promise.reject({
|
|
140
|
+
response: {
|
|
141
|
+
data: {
|
|
142
|
+
message:
|
|
143
|
+
"`dashboards/overview.malloy` changed in the package since you opened it.",
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
mount();
|
|
149
|
+
await screen.findByText("Storefront");
|
|
150
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
151
|
+
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
152
|
+
target: { value: "Categories" },
|
|
153
|
+
});
|
|
154
|
+
fireEvent.keyDown(screen.getByLabelText("Tile title"), { key: "Escape" });
|
|
155
|
+
fireEvent.click(button("Save changes"));
|
|
156
|
+
await waitFor(() =>
|
|
157
|
+
expect(screen.getByRole("alert").textContent).toContain(
|
|
158
|
+
"changed in the package since you opened it",
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
expect(button("Save changes")).toBeDefined();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import { BrowserDocumentStorage } from "../DocumentStorage/BrowserDocumentStorage";
|
|
13
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
14
|
+
import type { DashboardEvent } from "../Dashboard/telemetry";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The Console's path through the builder, with the server mocked at the
|
|
18
|
+
* client and the browser's storage real: open the package file, offer a
|
|
19
|
+
* saved draft, save an edit into storage, export the file.
|
|
20
|
+
*/
|
|
21
|
+
const PACKAGE_FILE = `## artifact { title="Storefront" tiles=["a -> by_cat"] } dashboard { columns=12 }
|
|
22
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
23
|
+
|
|
24
|
+
source: a is scoped_orders extend {
|
|
25
|
+
# colspan=6
|
|
26
|
+
# label="By category"
|
|
27
|
+
view: by_cat is by_category
|
|
28
|
+
}`;
|
|
29
|
+
|
|
30
|
+
const getModel = mock((_env: string, _pkg: string, path: string) =>
|
|
31
|
+
Promise.resolve({
|
|
32
|
+
data:
|
|
33
|
+
path === "dashboards/overview.malloy"
|
|
34
|
+
? { modelPath: path, sourceText: PACKAGE_FILE }
|
|
35
|
+
: {
|
|
36
|
+
modelPath: path,
|
|
37
|
+
sources: [
|
|
38
|
+
{
|
|
39
|
+
name: "scoped_orders",
|
|
40
|
+
views: [{ name: "by_category" }, { name: "by_brand" }],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
sourceInfos: [
|
|
44
|
+
JSON.stringify({
|
|
45
|
+
name: "scoped_orders",
|
|
46
|
+
schema: {
|
|
47
|
+
fields: [
|
|
48
|
+
{
|
|
49
|
+
name: "cat",
|
|
50
|
+
kind: "dimension",
|
|
51
|
+
type: { kind: "string_type" },
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
const getDashboard = mock(() =>
|
|
61
|
+
Promise.resolve({
|
|
62
|
+
data: { path: "dashboards/overview.malloy", givens: [], tiles: [] },
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
const listDashboards = mock(() =>
|
|
66
|
+
Promise.resolve({ data: [{ name: "overview" }, { name: "regions" }] }),
|
|
67
|
+
);
|
|
68
|
+
const executeQueryModel = mock(() => pending());
|
|
69
|
+
mockServerProvider({
|
|
70
|
+
models: { getModel, executeQueryModel },
|
|
71
|
+
dashboards: { getDashboard, listDashboards },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Imported after the stub is registered: a static import would hoist above it.
|
|
75
|
+
const { DashboardEditor } = await import("./DashboardEditor");
|
|
76
|
+
|
|
77
|
+
const DRAFT = {
|
|
78
|
+
workspace: "Local",
|
|
79
|
+
type: "dashboard" as const,
|
|
80
|
+
path: "env/pkg/dashboards/overview.malloy",
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const mount = (
|
|
84
|
+
onExit?: () => void,
|
|
85
|
+
onEvent?: (event: DashboardEvent) => void,
|
|
86
|
+
) => {
|
|
87
|
+
const storage = new BrowserDocumentStorage();
|
|
88
|
+
render(
|
|
89
|
+
<DocumentStorageProvider documentStorage={storage}>
|
|
90
|
+
<DashboardEditor
|
|
91
|
+
environmentName="env"
|
|
92
|
+
packageName="pkg"
|
|
93
|
+
dashboardName="overview"
|
|
94
|
+
{...(onExit ? { onExit } : {})}
|
|
95
|
+
{...(onEvent ? { onEvent } : {})}
|
|
96
|
+
/>
|
|
97
|
+
</DocumentStorageProvider>,
|
|
98
|
+
{ wrapper: serverWrapper },
|
|
99
|
+
);
|
|
100
|
+
return storage;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const button = (name: string | RegExp) =>
|
|
104
|
+
screen.getByRole("button", { name, hidden: true });
|
|
105
|
+
|
|
106
|
+
beforeEach(() => {
|
|
107
|
+
clearCache();
|
|
108
|
+
localStorage.clear();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("DashboardEditor", () => {
|
|
112
|
+
it("opens the package file in the builder, with the package's sources to pick from", async () => {
|
|
113
|
+
mount();
|
|
114
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
115
|
+
expect(screen.getByLabelText("Tile by_cat")).toBeDefined();
|
|
116
|
+
// The catalog came from the model the file imports, by its resolved path.
|
|
117
|
+
await waitFor(() =>
|
|
118
|
+
expect(
|
|
119
|
+
getModel.mock.calls.some((call) => call[2] === "data_app.malloy"),
|
|
120
|
+
).toBe(true),
|
|
121
|
+
);
|
|
122
|
+
await screen.findByRole("button", { name: "Add tile", hidden: true });
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("saves an edit into the browser and marks it saved", async () => {
|
|
126
|
+
const storage = mount();
|
|
127
|
+
await screen.findByText("Storefront");
|
|
128
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
129
|
+
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
130
|
+
target: { value: "Categories" },
|
|
131
|
+
});
|
|
132
|
+
fireEvent.keyDown(screen.getByLabelText("Tile title"), { key: "Escape" });
|
|
133
|
+
fireEvent.click(button("Save changes"));
|
|
134
|
+
await waitFor(async () =>
|
|
135
|
+
expect(await storage.getDocument(DRAFT)).toContain(
|
|
136
|
+
'# label="Categories"',
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
expect(await storage.getDocument(DRAFT)).toContain("# colspan=6");
|
|
140
|
+
// The copy just written is not "edits from an earlier visit": no offer
|
|
141
|
+
// to resume it appears over the page being edited.
|
|
142
|
+
await waitFor(() => expect(button("Saved")).toBeDefined());
|
|
143
|
+
expect(screen.queryByText(/saved in this browser/)).toBeNull();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("offers a saved draft that differs from the package, and opens it on Resume", async () => {
|
|
147
|
+
const draft = PACKAGE_FILE.replace(
|
|
148
|
+
'title="Storefront"',
|
|
149
|
+
'title="Drafted"',
|
|
150
|
+
);
|
|
151
|
+
await new BrowserDocumentStorage().saveDocument(DRAFT, draft);
|
|
152
|
+
const onEvent = mock((_event: DashboardEvent) => {});
|
|
153
|
+
mount(undefined, onEvent);
|
|
154
|
+
expect(
|
|
155
|
+
await screen.findByText(
|
|
156
|
+
/edits to this dashboard saved in this browser/,
|
|
157
|
+
),
|
|
158
|
+
).toBeDefined();
|
|
159
|
+
// Until the reader chooses, the package file is what is open.
|
|
160
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
161
|
+
fireEvent.click(button("Resume"));
|
|
162
|
+
expect(await screen.findByText("Drafted")).toBeDefined();
|
|
163
|
+
expect(onEvent.mock.calls.at(-1)?.[0]).toMatchObject({
|
|
164
|
+
type: "dashboard.opened",
|
|
165
|
+
from: "draft",
|
|
166
|
+
});
|
|
167
|
+
expect(screen.queryByText(/saved in this browser/)).toBeNull();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("hands the exit to the host and reports the open", async () => {
|
|
171
|
+
const onExit = mock(() => {});
|
|
172
|
+
const onEvent = mock((_event: DashboardEvent) => {});
|
|
173
|
+
mount(onExit, onEvent);
|
|
174
|
+
await screen.findByText("Storefront");
|
|
175
|
+
await waitFor(() =>
|
|
176
|
+
expect(onEvent.mock.calls.map((call) => call[0].type)).toContain(
|
|
177
|
+
"dashboard.opened",
|
|
178
|
+
),
|
|
179
|
+
);
|
|
180
|
+
expect(onEvent.mock.calls[0][0]).toMatchObject({
|
|
181
|
+
type: "dashboard.opened",
|
|
182
|
+
from: "package",
|
|
183
|
+
tiles: 1,
|
|
184
|
+
});
|
|
185
|
+
fireEvent.click(button("Done editing"));
|
|
186
|
+
expect(onExit).toHaveBeenCalledTimes(1);
|
|
187
|
+
});
|
|
188
|
+
});
|