@malloy-publisher/sdk 0.9.13 → 0.9.15
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-BClN_PG6.cjs.js +154 -0
- package/dist/{RenderedResult-DnBtf-cI.es.js → RenderedResult-YBzVMVH2.es.js} +295 -234
- package/dist/{ServerProvider-BV7IoDMR.es.js → ServerProvider-D7neZcTk.es.js} +283 -265
- package/dist/ServerProvider-e2369oom.cjs.js +1 -0
- package/dist/builder/index.cjs.js +80 -79
- package/dist/builder/index.es.js +7430 -6548
- package/dist/client/api.d.ts +30 -6
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +49 -1
- package/dist/components/Dashboard/DashboardTile.d.ts +5 -2
- package/dist/components/Dashboard/DashboardView.d.ts +9 -2
- package/dist/components/Dashboard/index.d.ts +1 -1
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +5 -7
- package/dist/components/Dashboard/useStuck.d.ts +18 -12
- package/dist/components/RenderedResult/RenderedResult.d.ts +3 -2
- package/dist/components/RenderedResult/ResultContainer.d.ts +11 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +5 -1
- package/dist/components/RenderedResult/chartPresentation.d.ts +15 -0
- package/dist/components/RenderedResult/chartShapeProblem.d.ts +55 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +42 -6
- package/dist/components/Report/Report.d.ts +7 -1
- package/dist/components/Report/ReportPage.d.ts +7 -0
- package/dist/components/Report/layoutRules.d.ts +45 -0
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +2 -1
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +14 -1
- package/dist/components/ReportBuilder/ChartPicker.d.ts +4 -2
- package/dist/components/ReportBuilder/EditorSurface.d.ts +17 -1
- package/dist/components/ReportBuilder/ReportEditor.d.ts +18 -0
- package/dist/components/ReportBuilder/TileFrame.d.ts +33 -1
- package/dist/components/ReportBuilder/TileMenu.d.ts +5 -2
- package/dist/components/ReportBuilder/catalog.d.ts +23 -0
- package/dist/components/ReportBuilder/chartLine.d.ts +38 -5
- package/dist/components/ReportBuilder/controls.d.ts +2 -2
- package/dist/components/ReportBuilder/document.d.ts +53 -5
- package/dist/components/ReportBuilder/imports.d.ts +7 -0
- package/dist/components/ReportBuilder/placement.d.ts +75 -0
- package/dist/components/ReportBuilder/preview.d.ts +59 -10
- package/dist/components/ReportBuilder/sortable.d.ts +3 -1
- package/dist/components/ReportBuilder/useTileHeight.d.ts +39 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +27 -3
- package/dist/components/ReportBuilder/useTileResize.d.ts +8 -0
- package/dist/index.cjs.js +7 -7
- package/dist/index.es.js +3328 -3287
- package/dist/text/index.es.js +1 -1
- package/dist/{text-entry-72YFLeNk.es.js → text-entry-YKJZbRPo.es.js} +2 -2
- package/dist/theme/resolveTheme.d.ts +15 -0
- package/dist/{useCompiledDocument-B4QF1mIl.es.js → useCompiledDocument-BGk38oaW.es.js} +5097 -4805
- package/dist/useCompiledDocument-D9t5ry_t.cjs.js +142 -0
- package/dist/utils/blankQuoted.d.ts +15 -0
- package/package.json +1 -1
- package/src/components/Dashboard/DashboardGrid.tsx +127 -10
- package/src/components/Dashboard/DashboardTile.tsx +11 -1
- package/src/components/Dashboard/DashboardView.tsx +63 -10
- package/src/components/Dashboard/TileCard.tsx +6 -0
- package/src/components/Dashboard/index.ts +1 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +19 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +15 -36
- package/src/components/Dashboard/tileHeight.spec.ts +72 -0
- package/src/components/Dashboard/useStuck.ts +76 -28
- package/src/components/Package/NewDocumentDialog.spec.tsx +20 -16
- package/src/components/Package/NewDocumentDialog.tsx +10 -11
- package/src/components/RenderedResult/RenderedResult.lifecycle.spec.tsx +167 -2
- package/src/components/RenderedResult/RenderedResult.tsx +21 -6
- package/src/components/RenderedResult/ResultContainer.tsx +60 -7
- package/src/components/RenderedResult/ResultPanel.tsx +21 -1
- package/src/components/RenderedResult/chartPresentation.spec.ts +153 -0
- package/src/components/RenderedResult/chartPresentation.ts +166 -0
- package/src/components/RenderedResult/chartShapeProblem.spec.tsx +245 -0
- package/src/components/RenderedResult/chartShapeProblem.ts +219 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +75 -3
- package/src/components/RenderedResult/resultSizing.ts +65 -11
- package/src/components/Report/Report.spec.tsx +19 -0
- package/src/components/Report/Report.tsx +8 -1
- package/src/components/Report/ReportPage.tsx +13 -1
- package/src/components/Report/layoutRules.spec.ts +43 -3
- package/src/components/Report/layoutRules.ts +70 -0
- package/src/components/Report/tileOverflow.spec.tsx +162 -0
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +2 -2
- package/src/components/ReportBuilder/AddTileDialog.tsx +11 -6
- package/src/components/ReportBuilder/BuilderBar.tsx +1 -1
- package/src/components/ReportBuilder/BuilderDialogs.tsx +20 -0
- package/src/components/ReportBuilder/BuilderGrid.tsx +126 -20
- package/src/components/ReportBuilder/ChartPicker.spec.ts +91 -4
- package/src/components/ReportBuilder/ChartPicker.tsx +45 -10
- package/src/components/ReportBuilder/DrillDialog.tsx +8 -2
- package/src/components/ReportBuilder/EditorSurface.tsx +110 -28
- package/src/components/ReportBuilder/FilterDialog.tsx +17 -8
- package/src/components/ReportBuilder/FilterStrip.tsx +2 -1
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +193 -2
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +143 -2
- package/src/components/ReportBuilder/ReportBuilder.tsx +73 -19
- package/src/components/ReportBuilder/ReportEditor.fileModel.spec.tsx +178 -0
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +3 -5
- package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +292 -0
- package/src/components/ReportBuilder/ReportEditor.readOnlyTitle.spec.tsx +92 -0
- package/src/components/ReportBuilder/ReportEditor.tsx +35 -0
- package/src/components/ReportBuilder/TileFrame.tsx +251 -6
- package/src/components/ReportBuilder/TileMenu.tsx +259 -20
- package/src/components/ReportBuilder/ViewPicker.tsx +4 -3
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +34 -0
- package/src/components/ReportBuilder/addTileToDocument.ts +26 -1
- package/src/components/ReportBuilder/catalog.aggregate.spec.ts +137 -1
- package/src/components/ReportBuilder/catalog.ts +90 -37
- package/src/components/ReportBuilder/chartLine.spec.ts +42 -5
- package/src/components/ReportBuilder/chartLine.ts +80 -2
- package/src/components/ReportBuilder/controls.ts +4 -3
- package/src/components/ReportBuilder/document.ts +65 -7
- package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
- package/src/components/ReportBuilder/entryLayout.spec.ts +151 -0
- package/src/components/ReportBuilder/imports.ts +1 -1
- package/src/components/ReportBuilder/invariants.spec.ts +18 -10
- package/src/components/ReportBuilder/layout.ts +3 -0
- package/src/components/ReportBuilder/placement.spec.ts +193 -0
- package/src/components/ReportBuilder/placement.ts +250 -0
- package/src/components/ReportBuilder/preview.shapes.spec.ts +46 -6
- package/src/components/ReportBuilder/preview.spec.ts +151 -11
- package/src/components/ReportBuilder/preview.ts +203 -40
- package/src/components/ReportBuilder/preview.unsaved.compile.spec.ts +190 -0
- package/src/components/ReportBuilder/readDocument.spec.ts +46 -2
- package/src/components/ReportBuilder/readDocument.ts +194 -23
- package/src/components/ReportBuilder/scannerShapes.spec.ts +10 -10
- package/src/components/ReportBuilder/sortable.tsx +4 -0
- package/src/components/ReportBuilder/spliceDocument.chart.spec.ts +1 -1
- package/src/components/ReportBuilder/spliceDocument.color.spec.ts +80 -0
- package/src/components/ReportBuilder/spliceDocument.colspan.spec.ts +78 -0
- package/src/components/ReportBuilder/spliceDocument.spec.ts +110 -18
- package/src/components/ReportBuilder/spliceDocument.ts +139 -52
- package/src/components/ReportBuilder/statementExtent.spec.ts +3 -3
- package/src/components/ReportBuilder/testing/reportGivenOrder.json +42 -0
- package/src/components/ReportBuilder/textTiles.spec.ts +2 -2
- package/src/components/ReportBuilder/tileDisplayTitle.ts +2 -2
- package/src/components/ReportBuilder/useTileEditing.ts +16 -3
- package/src/components/ReportBuilder/useTileHeight.ts +149 -0
- package/src/components/ReportBuilder/useTileReorder.ts +143 -6
- package/src/components/ReportBuilder/useTileResize.ts +16 -1
- package/src/components/given/FilterButton.spec.tsx +27 -11
- package/src/components/given/FilterButton.tsx +19 -6
- package/src/theme/resolveTheme.spec.ts +72 -1
- package/src/theme/resolveTheme.ts +43 -0
- package/src/utils/blankQuoted.spec.ts +50 -0
- package/src/utils/blankQuoted.ts +32 -0
- package/src/utils/malloyText.ts +2 -1
- package/dist/RenderedResult-DtQtNV0d.cjs.js +0 -153
- package/dist/ServerProvider-BIFPCzTD.cjs.js +0 -1
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +0 -142
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
cacheKeys,
|
|
8
|
+
clearCache,
|
|
9
|
+
mockServerProvider,
|
|
10
|
+
pending,
|
|
11
|
+
serverWrapper,
|
|
12
|
+
TEST_SERVER,
|
|
13
|
+
} from "../../../test/serverProvider";
|
|
14
|
+
import { BrowserDocumentStorage } from "../DocumentStorage/BrowserDocumentStorage";
|
|
15
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
16
|
+
import { editInline } from "./testing/inline";
|
|
17
|
+
import { reportDraftKey } from "./useReportDraft";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `queryVersionId`: the version the builder's queries run at, apart from the
|
|
21
|
+
* document's identity. A host whose package republishes on every change opens
|
|
22
|
+
* the builder on an unversioned `resourceUri` with its reader's version here,
|
|
23
|
+
* so the builder reuses the reader's results while the kept draft, the save
|
|
24
|
+
* target and the save caption stay with the unversioned document.
|
|
25
|
+
*/
|
|
26
|
+
const REPORT = "dashboards/overview.malloy";
|
|
27
|
+
const PACKAGE_FILE = `## artifact { title="Storefront" tiles=["a -> by_cat"] } dashboard { columns=12 }
|
|
28
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
29
|
+
|
|
30
|
+
source: a is scoped_orders extend {
|
|
31
|
+
# colspan=6
|
|
32
|
+
# label="By category"
|
|
33
|
+
view: by_cat is by_category
|
|
34
|
+
}`;
|
|
35
|
+
|
|
36
|
+
const getModel = mock(
|
|
37
|
+
(_env: string, _pkg: string, path: string, _versionId?: string) =>
|
|
38
|
+
Promise.resolve({
|
|
39
|
+
data:
|
|
40
|
+
path === REPORT
|
|
41
|
+
? { modelPath: path, sourceText: PACKAGE_FILE }
|
|
42
|
+
: {
|
|
43
|
+
modelPath: path,
|
|
44
|
+
modelInfo: JSON.stringify({
|
|
45
|
+
entries: [{ kind: "source", name: "scoped_orders" }],
|
|
46
|
+
}),
|
|
47
|
+
sources: [
|
|
48
|
+
{
|
|
49
|
+
name: "scoped_orders",
|
|
50
|
+
views: [{ name: "by_category" }],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
sourceInfos: [
|
|
54
|
+
JSON.stringify({
|
|
55
|
+
name: "scoped_orders",
|
|
56
|
+
schema: { fields: [] },
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
const getReport = mock(
|
|
63
|
+
(
|
|
64
|
+
_env: string,
|
|
65
|
+
_pkg: string,
|
|
66
|
+
_path: string,
|
|
67
|
+
_versionId?: string,
|
|
68
|
+
_options?: unknown,
|
|
69
|
+
) =>
|
|
70
|
+
Promise.resolve({
|
|
71
|
+
data: {
|
|
72
|
+
path: REPORT,
|
|
73
|
+
name: "overview",
|
|
74
|
+
title: "Storefront",
|
|
75
|
+
layout: "grid",
|
|
76
|
+
givens: [],
|
|
77
|
+
tiles: [{ kind: "query", query: "a -> by_cat", givenNames: [] }],
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
const listModels = mock((_env: string, _pkg: string, _versionId?: string) =>
|
|
82
|
+
Promise.resolve({ data: [{ path: "data_app.malloy" }] }),
|
|
83
|
+
);
|
|
84
|
+
const listReports = mock((_env: string, _pkg: string, _versionId?: string) =>
|
|
85
|
+
Promise.resolve({
|
|
86
|
+
data: [{ path: REPORT, name: "overview", layout: "grid" }],
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
const updateModelSource = mock(
|
|
90
|
+
(_env: string, _pkg: string, path: string, body: { source: string }) =>
|
|
91
|
+
Promise.resolve({
|
|
92
|
+
data: {
|
|
93
|
+
path,
|
|
94
|
+
contentHash: `hash-of-${body.source.length}`,
|
|
95
|
+
created: false,
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
// Answers by default, so the reader's tiles land in the cache; a test that
|
|
100
|
+
// wants nothing to settle swaps in `pending`.
|
|
101
|
+
let answer: () => Promise<unknown> = () =>
|
|
102
|
+
Promise.resolve({ data: { result: "{}" } });
|
|
103
|
+
const executeQueryModel = mock(
|
|
104
|
+
(
|
|
105
|
+
_env: string,
|
|
106
|
+
_pkg: string,
|
|
107
|
+
_path: string,
|
|
108
|
+
_body: { query?: string; givens?: unknown; versionId?: string },
|
|
109
|
+
) => answer(),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const serverContext = { mutable: false };
|
|
113
|
+
mockServerProvider(
|
|
114
|
+
{
|
|
115
|
+
models: { getModel, executeQueryModel, updateModelSource, listModels },
|
|
116
|
+
reports: { getReport, listReports },
|
|
117
|
+
notebooks: { getNotebook: () => pending() },
|
|
118
|
+
},
|
|
119
|
+
serverContext,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const { ReportEditor } = await import("./ReportEditor");
|
|
123
|
+
const { Report } = await import("../Report/Report");
|
|
124
|
+
|
|
125
|
+
const URI = "publisher://environments/env/packages/pkg";
|
|
126
|
+
|
|
127
|
+
const mountEditor = (
|
|
128
|
+
props: { queryVersionId?: string; keepDraft?: boolean } = {},
|
|
129
|
+
resourceUri = URI,
|
|
130
|
+
) =>
|
|
131
|
+
render(
|
|
132
|
+
<DocumentStorageProvider documentStorage={new BrowserDocumentStorage()}>
|
|
133
|
+
<ReportEditor resourceUri={resourceUri} path={REPORT} {...props} />
|
|
134
|
+
</DocumentStorageProvider>,
|
|
135
|
+
{ wrapper: serverWrapper },
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// The tile, as the reader and an untouched builder tile both ask for it.
|
|
139
|
+
const tileCalls = () =>
|
|
140
|
+
executeQueryModel.mock.calls.filter((call) =>
|
|
141
|
+
call[3].query?.includes("a -> by_cat"),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
beforeEach(() => {
|
|
145
|
+
clearCache();
|
|
146
|
+
localStorage.clear();
|
|
147
|
+
for (const fn of [
|
|
148
|
+
getModel,
|
|
149
|
+
getReport,
|
|
150
|
+
listModels,
|
|
151
|
+
listReports,
|
|
152
|
+
updateModelSource,
|
|
153
|
+
executeQueryModel,
|
|
154
|
+
])
|
|
155
|
+
fn.mockClear();
|
|
156
|
+
answer = () => Promise.resolve({ data: { result: "{}" } });
|
|
157
|
+
serverContext.mutable = false;
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("queryVersionId", () => {
|
|
161
|
+
it("serves the builder's tile from the result the reader cached at that version", async () => {
|
|
162
|
+
const reader = render(
|
|
163
|
+
<Report resourceUri={`${URI}?versionId=v7`} path={REPORT} />,
|
|
164
|
+
{ wrapper: serverWrapper },
|
|
165
|
+
);
|
|
166
|
+
await waitFor(() => expect(tileCalls()).toHaveLength(1));
|
|
167
|
+
expect(tileCalls()[0][3].versionId).toBe("v7");
|
|
168
|
+
await waitFor(() =>
|
|
169
|
+
expect(
|
|
170
|
+
cacheKeys("queryResult").some((key) => key.includes('"v7"')),
|
|
171
|
+
).toBe(true),
|
|
172
|
+
);
|
|
173
|
+
reader.unmount();
|
|
174
|
+
|
|
175
|
+
mountEditor({ queryVersionId: "v7" });
|
|
176
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
177
|
+
// Everything the builder reads besides the file itself has answered,
|
|
178
|
+
// so a tile that was going to run has run by now.
|
|
179
|
+
await waitFor(() =>
|
|
180
|
+
expect(
|
|
181
|
+
getModel.mock.calls.some((call) => call[2] === "data_app.malloy"),
|
|
182
|
+
).toBe(true),
|
|
183
|
+
);
|
|
184
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
185
|
+
expect(tileCalls()).toHaveLength(1);
|
|
186
|
+
// Nothing was asked unversioned: no second copy of the tile's result.
|
|
187
|
+
expect(
|
|
188
|
+
cacheKeys("queryResult").every((key) => key.includes('"v7"')),
|
|
189
|
+
).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("runs every query at that version, and reads the document unversioned", async () => {
|
|
193
|
+
answer = () => pending();
|
|
194
|
+
mountEditor({ queryVersionId: "v7" });
|
|
195
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
196
|
+
await waitFor(() =>
|
|
197
|
+
expect(
|
|
198
|
+
getModel.mock.calls.some((call) => call[2] === "data_app.malloy"),
|
|
199
|
+
).toBe(true),
|
|
200
|
+
);
|
|
201
|
+
await waitFor(() => expect(tileCalls().length).toBeGreaterThan(0));
|
|
202
|
+
|
|
203
|
+
// The document: the file the editor opens and saves.
|
|
204
|
+
expect(getModel.mock.calls.find((call) => call[2] === REPORT)).toEqual([
|
|
205
|
+
"env",
|
|
206
|
+
"pkg",
|
|
207
|
+
REPORT,
|
|
208
|
+
undefined,
|
|
209
|
+
]);
|
|
210
|
+
// The queries: the manifest, the listing, the catalog and the tiles.
|
|
211
|
+
expect(getReport.mock.calls[0].slice(0, 4)).toEqual([
|
|
212
|
+
"env",
|
|
213
|
+
"pkg",
|
|
214
|
+
REPORT,
|
|
215
|
+
"v7",
|
|
216
|
+
]);
|
|
217
|
+
expect(listReports.mock.calls[0]).toEqual(["env", "pkg", "v7"]);
|
|
218
|
+
expect(listModels.mock.calls[0]).toEqual(["env", "pkg", "v7"]);
|
|
219
|
+
expect(
|
|
220
|
+
getModel.mock.calls.find((call) => call[2] === "data_app.malloy"),
|
|
221
|
+
).toEqual(["env", "pkg", "data_app.malloy", "v7"]);
|
|
222
|
+
for (const call of tileCalls()) expect(call[3].versionId).toBe("v7");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("keeps the draft under the document's key, not the query version's", async () => {
|
|
226
|
+
answer = () => pending();
|
|
227
|
+
mountEditor({ queryVersionId: "v7", keepDraft: true });
|
|
228
|
+
await screen.findByText("Storefront");
|
|
229
|
+
editInline("By category", "Tile title", "Categories");
|
|
230
|
+
|
|
231
|
+
const unversioned = reportDraftKey({
|
|
232
|
+
server: TEST_SERVER,
|
|
233
|
+
environmentName: "env",
|
|
234
|
+
packageName: "pkg",
|
|
235
|
+
path: REPORT,
|
|
236
|
+
});
|
|
237
|
+
await waitFor(() =>
|
|
238
|
+
expect(
|
|
239
|
+
Object.keys(localStorage).some((key) => key.endsWith(unversioned)),
|
|
240
|
+
).toBe(true),
|
|
241
|
+
);
|
|
242
|
+
expect(
|
|
243
|
+
Object.keys(localStorage).some((key) => key.includes("@v7/")),
|
|
244
|
+
).toBe(false);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("saves to the package as an unpinned document, with no pinned-version caption", async () => {
|
|
248
|
+
answer = () => pending();
|
|
249
|
+
serverContext.mutable = true;
|
|
250
|
+
mountEditor({ queryVersionId: "v7" });
|
|
251
|
+
await screen.findByText("Storefront");
|
|
252
|
+
expect(screen.queryByText(/Reading version/)).toBeNull();
|
|
253
|
+
|
|
254
|
+
editInline("By category", "Tile title", "Categories");
|
|
255
|
+
fireEvent.click(
|
|
256
|
+
screen.getByRole("button", { name: "Save", hidden: true }),
|
|
257
|
+
);
|
|
258
|
+
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
259
|
+
expect(updateModelSource.mock.calls[0].slice(0, 3)).toEqual([
|
|
260
|
+
"env",
|
|
261
|
+
"pkg",
|
|
262
|
+
REPORT,
|
|
263
|
+
]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("unset, runs the queries at the resourceUri's version, pinned as before", async () => {
|
|
267
|
+
answer = () => pending();
|
|
268
|
+
serverContext.mutable = true;
|
|
269
|
+
mountEditor({}, `${URI}?versionId=v7`);
|
|
270
|
+
await screen.findByText("Storefront");
|
|
271
|
+
await waitFor(() => expect(tileCalls().length).toBeGreaterThan(0));
|
|
272
|
+
|
|
273
|
+
expect(getModel.mock.calls.find((call) => call[2] === REPORT)?.[3]).toBe(
|
|
274
|
+
"v7",
|
|
275
|
+
);
|
|
276
|
+
for (const call of tileCalls()) expect(call[3].versionId).toBe("v7");
|
|
277
|
+
expect(
|
|
278
|
+
screen.getByText(
|
|
279
|
+
"Reading version v7: a version is a fixed point in history, so Save is off.",
|
|
280
|
+
),
|
|
281
|
+
).toBeDefined();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("unset with no version anywhere, asks every query unversioned", async () => {
|
|
285
|
+
answer = () => pending();
|
|
286
|
+
mountEditor();
|
|
287
|
+
await screen.findByText("Storefront");
|
|
288
|
+
await waitFor(() => expect(tileCalls().length).toBeGreaterThan(0));
|
|
289
|
+
for (const call of tileCalls()) expect(call[3].versionId).toBeUndefined();
|
|
290
|
+
expect(getReport.mock.calls[0][3]).toBeUndefined();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { render, screen, within } from "@testing-library/react";
|
|
5
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import type { DashboardManifest } from "../../client";
|
|
7
|
+
import {
|
|
8
|
+
clearCache,
|
|
9
|
+
mockServerProvider,
|
|
10
|
+
pending,
|
|
11
|
+
serverWrapper,
|
|
12
|
+
} from "../../../test/serverProvider";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A tile the builder shows read-only keeps the title the reader gives it. Its
|
|
16
|
+
* `# label` sits on a declaration the builder does not read (a named query, or
|
|
17
|
+
* a view in the model), so the served manifest's label is the one to show.
|
|
18
|
+
*/
|
|
19
|
+
const packageFile = `## artifact { title="Flights" tiles=["by_carrier", "flights -> by_month"] }
|
|
20
|
+
import { flights } from "../flights.malloy"
|
|
21
|
+
|
|
22
|
+
# label="Flights by airline"
|
|
23
|
+
# bar_chart
|
|
24
|
+
query: by_carrier is flights -> { group_by: carrier; aggregate: flight_count }`;
|
|
25
|
+
|
|
26
|
+
const served: Partial<DashboardManifest> = {
|
|
27
|
+
tiles: [
|
|
28
|
+
{
|
|
29
|
+
kind: "query",
|
|
30
|
+
query: "by_carrier",
|
|
31
|
+
label: "Flights by airline",
|
|
32
|
+
givenNames: [],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
kind: "query",
|
|
36
|
+
query: "flights -> by_month",
|
|
37
|
+
label: "Flights each month",
|
|
38
|
+
givenNames: [],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
mockServerProvider(
|
|
44
|
+
{
|
|
45
|
+
models: {
|
|
46
|
+
getModel: mock((_env: string, _pkg: string, path: string) =>
|
|
47
|
+
Promise.resolve({
|
|
48
|
+
data:
|
|
49
|
+
path === "dashboards/flights.malloy"
|
|
50
|
+
? { modelPath: path, sourceText: packageFile }
|
|
51
|
+
: { modelPath: path, sources: [], sourceInfos: [] },
|
|
52
|
+
}),
|
|
53
|
+
),
|
|
54
|
+
executeQueryModel: mock(() => pending()),
|
|
55
|
+
listModels: mock(() => Promise.resolve({ data: [] })),
|
|
56
|
+
},
|
|
57
|
+
reports: {
|
|
58
|
+
getReport: mock(() =>
|
|
59
|
+
Promise.resolve({
|
|
60
|
+
data: { path: "dashboards/flights.malloy", ...served },
|
|
61
|
+
}),
|
|
62
|
+
),
|
|
63
|
+
listReports: mock(() => Promise.resolve({ data: [] })),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{ mutable: true },
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const { ReportEditor } = await import("./ReportEditor");
|
|
70
|
+
|
|
71
|
+
beforeEach(() => clearCache());
|
|
72
|
+
|
|
73
|
+
describe("a read-only tile's title in the builder", () => {
|
|
74
|
+
it("is the served label, as the reader shows it, not one derived from the name", async () => {
|
|
75
|
+
render(
|
|
76
|
+
<ReportEditor
|
|
77
|
+
environmentName="env"
|
|
78
|
+
packageName="pkg"
|
|
79
|
+
dashboardName="flights"
|
|
80
|
+
/>,
|
|
81
|
+
{ wrapper: serverWrapper },
|
|
82
|
+
);
|
|
83
|
+
const named = await screen.findByLabelText("Tile by_carrier");
|
|
84
|
+
expect(
|
|
85
|
+
await within(named).findByText("Flights by airline"),
|
|
86
|
+
).toBeDefined();
|
|
87
|
+
expect(within(named).queryByText("By carrier")).toBeNull();
|
|
88
|
+
// A view in the model is read-only too, and titled the same way.
|
|
89
|
+
const inherited = screen.getByLabelText("Tile by_month");
|
|
90
|
+
expect(within(inherited).getByText("Flights each month")).toBeDefined();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -5,6 +5,7 @@ import { clearReportDraft, reportDraftKey } from "./useReportDraft";
|
|
|
5
5
|
import { Alert, Button, Stack } from "@mui/material";
|
|
6
6
|
import { useQueryClient } from "@tanstack/react-query";
|
|
7
7
|
import { useCallback, useEffect, useRef } from "react";
|
|
8
|
+
import type { CompiledModel } from "../../client";
|
|
8
9
|
import type { HostGivenValue } from "../../hooks/givenValue";
|
|
9
10
|
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
10
11
|
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
@@ -155,6 +156,24 @@ export type ReportEditorProps = (
|
|
|
155
156
|
keepDraft?: boolean;
|
|
156
157
|
/** Edit a document held as text; see {@link TextSourceOptions}. */
|
|
157
158
|
textSource?: TextSourceOptions;
|
|
159
|
+
/**
|
|
160
|
+
* The package version the builder's queries run at, apart from the
|
|
161
|
+
* document's own identity: every tile, the report's manifest, filter
|
|
162
|
+
* options and suggestions, the report listing and the field catalog.
|
|
163
|
+
*
|
|
164
|
+
* The document is still the one `resourceUri` and `path` name, so the kept
|
|
165
|
+
* draft, where a save goes, the save caption and whether a save is a pinned
|
|
166
|
+
* one all follow `resourceUri` alone. A host editing a package that is
|
|
167
|
+
* republished on every change passes an unversioned `resourceUri` and the
|
|
168
|
+
* version its reader ran at here: the builder then reuses the reader's
|
|
169
|
+
* results instead of running every tile again, and kept edits survive the
|
|
170
|
+
* next republish.
|
|
171
|
+
*
|
|
172
|
+
* Unset, queries run at the `resourceUri`'s version, as before. A text-held
|
|
173
|
+
* document's compile has no version, so it is compiled as today; its tiles
|
|
174
|
+
* do run at this version.
|
|
175
|
+
*/
|
|
176
|
+
queryVersionId?: string;
|
|
158
177
|
};
|
|
159
178
|
|
|
160
179
|
/**
|
|
@@ -210,6 +229,7 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
210
229
|
kind,
|
|
211
230
|
path,
|
|
212
231
|
textSource,
|
|
232
|
+
queryVersionId,
|
|
213
233
|
} = props;
|
|
214
234
|
const layout: ReportLayout =
|
|
215
235
|
props.layout ?? (kind ? layoutOfKind(kind) : "grid");
|
|
@@ -389,6 +409,17 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
389
409
|
|
|
390
410
|
// One per report, version and server: a draft is never restored onto a
|
|
391
411
|
// file it was not made on.
|
|
412
|
+
// The file's compiled model, only while the builder is on the text it
|
|
413
|
+
// compiled. A kept draft, the host's record or a version held back is other
|
|
414
|
+
// text, whose views can differ under the same names.
|
|
415
|
+
const fileModel =
|
|
416
|
+
!textSource &&
|
|
417
|
+
modelQuery.data?.data &&
|
|
418
|
+
packageText !== undefined &&
|
|
419
|
+
opened?.source === packageText
|
|
420
|
+
? (modelQuery.data.data as CompiledModel)
|
|
421
|
+
: undefined;
|
|
422
|
+
|
|
392
423
|
const draftKey = keepDraft
|
|
393
424
|
? reportDraftKey({
|
|
394
425
|
server,
|
|
@@ -536,6 +567,9 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
536
567
|
{...(textSource ? { textSource } : {})}
|
|
537
568
|
slug={dashboardName}
|
|
538
569
|
{...(versionId !== undefined ? { versionId } : {})}
|
|
570
|
+
{...((queryVersionId ?? versionId) !== undefined
|
|
571
|
+
? { queryVersionId: queryVersionId ?? versionId }
|
|
572
|
+
: {})}
|
|
539
573
|
opened={opened}
|
|
540
574
|
{...(fromDraft &&
|
|
541
575
|
writer === "package" &&
|
|
@@ -552,6 +586,7 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
552
586
|
{...(saveLabel ? { saveLabel } : {})}
|
|
553
587
|
{...(onEvent ? { onEvent: reportEvent } : {})}
|
|
554
588
|
note={note}
|
|
589
|
+
{...(fileModel ? { fileModel } : {})}
|
|
555
590
|
/>
|
|
556
591
|
)}
|
|
557
592
|
</Stack>
|