@malloy-publisher/sdk 0.9.10 → 0.9.11
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-BlNoIiSi.cjs.js +153 -0
- package/dist/{RenderedResult-Dp1Qdajz.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
- package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
- package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
- package/dist/builder/index.cjs.js +78 -130
- package/dist/builder/index.es.js +7493 -6769
- package/dist/builder-entry.d.ts +3 -0
- package/dist/client/api.d.ts +26 -22
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/AppDialog.d.ts +9 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
- package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
- package/dist/components/Dashboard/DashboardView.d.ts +22 -34
- package/dist/components/Dashboard/TileCard.d.ts +10 -3
- package/dist/components/Dashboard/useStuck.d.ts +15 -7
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
- package/dist/components/Package/PackageProblems.d.ts +14 -0
- package/dist/components/RemoveBadge.d.ts +40 -0
- package/dist/components/Report/Report.d.ts +13 -4
- package/dist/components/Report/ReportPage.d.ts +60 -0
- package/dist/components/Report/layoutRules.d.ts +32 -0
- package/dist/components/Report/reportQuery.d.ts +30 -0
- package/dist/components/Report/telemetry.d.ts +0 -2
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
- package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
- package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
- package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
- package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
- package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
- package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
- package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -8
- package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
- package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
- package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
- package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
- package/dist/components/ReportBuilder/TileMenu.d.ts +12 -9
- package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
- package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
- package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
- package/dist/components/ReportBuilder/catalog.d.ts +2 -4
- package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
- package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
- package/dist/components/ReportBuilder/preview.d.ts +17 -2
- package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
- package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
- package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
- package/dist/components/ReportBuilder/sortable.d.ts +4 -3
- package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
- package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
- package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
- package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
- package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
- package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
- package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
- package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
- package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
- package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
- package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
- package/dist/components/ServerProvider.d.ts +9 -0
- package/dist/components/controlTokens.d.ts +45 -0
- package/dist/components/drill/markDrillableCells.d.ts +1 -1
- package/dist/components/given/FilterButton.d.ts +35 -0
- package/dist/components/given/GivensPanel.d.ts +2 -1
- package/dist/components/given/filterEditing.d.ts +54 -0
- package/dist/components/given/filterSummary.d.ts +9 -0
- package/dist/components/given/paramCodec.d.ts +11 -0
- package/dist/components/given/required.d.ts +25 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/legacy/index.d.ts +1 -1
- package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
- package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
- package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
- package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
- package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
- package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
- package/dist/components/styles.d.ts +0 -2
- package/dist/hooks/useQueryResult.d.ts +7 -0
- package/dist/index.cjs.js +16 -19
- package/dist/index.es.js +8324 -7769
- package/dist/theme/ThemeContext.d.ts +8 -1
- package/dist/theme/classes.d.ts +49 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/types.d.ts +7 -0
- package/dist/theme/ui.d.ts +75 -0
- package/dist/{useCompiledDocument-BMPDvdFx.es.js → useCompiledDocument-7j5cBjQd.es.js} +8669 -7851
- package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
- package/package.json +2 -2
- package/src/builder-entry.ts +9 -0
- package/src/components/AppDialog.tsx +23 -0
- package/src/components/Dashboard/DashboardGrid.tsx +39 -17
- package/src/components/Dashboard/DashboardTile.tsx +19 -2
- package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
- package/src/components/Dashboard/DashboardView.tsx +137 -155
- package/src/components/Dashboard/RowsDialog.tsx +1 -2
- package/src/components/Dashboard/TileCard.tsx +28 -10
- package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
- package/src/components/Dashboard/useStuck.ts +28 -17
- package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
- package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
- package/src/components/Package/NewDocumentDialog.tsx +383 -119
- package/src/components/Package/Package.artifacts.spec.tsx +1 -1
- package/src/components/Package/Package.create.spec.tsx +7 -6
- package/src/components/Package/Package.tsx +10 -7
- package/src/components/Package/PackageProblems.spec.tsx +41 -0
- package/src/components/Package/PackageProblems.tsx +95 -0
- package/src/components/Prose.tsx +12 -7
- package/src/components/RemoveBadge.tsx +94 -0
- package/src/components/RenderedResult/RenderedResult.tsx +5 -9
- package/src/components/RenderedResult/ResultPanel.tsx +59 -3
- package/src/components/Report/Report.spec.tsx +50 -32
- package/src/components/Report/Report.telemetry.spec.tsx +0 -45
- package/src/components/Report/Report.tsx +45 -77
- package/src/components/Report/ReportPage.tsx +168 -0
- package/src/components/Report/layoutRules.spec.ts +35 -0
- package/src/components/Report/layoutRules.ts +55 -0
- package/src/components/Report/reportQuery.ts +53 -0
- package/src/components/Report/telemetry.ts +0 -2
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
- package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
- package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
- package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
- package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
- package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
- package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
- package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
- package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
- package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
- package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
- package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
- package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
- package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
- package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
- package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
- package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
- package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
- package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
- package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
- package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
- package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
- package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
- package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
- package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
- package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
- package/src/components/ReportBuilder/TileFrame.tsx +212 -75
- package/src/components/ReportBuilder/TileMenu.tsx +241 -140
- package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
- package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
- package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
- package/src/components/ReportBuilder/builderControls.ts +164 -0
- package/src/components/ReportBuilder/builderReport.ts +1 -2
- package/src/components/ReportBuilder/catalog.ts +10 -26
- package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
- package/src/components/ReportBuilder/localGiven.ts +56 -0
- package/src/components/ReportBuilder/preview.spec.ts +125 -5
- package/src/components/ReportBuilder/preview.ts +60 -44
- package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
- package/src/components/ReportBuilder/readDocument.ts +14 -11
- package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
- package/src/components/ReportBuilder/readForEditor.ts +4 -26
- package/src/components/ReportBuilder/reportTag.ts +28 -7
- package/src/components/ReportBuilder/sortable.tsx +15 -7
- package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
- package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
- package/src/components/ReportBuilder/testing/inline.ts +25 -5
- package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
- package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
- package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
- package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
- package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
- package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
- package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
- package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
- package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
- package/src/components/ReportBuilder/useExitGuard.ts +16 -0
- package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
- package/src/components/ReportBuilder/useFilterForm.ts +5 -1
- package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
- package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
- package/src/components/ReportBuilder/useReportDraft.ts +292 -0
- package/src/components/ReportBuilder/useReportEditor.ts +3 -12
- package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
- package/src/components/ReportBuilder/useTileEditing.ts +43 -12
- package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
- package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
- package/src/components/ReportBuilder/widthLabel.ts +26 -0
- package/src/components/ServerProvider.tsx +11 -0
- package/src/components/controlTokens.ts +47 -0
- package/src/components/drill/markDrillableCells.ts +2 -1
- package/src/components/given/FilterButton.spec.tsx +143 -0
- package/src/components/given/FilterButton.tsx +478 -0
- package/src/components/given/GivenInput.spec.tsx +47 -0
- package/src/components/given/GivenInput.tsx +20 -2
- package/src/components/given/GivensPanel.spec.tsx +11 -3
- package/src/components/given/GivensPanel.tsx +45 -44
- package/src/components/given/filterEditing.ts +60 -0
- package/src/components/given/filterSummary.spec.ts +108 -0
- package/src/components/given/filterSummary.ts +109 -0
- package/src/components/given/paramCodec.ts +1 -1
- package/src/components/given/required.spec.ts +60 -0
- package/src/components/given/required.ts +78 -0
- package/src/components/index.ts +9 -0
- package/src/components/legacy/Dashboard.spec.tsx +3 -1
- package/src/components/legacy/index.ts +1 -1
- package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
- package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
- package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
- package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
- package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
- package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
- package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
- package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
- package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
- package/src/components/legacy/malloynb/cellKind.ts +24 -0
- package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
- package/src/components/styles.ts +0 -18
- package/src/hooks/useGivensState.ts +7 -3
- package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
- package/src/hooks/useQueryResult.ts +26 -1
- package/src/theme/ThemeContext.tsx +21 -1
- package/src/theme/classes.ts +52 -0
- package/src/theme/index.ts +8 -0
- package/src/theme/resolveTheme.ts +3 -0
- package/src/theme/types.ts +7 -0
- package/src/theme/ui.spec.tsx +91 -0
- package/src/theme/ui.ts +115 -0
- package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
- package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
- package/dist/components/Notebook/cellKind.d.ts +0 -20
- package/dist/components/Report/LinearReport.d.ts +0 -18
- package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
- package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
- package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
- package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
- package/src/components/Notebook/cellKind.spec.ts +0 -199
- package/src/components/Notebook/cellKind.ts +0 -74
- package/src/components/Report/LinearReport.tsx +0 -71
- package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
- package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
- package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
- package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
- package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
- package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
- package/src/components/legacy/Notebook.served.spec.tsx +0 -183
- /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
- /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
- /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A filter a tile reads through the model (the source's own `where:`) shows in
|
|
6
|
+
* the builder's row as it does in the reader's, settable, but not removable or
|
|
7
|
+
* configured: the builder never edits the model.
|
|
8
|
+
*/
|
|
9
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
10
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
11
|
+
import type { DashboardManifest } from "../../client";
|
|
12
|
+
import {
|
|
13
|
+
clearCache,
|
|
14
|
+
mockServerProvider,
|
|
15
|
+
pending,
|
|
16
|
+
serverWrapper,
|
|
17
|
+
} from "../../../test/serverProvider";
|
|
18
|
+
|
|
19
|
+
let packageFile = "";
|
|
20
|
+
let served: Partial<DashboardManifest> = {};
|
|
21
|
+
|
|
22
|
+
const MANUFACTURER = {
|
|
23
|
+
name: "manufacturer_filter",
|
|
24
|
+
label: "Manufacturer",
|
|
25
|
+
type: "filter<string>",
|
|
26
|
+
};
|
|
27
|
+
const SUBJECT = {
|
|
28
|
+
name: "subject_filter",
|
|
29
|
+
label: "Subject",
|
|
30
|
+
type: "filter<string>",
|
|
31
|
+
};
|
|
32
|
+
const SINCE = { name: "SINCE", label: "Since", type: "date" };
|
|
33
|
+
|
|
34
|
+
const executeQueryModel = mock(
|
|
35
|
+
(_env: string, _pkg: string, _path: string, _body: { query?: string }) =>
|
|
36
|
+
pending(),
|
|
37
|
+
);
|
|
38
|
+
const getModel = mock((_env: string, _pkg: string, path: string) =>
|
|
39
|
+
Promise.resolve({
|
|
40
|
+
data:
|
|
41
|
+
path === "README.malloy"
|
|
42
|
+
? { path, sourceText: packageFile }
|
|
43
|
+
: path === "reports/recalls.malloy"
|
|
44
|
+
? { path, sourceText: packageFile }
|
|
45
|
+
: { path, sources: [], sourceInfos: [] },
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
const getReport = mock(() =>
|
|
49
|
+
Promise.resolve({ data: { path: "README.malloy", tiles: [], ...served } }),
|
|
50
|
+
);
|
|
51
|
+
mockServerProvider(
|
|
52
|
+
{
|
|
53
|
+
models: {
|
|
54
|
+
getModel,
|
|
55
|
+
executeQueryModel,
|
|
56
|
+
listModels: mock(() => Promise.resolve({ data: [] })),
|
|
57
|
+
},
|
|
58
|
+
reports: {
|
|
59
|
+
getReport,
|
|
60
|
+
listReports: mock(() => Promise.resolve({ data: [] })),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{ mutable: true },
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const { ReportEditor } = await import("./ReportEditor");
|
|
67
|
+
|
|
68
|
+
beforeEach(() => {
|
|
69
|
+
clearCache();
|
|
70
|
+
executeQueryModel.mockClear();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const open = (
|
|
74
|
+
extra: { onOpenModel?: (modelPath: string) => void } = {},
|
|
75
|
+
path = "README.malloy",
|
|
76
|
+
) =>
|
|
77
|
+
render(
|
|
78
|
+
<ReportEditor
|
|
79
|
+
resourceUri="publisher://environments/env/packages/pkg"
|
|
80
|
+
path={path}
|
|
81
|
+
{...extra}
|
|
82
|
+
/>,
|
|
83
|
+
{ wrapper: serverWrapper },
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
/** The filter buttons in the row, by their names as a reader hears them. */
|
|
87
|
+
const row = async () =>
|
|
88
|
+
(
|
|
89
|
+
await screen.findAllByRole("button", {
|
|
90
|
+
name: /^(Manufacturer|Subject|Since): /,
|
|
91
|
+
})
|
|
92
|
+
).map((button) => button.getAttribute("aria-label")?.split(":")[0]);
|
|
93
|
+
|
|
94
|
+
describe("filters read through the model", () => {
|
|
95
|
+
it("are in the builder's row as in the reader's, with no remove and no settings", async () => {
|
|
96
|
+
packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year", "recalls_tiles -> by_maker"] } dashboard { columns=12 }
|
|
97
|
+
import "auto_recalls.malloy"
|
|
98
|
+
|
|
99
|
+
source: recalls_tiles is recalls extend {
|
|
100
|
+
view: by_year is by_year_view
|
|
101
|
+
view: by_maker is by_maker_view
|
|
102
|
+
}`;
|
|
103
|
+
served = {
|
|
104
|
+
givens: [MANUFACTURER, SUBJECT],
|
|
105
|
+
tiles: [
|
|
106
|
+
{
|
|
107
|
+
kind: "query",
|
|
108
|
+
query: "recalls_tiles -> by_year",
|
|
109
|
+
givenNames: ["manufacturer_filter"],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
kind: "query",
|
|
113
|
+
query: "recalls_tiles -> by_maker",
|
|
114
|
+
givenNames: ["manufacturer_filter", "subject_filter"],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
open();
|
|
119
|
+
expect(await row()).toEqual(["Manufacturer", "Subject"]);
|
|
120
|
+
expect(
|
|
121
|
+
screen.queryByRole("button", {
|
|
122
|
+
name: "Remove filter manufacturer_filter",
|
|
123
|
+
}),
|
|
124
|
+
).toBeNull();
|
|
125
|
+
|
|
126
|
+
fireEvent.click(screen.getByRole("button", { name: /^Manufacturer: / }));
|
|
127
|
+
const popover = await screen.findByRole("dialog", {
|
|
128
|
+
name: "Manufacturer filter",
|
|
129
|
+
});
|
|
130
|
+
expect(popover.textContent).toContain(
|
|
131
|
+
"Set in the model auto_recalls.malloy. Edit the model to change it.",
|
|
132
|
+
);
|
|
133
|
+
expect(
|
|
134
|
+
screen.queryByRole("button", {
|
|
135
|
+
name: "Edit filter manufacturer_filter",
|
|
136
|
+
}),
|
|
137
|
+
).toBeNull();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("come after this file's own bound filters, which stay removable", async () => {
|
|
141
|
+
packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year"] } dashboard { columns=12 }
|
|
142
|
+
import "auto_recalls.malloy"
|
|
143
|
+
|
|
144
|
+
#(control) label="Since"
|
|
145
|
+
given: SINCE :: date is @2020-01-01
|
|
146
|
+
|
|
147
|
+
source: recalls_tiles is recalls extend {
|
|
148
|
+
view: by_year is by_year_view + { where: recall_date >= $SINCE }
|
|
149
|
+
}`;
|
|
150
|
+
served = {
|
|
151
|
+
givens: [SINCE, MANUFACTURER],
|
|
152
|
+
tiles: [
|
|
153
|
+
{
|
|
154
|
+
kind: "query",
|
|
155
|
+
query: "recalls_tiles -> by_year",
|
|
156
|
+
givenNames: ["SINCE", "manufacturer_filter"],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
open();
|
|
161
|
+
expect(await row()).toEqual(["Since", "Manufacturer"]);
|
|
162
|
+
expect(
|
|
163
|
+
screen.getByRole("button", { name: "Remove filter SINCE" }),
|
|
164
|
+
).toBeTruthy();
|
|
165
|
+
expect(
|
|
166
|
+
screen.queryByRole("button", {
|
|
167
|
+
name: "Remove filter manufacturer_filter",
|
|
168
|
+
}),
|
|
169
|
+
).toBeNull();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("says a filter this report's own source applies is the file's, not the model's", async () => {
|
|
173
|
+
packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year"] } dashboard { columns=12 }
|
|
174
|
+
import "auto_recalls.malloy"
|
|
175
|
+
|
|
176
|
+
#(control) label="Since"
|
|
177
|
+
given: SINCE :: date is @2020-01-01
|
|
178
|
+
|
|
179
|
+
source: recalls_tiles is recalls extend {
|
|
180
|
+
where: recall_date >= $SINCE
|
|
181
|
+
view: by_year is by_year_view
|
|
182
|
+
}`;
|
|
183
|
+
served = {
|
|
184
|
+
givens: [SINCE],
|
|
185
|
+
tiles: [
|
|
186
|
+
{
|
|
187
|
+
kind: "query",
|
|
188
|
+
query: "recalls_tiles -> by_year",
|
|
189
|
+
givenNames: ["SINCE"],
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
};
|
|
193
|
+
open();
|
|
194
|
+
expect(await row()).toEqual(["Since"]);
|
|
195
|
+
fireEvent.click(screen.getByRole("button", { name: /^Since: / }));
|
|
196
|
+
const popover = await screen.findByRole("dialog", {
|
|
197
|
+
name: "Since filter",
|
|
198
|
+
});
|
|
199
|
+
expect(popover.textContent).not.toContain("Set in the model");
|
|
200
|
+
expect(popover.textContent).toContain("recalls_tiles");
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("what a report says about a filter it cannot change", () => {
|
|
205
|
+
const RECALLS = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year"] } dashboard { columns=12 }
|
|
206
|
+
import "auto_recalls.malloy"
|
|
207
|
+
|
|
208
|
+
source: recalls_tiles is recalls extend {
|
|
209
|
+
view: by_year is by_year_view
|
|
210
|
+
}`;
|
|
211
|
+
const READS_MANUFACTURER = {
|
|
212
|
+
givens: [MANUFACTURER],
|
|
213
|
+
startingGivens: { manufacturer_filter: "Ford" },
|
|
214
|
+
tiles: [
|
|
215
|
+
{
|
|
216
|
+
kind: "query" as const,
|
|
217
|
+
query: "recalls_tiles -> by_year",
|
|
218
|
+
givenNames: ["manufacturer_filter"],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
it("can open the report with the model filter's current value", async () => {
|
|
224
|
+
packageFile = RECALLS;
|
|
225
|
+
served = READS_MANUFACTURER;
|
|
226
|
+
open();
|
|
227
|
+
fireEvent.click(
|
|
228
|
+
await screen.findByRole("button", { name: /^Manufacturer: / }),
|
|
229
|
+
);
|
|
230
|
+
fireEvent.click(
|
|
231
|
+
await screen.findByRole("button", {
|
|
232
|
+
name: "Open the report with this value",
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
// The report now holds it: the popover says so, and Undo takes it back.
|
|
236
|
+
expect(
|
|
237
|
+
await screen.findByText("The report opens with this value."),
|
|
238
|
+
).toBeDefined();
|
|
239
|
+
expect(
|
|
240
|
+
(
|
|
241
|
+
screen.getByRole("button", {
|
|
242
|
+
name: "Undo",
|
|
243
|
+
hidden: true,
|
|
244
|
+
}) as HTMLButtonElement
|
|
245
|
+
).disabled,
|
|
246
|
+
).toBe(false);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("opens the model by its package path, from a report in a folder", async () => {
|
|
250
|
+
packageFile = RECALLS.replace(
|
|
251
|
+
'import "auto_recalls.malloy"',
|
|
252
|
+
'import "../auto_recalls.malloy"',
|
|
253
|
+
);
|
|
254
|
+
served = READS_MANUFACTURER;
|
|
255
|
+
const onOpenModel = mock((_path: string) => {});
|
|
256
|
+
open({ onOpenModel }, "reports/recalls.malloy");
|
|
257
|
+
fireEvent.click(
|
|
258
|
+
await screen.findByRole("button", { name: /^Manufacturer: / }),
|
|
259
|
+
);
|
|
260
|
+
fireEvent.click(
|
|
261
|
+
await screen.findByRole("button", { name: "Open the model" }),
|
|
262
|
+
);
|
|
263
|
+
expect(onOpenModel).toHaveBeenCalledWith("auto_recalls.malloy");
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe("a required filter the model reads, in the builder", () => {
|
|
268
|
+
it("runs no tile that reads it and asks for it, as the reader does", async () => {
|
|
269
|
+
packageFile = `## artifact { title="Recalls" tiles=["recalls_tiles -> by_year", "recalls_tiles -> everything"] } dashboard { columns=12 }
|
|
270
|
+
import "auto_recalls.malloy"
|
|
271
|
+
|
|
272
|
+
source: recalls_tiles is recalls extend {
|
|
273
|
+
view: by_year is by_year_view
|
|
274
|
+
view: everything is everything_view
|
|
275
|
+
}`;
|
|
276
|
+
served = {
|
|
277
|
+
givens: [
|
|
278
|
+
{
|
|
279
|
+
name: "RECALL_YEAR",
|
|
280
|
+
label: "Recall Year",
|
|
281
|
+
type: "number",
|
|
282
|
+
required: true,
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
tiles: [
|
|
286
|
+
{
|
|
287
|
+
kind: "query",
|
|
288
|
+
query: "recalls_tiles -> by_year",
|
|
289
|
+
givenNames: ["RECALL_YEAR"],
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
kind: "query",
|
|
293
|
+
query: "recalls_tiles -> everything",
|
|
294
|
+
givenNames: [],
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
};
|
|
298
|
+
open();
|
|
299
|
+
expect(
|
|
300
|
+
await screen.findByText(
|
|
301
|
+
"Pick a value for Recall Year to see this report.",
|
|
302
|
+
),
|
|
303
|
+
).toBeDefined();
|
|
304
|
+
expect(screen.getByText("Waiting for Recall Year.")).toBeDefined();
|
|
305
|
+
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
306
|
+
const queries = executeQueryModel.mock.calls.map((call) =>
|
|
307
|
+
JSON.stringify(call[3]),
|
|
308
|
+
);
|
|
309
|
+
expect(queries.some((q) => q.includes("everything"))).toBe(true);
|
|
310
|
+
expect(queries.some((q) => q.includes("by_year"))).toBe(false);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
waitFor,
|
|
10
10
|
} from "@testing-library/react";
|
|
11
11
|
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
12
|
-
import * as fs from "fs";
|
|
13
|
-
import * as path from "path";
|
|
14
12
|
import {
|
|
15
13
|
clearCache,
|
|
16
14
|
mockServerProvider,
|
|
@@ -31,16 +29,8 @@ import { editInline } from "./testing/inline";
|
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* The one editor opened as a notebook: how it reads the file, where it takes
|
|
34
|
-
* the manifest from
|
|
32
|
+
* the manifest from.
|
|
35
33
|
*/
|
|
36
|
-
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
37
|
-
const LEGACY = fs
|
|
38
|
-
.readFileSync(
|
|
39
|
-
path.join(REPO, "examples/storefront/category-review.malloy"),
|
|
40
|
-
"utf8",
|
|
41
|
-
)
|
|
42
|
-
.replace(/\r\n/g, "\n");
|
|
43
|
-
|
|
44
34
|
const LAYOUT = `## artifact { layout=linear title="Tour" tiles=[intro { kind=text }] }
|
|
45
35
|
|
|
46
36
|
##|(markdown) intro
|
|
@@ -48,12 +38,6 @@ Hello.
|
|
|
48
38
|
|##
|
|
49
39
|
`;
|
|
50
40
|
|
|
51
|
-
const REFUSED = `## artifact { layout=linear }
|
|
52
|
-
import { orders } from "../m.malloy"
|
|
53
|
-
|
|
54
|
-
run: orders extend { dimension: z is 1 } -> { select: z }
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
41
|
let served = LAYOUT;
|
|
58
42
|
let servedHash = await sha256Hex(LAYOUT);
|
|
59
43
|
let writes: string[] = [];
|
|
@@ -73,22 +57,15 @@ const getModel = mock(
|
|
|
73
57
|
},
|
|
74
58
|
}),
|
|
75
59
|
);
|
|
76
|
-
// One read for either layout, by path:
|
|
77
|
-
// one in cells carries its cells instead.
|
|
60
|
+
// One read for either layout, by path: the report's manifest.
|
|
78
61
|
const getReport = mock(
|
|
79
62
|
async (_env: string, _pkg: string, modelPath: string) => ({
|
|
80
|
-
data:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
: {
|
|
88
|
-
path: modelPath,
|
|
89
|
-
layout: "linear",
|
|
90
|
-
notebook: { notebookCells: [] },
|
|
91
|
-
},
|
|
63
|
+
data: {
|
|
64
|
+
path: modelPath,
|
|
65
|
+
layout: "linear",
|
|
66
|
+
givens: [{ name: "FROM_MANIFEST", type: "string" }],
|
|
67
|
+
tiles: [],
|
|
68
|
+
},
|
|
92
69
|
}),
|
|
93
70
|
);
|
|
94
71
|
const getDashboard = mock(() => pending());
|
|
@@ -207,6 +184,24 @@ describe("ReportEditor as a notebook", () => {
|
|
|
207
184
|
expect(getModel.mock.calls[0][2]).toBe("dashboards/tour.malloy");
|
|
208
185
|
});
|
|
209
186
|
|
|
187
|
+
it("refuses a file written as `run:` cells, saying why, and reports a category, never the reason", async () => {
|
|
188
|
+
served =
|
|
189
|
+
'## artifact { layout=linear }\nimport { orders } from "../m.malloy"\n\nrun: orders -> by_month\n';
|
|
190
|
+
const onEvent = mock((_event: ReportEvent) => {});
|
|
191
|
+
mount({}, onEvent);
|
|
192
|
+
expect(
|
|
193
|
+
await screen.findByText(/written as `run:` cells is no longer read/),
|
|
194
|
+
).toBeDefined();
|
|
195
|
+
expect(onEvent.mock.calls[0][0]).toMatchObject({
|
|
196
|
+
type: "report.load_failed",
|
|
197
|
+
surface: "edit",
|
|
198
|
+
category: "invalid",
|
|
199
|
+
});
|
|
200
|
+
// A category, never the message: the reason can carry the file's text.
|
|
201
|
+
expect(onEvent.mock.calls[0][0]).not.toHaveProperty("reason");
|
|
202
|
+
expect(writes).toEqual([]);
|
|
203
|
+
});
|
|
204
|
+
|
|
210
205
|
// DEPRECATED FEATURE COVERAGE — delete together with
|
|
211
206
|
// `.malloynb` notebooks (see RELEASE_NOTES deprecations).
|
|
212
207
|
describe("deprecated: .malloynb notebooks", () => {
|
|
@@ -226,50 +221,6 @@ describe("ReportEditor as a notebook", () => {
|
|
|
226
221
|
});
|
|
227
222
|
});
|
|
228
223
|
});
|
|
229
|
-
|
|
230
|
-
it("offers a notebook in the cell format as a conversion, and Save writes it exactly", async () => {
|
|
231
|
-
served = LEGACY;
|
|
232
|
-
servedHash = await sha256Hex(LEGACY);
|
|
233
|
-
const onEvent = mock((_event: ReportEvent) => {});
|
|
234
|
-
mount({}, onEvent);
|
|
235
|
-
expect(
|
|
236
|
-
await screen.findByText(/This report is in the cell format/),
|
|
237
|
-
).toBeDefined();
|
|
238
|
-
expect(screen.getByLabelText("Tile revenue_by_month")).toBeDefined();
|
|
239
|
-
|
|
240
|
-
fireEvent.click(button("Save"));
|
|
241
|
-
fireEvent.click(
|
|
242
|
-
await screen.findByRole("button", { name: "Convert and save" }),
|
|
243
|
-
);
|
|
244
|
-
await waitFor(() => expect(writes).toHaveLength(1));
|
|
245
|
-
expect(writes[0]).toContain("tiles=[\n text_1 { kind=text }");
|
|
246
|
-
expect(writes[0]).toContain("view: revenue_by_month is sales_by_month");
|
|
247
|
-
await waitFor(() =>
|
|
248
|
-
expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
|
|
249
|
-
"report.opened",
|
|
250
|
-
"report.saved",
|
|
251
|
-
]),
|
|
252
|
-
);
|
|
253
|
-
expect(onEvent.mock.calls[1][0]).toMatchObject({ converted: true });
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("says why a notebook cannot be converted, naming the line", async () => {
|
|
257
|
-
served = REFUSED;
|
|
258
|
-
const onEvent = mock((_event: ReportEvent) => {});
|
|
259
|
-
mount({}, onEvent);
|
|
260
|
-
const alert = await screen.findByText(/cannot be opened in the builder/);
|
|
261
|
-
expect(alert.textContent).toMatch(/line 4/i);
|
|
262
|
-
expect(
|
|
263
|
-
screen.queryByText(/This report is in the cell format/),
|
|
264
|
-
).toBeNull();
|
|
265
|
-
expect(onEvent.mock.calls[0][0]).toMatchObject({
|
|
266
|
-
type: "report.load_failed",
|
|
267
|
-
surface: "edit",
|
|
268
|
-
category: "invalid",
|
|
269
|
-
});
|
|
270
|
-
// A category, never the message: the reason can carry the file's text.
|
|
271
|
-
expect(onEvent.mock.calls[0][0]).not.toHaveProperty("reason");
|
|
272
|
-
});
|
|
273
224
|
});
|
|
274
225
|
|
|
275
226
|
describe("ReportEditor as a notebook: the host's record", () => {
|
|
@@ -118,8 +118,12 @@ describe("ReportEditor, when the server takes writes", () => {
|
|
|
118
118
|
await new BrowserDocumentStorage().saveDocument(DRAFT, "stale draft");
|
|
119
119
|
await screen.findByText("Storefront");
|
|
120
120
|
expect(
|
|
121
|
-
|
|
122
|
-
).
|
|
121
|
+
document.querySelector('[data-saves-to="package"]'),
|
|
122
|
+
).not.toBeNull();
|
|
123
|
+
// The ordinary case is not a line on the page; the status says it.
|
|
124
|
+
expect(
|
|
125
|
+
screen.queryByText("Save writes the file into the package."),
|
|
126
|
+
).toBeNull();
|
|
123
127
|
|
|
124
128
|
editInline("By category", "Tile title", "Categories");
|
|
125
129
|
fireEvent.click(button("Save"));
|
|
@@ -233,7 +233,8 @@ describe("versionId", () => {
|
|
|
233
233
|
expect(
|
|
234
234
|
getModel.mock.calls.find((call) => call[2] === "data_app.malloy"),
|
|
235
235
|
).toEqual(["env", "pkg", "data_app.malloy", "v7"]);
|
|
236
|
-
|
|
236
|
+
// The reader's request, which also carries its abort signal.
|
|
237
|
+
expect(getReport.mock.calls[0].slice(0, 4)).toEqual([
|
|
237
238
|
"env",
|
|
238
239
|
"pkg",
|
|
239
240
|
"dashboards/overview.malloy",
|
|
@@ -247,7 +248,7 @@ describe("versionId", () => {
|
|
|
247
248
|
// one dashboard apart, and nothing about that failure is visible on
|
|
248
249
|
// screen.
|
|
249
250
|
expect(cacheKeys("dashboard-editor-model")[0]).toContain('"v7"');
|
|
250
|
-
expect(cacheKeys("
|
|
251
|
+
expect(cacheKeys("report")[0]).toContain('"v7"');
|
|
251
252
|
expect(cacheKeys("reports")[0]).toContain('"v7"');
|
|
252
253
|
await waitFor(() =>
|
|
253
254
|
expect(cacheKeys("report-editor-models")[0]).toContain('"v7"'),
|
|
@@ -33,7 +33,7 @@ source: a is scoped_orders extend {
|
|
|
33
33
|
# label="By category"
|
|
34
34
|
view: by_cat is by_category
|
|
35
35
|
}`;
|
|
36
|
-
import { editInline } from "./testing/inline";
|
|
36
|
+
import { editInline, findViewOption } from "./testing/inline";
|
|
37
37
|
|
|
38
38
|
let served = PACKAGE_FILE;
|
|
39
39
|
/** Set, and the dashboard's own file fails to fetch: a refetch the server could not answer. */
|
|
@@ -246,9 +246,7 @@ describe("ReportEditor", () => {
|
|
|
246
246
|
fireEvent.click(
|
|
247
247
|
await screen.findByRole("button", { name: "Add tile", hidden: true }),
|
|
248
248
|
);
|
|
249
|
-
expect(
|
|
250
|
-
await screen.findByRole("button", { name: "View by_category" }),
|
|
251
|
-
).toBeDefined();
|
|
249
|
+
expect(await findViewOption("by_category")).toBeDefined();
|
|
252
250
|
});
|
|
253
251
|
|
|
254
252
|
it("leaves the package's listed reports out of the catalog, wherever they live", async () => {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { findViewOption } from "./testing/inline";
|
|
4
5
|
import {
|
|
5
6
|
cleanup,
|
|
6
7
|
fireEvent,
|
|
7
8
|
render,
|
|
8
9
|
screen,
|
|
9
10
|
waitFor,
|
|
10
|
-
within,
|
|
11
11
|
} from "@testing-library/react";
|
|
12
12
|
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
13
13
|
import {
|
|
@@ -128,6 +128,7 @@ const mount = (
|
|
|
128
128
|
textSource: {
|
|
129
129
|
modelPath: string;
|
|
130
130
|
givens?: Record<string, string | string[]>;
|
|
131
|
+
compileSource?: (text: string) => string | Promise<string>;
|
|
131
132
|
} = {
|
|
132
133
|
modelPath: "models/orders.malloy",
|
|
133
134
|
},
|
|
@@ -335,18 +336,15 @@ describe("ReportEditor in text-source mode", () => {
|
|
|
335
336
|
fireEvent.click(
|
|
336
337
|
await screen.findByRole("button", { name: "Add tile" }),
|
|
337
338
|
);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
]);
|
|
348
|
-
fireEvent.keyDown(screen.getByRole("listbox"), { key: "Escape" });
|
|
349
|
-
fireEvent.click(await screen.findByLabelText("View by_x"));
|
|
339
|
+
await findViewOption("by_x");
|
|
340
|
+
expect(
|
|
341
|
+
screen
|
|
342
|
+
.getAllByRole("group", { hidden: true })
|
|
343
|
+
.map((group) => group.getAttribute("aria-label"))
|
|
344
|
+
.filter((name) => name === "orders" || name === "other")
|
|
345
|
+
.sort(),
|
|
346
|
+
).toEqual(["orders", "other"]);
|
|
347
|
+
fireEvent.click(await findViewOption("by_x"));
|
|
350
348
|
fireEvent.click(
|
|
351
349
|
screen.getByRole("button", { name: "Add tile", hidden: false }),
|
|
352
350
|
);
|
|
@@ -391,3 +389,85 @@ describe("ReportEditor in text-source mode", () => {
|
|
|
391
389
|
expect(await screen.findByText(/authoritative/)).toBeDefined();
|
|
392
390
|
});
|
|
393
391
|
});
|
|
392
|
+
|
|
393
|
+
describe("a host that compiles its own text (compileSource)", () => {
|
|
394
|
+
/** A document that declares its own filter and binds it on its tile. */
|
|
395
|
+
const WITH_FILTER = `##! experimental.givens
|
|
396
|
+
## artifact { title="Ops" tiles=["a -> by_cat"] } dashboard { columns=12 }
|
|
397
|
+
|
|
398
|
+
# label="Category"
|
|
399
|
+
given: CAT :: filter<string> is f'Outerwear'
|
|
400
|
+
|
|
401
|
+
source: a is orders extend {
|
|
402
|
+
view: by_cat is by_category + { where: category ~ $CAT }
|
|
403
|
+
}
|
|
404
|
+
`;
|
|
405
|
+
/** What a host does with it: no flag, no declaration, the value as a literal. */
|
|
406
|
+
const resolve = (text: string) =>
|
|
407
|
+
text
|
|
408
|
+
.replace(/^##!.*\n/m, "")
|
|
409
|
+
.replace(/^# label="Category"\ngiven: CAT .*\n/m, "")
|
|
410
|
+
.replace(/\$CAT\b/g, "f'Outerwear'");
|
|
411
|
+
|
|
412
|
+
const storeOf = (text: string) => {
|
|
413
|
+
const storage = new FakeStorage();
|
|
414
|
+
storage.documents.set("env/pkg/dashboards/ops.malloy", text);
|
|
415
|
+
return storage;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
it("compiles what the host makes of the text, and turns Add filter on", async () => {
|
|
419
|
+
mount(storeOf(DOCUMENT), {
|
|
420
|
+
modelPath: "models/orders.malloy",
|
|
421
|
+
compileSource: (text) => `// resolved by the host\n${text}`,
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
await waitFor(() => expect(compileModelSource).toHaveBeenCalled());
|
|
425
|
+
expect(compileModelSource.mock.calls[0][3]).toEqual({
|
|
426
|
+
source: `// resolved by the host\n${DOCUMENT}`,
|
|
427
|
+
scope: "append",
|
|
428
|
+
});
|
|
429
|
+
const add = await screen.findByRole("button", { name: "Add filter" });
|
|
430
|
+
expect((add as HTMLButtonElement).disabled).toBe(false);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("runs the document's own filter as a literal, never as a given the server is sent", async () => {
|
|
434
|
+
mount(storeOf(WITH_FILTER), {
|
|
435
|
+
modelPath: "models/orders.malloy",
|
|
436
|
+
compileSource: resolve,
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
await waitFor(() => expect(compileModelSource).toHaveBeenCalled());
|
|
440
|
+
const sent = compileModelSource.mock.calls[0][3].source ?? "";
|
|
441
|
+
expect(sent).not.toContain("given:");
|
|
442
|
+
expect(sent).not.toContain("$CAT");
|
|
443
|
+
|
|
444
|
+
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
445
|
+
const body = JSON.stringify(executeQueryModel.mock.calls[0][3]);
|
|
446
|
+
expect(body).toContain("category ~ f'Outerwear'");
|
|
447
|
+
expect(body).not.toContain('"CAT"');
|
|
448
|
+
// The control is drawn from the document's own declaration.
|
|
449
|
+
expect(
|
|
450
|
+
await screen.findByRole("button", { name: /^Category: / }),
|
|
451
|
+
).toBeDefined();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("says so when the host cannot prepare the text, and compiles nothing", async () => {
|
|
455
|
+
mount(storeOf(DOCUMENT), {
|
|
456
|
+
modelPath: "models/orders.malloy",
|
|
457
|
+
compileSource: () => Promise.reject(new Error("CAT is the model's")),
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
expect(
|
|
461
|
+
await screen.findByText(
|
|
462
|
+
/could not be prepared to compile: CAT is the model's/,
|
|
463
|
+
),
|
|
464
|
+
).toBeDefined();
|
|
465
|
+
expect(compileModelSource).not.toHaveBeenCalled();
|
|
466
|
+
// Its tiles are drawn, but nothing runs them: no source is declared.
|
|
467
|
+
expect(
|
|
468
|
+
(await screen.findAllByText("Not run: this document did not compile."))
|
|
469
|
+
.length,
|
|
470
|
+
).toBeGreaterThan(0);
|
|
471
|
+
expect(executeQueryModel).not.toHaveBeenCalled();
|
|
472
|
+
});
|
|
473
|
+
});
|