@malloy-publisher/sdk 0.2.0 → 0.2.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.
Files changed (37) hide show
  1. package/dist/{ServerProvider-DUFPY6Rv.es.js → ServerProvider-CWkd55-c.es.js} +130 -126
  2. package/dist/ServerProvider-Cn_LhKda.cjs.js +1 -0
  3. package/dist/client/api.d.ts +86 -39
  4. package/dist/client/index.cjs.js +1 -1
  5. package/dist/client/index.es.js +14 -13
  6. package/dist/components/Dashboard/Dashboard.d.ts +14 -1
  7. package/dist/components/Dashboard/DashboardTile.d.ts +16 -7
  8. package/dist/{core-hLahnv0W.cjs.js → core-CqRKhtoy.cjs.js} +1 -1
  9. package/dist/{core-lb28vQkR.es.js → core-mFfgwzPH.es.js} +1 -1
  10. package/dist/hooks/useSuggestOptions.d.ts +1 -1
  11. package/dist/index-DD4b_bt0.cjs.js +356 -0
  12. package/dist/{index-txw04ZbN.es.js → index-hiul47sw.es.js} +13455 -13248
  13. package/dist/index.cjs.js +1 -1
  14. package/dist/index.es.js +9 -9
  15. package/dist/theme/buildTableCssVars.d.ts +17 -1
  16. package/package.json +1 -1
  17. package/src/components/Connections/AddConnectionDialog.tsx +102 -23
  18. package/src/components/Connections/EditConnectionDialog.tsx +134 -33
  19. package/src/components/Connections/common.ts +30 -2
  20. package/src/components/Dashboard/Dashboard.spec.tsx +216 -0
  21. package/src/components/Dashboard/Dashboard.tsx +77 -17
  22. package/src/components/Dashboard/DashboardTile.spec.tsx +81 -0
  23. package/src/components/Dashboard/DashboardTile.tsx +58 -12
  24. package/src/components/Dashboard/tileGridColumn.spec.ts +35 -0
  25. package/src/components/Notebook/Notebook.spec.tsx +88 -0
  26. package/src/components/Notebook/Notebook.tsx +1 -0
  27. package/src/components/Package/Package.spec.tsx +113 -0
  28. package/src/components/Package/Package.tsx +29 -3
  29. package/src/components/RenderedResult/RenderedResult.tsx +47 -7
  30. package/src/hooks/useSuggestOptions.dom.spec.ts +91 -0
  31. package/src/hooks/useSuggestOptions.ts +6 -1
  32. package/src/theme/buildTableCssVars.spec.ts +19 -0
  33. package/src/theme/buildTableCssVars.ts +31 -0
  34. package/test/README.md +44 -0
  35. package/test/serverProvider.tsx +72 -0
  36. package/dist/ServerProvider-CTopDUWW.cjs.js +0 -1
  37. package/dist/index-DvEanVgc.cjs.js +0 -339
@@ -0,0 +1,216 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * What a dashboard's queries are CACHED under, not what they render.
6
+ *
7
+ * A version that reaches the request but not the request's key is worse than
8
+ * no version at all: two versions of one dashboard share a cache entry and one
9
+ * silently serves the other's data, which looks correct on screen. Nothing a
10
+ * manual smoke test can see, so it is pinned here.
11
+ */
12
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
13
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
14
+ import {
15
+ cacheKeys,
16
+ clearCache,
17
+ mockServerProvider,
18
+ pending,
19
+ serverWrapper,
20
+ } from "../../../test/serverProvider";
21
+ import type { DashboardManifest } from "../../client";
22
+
23
+ const getDashboard = mock(
24
+ (
25
+ _environmentName: string,
26
+ _packageName: string,
27
+ _dashboardName: string,
28
+ _versionId?: string,
29
+ ) => pending<{ data: DashboardManifest }>(),
30
+ );
31
+ const executeQueryModel = mock(
32
+ (
33
+ _environmentName: string,
34
+ _packageName: string,
35
+ _modelPath: string,
36
+ _request: { versionId?: string; givens?: Record<string, string> },
37
+ ) => pending(),
38
+ );
39
+
40
+ mockServerProvider({
41
+ dashboards: { getDashboard },
42
+ models: { executeQueryModel },
43
+ });
44
+
45
+ // Imported after the stub is registered: a static import would hoist above it.
46
+ const { default: Dashboard } = await import("./Dashboard");
47
+
48
+ const URI = "publisher://environments/env/packages/pkg";
49
+
50
+ const dashboardAt = (versionId?: string) => (
51
+ <Dashboard
52
+ resourceUri={
53
+ versionId === undefined ? URI : `${URI}?versionId=${versionId}`
54
+ }
55
+ dashboard="ops"
56
+ />
57
+ );
58
+
59
+ /** The latest tile request, told apart from a suggest by its `givens`. */
60
+ const tileRequest = () =>
61
+ executeQueryModel.mock.calls
62
+ .filter((call) => call[3] !== undefined && "givens" in call[3])
63
+ .at(-1)?.[3];
64
+
65
+ beforeEach(() => {
66
+ clearCache();
67
+ // `mockClear` leaves a queued `mockImplementationOnce` in place, so a test
68
+ // that queued one it never consumed would hand it to the next test.
69
+ getDashboard.mockReset();
70
+ getDashboard.mockImplementation(() => pending());
71
+ executeQueryModel.mockReset();
72
+ executeQueryModel.mockImplementation(() => pending());
73
+ });
74
+
75
+ describe("the manifest fetch", () => {
76
+ it("sends the version the URI carried, and keys on it", async () => {
77
+ render(dashboardAt("v2"), { wrapper: serverWrapper });
78
+
79
+ await waitFor(() => expect(getDashboard).toHaveBeenCalled());
80
+ expect(getDashboard.mock.calls[0]).toEqual(["env", "pkg", "ops", "v2"]);
81
+ expect(cacheKeys("dashboard")[0]).toContain('"v2"');
82
+ });
83
+
84
+ it("sends and keys nothing when the URI named no version", async () => {
85
+ render(dashboardAt(), { wrapper: serverWrapper });
86
+
87
+ await waitFor(() => expect(getDashboard).toHaveBeenCalled());
88
+ expect(getDashboard.mock.calls[0]).toEqual([
89
+ "env",
90
+ "pkg",
91
+ "ops",
92
+ undefined,
93
+ ]);
94
+ // The whole key, not just the absence of a version: the slot is empty
95
+ // and nothing else about the key moved. A `toContain` here would pass
96
+ // for a key that had also grown something it should not carry.
97
+ expect(cacheKeys("dashboard")[0]).toBe(
98
+ '["dashboard","env","pkg",null,"ops","http://localhost/api/v0"]',
99
+ );
100
+ });
101
+
102
+ it("gives two versions of one dashboard two cache entries", async () => {
103
+ const { rerender } = render(dashboardAt("v1"), {
104
+ wrapper: serverWrapper,
105
+ });
106
+ await waitFor(() => expect(getDashboard).toHaveBeenCalledTimes(1));
107
+
108
+ rerender(dashboardAt("v2"));
109
+
110
+ await waitFor(() => expect(getDashboard).toHaveBeenCalledTimes(2));
111
+ expect(new Set(cacheKeys("dashboard")).size).toBe(2);
112
+ });
113
+
114
+ it("keys two spellings of one unversioned dashboard together", async () => {
115
+ // Built from what `parseResourceUri` returned rather than from the URI
116
+ // as the host spelled it, so an empty `?versionId=` and no query string
117
+ // at all stay one cache entry instead of fetching the same thing twice.
118
+ const { rerender } = render(dashboardAt(), { wrapper: serverWrapper });
119
+ await waitFor(() => expect(getDashboard).toHaveBeenCalledTimes(1));
120
+
121
+ rerender(<Dashboard resourceUri={`${URI}?versionId=`} dashboard="ops" />);
122
+
123
+ await waitFor(() => expect(cacheKeys("dashboard").length).toBe(1));
124
+ expect(getDashboard).toHaveBeenCalledTimes(1);
125
+ });
126
+ });
127
+
128
+ describe("the version reaches what the manifest drives", () => {
129
+ // End to end through the manifest: the version has to survive the fetch and
130
+ // be handed on, which is the step a key-only test cannot see.
131
+ const manifest: DashboardManifest = {
132
+ name: "ops",
133
+ path: "dashboards/ops.malloy",
134
+ query: "overview",
135
+ givens: [
136
+ { name: "REGION", type: "string" },
137
+ {
138
+ name: "TIER",
139
+ control: "select",
140
+ suggest: { source: "orders", dimension: "tier" },
141
+ },
142
+ ],
143
+ };
144
+
145
+ beforeEach(() => {
146
+ getDashboard.mockImplementation(() =>
147
+ Promise.resolve({ data: manifest }),
148
+ );
149
+ });
150
+
151
+ it("runs the tile's query against the same version", async () => {
152
+ render(dashboardAt("v2"), { wrapper: serverWrapper });
153
+
154
+ await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(1));
155
+ expect(tileRequest()?.versionId).toBe("v2");
156
+ expect(cacheKeys("dashboardTile")[0]).toContain('"v2"');
157
+ });
158
+
159
+ it("runs every composite tile against the same version", async () => {
160
+ // The composite branch wraps each tile in its own grid cell, so the prop
161
+ // is threaded at a different call site than the single-query form above.
162
+ getDashboard.mockImplementation(() =>
163
+ Promise.resolve({
164
+ data: {
165
+ ...manifest,
166
+ query: undefined,
167
+ tiles: [{ query: "by_month" }, { query: "by_region" }],
168
+ },
169
+ }),
170
+ );
171
+
172
+ render(dashboardAt("v2"), { wrapper: serverWrapper });
173
+
174
+ await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(2));
175
+ for (const key of cacheKeys("dashboardTile"))
176
+ expect(key).toContain('"v2"');
177
+ });
178
+
179
+ it("runs the control's suggest query against the same version", async () => {
180
+ render(dashboardAt("v2"), { wrapper: serverWrapper });
181
+
182
+ await waitFor(() => expect(cacheKeys("givenSuggest").length).toBe(1));
183
+ expect(cacheKeys("givenSuggest")[0]).toContain('"v2"');
184
+ });
185
+
186
+ it("does not carry one version's applied values into another", async () => {
187
+ // `documentKey` is what tells `useGivensState` the document changed. With
188
+ // the version missing from it, a host swapping versions kept the values
189
+ // the reader applied to the old one and filtered the new one by them —
190
+ // the same confusion the keys above exist to prevent, one layer up.
191
+ //
192
+ // Mounted with no `givens` prop, which is the case the key governs. A
193
+ // host feeding its URL back in through `givens` re-supplies the values
194
+ // itself, and no `documentKey` can override that.
195
+ const { rerender } = render(dashboardAt("v1"), {
196
+ wrapper: serverWrapper,
197
+ });
198
+ await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(1));
199
+
200
+ fireEvent.change(await screen.findByLabelText("REGION"), {
201
+ target: { value: "CA" },
202
+ });
203
+ await waitFor(() =>
204
+ expect(tileRequest()?.givens).toEqual({ REGION: "CA" }),
205
+ );
206
+
207
+ rerender(dashboardAt("v2"));
208
+
209
+ await waitFor(() => expect(cacheKeys("dashboardTile").length).toBe(3));
210
+ const v2 = cacheKeys("dashboardTile").filter((key) =>
211
+ key.includes('"v2"'),
212
+ );
213
+ expect(v2).toHaveLength(1);
214
+ expect(v2[0]).not.toContain("CA");
215
+ });
216
+ });
@@ -16,7 +16,7 @@ import { useServer } from "../ServerProvider";
16
16
  import { DashboardTile } from "./DashboardTile";
17
17
 
18
18
  export interface DashboardProps {
19
- /** `publisher://environments/{env}/packages/{pkg}`, env and package only. */
19
+ /** `publisher://environments/{env}/packages/{pkg}`, optionally `?versionId=`. */
20
20
  resourceUri: string;
21
21
  /** The dashboard's slug, as listed by the dashboards endpoint. */
22
22
  dashboard: string;
@@ -80,6 +80,26 @@ const TILE_HEIGHT = 400;
80
80
  */
81
81
  const WHOLE_PAGE_HEIGHT = 20000;
82
82
 
83
+ /** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
84
+ const DEFAULT_COLUMNS = 2;
85
+
86
+ /**
87
+ * The `grid-column` one tile occupies: its `# colspan`, and a `# break` forcing
88
+ * it to start a fresh row.
89
+ *
90
+ * Clamped to the grid width the same way @malloydata/render clamps it, so one
91
+ * view laid out as a composite tile and as a `nest:` under `# dashboard` lands
92
+ * in the same place. A break is `1 / span N` — an explicit start line, which is
93
+ * what pushes the tile down to the next row; the renderer's grid does the same.
94
+ */
95
+ export function tileGridColumn(
96
+ tile: { colspan?: number; break?: boolean },
97
+ columns: number,
98
+ ): string {
99
+ const span = Math.min(tile.colspan ?? 1, columns);
100
+ return tile.break ? `1 / span ${span}` : `span ${span}`;
101
+ }
102
+
83
103
  /**
84
104
  * A Malloyyo-style dashboard: a control row over one or more query results,
85
105
  * declared entirely by tags in a package's `dashboards/*.malloy`.
@@ -110,6 +130,7 @@ export function Dashboard({
110
130
  // than here, so every hook still runs in the same order.
111
131
  const environmentName = parsed.environmentName ?? "";
112
132
  const packageName = parsed.packageName ?? "";
133
+ const versionId = parsed.versionId;
113
134
  const uriNamesBoth = !!parsed.environmentName && !!parsed.packageName;
114
135
 
115
136
  const {
@@ -118,12 +139,23 @@ export function Dashboard({
118
139
  isError,
119
140
  error,
120
141
  } = useQueryWithApiError({
121
- queryKey: ["dashboard", environmentName, packageName, dashboard],
142
+ // Every value the request is built from, so the key cannot drift out of
143
+ // step with it. A version that reached the request alone would leave two
144
+ // versions of one dashboard on a single cache entry, each able to serve
145
+ // the other's manifest.
146
+ queryKey: [
147
+ "dashboard",
148
+ environmentName,
149
+ packageName,
150
+ versionId,
151
+ dashboard,
152
+ ],
122
153
  queryFn: () =>
123
154
  apiClients.dashboards.getDashboard(
124
155
  environmentName,
125
156
  packageName,
126
157
  dashboard,
158
+ versionId,
127
159
  ),
128
160
  // No point asking for a dashboard under a name the URI never carried.
129
161
  enabled: uriNamesBoth,
@@ -171,7 +203,13 @@ export function Dashboard({
171
203
  // their starting VALUES alone, so two dashboards whose starting values
172
204
  // coincide (the common case: both empty) look like one document, and the
173
205
  // one you came from keeps filtering the one you drilled into.
174
- documentKey: `${environmentName}/${packageName}/${dashboard}`,
206
+ // The version belongs in that identity too, so a swap between versions
207
+ // drops the edits a reader made to the one they came from. Only the
208
+ // EDITS: `initial` is `startingValues` merged with `params`, so a host
209
+ // that round-trips givens through its own URL hands them straight back
210
+ // and they still apply across the swap. That one is the host's call, and
211
+ // this key neither can nor should overrule it.
212
+ documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${dashboard}`,
175
213
  // Absent means autorun; only an explicit `autorun=false` batches.
176
214
  autorun: manifest?.autorun !== false,
177
215
  });
@@ -180,7 +218,13 @@ export function Dashboard({
180
218
  options,
181
219
  isLoading: optionsLoading,
182
220
  failed: optionsFailed,
183
- } = useSuggestOptions(environmentName, packageName, manifest?.path, specs);
221
+ } = useSuggestOptions(
222
+ environmentName,
223
+ packageName,
224
+ manifest?.path,
225
+ specs,
226
+ versionId,
227
+ );
184
228
 
185
229
  // A drill tag names its given as the model spells it, and `# drill` with no
186
230
  // `given=` falls back to the DIMENSION's spelling, which need not match. The
@@ -295,6 +339,7 @@ export function Dashboard({
295
339
 
296
340
  const modelPath = manifest.path;
297
341
  const tiles = manifest.tiles ?? [];
342
+ const columns = manifest.dashboardColumns ?? DEFAULT_COLUMNS;
298
343
 
299
344
  return (
300
345
  <Stack spacing={2}>
@@ -327,6 +372,7 @@ export function Dashboard({
327
372
  <DashboardTile
328
373
  environmentName={environmentName}
329
374
  packageName={packageName}
375
+ versionId={versionId}
330
376
  modelPath={modelPath}
331
377
  queryName={manifest.query}
332
378
  givens={applied}
@@ -344,29 +390,43 @@ export function Dashboard({
344
390
  display: "grid",
345
391
  gridTemplateColumns: {
346
392
  xs: "1fr",
347
- md: `repeat(${manifest.dashboardColumns ?? 2}, minmax(0, 1fr))`,
393
+ md: `repeat(${columns}, minmax(0, 1fr))`,
348
394
  },
349
395
  gap: 2,
350
396
  }}
351
397
  >
352
398
  {tiles.map((tile, index) => (
353
- <DashboardTile
399
+ <Box
354
400
  // Position too, not the expression alone: `tiles=[…]` can
355
401
  // repeat one, which is a typo rather than a request for two
356
402
  // identical panels, and keying on the expression made the
357
403
  // duplicate warn and reconcile onto its twin.
358
404
  key={`${index}:${tile.query}`}
359
- environmentName={environmentName}
360
- packageName={packageName}
361
- modelPath={modelPath}
362
- tile={tile.query}
363
- givens={applied}
364
- declaredTypes={declaredTypes}
365
- givenNames={tile.givenNames}
366
- height={height ?? TILE_HEIGHT}
367
- maxResultSize={maxResultSize}
368
- drill={drill}
369
- />
405
+ sx={{
406
+ display: "grid",
407
+ // Only above `md`: the narrow breakpoint is one column,
408
+ // where a span would overflow the grid rather than widen
409
+ // anything.
410
+ gridColumn: { md: tileGridColumn(tile, columns) },
411
+ }}
412
+ >
413
+ <DashboardTile
414
+ environmentName={environmentName}
415
+ packageName={packageName}
416
+ versionId={versionId}
417
+ modelPath={modelPath}
418
+ tile={tile.query}
419
+ label={tile.label}
420
+ subtitle={tile.subtitle}
421
+ borderless={tile.borderless}
422
+ givens={applied}
423
+ declaredTypes={declaredTypes}
424
+ givenNames={tile.givenNames}
425
+ height={height ?? TILE_HEIGHT}
426
+ maxResultSize={maxResultSize}
427
+ drill={drill}
428
+ />
429
+ </Box>
370
430
  ))}
371
431
  </Box>
372
432
  ) : (
@@ -0,0 +1,81 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * The tile's own query key, asserted directly rather than through `Dashboard`.
6
+ *
7
+ * `DashboardTile` is exported from the package root, so a host can mount one
8
+ * itself, and `versionId` has to land in both the request and the key from the
9
+ * prop alone.
10
+ */
11
+ import { beforeEach, expect, it, mock } from "bun:test";
12
+ import { render, waitFor } from "@testing-library/react";
13
+ import {
14
+ cacheKeys,
15
+ clearCache,
16
+ mockServerProvider,
17
+ pending,
18
+ serverWrapper,
19
+ } from "../../../test/serverProvider";
20
+
21
+ const executeQueryModel = mock(
22
+ (
23
+ _environmentName: string,
24
+ _packageName: string,
25
+ _modelPath: string,
26
+ _request: { versionId?: string },
27
+ ) => pending(),
28
+ );
29
+
30
+ mockServerProvider({ models: { executeQueryModel } });
31
+
32
+ const { DashboardTile } = await import("./DashboardTile");
33
+
34
+ const tileAt = (versionId?: string) => (
35
+ <DashboardTile
36
+ environmentName="env"
37
+ packageName="pkg"
38
+ versionId={versionId}
39
+ modelPath="dashboards/ops.malloy"
40
+ tile="sales_by_month"
41
+ givens={new Map()}
42
+ declaredTypes={new Map()}
43
+ height={400}
44
+ />
45
+ );
46
+
47
+ beforeEach(() => {
48
+ clearCache();
49
+ executeQueryModel.mockClear();
50
+ });
51
+
52
+ it("puts the version in the request body and in the key", async () => {
53
+ render(tileAt("v2"), { wrapper: serverWrapper });
54
+
55
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
56
+ expect(executeQueryModel.mock.calls[0][3].versionId).toBe("v2");
57
+ expect(cacheKeys("dashboardTile")[0]).toContain('"v2"');
58
+ });
59
+
60
+ it("sends and keys nothing extra without one", async () => {
61
+ render(tileAt(), { wrapper: serverWrapper });
62
+
63
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
64
+ expect(executeQueryModel.mock.calls[0][3].versionId).toBeUndefined();
65
+ // The whole key: an empty slot rather than a literal "undefined", and
66
+ // nothing else disturbed. The narrow assertion above cannot see either.
67
+ expect(cacheKeys("dashboardTile")[0]).toBe(
68
+ '["dashboardTile","env","pkg",null,"dashboards/ops.malloy",null,' +
69
+ '"sales_by_month","{}","http://localhost/api/v0"]',
70
+ );
71
+ });
72
+
73
+ it("keeps two versions of one tile apart", async () => {
74
+ const { rerender } = render(tileAt("v1"), { wrapper: serverWrapper });
75
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(1));
76
+
77
+ rerender(tileAt("v2"));
78
+
79
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(2));
80
+ expect(new Set(cacheKeys("dashboardTile")).size).toBe(2);
81
+ });
@@ -2,6 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { Box, Paper, Typography } from "@mui/material";
5
+ import { DASHBOARD_CARD_PADDING_PX } from "../../theme/buildTableCssVars";
6
+ import { usePublisherTheme } from "../../theme/ThemeContext";
5
7
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
6
8
  import type { GivenValue } from "../../hooks/givenValue";
7
9
  import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
@@ -15,11 +17,19 @@ import { useServer } from "../ServerProvider";
15
17
  export interface DashboardTileProps {
16
18
  environmentName: string;
17
19
  packageName: string;
20
+ /** The package version the dashboard's URI named, when it named one. */
21
+ versionId?: string;
18
22
  modelPath: string;
19
23
  /** A named query (the single-query form). */
20
24
  queryName?: string;
21
25
  /** A run expression (a composite tile). */
22
26
  tile?: string;
27
+ /** `# label` on the view the tile names, when it has one. */
28
+ label?: string;
29
+ /** `# subtitle` on it: a second line under the heading. */
30
+ subtitle?: string;
31
+ /** `# borderless` on it: no card around the result. */
32
+ borderless?: boolean;
23
33
  /**
24
34
  * The whole applied control row, NOT this tile's share of it. The narrowing
25
35
  * happens here, in `givensToRequest` below, using {@link givenNames}: the
@@ -42,13 +52,14 @@ export interface DashboardTileProps {
42
52
  }
43
53
 
44
54
  /**
45
- * A composite tile's heading, read off its run expression: the last step's name
46
- * as a sentence, so `scoped_sales -> sales_by_month` is titled "Sales by month".
55
+ * A composite tile's heading when the view it names carries no `# label`: the
56
+ * last step's name as a sentence, so `scoped_sales -> sales_by_month` is titled
57
+ * "Sales by month".
47
58
  *
48
- * A tile in the single-query form gets its heading from a `# label` on the nest,
49
- * and a composite tile has no nest to label: the entry is a string in
50
- * `tiles=[…]`. Deriving it keeps the two forms reading alike instead of one
51
- * showing titles and the other showing code.
59
+ * The label itself is the same `# label` a nest gets in the single-query form,
60
+ * read off the view server-side, so one view is titled identically whichever way
61
+ * it is consumed. This derivation is the fallback for an untitled view, so a
62
+ * tile shows a heading rather than code.
52
63
  */
53
64
  export function tileTitle(tile: string): string {
54
65
  const lastStep = tile.split("->").at(-1)?.trim() ?? tile;
@@ -67,9 +78,13 @@ export function tileTitle(tile: string): string {
67
78
  export function DashboardTile({
68
79
  environmentName,
69
80
  packageName,
81
+ versionId,
70
82
  modelPath,
71
83
  queryName,
72
84
  tile,
85
+ label,
86
+ subtitle,
87
+ borderless,
73
88
  givens,
74
89
  declaredTypes,
75
90
  givenNames,
@@ -78,6 +93,7 @@ export function DashboardTile({
78
93
  drill,
79
94
  }: DashboardTileProps) {
80
95
  const { apiClients } = useServer();
96
+ const { theme } = usePublisherTheme();
81
97
  const requestGivens = givensToRequest(givens, declaredTypes, givenNames);
82
98
 
83
99
  const { data, isSuccess, isError, error } = useQueryWithApiError({
@@ -85,6 +101,7 @@ export function DashboardTile({
85
101
  "dashboardTile",
86
102
  environmentName,
87
103
  packageName,
104
+ versionId,
88
105
  modelPath,
89
106
  queryName,
90
107
  tile,
@@ -101,6 +118,7 @@ export function DashboardTile({
101
118
  queryName,
102
119
  query: tile !== undefined ? `run: ${tile}` : undefined,
103
120
  givens: requestGivens,
121
+ versionId,
104
122
  },
105
123
  ),
106
124
  ...CHART_RESULT_QUERY_OPTIONS,
@@ -110,24 +128,52 @@ export function DashboardTile({
110
128
  <Paper
111
129
  elevation={0}
112
130
  sx={{
113
- border: 1,
114
- borderColor: "divider",
115
- borderRadius: 1,
131
+ // The instance theme's border, not MUI's `divider`: the renderer
132
+ // card's edge is this same value, and a card that agrees with the
133
+ // theme everywhere except its outline still reads as a different
134
+ // card. Radius stays on the host's `shape.borderRadius`, which the
135
+ // renderer card is now pointed at too.
136
+ //
137
+ // `# borderless` asks for the result with no card, which the renderer
138
+ // honours by dropping background, border, radius and most padding on
139
+ // its own `.dashboard-item`. Same here, so the tag reads the same on
140
+ // both forms.
141
+ border: borderless ? "none" : theme.border,
142
+ borderRadius: borderless ? 0 : 1,
143
+ background: borderless ? "none" : undefined,
116
144
  overflow: "hidden",
117
145
  minHeight: 120,
146
+ p: borderless ? "12px 0" : `${DASHBOARD_CARD_PADDING_PX}px`,
118
147
  }}
119
148
  >
120
149
  {tile !== undefined && (
121
- <Box sx={{ px: 2.5, pt: 2 }}>
150
+ <Box sx={{ pb: 1.5 }}>
122
151
  <Typography
123
152
  variant="subtitle2"
124
- sx={{ fontWeight: 500, color: "text.secondary" }}
153
+ sx={{
154
+ fontWeight: 500,
155
+ color: theme.tileTitle,
156
+ fontFamily: theme.font.family,
157
+ }}
125
158
  // The expression is what actually ran, so it stays reachable
126
159
  // as a tooltip rather than as the heading.
127
160
  title={tile}
128
161
  >
129
- {tileTitle(tile)}
162
+ {label ?? tileTitle(tile)}
130
163
  </Typography>
164
+ {subtitle !== undefined && (
165
+ <Typography
166
+ variant="caption"
167
+ sx={{
168
+ display: "block",
169
+ color: theme.tileTitle,
170
+ fontFamily: theme.font.family,
171
+ opacity: 0.8,
172
+ }}
173
+ >
174
+ {subtitle}
175
+ </Typography>
176
+ )}
131
177
  </Box>
132
178
  )}
133
179
  {!isSuccess && !isError && <Loading text="Running…" />}
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { tileGridColumn } from "./Dashboard";
6
+
7
+ describe("tileGridColumn", () => {
8
+ it("spans one column when the view carries no colspan", () => {
9
+ expect(tileGridColumn({}, 12)).toBe("span 1");
10
+ });
11
+
12
+ it("spans the colspan the view asked for", () => {
13
+ expect(tileGridColumn({ colspan: 8 }, 12)).toBe("span 8");
14
+ });
15
+
16
+ // Clamped rather than allowed to overflow the grid, matching how
17
+ // @malloydata/render clamps the same tag on a `# dashboard` nest child. The
18
+ // whole point of reading the tag off the view is that one view lays out the
19
+ // same either way, which a different overflow rule would break.
20
+ it("clamps a colspan wider than the grid", () => {
21
+ expect(tileGridColumn({ colspan: 20 }, 4)).toBe("span 4");
22
+ });
23
+
24
+ // An explicit start line is what pushes the tile onto a fresh row; `span N`
25
+ // alone would let it flow into whatever columns are left beside its sibling.
26
+ it("starts a new row for a break", () => {
27
+ expect(tileGridColumn({ colspan: 6, break: true }, 12)).toBe(
28
+ "1 / span 6",
29
+ );
30
+ });
31
+
32
+ it("breaks with no colspan too", () => {
33
+ expect(tileGridColumn({ break: true }, 12)).toBe("1 / span 1");
34
+ });
35
+ });