@malloy-publisher/sdk 0.8.0 → 0.8.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 (40) hide show
  1. package/dist/{DocumentStorage-D7yF4_T3.cjs.js → DocumentStorage-B0_YgSzt.cjs.js} +32 -32
  2. package/dist/{DocumentStorage-BypSIWDg.es.js → DocumentStorage-BZqn0x5r.es.js} +3826 -3741
  3. package/dist/{RenderedResult-ChkvK7b2.cjs.js → RenderedResult-Bu25oAAr.cjs.js} +1 -1
  4. package/dist/{RenderedResult-CYyhQekT.es.js → RenderedResult-DKOl0FQ8.es.js} +2 -2
  5. package/dist/{ServerProvider-AsUiy22k.es.js → ServerProvider-CfUFleYe.es.js} +24 -24
  6. package/dist/builder/index.cjs.js +31 -31
  7. package/dist/builder/index.es.js +1167 -1142
  8. package/dist/client/api.d.ts +36 -30
  9. package/dist/client/index.es.js +1 -1
  10. package/dist/components/Dashboard/ExploreDialog.d.ts +3 -1
  11. package/dist/components/DashboardBuilder/catalog.d.ts +18 -0
  12. package/dist/components/Model/Model.d.ts +10 -3
  13. package/dist/components/Model/ModelExplorer.d.ts +21 -1
  14. package/dist/components/Model/ModelExplorerDialog.d.ts +4 -1
  15. package/dist/components/Model/SourcesExplorer.d.ts +8 -1
  16. package/dist/components/Model/index.d.ts +1 -0
  17. package/dist/components/Model/runGate.d.ts +19 -0
  18. package/dist/components/Notebook/NotebookCell.d.ts +10 -1
  19. package/dist/index.cjs.js +13 -13
  20. package/dist/index.es.js +3754 -3732
  21. package/package.json +1 -1
  22. package/src/components/Dashboard/Dashboard.spec.tsx +58 -2
  23. package/src/components/Dashboard/Dashboard.tsx +8 -1
  24. package/src/components/Dashboard/ExploreDialog.tsx +5 -0
  25. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +6 -1
  26. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +60 -30
  27. package/src/components/DashboardBuilder/DashboardEditor.tsx +35 -16
  28. package/src/components/DashboardBuilder/catalog.spec.ts +44 -0
  29. package/src/components/DashboardBuilder/catalog.ts +36 -0
  30. package/src/components/Model/Model.tsx +28 -1
  31. package/src/components/Model/ModelExplorer.spec.tsx +404 -0
  32. package/src/components/Model/ModelExplorer.tsx +65 -2
  33. package/src/components/Model/ModelExplorerDialog.tsx +12 -0
  34. package/src/components/Model/SourcesExplorer.tsx +70 -15
  35. package/src/components/Model/index.ts +1 -0
  36. package/src/components/Model/runGate.spec.ts +102 -0
  37. package/src/components/Model/runGate.ts +67 -0
  38. package/src/components/Notebook/Notebook.spec.tsx +67 -3
  39. package/src/components/Notebook/Notebook.tsx +12 -2
  40. package/src/components/Notebook/NotebookCell.tsx +26 -7
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.8.0",
4
+ "version": "0.8.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { beforeEach, describe, expect, it, mock } from "bun:test";
13
13
  import { fireEvent, render, screen, waitFor } from "@testing-library/react";
14
+ import type { ReactNode } from "react";
14
15
  import {
15
16
  cacheKeys,
16
17
  clearCache,
@@ -18,7 +19,7 @@ import {
18
19
  pending,
19
20
  serverWrapper,
20
21
  } from "../../../test/serverProvider";
21
- import type { DashboardManifest } from "../../client";
22
+ import type { CompiledModel, DashboardManifest } from "../../client";
22
23
 
23
24
  const getDashboard = mock(
24
25
  (
@@ -36,10 +37,35 @@ const executeQueryModel = mock(
36
37
  _request: { versionId?: string; givens?: Record<string, string> },
37
38
  ) => pending(),
38
39
  );
40
+ const getModel = mock(
41
+ (
42
+ _environmentName: string,
43
+ _packageName: string,
44
+ _modelPath: string,
45
+ _versionId?: string,
46
+ ) => pending<{ data: CompiledModel }>(),
47
+ );
48
+
49
+ // Stubbed rather than let "Explore from here" reach the real ModelExplorer:
50
+ // that pulls in the lazy-loaded, WASM-backed `@malloydata/malloy-explorer`,
51
+ // which is not this file's business. Only what the dashboard hands it matters
52
+ // here, so the stub just records its props.
53
+ const exploreDialogProps = mock(
54
+ (_props: { open: boolean; startingGivens?: Record<string, string> }) => {},
55
+ );
56
+ mock.module("../Model/ModelExplorerDialog", () => ({
57
+ ModelExplorerDialog: (props: {
58
+ open: boolean;
59
+ startingGivens?: Record<string, string>;
60
+ }) => {
61
+ exploreDialogProps(props);
62
+ return null as ReactNode;
63
+ },
64
+ }));
39
65
 
40
66
  mockServerProvider({
41
67
  dashboards: { getDashboard },
42
- models: { executeQueryModel },
68
+ models: { executeQueryModel, getModel },
43
69
  });
44
70
 
45
71
  // Imported after the stub is registered: a static import would hoist above it.
@@ -70,6 +96,9 @@ beforeEach(() => {
70
96
  getDashboard.mockImplementation(() => pending());
71
97
  executeQueryModel.mockReset();
72
98
  executeQueryModel.mockImplementation(() => pending());
99
+ getModel.mockReset();
100
+ getModel.mockImplementation(() => pending());
101
+ exploreDialogProps.mockClear();
73
102
  });
74
103
 
75
104
  describe("the manifest fetch", () => {
@@ -210,4 +239,31 @@ describe("the version reaches what the manifest drives", () => {
210
239
  expect(v2).toHaveLength(1);
211
240
  expect(v2[0]).not.toContain("CA");
212
241
  });
242
+
243
+ it("opens 'Explore from here' with the dashboard's current values", async () => {
244
+ getDashboard.mockImplementation(() =>
245
+ Promise.resolve({
246
+ data: {
247
+ ...manifest,
248
+ query: undefined,
249
+ tiles: [{ query: "by_month" }],
250
+ },
251
+ }),
252
+ );
253
+ getModel.mockImplementation(() =>
254
+ Promise.resolve({ data: { sourceInfos: [] } }),
255
+ );
256
+
257
+ render(dashboardAt(), { wrapper: serverWrapper });
258
+
259
+ fireEvent.change(await screen.findByLabelText("REGION"), {
260
+ target: { value: "CA" },
261
+ });
262
+ fireEvent.click(await screen.findByRole("button", { name: /Explore/ }));
263
+
264
+ await waitFor(() => expect(exploreDialogProps).toHaveBeenCalled());
265
+ const lastCall = exploreDialogProps.mock.calls.at(-1)?.[0];
266
+ expect(lastCall?.open).toBe(true);
267
+ expect(lastCall?.startingGivens).toEqual({ REGION: "CA" });
268
+ });
213
269
  });
@@ -17,7 +17,7 @@ import {
17
17
  } from "../drill";
18
18
  import { GivensPanel } from "../given";
19
19
  import { Prose } from "../Prose";
20
- import { givensToRequest } from "../given/paramCodec";
20
+ import { givensToParams, givensToRequest } from "../given/paramCodec";
21
21
  import { Loading } from "../Loading";
22
22
  import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
23
23
  import { useServer } from "../ServerProvider";
@@ -189,6 +189,12 @@ export function Dashboard({
189
189
  [applied, declaredTypes],
190
190
  );
191
191
 
192
+ // The explorer's controls take the URL-string form, not the request form.
193
+ const exploreGivens = useMemo(
194
+ () => givensToParams(applied, declaredTypes),
195
+ [applied, declaredTypes],
196
+ );
197
+
192
198
  const { drill, drillMenu } = useDrill({
193
199
  onNavigate,
194
200
  onSelf,
@@ -350,6 +356,7 @@ export function Dashboard({
350
356
  packageName={packageName}
351
357
  {...(versionId === undefined ? {} : { versionId })}
352
358
  modelPath={modelPath}
359
+ givens={exploreGivens}
353
360
  onClose={() => setExploring(undefined)}
354
361
  />
355
362
  </>
@@ -23,6 +23,7 @@ export function ExploreDialog({
23
23
  packageName,
24
24
  versionId,
25
25
  modelPath,
26
+ givens,
26
27
  onClose,
27
28
  }: {
28
29
  /** The tile expression to open, or undefined when closed. */
@@ -31,6 +32,8 @@ export function ExploreDialog({
31
32
  packageName: string;
32
33
  versionId?: string;
33
34
  modelPath: string;
35
+ /** The dashboard's current control values, to seed the explorer's own. */
36
+ givens?: Record<string, string>;
34
37
  onClose: () => void;
35
38
  }) {
36
39
  const resourceUri = encodeResourceUri({
@@ -79,6 +82,8 @@ export function ExploreDialog({
79
82
  title={`Explore: ${tile}`}
80
83
  existingQuery={existingQuery}
81
84
  initialSelectedSourceIndex={sourceIndex}
85
+ // Reset returns to the dashboard's values, not the model's defaults.
86
+ startingGivens={givens}
82
87
  />
83
88
  );
84
89
  }
@@ -63,6 +63,9 @@ const getDashboard = mock(
63
63
  data: { path: "dashboards/overview.malloy", givens: [], tiles: [] },
64
64
  }),
65
65
  );
66
+ const listModels = mock((_env: string, _pkg: string, _versionId?: string) =>
67
+ Promise.resolve({ data: [{ path: "data_app.malloy" }] }),
68
+ );
66
69
  const listDashboards = mock((_env: string, _pkg: string, _versionId?: string) =>
67
70
  Promise.resolve({ data: [{ name: "overview" }] }),
68
71
  );
@@ -94,7 +97,7 @@ const executeQueryModel = mock(
94
97
  const serverContext = { mutable: false };
95
98
  mockServerProvider(
96
99
  {
97
- models: { getModel, executeQueryModel, updateModelSource },
100
+ models: { getModel, executeQueryModel, updateModelSource, listModels },
98
101
  dashboards: { getDashboard, listDashboards },
99
102
  },
100
103
  serverContext,
@@ -137,6 +140,7 @@ beforeEach(() => {
137
140
  getModel.mockClear();
138
141
  getDashboard.mockClear();
139
142
  listDashboards.mockClear();
143
+ listModels.mockClear();
140
144
  updateModelSource.mockClear();
141
145
  // Uncleared, a tile query from an earlier test carries into the next one's
142
146
  // assertions, where it looks like the component under test made it.
@@ -200,6 +204,7 @@ describe("versionId", () => {
200
204
  "v7",
201
205
  ]);
202
206
  expect(listDashboards.mock.calls[0]).toEqual(["env", "pkg", "v7"]);
207
+ expect(listModels.mock.calls[0]).toEqual(["env", "pkg", "v7"]);
203
208
 
204
209
  // The key too, appended last, never spliced in the middle of it: a
205
210
  // version in the wrong slot is a key that cannot tell two versions of
@@ -28,34 +28,39 @@ source: a is scoped_orders extend {
28
28
  }`;
29
29
 
30
30
  const getModel = mock((_env: string, _pkg: string, path: string) =>
31
- Promise.resolve({
32
- data:
33
- path === "dashboards/overview.malloy"
34
- ? { modelPath: path, sourceText: PACKAGE_FILE }
35
- : {
36
- modelPath: path,
37
- sources: [
38
- {
39
- name: "scoped_orders",
40
- views: [{ name: "by_category" }, { name: "by_brand" }],
41
- },
42
- ],
43
- sourceInfos: [
44
- JSON.stringify({
45
- name: "scoped_orders",
46
- schema: {
47
- fields: [
48
- {
49
- name: "cat",
50
- kind: "dimension",
51
- type: { kind: "string_type" },
52
- },
53
- ],
54
- },
55
- }),
56
- ],
57
- },
58
- }),
31
+ path === "broken.malloy"
32
+ ? Promise.reject(new Error("reloading"))
33
+ : Promise.resolve({
34
+ data:
35
+ path === "dashboards/overview.malloy"
36
+ ? { modelPath: path, sourceText: PACKAGE_FILE }
37
+ : {
38
+ modelPath: path,
39
+ sources: [
40
+ {
41
+ name: "scoped_orders",
42
+ views: [
43
+ { name: "by_category" },
44
+ { name: "by_brand" },
45
+ ],
46
+ },
47
+ ],
48
+ sourceInfos: [
49
+ JSON.stringify({
50
+ name: "scoped_orders",
51
+ schema: {
52
+ fields: [
53
+ {
54
+ name: "cat",
55
+ kind: "dimension",
56
+ type: { kind: "string_type" },
57
+ },
58
+ ],
59
+ },
60
+ }),
61
+ ],
62
+ },
63
+ }),
59
64
  );
60
65
  const getDashboard = mock(() =>
61
66
  Promise.resolve({
@@ -66,8 +71,13 @@ const listDashboards = mock(() =>
66
71
  Promise.resolve({ data: [{ name: "overview" }, { name: "regions" }] }),
67
72
  );
68
73
  const executeQueryModel = mock(() => pending());
74
+ // What the package publishes: the catalog is built from these, not from
75
+ // whatever file the dashboard imports.
76
+ const listModels = mock(() =>
77
+ Promise.resolve({ data: [{ path: "data_app.malloy" }] }),
78
+ );
69
79
  mockServerProvider({
70
- models: { getModel, executeQueryModel },
80
+ models: { getModel, executeQueryModel, listModels },
71
81
  dashboards: { getDashboard, listDashboards },
72
82
  });
73
83
 
@@ -113,7 +123,11 @@ describe("DashboardEditor", () => {
113
123
  mount();
114
124
  expect(await screen.findByText("Storefront")).toBeDefined();
115
125
  expect(screen.getByLabelText("Tile by_cat")).toBeDefined();
116
- // The catalog came from the model the file imports, by its resolved path.
126
+ // The catalog came from the published models, and the file's import of
127
+ // scoped_orders is what keeps it on offer.
128
+ await waitFor(() =>
129
+ expect(listModels.mock.calls.length).toBeGreaterThan(0),
130
+ );
117
131
  await waitFor(() =>
118
132
  expect(
119
133
  getModel.mock.calls.some((call) => call[2] === "data_app.malloy"),
@@ -122,6 +136,22 @@ describe("DashboardEditor", () => {
122
136
  await screen.findByRole("button", { name: "Add tile", hidden: true });
123
137
  });
124
138
 
139
+ it("keeps the catalog when one published model fails to load", async () => {
140
+ listModels.mockImplementationOnce(() =>
141
+ Promise.resolve({
142
+ data: [{ path: "data_app.malloy" }, { path: "broken.malloy" }],
143
+ }),
144
+ );
145
+ mount();
146
+ await waitFor(() =>
147
+ expect(
148
+ getModel.mock.calls.some((call) => call[2] === "broken.malloy"),
149
+ ).toBe(true),
150
+ );
151
+ // Adding a tile needs a catalog, so the button is the proof it built.
152
+ await screen.findByRole("button", { name: "Add tile", hidden: true });
153
+ });
154
+
125
155
  it("saves an edit into the browser and marks it saved", async () => {
126
156
  const storage = mount();
127
157
  await screen.findByText("Storefront");
@@ -27,7 +27,11 @@ import { DashboardBar } from "../Dashboard/DashboardBar";
27
27
  import { Loading } from "../Loading";
28
28
  import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
29
29
  import { useServer } from "../ServerProvider";
30
- import { buildCatalog, type PackageCatalog } from "./catalog";
30
+ import {
31
+ buildCatalog,
32
+ visibleToDashboard,
33
+ type PackageCatalog,
34
+ } from "./catalog";
31
35
  import { DashboardBuilder } from "./DashboardBuilder";
32
36
  import type { DashboardDocument } from "./document";
33
37
  import { previewGivens, previewTileQuery } from "./preview";
@@ -785,36 +789,51 @@ function Surface({
785
789
  [dashboardList, slug],
786
790
  );
787
791
 
788
- // The catalog: the models this file imports, which is where its tiles'
789
- // sources and their fields are declared.
790
- const importPaths = useMemo(() => {
792
+ // The catalog: what the package publishes, limited to what this file can
793
+ // see. A tile runs against this file and may read only the package surface,
794
+ // so offering a source from any other file would offer a tile that 404s.
795
+ // Files off the surface are not readable anyway (their model GET is 404).
796
+ const imports = useMemo(() => {
791
797
  const dir = modelPath.slice(0, modelPath.lastIndexOf("/") + 1);
792
- const resolved = new Set<string>();
793
- for (const imported of opened.document.imports) {
794
- const url = new URL(imported.from, `https://malloy.invalid/${dir}`);
795
- resolved.add(url.pathname.slice(1));
796
- }
797
- return [...resolved];
798
+ return opened.document.imports.map((imported) => ({
799
+ ...imported,
800
+ path: new URL(
801
+ imported.from,
802
+ `https://malloy.invalid/${dir}`,
803
+ ).pathname.slice(1),
804
+ }));
798
805
  }, [opened.document.imports, modelPath]);
799
806
  const { data: catalog } = useQueryWithApiError<PackageCatalog>({
800
807
  queryKey: [
801
808
  "dashboard-editor-catalog",
802
809
  environmentName,
803
810
  packageName,
804
- ...importPaths,
811
+ ...imports.map((i) => i.path),
805
812
  versionId,
806
813
  ],
807
814
  queryFn: async () => {
808
- const models = await Promise.all(
809
- importPaths.map((path) =>
815
+ const listed = (
816
+ await apiClients.models.listModels(
817
+ environmentName,
818
+ packageName,
819
+ versionId,
820
+ )
821
+ ).data.filter((m) => m.path && !m.error);
822
+ // One model that fails to load (a reload racing this fetch, say)
823
+ // costs the catalog that model's sources, not every suggestion.
824
+ const settled = await Promise.allSettled(
825
+ listed.map((m) =>
810
826
  apiClients.models
811
- .getModel(environmentName, packageName, path, versionId)
827
+ .getModel(environmentName, packageName, m.path!, versionId)
812
828
  .then((response) => response.data),
813
829
  ),
814
830
  );
815
- return buildCatalog(models);
831
+ const models = settled.flatMap((result) =>
832
+ result.status === "fulfilled" ? [result.value] : [],
833
+ );
834
+ return visibleToDashboard(buildCatalog(models), imports, models);
816
835
  },
817
- enabled: importPaths.length > 0,
836
+ enabled: imports.length > 0,
818
837
  });
819
838
 
820
839
  const [doc, setDoc] = useState(opened.document);
@@ -9,6 +9,7 @@ import {
9
9
  docOf,
10
10
  filterableFields,
11
11
  isDashboardModel,
12
+ visibleToDashboard,
12
13
  } from "./catalog";
13
14
 
14
15
  /**
@@ -137,6 +138,49 @@ describe("buildCatalog", () => {
137
138
  });
138
139
  });
139
140
 
141
+ describe("visibleToDashboard", () => {
142
+ const published: CompiledModel[] = [
143
+ {
144
+ path: "index.malloy",
145
+ sources: [{ name: "orders" }, { name: "users" }],
146
+ },
147
+ ];
148
+ const catalog = buildCatalog(published);
149
+ const names = (c: ReturnType<typeof buildCatalog>) =>
150
+ c.sources.map((s) => s.name).sort();
151
+
152
+ it("offers only the names a named import brings", () => {
153
+ const seen = visibleToDashboard(
154
+ catalog,
155
+ [{ kind: "names", names: ["orders"], path: "orders.malloy" }],
156
+ published,
157
+ );
158
+ expect(names(seen)).toEqual(["orders"]);
159
+ });
160
+
161
+ it("offers a published model's sources to a whole-file import of it", () => {
162
+ const seen = visibleToDashboard(
163
+ catalog,
164
+ [{ kind: "all", path: "index.malloy" }],
165
+ published,
166
+ );
167
+ expect(names(seen)).toEqual(["orders", "users"]);
168
+ });
169
+
170
+ it("offers everything published when a whole-file import cannot be read", () => {
171
+ // The imported file is off the surface, so what it declares is unknown.
172
+ const seen = visibleToDashboard(
173
+ catalog,
174
+ [
175
+ { kind: "names", names: ["orders"], path: "orders.malloy" },
176
+ { kind: "all", path: "hidden.malloy" },
177
+ ],
178
+ published,
179
+ );
180
+ expect(names(seen)).toEqual(["orders", "users"]);
181
+ });
182
+ });
183
+
140
184
  describe("filterableFields", () => {
141
185
  // Captured from the storefront package's `order_items`: a join's fields are
142
186
  // what people filter on, and a view is not a field at all.
@@ -223,3 +223,39 @@ export function buildCatalog(models: CompiledModel[]): PackageCatalog {
223
223
 
224
224
  return { sources };
225
225
  }
226
+
227
+ /**
228
+ * The part of the package catalog a dashboard file can actually use.
229
+ *
230
+ * The builder never writes an import, so a source the file cannot see would
231
+ * produce a tile that does not compile. A named import says exactly which
232
+ * names it brings. A whole-file import of a published model brings that
233
+ * model's sources. A whole-file import of a file off the surface cannot be
234
+ * read, so then every published source is offered and a wrong pick is caught
235
+ * by the compile check the editor already runs.
236
+ */
237
+ export function visibleToDashboard(
238
+ catalog: PackageCatalog,
239
+ imports: ReadonlyArray<
240
+ | { kind: "all"; path: string }
241
+ | { kind: "names"; names: string[]; path: string }
242
+ >,
243
+ published: CompiledModel[],
244
+ ): PackageCatalog {
245
+ const visible = new Set<string>();
246
+ for (const imported of imports) {
247
+ if (imported.kind === "names") {
248
+ for (const name of imported.names) visible.add(name);
249
+ continue;
250
+ }
251
+ const model = published.find((m) => pathOf(m) === imported.path);
252
+ if (!model) return catalog;
253
+ for (const source of model.sources ?? []) {
254
+ if (source.name) visible.add(source.name);
255
+ }
256
+ }
257
+ return {
258
+ ...catalog,
259
+ sources: catalog.sources.filter((source) => visible.has(source.name)),
260
+ };
261
+ }
@@ -16,11 +16,22 @@ import { ModelExplorerDialog } from "./ModelExplorerDialog";
16
16
  import { QueryExplorerResult } from "./SourcesExplorer";
17
17
  import { useModelData } from "./useModelData";
18
18
 
19
- interface ModelProps {
19
+ export interface ModelProps {
20
20
  onChange?: (query: QueryExplorerResult) => void;
21
21
  resourceUri: string;
22
22
  runOnDemand?: boolean;
23
23
  maxResultSize?: number;
24
+ /**
25
+ * Control values from the host, typically its URL query parameters. When
26
+ * omitted, `Model` holds them itself, so the embedded explorer and the
27
+ * maximized dialog still agree with each other.
28
+ */
29
+ givens?: Record<string, string>;
30
+ /** Applied control values, for a host that wants them in its URL. */
31
+ onGivensChange?: (
32
+ givens: Record<string, string>,
33
+ managed: readonly string[],
34
+ ) => void;
24
35
  }
25
36
 
26
37
  // Note: For this to properly render outside of publisher,
@@ -32,6 +43,8 @@ export default function Model({
32
43
  resourceUri,
33
44
  runOnDemand = false,
34
45
  maxResultSize = 0,
46
+ givens,
47
+ onGivensChange,
35
48
  }: ModelProps) {
36
49
  const { modelPath } = parseResourceUri(resourceUri);
37
50
  const { data, isError, isLoading, error } = useModelData(resourceUri);
@@ -41,6 +54,16 @@ export default function Model({
41
54
  >();
42
55
  const [sharedSourceIndex, setSharedSourceIndex] = React.useState(0);
43
56
  const [copyMessage, setCopyMessage] = useState("");
57
+ // Held here only when the host passes neither prop, so the embedded
58
+ // explorer and the maximized dialog still agree on one set of values
59
+ // rather than each defaulting independently.
60
+ const [localGivens, setLocalGivens] = React.useState<Record<string, string>>(
61
+ {},
62
+ );
63
+ const effectiveGivens = givens ?? localGivens;
64
+ const effectiveOnGivensChange =
65
+ onGivensChange ??
66
+ ((applied: Record<string, string>) => setLocalGivens(applied));
44
67
 
45
68
  // Whether the model imports other files — drives the empty-state hint for
46
69
  // import-only models, whose discovery surface is legitimately empty (no
@@ -142,6 +165,8 @@ export default function Model({
142
165
  existingQuery={sharedQuery}
143
166
  initialSelectedSourceIndex={sharedSourceIndex}
144
167
  resourceUri={resourceUri}
168
+ givens={effectiveGivens}
169
+ onGivensChange={effectiveOnGivensChange}
145
170
  />
146
171
 
147
172
  {/* Magnifying glass icon */}
@@ -232,6 +257,8 @@ export default function Model({
232
257
  initialSelectedSourceIndex={sharedSourceIndex}
233
258
  onChange={handleQueryChange}
234
259
  onSourceChange={handleSourceChange}
260
+ givens={effectiveGivens}
261
+ onGivensChange={effectiveOnGivensChange}
235
262
  />
236
263
  </Box>
237
264
  <Snackbar