@malloy-publisher/sdk 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DocumentStorage-BiFqO15i.es.js → DocumentStorage-B04sZ5Ie.es.js} +2284 -2319
- package/dist/{DocumentStorage-CMyLifsz.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +29 -29
- package/dist/{RenderedResult-CvrmYyr5.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
- package/dist/{RenderedResult-CZzE8wv-.cjs.js → RenderedResult-DVuGhatg.cjs.js} +27 -7
- package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
- package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
- package/dist/builder/index.cjs.js +54 -49
- package/dist/builder/index.es.js +4124 -3521
- package/dist/client/api.d.ts +14 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/TileCard.d.ts +7 -3
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +15 -4
- package/dist/components/DashboardBuilder/controls.d.ts +8 -6
- package/dist/components/DashboardBuilder/document.d.ts +19 -5
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
- package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
- package/dist/components/DashboardBuilder/preview.d.ts +17 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +5 -5
- package/dist/theme/resolveTheme.d.ts +1 -1
- package/dist/theme/types.d.ts +12 -2
- package/package.json +1 -1
- package/src/components/Dashboard/TileCard.tsx +8 -4
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +116 -25
- package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
- package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
- package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
- package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
- package/src/components/DashboardBuilder/controls.spec.ts +53 -3
- package/src/components/DashboardBuilder/controls.ts +9 -7
- package/src/components/DashboardBuilder/document.ts +17 -5
- package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
- package/src/components/DashboardBuilder/malloyText.ts +4 -109
- package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
- package/src/components/DashboardBuilder/malloyTree.ts +954 -0
- package/src/components/DashboardBuilder/preview.spec.ts +18 -0
- package/src/components/DashboardBuilder/preview.ts +24 -6
- package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
- package/src/components/DashboardBuilder/readDocument.ts +144 -165
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
- package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
- package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
- package/src/components/RenderedResult/RenderedResult.tsx +21 -1
- package/src/components/given/GivensPanel.tsx +15 -3
- package/src/theme/buildTableCssVars.spec.ts +3 -0
- package/src/theme/buildTableCssVars.ts +6 -0
- package/src/theme/defaults.ts +16 -12
- package/src/theme/resolveTheme.spec.ts +14 -7
- package/src/theme/resolveTheme.ts +14 -8
- package/src/theme/types.ts +12 -2
- package/tsconfig.spec.json +5 -1
- package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
package/dist/index.es.js
CHANGED
|
@@ -2,14 +2,14 @@ import { jsx as a, jsxs as T, Fragment as se } from "react/jsx-runtime";
|
|
|
2
2
|
import { Link as tc, Box as re, Typography as ee, Stack as Oe, Tooltip as Ot, IconButton as ut, TextField as Nt, Button as dt, Grid as ln, Paper as ia, FormControlLabel as Es, Switch as Is, Divider as un, List as $s, ListItemButton as Ns, ListItemText as Lt, TableContainer as nc, Table as Bn, TableHead as jn, TableRow as bt, TableCell as le, TableBody as Zn, Snackbar as wr, Menu as Yn, MenuItem as Ft, ListItemIcon as hn, Container as ka, FormGroup as rc, Dialog as sa, DialogTitle as oa, Chip as ac, DialogContent as la, Alert as pr, CircularProgress as ic, LinearProgress as sc } from "@mui/material";
|
|
3
3
|
import * as pe from "react";
|
|
4
4
|
import be, { useMemo as Qe, useRef as ot, useCallback as gt, useState as G, useEffect as Re, useId as oc } from "react";
|
|
5
|
-
import { e as Ne,
|
|
6
|
-
import {
|
|
7
|
-
import { u as Se, aG as Je, d as Ki, A as Hs, aH as Ca, m as Pe, P as hr, ag as Rc, aE as Vs, aI as Rn, aJ as qc, aK as Wc, aL as an } from "./ServerProvider-
|
|
8
|
-
import { aM as im, S as sm, aO as om, aN as lm, aF as cm } from "./ServerProvider-
|
|
5
|
+
import { e as Ne, q as xe, p as De, L as vt, P as ca, S as Gn, v as et, E as lc, F as ua, H as zi, I as Fs, J as cc, K as jr, M as Pt, N as wt, O as Rt, Q as je, R as At, U as qt, V as uc, W as Bt, X as Hi, Y as dc, Z as ct, _ as hc, $ as ht, a0 as xt, a1 as Xn, g as Le, a2 as fc, a3 as mc, a4 as pc, a5 as yr, a6 as ge, a7 as Vi, a8 as yc, a9 as As, aa as Sa, ab as de, A as _s, ac as Ls, ad as $e, ae as kr, af as Ct, ag as Ui, ah as Bi, ai as ji, aj as Zi, ak as gc, al as Yi, am as Gi, an as Zr, ao as bc, ap as _t, aq as vc, ar as wc, as as da, at as kc, au as Ps, av as Sc, aw as Xi, ax as Cc, ay as xc, C as Tc, az as Rs, aA as Mc, aB as qs, aC as Hn, aD as Ws, aE as Oc, aF as Dc, aG as Ec, aH as zs, aI as Ic, aJ as $c, w as Nc, aK as Fc, B as Ac, aL as _c, u as Lc, aM as Pc } from "./DocumentStorage-B04sZ5Ie.es.js";
|
|
6
|
+
import { aO as Df, aN as Ef, f as If, x as $f, a$ as Nf, aV as Ff, aX as Af, aW as _f, y as Lf, T as Pf, h as Rf, a_ as qf, b as Wf, d as zf, aP as Hf, aQ as Vf, aR as Uf, aS as Bf, aY as jf, s as Zf, m as Yf, b3 as Gf, a as Xf, aT as Kf, aZ as Jf, r as Qf, b0 as em, aU as tm, b1 as nm, b2 as rm } from "./DocumentStorage-B04sZ5Ie.es.js";
|
|
7
|
+
import { u as Se, aG as Je, d as Ki, A as Hs, aH as Ca, m as Pe, P as hr, ag as Rc, aE as Vs, aI as Rn, aJ as qc, aK as Wc, aL as an } from "./ServerProvider-Do-GBvpn.es.js";
|
|
8
|
+
import { aM as im, S as sm, aO as om, aN as lm, aF as cm } from "./ServerProvider-Do-GBvpn.es.js";
|
|
9
9
|
import { useQueryClient as Sr } from "@tanstack/react-query";
|
|
10
10
|
import { createBox as zc, createStack as Hc } from "@mui/system";
|
|
11
11
|
import { Delete as Cr, Edit as xa, MoreVert as xr } from "@mui/icons-material";
|
|
12
|
-
import { D as dm, R as hm, b as fm, a as mm, d as pm, m as ym, r as gm } from "./RenderedResult-
|
|
12
|
+
import { D as dm, R as hm, b as fm, a as mm, d as pm, m as ym, r as gm } from "./RenderedResult-BB7eokcf.es.js";
|
|
13
13
|
import { useNavigate as Us, useSearchParams as Vc, useLocation as Uc } from "react-router-dom";
|
|
14
14
|
const Bc = Ne(/* @__PURE__ */ a("path", {
|
|
15
15
|
d: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20z"
|
|
@@ -7,7 +7,7 @@ import { ResolvedTheme, Theme, ThemeMode } from './types';
|
|
|
7
7
|
* (a layer that sets only `palette.tile.dark` doesn't clobber the
|
|
8
8
|
* instance-level `palette.tile.light`).
|
|
9
9
|
*
|
|
10
|
-
* The derived fields on ResolvedTheme (border, pinnedBorder,
|
|
10
|
+
* The derived fields on ResolvedTheme (border, cardBorder, pinnedBorder,
|
|
11
11
|
* valueColor, foreground, axisFaint) are computed once here from the
|
|
12
12
|
* active mode so the three builders that consume the theme stop
|
|
13
13
|
* recomputing them with duplicated hex literals.
|
package/dist/theme/types.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export type ThemeMode = "light" | "dark";
|
|
|
10
10
|
*
|
|
11
11
|
* The seven `palette.*` colour keys are stored per-mode on the raw Theme
|
|
12
12
|
* (one of light/dark per field) and collapse to the active mode here.
|
|
13
|
-
* The
|
|
14
|
-
* foreground, axisFaint) are computed once from the resolved mode so
|
|
13
|
+
* The six "derived" fields (border, cardBorder, pinnedBorder,
|
|
14
|
+
* valueColor, foreground, axisFaint) are computed once from the resolved mode so
|
|
15
15
|
* the same hex literal isn't repeated across three builders.
|
|
16
16
|
*/
|
|
17
17
|
export interface ResolvedTheme {
|
|
@@ -34,6 +34,16 @@ export interface ResolvedTheme {
|
|
|
34
34
|
*/
|
|
35
35
|
mapColor: string;
|
|
36
36
|
border: string;
|
|
37
|
+
/**
|
|
38
|
+
* The edge of a dashboard CARD, kept off `border` on purpose. `border` is
|
|
39
|
+
* the gridline inside a table, where a hairline is right because there are
|
|
40
|
+
* dozens of them and they only have to separate rows. A card's edge has one
|
|
41
|
+
* job — say where the card stops — and at the gridline's weight, on a page
|
|
42
|
+
* whose ground and tile are both white, it did not do it: the cards read as
|
|
43
|
+
* floating content rather than as cards. A step down the same slate ramp,
|
|
44
|
+
* so the two still read as one system.
|
|
45
|
+
*/
|
|
46
|
+
cardBorder: string;
|
|
37
47
|
pinnedBorder: string;
|
|
38
48
|
valueColor: string;
|
|
39
49
|
foreground: string;
|
package/package.json
CHANGED
|
@@ -17,9 +17,13 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
|
17
17
|
* draws a stand-in tile when it has no server to run one, draws the same card
|
|
18
18
|
* the reader does rather than restating its geometry.
|
|
19
19
|
*
|
|
20
|
-
* The instance theme's
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* The instance theme's `cardBorder`, not MUI's `divider` and not the `border`
|
|
21
|
+
* a table's gridlines take: the renderer card's edge is this same value, and a
|
|
22
|
+
* card that agrees with the theme everywhere except its outline still reads as
|
|
23
|
+
* a different card. Both surfaces moved together when the edge was darkened;
|
|
24
|
+
* either one left behind is a dashboard whose tiles are outlined two ways.
|
|
25
|
+
*
|
|
26
|
+
* Radius stays on the host's
|
|
23
27
|
* `shape.borderRadius`, which the renderer card is pointed at too. The
|
|
24
28
|
* background is `theme.tile`, the value the renderer card paints — left unset,
|
|
25
29
|
* on a theme whose page is also white the composite tiles lost the tint that
|
|
@@ -51,7 +55,7 @@ export function TileCard({
|
|
|
51
55
|
elevation={0}
|
|
52
56
|
sx={[
|
|
53
57
|
{
|
|
54
|
-
border: borderless ? "none" : theme.
|
|
58
|
+
border: borderless ? "none" : theme.cardBorder,
|
|
55
59
|
borderRadius: borderless ? 0 : 1,
|
|
56
60
|
background: borderless ? "none" : theme.tile,
|
|
57
61
|
overflow: "hidden",
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import AddIcon from "@mui/icons-material/Add";
|
|
5
|
-
import CheckIcon from "@mui/icons-material/Check";
|
|
6
5
|
import TuneIcon from "@mui/icons-material/Tune";
|
|
7
6
|
import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
|
|
8
7
|
import RedoIcon from "@mui/icons-material/Redo";
|
|
@@ -136,13 +135,13 @@ export function BuilderToolbar({
|
|
|
136
135
|
variant={dirty ? "contained" : "outlined"}
|
|
137
136
|
disabled={!dirty || saving}
|
|
138
137
|
onClick={onSave}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
138
|
+
// Wide enough for the longest of the three labels, so
|
|
139
|
+
// the bar does not reflow as the state cycles.
|
|
142
140
|
sx={{ minWidth: 124 }}
|
|
143
141
|
>
|
|
144
142
|
{/* Says what will happen, then that it is happening,
|
|
145
|
-
then what did.
|
|
143
|
+
then what did. One tick in the bar, on "Done
|
|
144
|
+
editing"; here the word carries the state. */}
|
|
146
145
|
{saving ? "Saving…" : dirty ? "Save changes" : "Saved"}
|
|
147
146
|
</Button>
|
|
148
147
|
</span>
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
cleanup,
|
|
6
|
+
fireEvent,
|
|
7
|
+
render,
|
|
8
|
+
screen,
|
|
9
|
+
waitFor,
|
|
10
|
+
} from "@testing-library/react";
|
|
11
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
12
|
+
import {
|
|
13
|
+
cacheKeys,
|
|
14
|
+
clearCache,
|
|
15
|
+
mockServerProvider,
|
|
16
|
+
pending,
|
|
17
|
+
serverWrapper,
|
|
18
|
+
} from "../../../test/serverProvider";
|
|
19
|
+
import { BrowserDocumentStorage } from "../DocumentStorage/BrowserDocumentStorage";
|
|
20
|
+
import { DocumentStorageProvider } from "../DocumentStorage/DocumentStorageProvider";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `resourceUri` + `dashboard`, alongside the deprecated `environmentName` /
|
|
24
|
+
* `packageName` / `dashboardName` form, and the `versionId` a `resourceUri`
|
|
25
|
+
* can carry: what it reaches (every READ), what it never reaches (the write),
|
|
26
|
+
* and what it does to Save when the write target is the package itself.
|
|
27
|
+
*/
|
|
28
|
+
const PACKAGE_FILE = `## artifact { title="Storefront" tiles=["a -> by_cat"] } dashboard { columns=12 }
|
|
29
|
+
import { scoped_orders } from "../data_app.malloy"
|
|
30
|
+
|
|
31
|
+
source: a is scoped_orders extend {
|
|
32
|
+
# colspan=6
|
|
33
|
+
# label="By category"
|
|
34
|
+
view: by_cat is by_category
|
|
35
|
+
}`;
|
|
36
|
+
|
|
37
|
+
const getModel = mock(
|
|
38
|
+
(_env: string, _pkg: string, path: string, _versionId?: string) =>
|
|
39
|
+
Promise.resolve({
|
|
40
|
+
data:
|
|
41
|
+
path === "dashboards/overview.malloy"
|
|
42
|
+
? { modelPath: path, sourceText: PACKAGE_FILE }
|
|
43
|
+
: {
|
|
44
|
+
modelPath: path,
|
|
45
|
+
sources: [
|
|
46
|
+
{
|
|
47
|
+
name: "scoped_orders",
|
|
48
|
+
views: [{ name: "by_category" }],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
sourceInfos: [
|
|
52
|
+
JSON.stringify({
|
|
53
|
+
name: "scoped_orders",
|
|
54
|
+
schema: { fields: [] },
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
const getDashboard = mock(
|
|
61
|
+
(_env: string, _pkg: string, _slug: string, _versionId?: string) =>
|
|
62
|
+
Promise.resolve({
|
|
63
|
+
data: { path: "dashboards/overview.malloy", givens: [], tiles: [] },
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
const listDashboards = mock((_env: string, _pkg: string, _versionId?: string) =>
|
|
67
|
+
Promise.resolve({ data: [{ name: "overview" }] }),
|
|
68
|
+
);
|
|
69
|
+
const updateModelSource = mock(
|
|
70
|
+
(_env: string, _pkg: string, path: string, body: { source: string }) =>
|
|
71
|
+
Promise.resolve({
|
|
72
|
+
data: {
|
|
73
|
+
path,
|
|
74
|
+
contentHash: `hash-of-${body.source.length}`,
|
|
75
|
+
created: false,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
// Typed with the client's own signature, so a spec can read the request body
|
|
80
|
+
// off `mock.calls`. Inferred from `() => …` the call tuple is empty, and
|
|
81
|
+
// indexing it is a type error the spec typecheck catches but `bun test` does
|
|
82
|
+
// not.
|
|
83
|
+
const executeQueryModel = mock(
|
|
84
|
+
(
|
|
85
|
+
_env: string,
|
|
86
|
+
_pkg: string,
|
|
87
|
+
_path: string,
|
|
88
|
+
_body: { query?: string; givens?: unknown; versionId?: string },
|
|
89
|
+
) => pending(),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Mutated between tests: a `mutable` server is what puts Save into the
|
|
93
|
+
// package, which is the branch `versionId` has to gate.
|
|
94
|
+
const serverContext = { mutable: false };
|
|
95
|
+
mockServerProvider(
|
|
96
|
+
{
|
|
97
|
+
models: { getModel, executeQueryModel, updateModelSource },
|
|
98
|
+
dashboards: { getDashboard, listDashboards },
|
|
99
|
+
},
|
|
100
|
+
serverContext,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const { DashboardEditor } = await import("./DashboardEditor");
|
|
104
|
+
|
|
105
|
+
const URI = "publisher://environments/env/packages/pkg";
|
|
106
|
+
const button = (name: string | RegExp) =>
|
|
107
|
+
screen.getByRole("button", { name, hidden: true });
|
|
108
|
+
|
|
109
|
+
const mountByUri = (versionId?: string) =>
|
|
110
|
+
render(
|
|
111
|
+
<DocumentStorageProvider documentStorage={new BrowserDocumentStorage()}>
|
|
112
|
+
<DashboardEditor
|
|
113
|
+
resourceUri={
|
|
114
|
+
versionId === undefined ? URI : `${URI}?versionId=${versionId}`
|
|
115
|
+
}
|
|
116
|
+
dashboard="overview"
|
|
117
|
+
/>
|
|
118
|
+
</DocumentStorageProvider>,
|
|
119
|
+
{ wrapper: serverWrapper },
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const mountLegacy = () =>
|
|
123
|
+
render(
|
|
124
|
+
<DocumentStorageProvider documentStorage={new BrowserDocumentStorage()}>
|
|
125
|
+
<DashboardEditor
|
|
126
|
+
environmentName="env"
|
|
127
|
+
packageName="pkg"
|
|
128
|
+
dashboardName="overview"
|
|
129
|
+
/>
|
|
130
|
+
</DocumentStorageProvider>,
|
|
131
|
+
{ wrapper: serverWrapper },
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
clearCache();
|
|
136
|
+
localStorage.clear();
|
|
137
|
+
getModel.mockClear();
|
|
138
|
+
getDashboard.mockClear();
|
|
139
|
+
listDashboards.mockClear();
|
|
140
|
+
updateModelSource.mockClear();
|
|
141
|
+
// Uncleared, a tile query from an earlier test carries into the next one's
|
|
142
|
+
// assertions, where it looks like the component under test made it.
|
|
143
|
+
executeQueryModel.mockClear();
|
|
144
|
+
serverContext.mutable = false;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("the two prop forms", () => {
|
|
148
|
+
it("open the same dashboard", async () => {
|
|
149
|
+
mountLegacy();
|
|
150
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
151
|
+
const legacyCall = getModel.mock.calls.find(
|
|
152
|
+
(call) => call[2] === "dashboards/overview.malloy",
|
|
153
|
+
);
|
|
154
|
+
cleanup();
|
|
155
|
+
clearCache();
|
|
156
|
+
getModel.mockClear();
|
|
157
|
+
|
|
158
|
+
mountByUri();
|
|
159
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
160
|
+
const uriCall = getModel.mock.calls.find(
|
|
161
|
+
(call) => call[2] === "dashboards/overview.malloy",
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Same environment, package, path and (absent) version either way: the
|
|
165
|
+
// union resolves to the same locals, not a second code path that
|
|
166
|
+
// happens to agree today.
|
|
167
|
+
expect(uriCall).toEqual(legacyCall);
|
|
168
|
+
expect(uriCall).toEqual([
|
|
169
|
+
"env",
|
|
170
|
+
"pkg",
|
|
171
|
+
"dashboards/overview.malloy",
|
|
172
|
+
undefined,
|
|
173
|
+
]);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe("versionId", () => {
|
|
178
|
+
it("reaches every read: the model, the manifest, the list, and the catalog", async () => {
|
|
179
|
+
mountByUri("v7");
|
|
180
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
181
|
+
|
|
182
|
+
await waitFor(() =>
|
|
183
|
+
expect(
|
|
184
|
+
getModel.mock.calls.some((call) => call[2] === "data_app.malloy"),
|
|
185
|
+
).toBe(true),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(
|
|
189
|
+
getModel.mock.calls.find(
|
|
190
|
+
(call) => call[2] === "dashboards/overview.malloy",
|
|
191
|
+
),
|
|
192
|
+
).toEqual(["env", "pkg", "dashboards/overview.malloy", "v7"]);
|
|
193
|
+
expect(
|
|
194
|
+
getModel.mock.calls.find((call) => call[2] === "data_app.malloy"),
|
|
195
|
+
).toEqual(["env", "pkg", "data_app.malloy", "v7"]);
|
|
196
|
+
expect(getDashboard.mock.calls[0]).toEqual([
|
|
197
|
+
"env",
|
|
198
|
+
"pkg",
|
|
199
|
+
"overview",
|
|
200
|
+
"v7",
|
|
201
|
+
]);
|
|
202
|
+
expect(listDashboards.mock.calls[0]).toEqual(["env", "pkg", "v7"]);
|
|
203
|
+
|
|
204
|
+
// The key too, appended last, never spliced in the middle of it: a
|
|
205
|
+
// version in the wrong slot is a key that cannot tell two versions of
|
|
206
|
+
// one dashboard apart, and nothing about that failure is visible on
|
|
207
|
+
// screen.
|
|
208
|
+
expect(cacheKeys("dashboard-editor-model")[0]).toContain('"v7"');
|
|
209
|
+
expect(cacheKeys("dashboard-editor-manifest")[0]).toContain('"v7"');
|
|
210
|
+
expect(cacheKeys("dashboard-editor-dashboards")[0]).toContain('"v7"');
|
|
211
|
+
await waitFor(() =>
|
|
212
|
+
expect(cacheKeys("dashboard-editor-catalog")[0]).toContain('"v7"'),
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// The pin has to reach the TILE QUERIES too, not just the file, manifest
|
|
217
|
+
// and catalog. Half-applied it is worse than absent: the editor shows v7's
|
|
218
|
+
// text and field list while every tile runs against the current package, so
|
|
219
|
+
// a view that changed between them displays data the file on screen does
|
|
220
|
+
// not describe, and nothing says so.
|
|
221
|
+
it("reaches the tile queries, not only the file the editor opens", async () => {
|
|
222
|
+
mountByUri("v7");
|
|
223
|
+
expect(await screen.findByText("Storefront")).toBeDefined();
|
|
224
|
+
|
|
225
|
+
await waitFor(() =>
|
|
226
|
+
expect(executeQueryModel.mock.calls.length).toBeGreaterThan(0),
|
|
227
|
+
);
|
|
228
|
+
for (const call of executeQueryModel.mock.calls)
|
|
229
|
+
expect((call[3] as { versionId?: string }).versionId).toBe("v7");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("never reaches the write", async () => {
|
|
233
|
+
serverContext.mutable = true;
|
|
234
|
+
mountByUri();
|
|
235
|
+
await screen.findByText("Storefront");
|
|
236
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
237
|
+
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
238
|
+
target: { value: "Categories" },
|
|
239
|
+
});
|
|
240
|
+
fireEvent.keyDown(screen.getByLabelText("Tile title"), {
|
|
241
|
+
key: "Escape",
|
|
242
|
+
});
|
|
243
|
+
fireEvent.click(button("Save changes"));
|
|
244
|
+
|
|
245
|
+
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
246
|
+
// Four positional arguments, none of them a version: the client's
|
|
247
|
+
// `updateModelSource` accepts one as a fifth, and Publisher answers 501
|
|
248
|
+
// to it on this route, so threading it through here would make every
|
|
249
|
+
// save from this component fail outright.
|
|
250
|
+
// Length alone: the mock is typed at four arguments, so naming a fifth
|
|
251
|
+
// is a type error rather than an assertion, and a fifth passed at
|
|
252
|
+
// runtime still shows up here.
|
|
253
|
+
expect(updateModelSource.mock.calls[0]).toHaveLength(4);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("does not stop a package save from invalidating the read it moved", async () => {
|
|
257
|
+
serverContext.mutable = true;
|
|
258
|
+
mountByUri();
|
|
259
|
+
await screen.findByText("Storefront");
|
|
260
|
+
const modelReadsBeforeSave = getModel.mock.calls.filter(
|
|
261
|
+
(call) => call[2] === "dashboards/overview.malloy",
|
|
262
|
+
).length;
|
|
263
|
+
|
|
264
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
265
|
+
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
266
|
+
target: { value: "Categories" },
|
|
267
|
+
});
|
|
268
|
+
fireEvent.keyDown(screen.getByLabelText("Tile title"), {
|
|
269
|
+
key: "Escape",
|
|
270
|
+
});
|
|
271
|
+
fireEvent.click(button("Save changes"));
|
|
272
|
+
await waitFor(() => expect(updateModelSource).toHaveBeenCalledTimes(1));
|
|
273
|
+
|
|
274
|
+
// Proof, not a proxy for one: the live query's key now ends in a
|
|
275
|
+
// version slot rather than at `modelPath`, and the invalidate call
|
|
276
|
+
// that follows a save has to end in the same slot to still match it.
|
|
277
|
+
// A version spliced into the middle of either key (as `Dashboard`
|
|
278
|
+
// does for its own, unrelated, key) would leave this read stale
|
|
279
|
+
// until something else happened to touch it.
|
|
280
|
+
await waitFor(() =>
|
|
281
|
+
expect(
|
|
282
|
+
getModel.mock.calls.filter(
|
|
283
|
+
(call) => call[2] === "dashboards/overview.malloy",
|
|
284
|
+
).length,
|
|
285
|
+
).toBeGreaterThan(modelReadsBeforeSave),
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("Save, pinned to a version", () => {
|
|
291
|
+
it("is off when the write target is the package, and the caption says why", async () => {
|
|
292
|
+
serverContext.mutable = true;
|
|
293
|
+
mountByUri("v7");
|
|
294
|
+
await screen.findByText("Storefront");
|
|
295
|
+
|
|
296
|
+
expect(
|
|
297
|
+
screen.getByText(
|
|
298
|
+
"Reading version v7: a version is a fixed point in history, so Save is off.",
|
|
299
|
+
),
|
|
300
|
+
).toBeDefined();
|
|
301
|
+
expect(
|
|
302
|
+
screen.queryByRole("button", { name: "Save changes", hidden: true }),
|
|
303
|
+
).toBeNull();
|
|
304
|
+
expect(
|
|
305
|
+
screen.queryByRole("button", { name: "Saved", hidden: true }),
|
|
306
|
+
).toBeNull();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("is not off when the write target is storage instead of the package", async () => {
|
|
310
|
+
serverContext.mutable = false;
|
|
311
|
+
mountByUri("v7");
|
|
312
|
+
await screen.findByText("Storefront");
|
|
313
|
+
|
|
314
|
+
// Unaffected: a copy kept beside the package never goes through
|
|
315
|
+
// `updateModelSource`, so the version pin has nothing to refuse.
|
|
316
|
+
fireEvent.click(screen.getByLabelText("Settings for By category"));
|
|
317
|
+
fireEvent.change(screen.getByLabelText("Tile title"), {
|
|
318
|
+
target: { value: "Categories" },
|
|
319
|
+
});
|
|
320
|
+
fireEvent.keyDown(screen.getByLabelText("Tile title"), {
|
|
321
|
+
key: "Escape",
|
|
322
|
+
});
|
|
323
|
+
fireEvent.click(button("Save changes"));
|
|
324
|
+
await waitFor(() => expect(button("Saved")).toBeDefined());
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A render body that throws takes the host's whole tree down, which is a white
|
|
330
|
+
* screen rather than a message. `parseResourceUri` throws on a string that is
|
|
331
|
+
* not a `publisher://` URI at all and returns for one that merely names too
|
|
332
|
+
* little, so both shapes have to reach the same display. An embedding host is
|
|
333
|
+
* exactly who can pass either; the Console builds its URI from guarded params.
|
|
334
|
+
*/
|
|
335
|
+
describe("a malformed resourceUri", () => {
|
|
336
|
+
const badUris = [
|
|
337
|
+
["names no package", "publisher://environments/env"],
|
|
338
|
+
["is not a URL at all", "nonsense"],
|
|
339
|
+
["is a URL of another scheme", "http://example.com/env"],
|
|
340
|
+
] as const;
|
|
341
|
+
|
|
342
|
+
for (const [what, resourceUri] of badUris) {
|
|
343
|
+
it(`degrades to an error display when it ${what}`, async () => {
|
|
344
|
+
render(
|
|
345
|
+
<DashboardEditor resourceUri={resourceUri} dashboard="overview" />,
|
|
346
|
+
{ wrapper: serverWrapper },
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
expect(
|
|
350
|
+
await screen.findByText(
|
|
351
|
+
/A dashboard resource URI must name an environment and a package/,
|
|
352
|
+
),
|
|
353
|
+
).toBeDefined();
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
});
|