@malloy-publisher/sdk 0.17.0 → 0.17.2
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 +32 -50
- package/dist/{RenderedResult-BcEDcw0V.es.js → RenderedResult-CYJ2Y9Fm.es.js} +24 -24
- package/dist/{RenderedResult-uT2oc6ke.cjs.js → RenderedResult-hRvgFMAF.cjs.js} +1 -1
- package/dist/ServerProvider-DeVejmVr.cjs.js +1 -0
- package/dist/{ServerProvider-vmEUjlEu.es.js → ServerProvider-DzzfVDg_.es.js} +1314 -1712
- package/dist/builder/index.cjs.js +12 -12
- package/dist/builder/index.es.js +4 -9
- package/dist/client/api.d.ts +63 -506
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +132 -144
- package/dist/components/Dashboard/DashboardGrid.d.ts +1 -1
- package/dist/components/Model/ExplorerPage.d.ts +1 -3
- package/dist/components/Model/Model.d.ts +1 -4
- package/dist/components/Model/ModelExplorer.d.ts +1 -2
- package/dist/components/Package/reportQueries.d.ts +2 -4
- package/dist/components/Report/Report.d.ts +20 -9
- package/dist/components/{legacy → Report}/malloynb/CellRunnerView.d.ts +13 -16
- package/dist/components/Report/malloynb/MalloynbReport.d.ts +11 -0
- package/dist/components/{legacy → Report}/malloynb/cellKind.d.ts +1 -1
- package/dist/components/ServerProvider.d.ts +1 -3
- package/dist/components/drill/drillClauses.d.ts +8 -9
- package/dist/components/drill/rowsTarget.d.ts +7 -9
- package/dist/components/legacy/index.d.ts +3 -7
- package/dist/components/modelPage.d.ts +2 -5
- package/dist/hooks/useModelGivens.d.ts +2 -2
- package/dist/hooks/useQueryResult.d.ts +7 -0
- package/dist/index.cjs.js +33 -33
- package/dist/index.es.js +8799 -8903
- package/dist/{useCompiledDocument-h5-Kc1Zh.cjs.js → useCompiledDocument-BCr-xB_i.cjs.js} +4 -4
- package/dist/{useCompiledDocument-rOwDSK_s.es.js → useCompiledDocument-E0tU5KzP.es.js} +266 -277
- package/package.json +1 -1
- package/src/components/Dashboard/DashboardGrid.tsx +1 -1
- package/src/components/Dashboard/DashboardTile.spec.tsx +1 -1
- package/src/components/Model/ExplorerPage.tsx +1 -3
- package/src/components/Model/Model.tsx +1 -4
- package/src/components/Model/ModelExplorer.tsx +1 -2
- package/src/components/Package/Package.tsx +1 -5
- package/src/components/Package/reportQueries.ts +3 -15
- package/src/components/Report/Report.malloynb.spec.tsx +230 -0
- package/src/components/Report/Report.spec.tsx +429 -38
- package/src/components/Report/Report.telemetry.spec.tsx +51 -10
- package/src/components/Report/Report.tsx +63 -44
- package/src/components/{legacy → Report}/malloynb/CellRunnerView.spec.tsx +11 -44
- package/src/components/{legacy → Report}/malloynb/CellRunnerView.tsx +63 -107
- package/src/components/Report/malloynb/MalloynbReport.tsx +110 -0
- package/src/components/{legacy → Report}/malloynb/cellKind.ts +5 -4
- package/src/components/ReportBuilder/EditorSurface.tsx +3 -3
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +2 -2
- package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +0 -4
- package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +0 -1
- package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -3
- package/src/components/ReportBuilder/ReportEditor.tsx +1 -1
- package/src/components/ReportBuilder/loadMalloy.ts +1 -4
- package/src/components/ReportBuilder/useSaveChannel.ts +1 -6
- package/src/components/ServerProvider.tsx +0 -4
- package/src/components/drill/drillClauses.ts +8 -9
- package/src/components/drill/rowsTarget.ts +7 -9
- package/src/components/index.ts +2 -3
- package/src/components/legacy/index.ts +3 -7
- package/src/components/modelPage.ts +2 -5
- package/src/hooks/useGivensState.ts +8 -8
- package/src/hooks/useModelGivens.ts +2 -2
- package/src/hooks/useQueryResult.ts +30 -18
- package/test/README.md +4 -4
- package/dist/ServerProvider-DDRwHiPz.cjs.js +0 -1
- package/dist/components/legacy/Dashboard.d.ts +0 -68
- package/dist/components/legacy/malloynb/MalloynbCells.d.ts +0 -13
- package/dist/components/legacy/malloynb/Notebook.d.ts +0 -15
- package/dist/components/legacy/queryKeys.d.ts +0 -8
- package/src/components/legacy/Dashboard.spec.tsx +0 -242
- package/src/components/legacy/Dashboard.tsx +0 -181
- package/src/components/legacy/malloynb/MalloynbCells.tsx +0 -88
- package/src/components/legacy/malloynb/Notebook.layout.spec.tsx +0 -103
- package/src/components/legacy/malloynb/Notebook.served.spec.tsx +0 -84
- package/src/components/legacy/malloynb/Notebook.spec.tsx +0 -223
- package/src/components/legacy/malloynb/Notebook.tsx +0 -46
- package/src/components/legacy/queryKeys.ts +0 -26
- /package/dist/components/{legacy → Report}/malloynb/NotebookCell.d.ts +0 -0
- /package/dist/components/{legacy → Report}/malloynb/runPlan.d.ts +0 -0
- /package/dist/components/{legacy → Report}/malloynb/types.d.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/NotebookCell.tsx +0 -0
- /package/src/components/{legacy → Report}/malloynb/cellKind.spec.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/runPlan.spec.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/runPlan.ts +0 -0
- /package/src/components/{legacy → Report}/malloynb/types.ts +0 -0
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { Alert } from "@mui/material";
|
|
5
|
-
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
6
|
-
import { parseResourceUri } from "../../utils/formatting";
|
|
7
|
-
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
8
|
-
import type { DrillNavigation } from "../drill";
|
|
9
|
-
import { Loading, LOADING_COPY } from "../Loading";
|
|
10
|
-
import { useServer } from "../ServerProvider";
|
|
11
|
-
import { DashboardView } from "../Dashboard/DashboardView";
|
|
12
|
-
import {
|
|
13
|
-
ReportEventsContext,
|
|
14
|
-
useReportEmitter,
|
|
15
|
-
type ReportEventHandler,
|
|
16
|
-
} from "../Report/telemetry";
|
|
17
|
-
import type { TileChrome } from "../Dashboard/TileCard";
|
|
18
|
-
|
|
19
|
-
export interface DashboardProps {
|
|
20
|
-
/** `publisher://environments/{env}/packages/{pkg}`, optionally `?versionId=`. */
|
|
21
|
-
resourceUri: string;
|
|
22
|
-
/** The report's basename, as listed by the deprecated dashboards endpoint. */
|
|
23
|
-
dashboard: string;
|
|
24
|
-
/**
|
|
25
|
-
* Control values from the host, typically its URL query parameters. These
|
|
26
|
-
* beat the dashboard's own starting values, so a shared link shows what the
|
|
27
|
-
* sender was looking at.
|
|
28
|
-
*/
|
|
29
|
-
givens?: Record<string, string>;
|
|
30
|
-
/**
|
|
31
|
-
* Applied control values, for a host that wants them in its URL. Fires with
|
|
32
|
-
* what the results reflect, not with every keystroke.
|
|
33
|
-
*
|
|
34
|
-
* `managed` is every given this dashboard declares, whether or not it
|
|
35
|
-
* currently holds a value, and a host writing to a shared query string needs
|
|
36
|
-
* it. `givens` alone says which parameters to write but not which to REMOVE,
|
|
37
|
-
* so a host that guesses by deleting everything it did not just receive
|
|
38
|
-
* deletes the unrelated parameters it has no business touching. Same contract
|
|
39
|
-
* as `Notebook`, so a host can treat the two surfaces alike.
|
|
40
|
-
*/
|
|
41
|
-
onGivensChange?: (
|
|
42
|
-
givens: Record<string, string>,
|
|
43
|
-
managed: readonly string[],
|
|
44
|
-
) => void;
|
|
45
|
-
/**
|
|
46
|
-
* Where to go when a `# drill` cell is clicked. Without it, drilling to
|
|
47
|
-
* another dashboard is inert: `to=self` still filters in place, since that
|
|
48
|
-
* never leaves the component.
|
|
49
|
-
*/
|
|
50
|
-
onNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
51
|
-
/**
|
|
52
|
-
* Height cap for a result panel. Left unset, each form gets the cap that
|
|
53
|
-
* suits its shape: {@link TILE_MAX_HEIGHT} per tile for the composite form,
|
|
54
|
-
* and no cap at all for the single-query form, where the one result IS the
|
|
55
|
-
* dashboard and a cap would clip the page rather than tidy it. Set it to
|
|
56
|
-
* hold a dashboard to a fixed box, as an embedding host might.
|
|
57
|
-
*/
|
|
58
|
-
height?: number;
|
|
59
|
-
maxResultSize?: number;
|
|
60
|
-
/**
|
|
61
|
-
* The rows shown and failed tile queries, for the host to log or count;
|
|
62
|
-
* see `ReportEvent`. `path` is the manifest's model path.
|
|
63
|
-
*/
|
|
64
|
-
onEvent?: ReportEventHandler;
|
|
65
|
-
/**
|
|
66
|
-
* `card` (default) draws each tile as a panel; `none` draws them bare, a
|
|
67
|
-
* document that reads top to bottom.
|
|
68
|
-
*/
|
|
69
|
-
chrome?: TileChrome;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* A grid report by its basename: a control row over one or more query
|
|
74
|
-
* results, declared entirely by the file's tags.
|
|
75
|
-
*
|
|
76
|
-
* @deprecated Render `Report` with the file's path instead. This reads the
|
|
77
|
-
* deprecated `GET …/dashboards/{name}`, which resolves a basename only when one
|
|
78
|
-
* grid report has it, and draws the result with the same renderer as `Report`.
|
|
79
|
-
* Kept for hosts that still mount it.
|
|
80
|
-
*
|
|
81
|
-
* Host-agnostic on purpose. It takes props rather than reading a router, and
|
|
82
|
-
* hands navigation and URL state back to whoever mounted it, so the Publisher
|
|
83
|
-
* Console and an external React app render the same component and differ only
|
|
84
|
-
* in what they do with `onNavigate` and `onGivensChange`.
|
|
85
|
-
*/
|
|
86
|
-
export function Dashboard({
|
|
87
|
-
resourceUri,
|
|
88
|
-
dashboard,
|
|
89
|
-
givens,
|
|
90
|
-
onGivensChange,
|
|
91
|
-
onNavigate,
|
|
92
|
-
height,
|
|
93
|
-
maxResultSize,
|
|
94
|
-
onEvent,
|
|
95
|
-
chrome,
|
|
96
|
-
}: DashboardProps) {
|
|
97
|
-
const parsed = parseResourceUri(resourceUri);
|
|
98
|
-
const { apiClients } = useServer();
|
|
99
|
-
|
|
100
|
-
// Degraded, not thrown: a throw in the render body takes the embedding
|
|
101
|
-
// host's whole tree down with it, which is a white screen rather than a
|
|
102
|
-
// message.
|
|
103
|
-
const environmentName = parsed.environmentName ?? "";
|
|
104
|
-
const packageName = parsed.packageName ?? "";
|
|
105
|
-
const versionId = parsed.versionId;
|
|
106
|
-
const uriNamesBoth = !!parsed.environmentName && !!parsed.packageName;
|
|
107
|
-
|
|
108
|
-
const {
|
|
109
|
-
data: manifestResponse,
|
|
110
|
-
isSuccess,
|
|
111
|
-
isError,
|
|
112
|
-
error,
|
|
113
|
-
} = useQueryWithApiError({
|
|
114
|
-
// Every value the request is built from, so the key cannot drift out of
|
|
115
|
-
// step with it. A version that reached the request alone would leave two
|
|
116
|
-
// versions of one dashboard on a single cache entry, each able to serve
|
|
117
|
-
// the other's manifest.
|
|
118
|
-
queryKey: [
|
|
119
|
-
"dashboard",
|
|
120
|
-
environmentName,
|
|
121
|
-
packageName,
|
|
122
|
-
versionId,
|
|
123
|
-
dashboard,
|
|
124
|
-
],
|
|
125
|
-
queryFn: () =>
|
|
126
|
-
apiClients.dashboards.getDashboard(
|
|
127
|
-
environmentName,
|
|
128
|
-
packageName,
|
|
129
|
-
dashboard,
|
|
130
|
-
versionId,
|
|
131
|
-
),
|
|
132
|
-
// No point asking for a dashboard under a name the URI never carried.
|
|
133
|
-
enabled: uriNamesBoth,
|
|
134
|
-
});
|
|
135
|
-
const manifest = manifestResponse?.data;
|
|
136
|
-
const events = useReportEmitter(
|
|
137
|
-
{ path: manifest?.path ?? dashboard, layout: "grid" },
|
|
138
|
-
onEvent,
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
if (!uriNamesBoth) {
|
|
142
|
-
return (
|
|
143
|
-
<Alert severity="error">
|
|
144
|
-
A dashboard resource URI must name an environment and a package.
|
|
145
|
-
Received: {resourceUri}
|
|
146
|
-
</Alert>
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (isError) {
|
|
151
|
-
return (
|
|
152
|
-
<ApiErrorDisplay
|
|
153
|
-
context={`${environmentName} > ${packageName} > ${dashboard}`}
|
|
154
|
-
error={error}
|
|
155
|
-
/>
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (!isSuccess || !manifest) {
|
|
159
|
-
return <Loading text={LOADING_COPY.opening("report")} />;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<ReportEventsContext.Provider value={events}>
|
|
164
|
-
<DashboardView
|
|
165
|
-
manifest={manifest}
|
|
166
|
-
environmentName={environmentName}
|
|
167
|
-
packageName={packageName}
|
|
168
|
-
versionId={versionId}
|
|
169
|
-
documentName={dashboard}
|
|
170
|
-
givens={givens}
|
|
171
|
-
onGivensChange={onGivensChange}
|
|
172
|
-
onNavigate={onNavigate}
|
|
173
|
-
height={height}
|
|
174
|
-
maxResultSize={maxResultSize}
|
|
175
|
-
chrome={chrome}
|
|
176
|
-
/>
|
|
177
|
-
</ReportEventsContext.Provider>
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export default Dashboard;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { useCallback } from "react";
|
|
5
|
-
import type { RawNotebook } from "../../../client";
|
|
6
|
-
import { useQueryWithApiError } from "../../../hooks/useQueryWithApiError";
|
|
7
|
-
import { parseResourceUri } from "../../../utils/formatting";
|
|
8
|
-
import { givensToRequest } from "../../given/paramCodec";
|
|
9
|
-
import {
|
|
10
|
-
CellRunnerView,
|
|
11
|
-
type CellReportProps,
|
|
12
|
-
type CellRunner,
|
|
13
|
-
} from "./CellRunnerView";
|
|
14
|
-
import { useServer } from "../../ServerProvider";
|
|
15
|
-
|
|
16
|
-
/** The deprecated notebook read, one cache entry per URI however many components ask. */
|
|
17
|
-
export function useNotebookQuery(resourceUri: string) {
|
|
18
|
-
const { apiClients } = useServer();
|
|
19
|
-
const {
|
|
20
|
-
environmentName,
|
|
21
|
-
packageName,
|
|
22
|
-
versionId,
|
|
23
|
-
modelPath: notebookPath,
|
|
24
|
-
} = parseResourceUri(resourceUri);
|
|
25
|
-
return useQueryWithApiError<RawNotebook>({
|
|
26
|
-
queryKey: [resourceUri],
|
|
27
|
-
queryFn: async () => {
|
|
28
|
-
const response = await apiClients.notebooks.getNotebook(
|
|
29
|
-
environmentName,
|
|
30
|
-
packageName,
|
|
31
|
-
notebookPath,
|
|
32
|
-
versionId,
|
|
33
|
-
);
|
|
34
|
-
return response.data;
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* A notebook's cells read and run through the deprecated notebooks routes,
|
|
41
|
-
* `GET …/notebooks/{path}` and `GET …/notebooks/{path}/cells/{i}`: the only
|
|
42
|
-
* routes that run a `.malloynb`, and what the `Notebook` wrapper has always
|
|
43
|
-
* read a cell-format report through.
|
|
44
|
-
*/
|
|
45
|
-
export function MalloynbCells(props: CellReportProps) {
|
|
46
|
-
const { apiClients } = useServer();
|
|
47
|
-
const { environmentName, packageName, versionId, modelPath } =
|
|
48
|
-
parseResourceUri(props.resourceUri);
|
|
49
|
-
const query = useNotebookQuery(props.resourceUri);
|
|
50
|
-
const runCell = useCallback<CellRunner>(
|
|
51
|
-
async ({ index, givens, declaredTypes, signal }) => {
|
|
52
|
-
const request = givensToRequest(givens, declaredTypes);
|
|
53
|
-
// `filterParams` and `bypassFilters` go over as undefined: `given:`
|
|
54
|
-
// takes the `#(filter)` panel's place, and a `required` filter the
|
|
55
|
-
// server enforces fails the cell visibly rather than blankly.
|
|
56
|
-
return (
|
|
57
|
-
await apiClients.notebooks.executeNotebookCell(
|
|
58
|
-
environmentName,
|
|
59
|
-
packageName,
|
|
60
|
-
modelPath,
|
|
61
|
-
index,
|
|
62
|
-
versionId,
|
|
63
|
-
undefined,
|
|
64
|
-
undefined,
|
|
65
|
-
Object.keys(request).length > 0
|
|
66
|
-
? JSON.stringify(request)
|
|
67
|
-
: undefined,
|
|
68
|
-
{ signal },
|
|
69
|
-
)
|
|
70
|
-
).data;
|
|
71
|
-
},
|
|
72
|
-
[
|
|
73
|
-
apiClients.notebooks,
|
|
74
|
-
environmentName,
|
|
75
|
-
packageName,
|
|
76
|
-
modelPath,
|
|
77
|
-
versionId,
|
|
78
|
-
],
|
|
79
|
-
);
|
|
80
|
-
return (
|
|
81
|
-
<CellRunnerView
|
|
82
|
-
{...props}
|
|
83
|
-
notebook={query.isSuccess ? query.data : undefined}
|
|
84
|
-
error={query.isError ? query.error : undefined}
|
|
85
|
-
runCell={runCell}
|
|
86
|
-
/>
|
|
87
|
-
);
|
|
88
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { beforeEach, expect, it, mock } from "bun:test";
|
|
5
|
-
import { render, screen, waitFor } from "@testing-library/react";
|
|
6
|
-
import {
|
|
7
|
-
clearCache,
|
|
8
|
-
mockServerProvider,
|
|
9
|
-
pending,
|
|
10
|
-
serverWrapper,
|
|
11
|
-
} from "../../../../test/serverProvider";
|
|
12
|
-
import type { RawNotebook } from "../../../client";
|
|
13
|
-
|
|
14
|
-
const LAYOUT = {
|
|
15
|
-
format: "malloy",
|
|
16
|
-
notebookCells: [{ type: "markdown", kind: "markdown", text: "Intro" }],
|
|
17
|
-
dashboard: {
|
|
18
|
-
name: "tour",
|
|
19
|
-
kind: "notebook",
|
|
20
|
-
path: "notebooks/tour.malloy",
|
|
21
|
-
dashboardColumns: 1,
|
|
22
|
-
tiles: [
|
|
23
|
-
{ kind: "text", name: "intro", markdown: "Layout **intro**" },
|
|
24
|
-
{ kind: "query", query: "orders -> by_month", label: "Monthly" },
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
} as RawNotebook;
|
|
28
|
-
|
|
29
|
-
const TITLED = {
|
|
30
|
-
...LAYOUT,
|
|
31
|
-
dashboard: {
|
|
32
|
-
...LAYOUT.dashboard,
|
|
33
|
-
title: "Tour title",
|
|
34
|
-
description: "Tour **description**",
|
|
35
|
-
},
|
|
36
|
-
} as RawNotebook;
|
|
37
|
-
|
|
38
|
-
let served: RawNotebook = LAYOUT;
|
|
39
|
-
const getNotebook = mock(() => Promise.resolve({ data: served }));
|
|
40
|
-
const executeNotebookCell = mock(() => pending());
|
|
41
|
-
const executeQueryModel = mock(
|
|
42
|
-
(_env: string, _pkg: string, _path: string, _request: unknown) => pending(),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
mockServerProvider({
|
|
46
|
-
notebooks: { getNotebook, executeNotebookCell },
|
|
47
|
-
models: { executeQueryModel, getModel: () => pending() },
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const { default: Notebook } = await import("./Notebook");
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
served = LAYOUT;
|
|
54
|
-
clearCache();
|
|
55
|
-
executeNotebookCell.mockClear();
|
|
56
|
-
executeQueryModel.mockClear();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("renders a layout notebook as a grid report draws its tiles", async () => {
|
|
60
|
-
const { container } = render(
|
|
61
|
-
<Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
|
|
62
|
-
{ wrapper: serverWrapper },
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
expect((await screen.findByText("intro")).tagName).toBe("STRONG");
|
|
66
|
-
// Text as prose, a query tile in a card: the same look as a grid.
|
|
67
|
-
expect(
|
|
68
|
-
(await screen.findByText("intro"))
|
|
69
|
-
.closest("[data-chrome]")
|
|
70
|
-
?.getAttribute("data-chrome"),
|
|
71
|
-
).toBe("none");
|
|
72
|
-
await waitFor(() =>
|
|
73
|
-
expect(container.querySelector('[data-chrome="card"]')).not.toBeNull(),
|
|
74
|
-
);
|
|
75
|
-
// Tiles run through the model query endpoint, not the cell endpoint.
|
|
76
|
-
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
77
|
-
expect(executeQueryModel.mock.calls[0]?.[2]).toBe("notebooks/tour.malloy");
|
|
78
|
-
expect(executeNotebookCell).not.toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("shows a layout notebook's title and description above its tiles", async () => {
|
|
82
|
-
served = TITLED;
|
|
83
|
-
render(
|
|
84
|
-
<Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
|
|
85
|
-
{ wrapper: serverWrapper },
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
expect(
|
|
89
|
-
(await screen.findByRole("heading", { name: "Tour title" })).tagName,
|
|
90
|
-
// The page's main heading: the report title is the page.
|
|
91
|
-
).toBe("H1");
|
|
92
|
-
expect((await screen.findByText("description")).tagName).toBe("STRONG");
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("titles an untitled layout notebook with its name, as a grid report does", async () => {
|
|
96
|
-
render(
|
|
97
|
-
<Notebook resourceUri="publisher://environments/env/packages/pkg/models/notebooks/tour.malloy" />,
|
|
98
|
-
{ wrapper: serverWrapper },
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
await screen.findByText("intro");
|
|
102
|
-
expect(screen.getByRole("heading", { name: "tour" })).toBeDefined();
|
|
103
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
5
|
-
import { render, screen, waitFor } from "@testing-library/react";
|
|
6
|
-
import {
|
|
7
|
-
clearCache,
|
|
8
|
-
mockServerProvider,
|
|
9
|
-
pending,
|
|
10
|
-
serverWrapper,
|
|
11
|
-
} from "../../../../test/serverProvider";
|
|
12
|
-
import type { RawNotebook } from "../../../client";
|
|
13
|
-
|
|
14
|
-
const SERVED = {
|
|
15
|
-
format: "malloynb",
|
|
16
|
-
notebookCells: [
|
|
17
|
-
{ type: "markdown", text: "Served prose" },
|
|
18
|
-
{ type: "code", text: 'import { orders } from "../orders.malloy"' },
|
|
19
|
-
{ type: "code", text: "run: orders -> by_month" },
|
|
20
|
-
],
|
|
21
|
-
} as RawNotebook;
|
|
22
|
-
|
|
23
|
-
let current: RawNotebook = SERVED;
|
|
24
|
-
const getNotebook = mock(() => Promise.resolve({ data: current }));
|
|
25
|
-
const executeNotebookCell = mock(
|
|
26
|
-
(
|
|
27
|
-
_env: string,
|
|
28
|
-
_pkg: string,
|
|
29
|
-
_path: string,
|
|
30
|
-
_index: number,
|
|
31
|
-
): Promise<never> => pending(),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
mockServerProvider({
|
|
35
|
-
notebooks: { getNotebook, executeNotebookCell },
|
|
36
|
-
models: { executeQueryModel: () => pending() },
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const { default: Notebook } = await import("./Notebook");
|
|
40
|
-
|
|
41
|
-
const URI =
|
|
42
|
-
"publisher://environments/env/packages/pkg/models/notebooks/ops.malloynb";
|
|
43
|
-
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
current = SERVED;
|
|
46
|
-
clearCache();
|
|
47
|
-
getNotebook.mockClear();
|
|
48
|
-
executeNotebookCell.mockClear();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("runs every code cell of a .malloynb", async () => {
|
|
52
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
53
|
-
|
|
54
|
-
await waitFor(() =>
|
|
55
|
-
expect(executeNotebookCell.mock.calls.map((call) => call[3])).toEqual([
|
|
56
|
-
1, 2,
|
|
57
|
-
]),
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("puts the copy-link icon on a leading markdown cell", async () => {
|
|
62
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
63
|
-
|
|
64
|
-
await screen.findByText("Served prose");
|
|
65
|
-
expect(screen.getAllByTestId("LinkOutlinedIcon")).toHaveLength(1);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// DEPRECATED FEATURE COVERAGE — delete together with
|
|
69
|
-
// `.malloynb` notebooks (see RELEASE_NOTES deprecations).
|
|
70
|
-
describe("deprecated: .malloynb notebooks", () => {
|
|
71
|
-
it("keeps the copy-link icon off a .malloynb that opens with a code cell", async () => {
|
|
72
|
-
current = {
|
|
73
|
-
format: "malloynb",
|
|
74
|
-
notebookCells: [
|
|
75
|
-
{ type: "code", text: "import { orders } from '../orders.malloy'" },
|
|
76
|
-
{ type: "markdown", text: "Legacy prose" },
|
|
77
|
-
],
|
|
78
|
-
} as RawNotebook;
|
|
79
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
80
|
-
|
|
81
|
-
await screen.findByText("Legacy prose");
|
|
82
|
-
expect(screen.queryAllByTestId("LinkOutlinedIcon")).toHaveLength(0);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Credible Data Inc.
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A notebook's suggest queries are version-scoped like the rest of it.
|
|
6
|
-
*
|
|
7
|
-
* The notebook already versioned its own fetch and its cell execution while
|
|
8
|
-
* its dropdowns ran unversioned, so a versioned notebook filled its controls
|
|
9
|
-
* from whatever the latest version happened to hold. The forwarding is a bare
|
|
10
|
-
* trailing optional argument, which is the kind that goes missing without a
|
|
11
|
-
* test noticing, so it is asserted here rather than only on the hook.
|
|
12
|
-
*/
|
|
13
|
-
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
14
|
-
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
15
|
-
import type { ReactNode } from "react";
|
|
16
|
-
import {
|
|
17
|
-
cacheKeys,
|
|
18
|
-
clearCache,
|
|
19
|
-
mockServerProvider,
|
|
20
|
-
pending,
|
|
21
|
-
serverWrapper,
|
|
22
|
-
} from "../../../../test/serverProvider";
|
|
23
|
-
import type { RawNotebook } from "../../../client";
|
|
24
|
-
|
|
25
|
-
const NOTEBOOK: RawNotebook = {
|
|
26
|
-
notebookCells: [
|
|
27
|
-
{
|
|
28
|
-
type: "code",
|
|
29
|
-
text: "import { orders } from './orders.malloy'",
|
|
30
|
-
// `newSources` is what makes the cell's "Data sources" icon appear;
|
|
31
|
-
// see `NotebookCell.tsx`'s `hasValidImport` check.
|
|
32
|
-
newSources: [JSON.stringify({ name: "orders" })],
|
|
33
|
-
} as RawNotebook["notebookCells"][number],
|
|
34
|
-
],
|
|
35
|
-
sources: [
|
|
36
|
-
{
|
|
37
|
-
name: "orders",
|
|
38
|
-
givens: [
|
|
39
|
-
{
|
|
40
|
-
name: "REGION",
|
|
41
|
-
control: "select",
|
|
42
|
-
suggest: { source: "orders", dimension: "region" },
|
|
43
|
-
},
|
|
44
|
-
// Plain text, unlike REGION: the "Data sources" dialog test below
|
|
45
|
-
// needs a control `fireEvent.change` can drive directly, rather
|
|
46
|
-
// than a select whose options load from a suggest query.
|
|
47
|
-
{ name: "TENANT", type: "string" },
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
let current: RawNotebook = NOTEBOOK;
|
|
54
|
-
|
|
55
|
-
const getNotebook = mock(
|
|
56
|
-
(
|
|
57
|
-
_environmentName: string,
|
|
58
|
-
_packageName: string,
|
|
59
|
-
_notebookPath: string,
|
|
60
|
-
_versionId?: string,
|
|
61
|
-
) => Promise.resolve({ data: current }),
|
|
62
|
-
);
|
|
63
|
-
const executeQueryModel = mock(
|
|
64
|
-
(
|
|
65
|
-
_environmentName: string,
|
|
66
|
-
_packageName: string,
|
|
67
|
-
_modelPath: string,
|
|
68
|
-
_request: { versionId?: string },
|
|
69
|
-
) => pending(),
|
|
70
|
-
);
|
|
71
|
-
// The notebook's real run path for a code cell, distinct from
|
|
72
|
-
// `executeQueryModel`: without it, the cell this spec adds (for the "Data
|
|
73
|
-
// sources" dialog) fails with "not a function" on every render.
|
|
74
|
-
const executeNotebookCell = mock(
|
|
75
|
-
(
|
|
76
|
-
_environmentName: string,
|
|
77
|
-
_packageName: string,
|
|
78
|
-
_notebookPath: string,
|
|
79
|
-
_cellIndex: number,
|
|
80
|
-
) => pending(),
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
// Stubbed rather than let the cell's "Data sources" dialog reach the real
|
|
84
|
-
// ModelExplorer: that pulls in the lazy-loaded, WASM-backed
|
|
85
|
-
// `@malloydata/malloy-explorer`, which is not this file's business. Only what
|
|
86
|
-
// the notebook hands it matters here, so the stub just records its props.
|
|
87
|
-
const dataSourcesDialogProps = mock(
|
|
88
|
-
(_props: {
|
|
89
|
-
open: boolean;
|
|
90
|
-
startingGivens?: Record<string, string>;
|
|
91
|
-
data?: { givens?: { name?: string }[] };
|
|
92
|
-
}) => {},
|
|
93
|
-
);
|
|
94
|
-
mock.module("../../Model/ModelExplorerDialog", () => ({
|
|
95
|
-
ModelExplorerDialog: (props: {
|
|
96
|
-
open: boolean;
|
|
97
|
-
startingGivens?: Record<string, string>;
|
|
98
|
-
data?: { givens?: { name?: string }[] };
|
|
99
|
-
}) => {
|
|
100
|
-
dataSourcesDialogProps(props);
|
|
101
|
-
return null as ReactNode;
|
|
102
|
-
},
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
// The server's /status answer: the model page a test switches to `viewer`.
|
|
106
|
-
const serverContext: { modelPage?: string; isLoadingStatus?: boolean } = {};
|
|
107
|
-
mockServerProvider(
|
|
108
|
-
{
|
|
109
|
-
notebooks: { getNotebook, executeNotebookCell },
|
|
110
|
-
models: { executeQueryModel },
|
|
111
|
-
},
|
|
112
|
-
serverContext,
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const { default: Notebook } = await import("./Notebook");
|
|
116
|
-
|
|
117
|
-
const URI =
|
|
118
|
-
"publisher://environments/env/packages/pkg/models/notebooks/ops.malloynb";
|
|
119
|
-
|
|
120
|
-
beforeEach(() => {
|
|
121
|
-
current = NOTEBOOK;
|
|
122
|
-
clearCache();
|
|
123
|
-
getNotebook.mockClear();
|
|
124
|
-
executeQueryModel.mockClear();
|
|
125
|
-
executeNotebookCell.mockClear();
|
|
126
|
-
dataSourcesDialogProps.mockClear();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("runs its suggest queries against the version it was opened at", async () => {
|
|
130
|
-
render(<Notebook resourceUri={`${URI}?versionId=v2`} />, {
|
|
131
|
-
wrapper: serverWrapper,
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
135
|
-
expect(executeQueryModel.mock.calls[0][3].versionId).toBe("v2");
|
|
136
|
-
expect(cacheKeys("givenSuggest")[0]).toContain('"v2"');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("sends none when the notebook was opened without one", async () => {
|
|
140
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
141
|
-
|
|
142
|
-
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
143
|
-
expect(executeQueryModel.mock.calls[0][3].versionId).toBeUndefined();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("opens a cell's 'Data sources' dialog with the notebook's current values", async () => {
|
|
147
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
148
|
-
|
|
149
|
-
// The control sits in its filter button's popover.
|
|
150
|
-
fireEvent.click(await screen.findByRole("button", { name: /^TENANT: / }));
|
|
151
|
-
const input = (await screen.findByLabelText("TENANT")) as HTMLInputElement;
|
|
152
|
-
fireEvent.change(input, { target: { value: "acme" } });
|
|
153
|
-
// Wait for the control's own re-render before opening the dialog: without
|
|
154
|
-
// it the click can land on the render that has not yet carried the new
|
|
155
|
-
// value into `cellStartingGivens`.
|
|
156
|
-
await waitFor(() => expect(input.value).toBe("acme"));
|
|
157
|
-
|
|
158
|
-
fireEvent.click(await screen.findByLabelText("Data sources"));
|
|
159
|
-
|
|
160
|
-
await waitFor(() =>
|
|
161
|
-
expect(dataSourcesDialogProps.mock.calls.at(-1)?.[0]?.open).toBe(true),
|
|
162
|
-
);
|
|
163
|
-
const lastCall = dataSourcesDialogProps.mock.calls.at(-1)?.[0];
|
|
164
|
-
expect(lastCall?.startingGivens).toEqual({ TENANT: "acme" });
|
|
165
|
-
// The values alone render nothing: the dialog needs the declarations too.
|
|
166
|
-
expect(lastCall?.data?.givens?.map((given) => given.name)).toContain(
|
|
167
|
-
"TENANT",
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// A server with PUBLISHER_MODEL_PAGE=viewer takes the Explorer out of the
|
|
172
|
-
// Console, and the "Data sources" dialog is the Explorer.
|
|
173
|
-
it("offers no 'Data sources' dialog on a server whose model page is the viewer", async () => {
|
|
174
|
-
serverContext.modelPage = "viewer";
|
|
175
|
-
try {
|
|
176
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
177
|
-
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
178
|
-
expect(screen.queryByLabelText("Data sources")).toBeNull();
|
|
179
|
-
expect(dataSourcesDialogProps).not.toHaveBeenCalledWith(
|
|
180
|
-
expect.objectContaining({ open: true }),
|
|
181
|
-
);
|
|
182
|
-
} finally {
|
|
183
|
-
delete serverContext.modelPage;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// Nor while /status loads: until the server has said which page it shows, a
|
|
188
|
-
// viewer server must not offer the Explorer even briefly.
|
|
189
|
-
it("offers no 'Data sources' dialog while /status loads", async () => {
|
|
190
|
-
serverContext.isLoadingStatus = true;
|
|
191
|
-
try {
|
|
192
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
193
|
-
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
194
|
-
expect(screen.queryByLabelText("Data sources")).toBeNull();
|
|
195
|
-
} finally {
|
|
196
|
-
delete serverContext.isLoadingStatus;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
// DEPRECATED FEATURE COVERAGE — delete together with
|
|
201
|
-
// `.malloynb` notebooks (see RELEASE_NOTES deprecations).
|
|
202
|
-
describe("deprecated: .malloynb notebooks", () => {
|
|
203
|
-
it("renders a .malloynb as before: runs every code cell, no caption, no folded definition", async () => {
|
|
204
|
-
current = {
|
|
205
|
-
notebookCells: [
|
|
206
|
-
{ type: "markdown", text: "Prose" },
|
|
207
|
-
{ type: "code", text: "run: a -> b" },
|
|
208
|
-
{ type: "code", text: '#" x\nrun: a -> c' },
|
|
209
|
-
],
|
|
210
|
-
} as RawNotebook;
|
|
211
|
-
render(<Notebook resourceUri={URI} />, { wrapper: serverWrapper });
|
|
212
|
-
|
|
213
|
-
await screen.findByText("Prose");
|
|
214
|
-
await waitFor(() => expect(executeNotebookCell).toHaveBeenCalledTimes(2));
|
|
215
|
-
expect(executeNotebookCell.mock.calls.map((call) => call[3])).toEqual([
|
|
216
|
-
1, 2,
|
|
217
|
-
]);
|
|
218
|
-
expect(screen.queryByText("x")).toBeNull();
|
|
219
|
-
expect(
|
|
220
|
-
screen.queryByRole("button", { name: /^(run|source|import)/ }),
|
|
221
|
-
).toBeNull();
|
|
222
|
-
});
|
|
223
|
-
});
|