@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
|
@@ -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
|
+
});
|
|
@@ -167,7 +167,7 @@ describe("DashboardEditor", () => {
|
|
|
167
167
|
expect(screen.queryByText(/saved in this browser/)).toBeNull();
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
-
it("
|
|
170
|
+
it("hands the exit to the host and reports the open", async () => {
|
|
171
171
|
const onExit = mock(() => {});
|
|
172
172
|
const onEvent = mock((_event: DashboardEvent) => {});
|
|
173
173
|
mount(onExit, onEvent);
|
|
@@ -182,30 +182,7 @@ describe("DashboardEditor", () => {
|
|
|
182
182
|
from: "package",
|
|
183
183
|
tiles: 1,
|
|
184
184
|
});
|
|
185
|
-
|
|
186
|
-
const createObjectURL = mock((blob: Blob) => {
|
|
187
|
-
created.push(blob);
|
|
188
|
-
return "blob:test";
|
|
189
|
-
});
|
|
190
|
-
const revoked = mock(() => {});
|
|
191
|
-
Object.assign(URL, { createObjectURL, revokeObjectURL: revoked });
|
|
192
|
-
const clicked = mock(() => {});
|
|
193
|
-
const click = HTMLAnchorElement.prototype.click;
|
|
194
|
-
HTMLAnchorElement.prototype.click = clicked;
|
|
195
|
-
try {
|
|
196
|
-
fireEvent.click(button("Export"));
|
|
197
|
-
await waitFor(() => expect(created).toHaveLength(1));
|
|
198
|
-
expect(await created[0].text()).toBe(PACKAGE_FILE);
|
|
199
|
-
expect(clicked).toHaveBeenCalledTimes(1);
|
|
200
|
-
expect(revoked).toHaveBeenCalledWith("blob:test");
|
|
201
|
-
expect(onEvent.mock.calls.at(-1)?.[0]).toEqual({
|
|
202
|
-
type: "dashboard.exported",
|
|
203
|
-
bytes: PACKAGE_FILE.length,
|
|
204
|
-
});
|
|
205
|
-
} finally {
|
|
206
|
-
HTMLAnchorElement.prototype.click = click;
|
|
207
|
-
}
|
|
208
|
-
fireEvent.click(button("Done"));
|
|
185
|
+
fireEvent.click(button("Done editing"));
|
|
209
186
|
expect(onExit).toHaveBeenCalledTimes(1);
|
|
210
187
|
});
|
|
211
188
|
});
|