@malloy-publisher/sdk 0.12.0 → 0.12.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 (214) hide show
  1. package/README.md +79 -6
  2. package/dist/{RenderedResult-SgDlxzs9.cjs.js → RenderedResult-Cgw4iqev.cjs.js} +1 -1
  3. package/dist/{RenderedResult-D8bCgThO.es.js → RenderedResult-DEjFM1DL.es.js} +2 -2
  4. package/dist/ServerProvider-BRQl_cBo.cjs.js +1 -0
  5. package/dist/{ServerProvider-DBw-thY0.es.js → ServerProvider-RnliA2Ao.es.js} +1084 -723
  6. package/dist/builder/index.cjs.js +1 -1
  7. package/dist/builder/index.es.js +3 -3
  8. package/dist/client/api.d.ts +754 -41
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +120 -110
  11. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +16 -1
  12. package/dist/components/Model/ExplorerPage.d.ts +9 -0
  13. package/dist/components/Model/Model.d.ts +27 -11
  14. package/dist/components/ModelViewer/AccessChips.d.ts +34 -0
  15. package/dist/components/ModelViewer/EmptyRow.d.ts +23 -0
  16. package/dist/components/ModelViewer/Facts.d.ts +15 -0
  17. package/dist/components/ModelViewer/FieldGroup.d.ts +31 -0
  18. package/dist/components/ModelViewer/FieldRow.d.ts +69 -0
  19. package/dist/components/ModelViewer/GivenFacts.d.ts +21 -0
  20. package/dist/components/ModelViewer/HeaderBar.d.ts +75 -0
  21. package/dist/components/ModelViewer/InlineDoc.d.ts +13 -0
  22. package/dist/components/ModelViewer/ModelGivensSection.d.ts +32 -0
  23. package/dist/components/ModelViewer/ModelSection.d.ts +21 -0
  24. package/dist/components/ModelViewer/ModelViewer.d.ts +91 -0
  25. package/dist/components/ModelViewer/QueriesGroup.d.ts +15 -0
  26. package/dist/components/ModelViewer/RowGlyph.d.ts +27 -0
  27. package/dist/components/ModelViewer/RunResult.d.ts +46 -0
  28. package/dist/components/ModelViewer/SampleValues.d.ts +20 -0
  29. package/dist/components/ModelViewer/SchemaJoin.d.ts +51 -0
  30. package/dist/components/ModelViewer/SchemaView.d.ts +52 -0
  31. package/dist/components/ModelViewer/SegmentIcons.d.ts +70 -0
  32. package/dist/components/ModelViewer/SourcesDropdown.d.ts +53 -0
  33. package/dist/components/ModelViewer/SourcesNav.d.ts +25 -0
  34. package/dist/components/ModelViewer/StatusPill.d.ts +56 -0
  35. package/dist/components/ModelViewer/ValueChip.d.ts +17 -0
  36. package/dist/components/ModelViewer/ViewRow.d.ts +36 -0
  37. package/dist/components/ModelViewer/clickableBox.d.ts +29 -0
  38. package/dist/components/ModelViewer/codeDisplay.d.ts +44 -0
  39. package/dist/components/ModelViewer/docAnnotations.d.ts +90 -0
  40. package/dist/components/ModelViewer/explorerModel.d.ts +12 -0
  41. package/dist/components/ModelViewer/extensions.d.ts +94 -0
  42. package/dist/components/ModelViewer/fieldCode.d.ts +74 -0
  43. package/dist/components/ModelViewer/fieldEntities.d.ts +45 -0
  44. package/dist/components/ModelViewer/fieldExpansion.d.ts +41 -0
  45. package/dist/components/ModelViewer/givenUsage.d.ts +71 -0
  46. package/dist/components/ModelViewer/headerCard.d.ts +31 -0
  47. package/dist/components/ModelViewer/httpStatus.d.ts +4 -0
  48. package/dist/components/ModelViewer/icons.d.ts +31 -0
  49. package/dist/components/ModelViewer/index.d.ts +9 -0
  50. package/dist/components/ModelViewer/joinAccess.d.ts +52 -0
  51. package/dist/components/ModelViewer/malloyRunText.d.ts +22 -0
  52. package/dist/components/ModelViewer/malloyText.d.ts +21 -0
  53. package/dist/components/ModelViewer/modelGivens.d.ts +61 -0
  54. package/dist/components/ModelViewer/modelGivensContext.d.ts +9 -0
  55. package/dist/components/ModelViewer/modelHeaderPresentation.d.ts +28 -0
  56. package/dist/components/ModelViewer/modelTextDeclarations.d.ts +32 -0
  57. package/dist/components/ModelViewer/modelTextParse.d.ts +27 -0
  58. package/dist/components/ModelViewer/namedQueryCode.d.ts +12 -0
  59. package/dist/components/ModelViewer/offSurface.d.ts +54 -0
  60. package/dist/components/ModelViewer/rowLayers.d.ts +30 -0
  61. package/dist/components/ModelViewer/runGate.d.ts +49 -0
  62. package/dist/components/ModelViewer/schemaModel.d.ts +109 -0
  63. package/dist/components/ModelViewer/sectionOpenCommand.d.ts +45 -0
  64. package/dist/components/ModelViewer/sourceAccess.d.ts +67 -0
  65. package/dist/components/ModelViewer/sourceLineage.d.ts +14 -0
  66. package/dist/components/ModelViewer/sourcePicker.d.ts +66 -0
  67. package/dist/components/ModelViewer/surface.d.ts +47 -0
  68. package/dist/components/ModelViewer/text.d.ts +6 -0
  69. package/dist/components/ModelViewer/theme.d.ts +63 -0
  70. package/dist/components/ModelViewer/tokens.d.ts +52 -0
  71. package/dist/components/ModelViewer/ui.d.ts +48 -0
  72. package/dist/components/ModelViewer/useDimensionSamples.d.ts +76 -0
  73. package/dist/components/ModelViewer/useModelSources.d.ts +92 -0
  74. package/dist/components/ModelViewer/useRunQuery.d.ts +115 -0
  75. package/dist/components/ReportBuilder/loadMalloy.d.ts +4 -0
  76. package/dist/components/ServerProvider.d.ts +17 -2
  77. package/dist/components/filter/utils.d.ts +1 -1
  78. package/dist/components/given/GivenInput.d.ts +7 -1
  79. package/dist/components/given/GivensPanel.d.ts +3 -1
  80. package/dist/components/given/filterSummary.d.ts +6 -0
  81. package/dist/components/given/useGivenUrlParams.d.ts +11 -0
  82. package/dist/components/index.d.ts +2 -1
  83. package/dist/components/modelPage.d.ts +36 -0
  84. package/dist/hooks/useDimensionalFilterRangeData.d.ts +9 -0
  85. package/dist/hooks/useSuggestOptions.d.ts +26 -2
  86. package/dist/index.cjs.js +47 -19
  87. package/dist/index.es.js +14137 -9697
  88. package/dist/useCompiledDocument-D88_2cGS.cjs.js +143 -0
  89. package/dist/{useCompiledDocument-CXMPtJkJ.es.js → useCompiledDocument-Dmm6xkom.es.js} +6975 -6893
  90. package/dist/utils/filterCondition.d.ts +14 -0
  91. package/dist/utils/malloyLiteral.d.ts +20 -1
  92. package/package.json +2 -2
  93. package/src/components/Materializations/MaterializationDetailDialog.tsx +33 -7
  94. package/src/components/Materializations/Materializations.tsx +47 -4
  95. package/src/components/Materializations/Materializations.versions.spec.tsx +140 -1
  96. package/src/components/Model/ExplorerPage.tsx +269 -0
  97. package/src/components/Model/Model.tsx +66 -250
  98. package/src/components/Model/ModelExplorer.spec.tsx +64 -1
  99. package/src/components/ModelViewer/AccessChips.tsx +149 -0
  100. package/src/components/ModelViewer/EmptyRow.tsx +71 -0
  101. package/src/components/ModelViewer/Facts.tsx +46 -0
  102. package/src/components/ModelViewer/FieldGroup.tsx +137 -0
  103. package/src/components/ModelViewer/FieldRow.tsx +566 -0
  104. package/src/components/ModelViewer/GivenFacts.tsx +89 -0
  105. package/src/components/ModelViewer/HeaderBar.tsx +362 -0
  106. package/src/components/ModelViewer/InlineDoc.tsx +50 -0
  107. package/src/components/ModelViewer/ModelGivensSection.tsx +142 -0
  108. package/src/components/ModelViewer/ModelSection.tsx +98 -0
  109. package/src/components/ModelViewer/ModelViewer.spec.tsx +937 -0
  110. package/src/components/ModelViewer/ModelViewer.tsx +777 -0
  111. package/src/components/ModelViewer/QueriesGroup.tsx +107 -0
  112. package/src/components/ModelViewer/RowGlyph.tsx +138 -0
  113. package/src/components/ModelViewer/RunResult.tsx +298 -0
  114. package/src/components/ModelViewer/SampleValues.tsx +97 -0
  115. package/src/components/ModelViewer/SchemaJoin.tsx +258 -0
  116. package/src/components/ModelViewer/SchemaView.tsx +222 -0
  117. package/src/components/ModelViewer/SegmentIcons.tsx +129 -0
  118. package/src/components/ModelViewer/SourcesDropdown.tsx +265 -0
  119. package/src/components/ModelViewer/SourcesNav.tsx +75 -0
  120. package/src/components/ModelViewer/StatusPill.tsx +145 -0
  121. package/src/components/ModelViewer/ValueChip.tsx +39 -0
  122. package/src/components/ModelViewer/ViewRow.tsx +274 -0
  123. package/src/components/ModelViewer/clickableBox.ts +59 -0
  124. package/src/components/ModelViewer/codeDisplay.spec.ts +176 -0
  125. package/src/components/ModelViewer/codeDisplay.ts +118 -0
  126. package/src/components/ModelViewer/docAnnotations.spec.ts +181 -0
  127. package/src/components/ModelViewer/docAnnotations.ts +244 -0
  128. package/src/components/ModelViewer/docAnnotations.typeDetail.spec.ts +114 -0
  129. package/src/components/ModelViewer/explorerModel.spec.ts +43 -0
  130. package/src/components/ModelViewer/explorerModel.ts +31 -0
  131. package/src/components/ModelViewer/extensions.tsx +112 -0
  132. package/src/components/ModelViewer/fieldCode.spec.ts +168 -0
  133. package/src/components/ModelViewer/fieldCode.ts +118 -0
  134. package/src/components/ModelViewer/fieldEntities.ts +63 -0
  135. package/src/components/ModelViewer/fieldExpansion.spec.ts +116 -0
  136. package/src/components/ModelViewer/fieldExpansion.ts +95 -0
  137. package/src/components/ModelViewer/givenUsage.spec.ts +304 -0
  138. package/src/components/ModelViewer/givenUsage.ts +325 -0
  139. package/src/components/ModelViewer/headerCard.tsx +102 -0
  140. package/src/components/ModelViewer/httpStatus.ts +15 -0
  141. package/src/components/ModelViewer/icons.tsx +67 -0
  142. package/src/components/ModelViewer/index.ts +26 -0
  143. package/src/components/ModelViewer/joinAccess.spec.ts +95 -0
  144. package/src/components/ModelViewer/joinAccess.ts +54 -0
  145. package/src/components/ModelViewer/malloyRunText.spec.ts +48 -0
  146. package/src/components/ModelViewer/malloyRunText.ts +51 -0
  147. package/src/components/ModelViewer/malloyText.spec.ts +47 -0
  148. package/src/components/ModelViewer/malloyText.ts +77 -0
  149. package/src/components/ModelViewer/modelGivens.ts +228 -0
  150. package/src/components/ModelViewer/modelGivensContext.ts +13 -0
  151. package/src/components/ModelViewer/modelHeaderPresentation.spec.ts +31 -0
  152. package/src/components/ModelViewer/modelHeaderPresentation.ts +41 -0
  153. package/src/components/ModelViewer/modelTextDeclarations.spec.ts +336 -0
  154. package/src/components/ModelViewer/modelTextDeclarations.ts +228 -0
  155. package/src/components/ModelViewer/modelTextParse.ts +112 -0
  156. package/src/components/ModelViewer/namedQueryCode.spec.ts +58 -0
  157. package/src/components/ModelViewer/namedQueryCode.ts +26 -0
  158. package/src/components/ModelViewer/offSurface.tsx +124 -0
  159. package/src/components/ModelViewer/rowLayers.tsx +104 -0
  160. package/src/components/ModelViewer/runGate.spec.ts +219 -0
  161. package/src/components/ModelViewer/runGate.ts +145 -0
  162. package/src/components/ModelViewer/schemaModel.defaultSource.spec.ts +126 -0
  163. package/src/components/ModelViewer/schemaModel.queries.spec.ts +37 -0
  164. package/src/components/ModelViewer/schemaModel.ts +300 -0
  165. package/src/components/ModelViewer/sectionOpenCommand.tsx +125 -0
  166. package/src/components/ModelViewer/sourceAccess.spec.ts +130 -0
  167. package/src/components/ModelViewer/sourceAccess.ts +194 -0
  168. package/src/components/ModelViewer/sourceLineage.spec.ts +73 -0
  169. package/src/components/ModelViewer/sourceLineage.ts +38 -0
  170. package/src/components/ModelViewer/sourcePicker.spec.ts +294 -0
  171. package/src/components/ModelViewer/sourcePicker.ts +162 -0
  172. package/src/components/ModelViewer/surface.ts +51 -0
  173. package/src/components/ModelViewer/text.tsx +33 -0
  174. package/src/components/ModelViewer/theme.spec.ts +38 -0
  175. package/src/components/ModelViewer/theme.ts +58 -0
  176. package/src/components/ModelViewer/tokens.ts +87 -0
  177. package/src/components/ModelViewer/ui.tsx +201 -0
  178. package/src/components/ModelViewer/useDimensionSamples.spec.tsx +139 -0
  179. package/src/components/ModelViewer/useDimensionSamples.ts +220 -0
  180. package/src/components/ModelViewer/useModelSources.spec.ts +110 -0
  181. package/src/components/ModelViewer/useModelSources.ts +238 -0
  182. package/src/components/ModelViewer/useRunQuery.spec.ts +50 -0
  183. package/src/components/ModelViewer/useRunQuery.ts +223 -0
  184. package/src/components/Package/Package.agents.spec.tsx +5 -4
  185. package/src/components/Package/Package.tsx +8 -1
  186. package/src/components/ReportBuilder/emptyStart.spec.ts +8 -0
  187. package/src/components/ReportBuilder/loadMalloy.ts +8 -1
  188. package/src/components/ServerProvider.tsx +29 -3
  189. package/src/components/filter/utils.ts +4 -60
  190. package/src/components/given/FilterButton.tsx +4 -1
  191. package/src/components/given/GivenInput.tsx +8 -0
  192. package/src/components/given/GivensPanel.tsx +6 -1
  193. package/src/components/given/filterSummary.spec.ts +31 -1
  194. package/src/components/given/filterSummary.ts +41 -19
  195. package/src/components/given/useGivenUrlParams.spec.tsx +32 -0
  196. package/src/components/given/useGivenUrlParams.ts +49 -14
  197. package/src/components/index.ts +6 -1
  198. package/src/components/legacy/malloynb/Notebook.spec.tsx +38 -4
  199. package/src/components/legacy/malloynb/NotebookCell.tsx +8 -2
  200. package/src/components/modelPage.spec.ts +79 -0
  201. package/src/components/modelPage.ts +48 -0
  202. package/src/hooks/useDimensionFilters.ts +3 -58
  203. package/src/hooks/useDimensionFiltersQuery.ts +3 -58
  204. package/src/hooks/useDimensionalFilterRangeData.spec.ts +57 -0
  205. package/src/hooks/useDimensionalFilterRangeData.ts +8 -63
  206. package/src/hooks/useSuggestOptions.dom.spec.ts +54 -1
  207. package/src/hooks/useSuggestOptions.spec.ts +71 -0
  208. package/src/hooks/useSuggestOptions.ts +102 -12
  209. package/src/utils/filterCondition.spec.ts +87 -0
  210. package/src/utils/filterCondition.ts +66 -0
  211. package/src/utils/malloyLiteral.spec.ts +53 -1
  212. package/src/utils/malloyLiteral.ts +47 -12
  213. package/dist/ServerProvider-BHfg1Ed6.cjs.js +0 -1
  214. package/dist/useCompiledDocument-D7X_K6YU.cjs.js +0 -142
@@ -1,13 +1,13 @@
1
1
  // Copyright (c) Credible Data Inc.
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
- import * as Malloy from "@malloydata/malloy-interfaces";
4
+ import type * as Malloy from "@malloydata/malloy-interfaces";
5
5
  import {
6
6
  DimensionSpec,
7
7
  FilterType,
8
8
  } from "../../hooks/useDimensionalFilterRangeData";
9
9
  import { FilterSelection } from "../../hooks/useDimensionFilters";
10
- import { escapeMalloyString } from "../../utils/malloyString";
10
+ import { filterCondition } from "../../utils/filterCondition";
11
11
 
12
12
  /**
13
13
  * A single filter specification with source and dimension
@@ -281,13 +281,7 @@ export function generateFilterClause(
281
281
 
282
282
  const conditions = activeFilters
283
283
  .map((selection) => {
284
- const {
285
- dimensionName,
286
- source: filterSourceName,
287
- matchType,
288
- value,
289
- value2,
290
- } = selection;
284
+ const { dimensionName, source: filterSourceName } = selection;
291
285
  // Only use source.dimension format if the filter's source is different from the query's source
292
286
  // (i.e., it's a joined source, not the main source)
293
287
  const needsSourcePrefix =
@@ -295,57 +289,7 @@ export function generateFilterClause(
295
289
  const fieldName = needsSourcePrefix
296
290
  ? `\`${filterSourceName}\`.\`${dimensionName}\``
297
291
  : `\`${dimensionName}\``;
298
- const isDate = value instanceof Date;
299
-
300
- const formatValue = (
301
- v: unknown,
302
- isDateVal: boolean = false,
303
- ): string => {
304
- if (v === null || v === undefined) return "null";
305
- if (isDateVal && v instanceof Date) {
306
- return `@${v.getFullYear()}-${String(v.getMonth() + 1).padStart(2, "0")}-${String(v.getDate()).padStart(2, "0")}`;
307
- }
308
- if (typeof v === "string") {
309
- return `'${escapeMalloyString(v)}'`;
310
- }
311
- if (typeof v === "boolean") return v ? "true" : "false";
312
- return String(v);
313
- };
314
-
315
- switch (matchType) {
316
- case "Equals":
317
- case "Semantic Search":
318
- if (Array.isArray(value) && value.length > 0) {
319
- const conditions = value.map(
320
- (v) => `${fieldName} = ${formatValue(v, isDate)}`,
321
- );
322
- return `(${conditions.join(" or ")})`;
323
- }
324
- return `${fieldName} = ${formatValue(value, isDate)}`;
325
-
326
- case "Contains":
327
- if (typeof value === "string") {
328
- return `${fieldName} ~ f'%${escapeMalloyString(value)}%'`;
329
- }
330
- return `${fieldName} = ${formatValue(value)}`;
331
-
332
- case "After":
333
- case "Greater Than":
334
- return `${fieldName} > ${formatValue(value, isDate)}`;
335
-
336
- case "Before":
337
- case "Less Than":
338
- return `${fieldName} < ${formatValue(value, isDate)}`;
339
-
340
- case "Between":
341
- if (value2 !== undefined) {
342
- return `${fieldName} >= ${formatValue(value, isDate)} and ${fieldName} <= ${formatValue(value2, isDate)}`;
343
- }
344
- return `${fieldName} >= ${formatValue(value, isDate)}`;
345
-
346
- default:
347
- return "";
348
- }
292
+ return filterCondition(fieldName, selection);
349
293
  })
350
294
  .filter((c) => c.length > 0);
351
295
 
@@ -74,7 +74,10 @@ export function FilterButton(props: GivenInputProps) {
74
74
  aria-haspopup="dialog"
75
75
  aria-expanded={open}
76
76
  aria-label={`${label}: ${summary}`}
77
- onClick={(event) => setAnchor(event.currentTarget)}
77
+ onClick={(event) => {
78
+ setAnchor(event.currentTarget);
79
+ props.onOpen?.();
80
+ }}
78
81
  sx={(mui) => ({
79
82
  height: "100%",
80
83
  borderRadius: ui.radius.control,
@@ -114,6 +114,12 @@ export interface GivenInputProps {
114
114
  * that was cut off. Absent, typing filters `options` in the browser.
115
115
  */
116
116
  optionSearch?: OptionSearch;
117
+ /**
118
+ * The control is opening, for a caller that fetches `options` only when
119
+ * one is wanted (see `useSuggestOptions`' `only`). Called by a picker's
120
+ * list and by a filter button's popover; harmless to call again.
121
+ */
122
+ onOpen?: () => void;
117
123
  }
118
124
 
119
125
  /**
@@ -176,6 +182,7 @@ export function GivenInput({
176
182
  optionsFailed,
177
183
  optionsTruncated,
178
184
  optionSearch,
185
+ onOpen,
179
186
  }: GivenInputProps) {
180
187
  const label = given.label ?? given.name ?? "";
181
188
  const { theme: publisherTheme } = usePublisherTheme();
@@ -355,6 +362,7 @@ export function GivenInput({
355
362
  // MUI closes on select by default, which makes "and also Aurora"
356
363
  // cost a second click to reopen.
357
364
  disableCloseOnSelect={multiple}
365
+ onOpen={onOpen}
358
366
  // Free text keeps the control from being a cage: the suggest query
359
367
  // returns the common values, not necessarily every legal one.
360
368
  freeSolo
@@ -58,6 +58,8 @@ export interface GivensPanelProps {
58
58
  };
59
59
  /** Overrides the `panel` layout's "Filters" heading. */
60
60
  title?: string;
61
+ /** A control is opening: for options fetched only once one is wanted. */
62
+ onControlOpen?: (name: string) => void;
61
63
  }
62
64
 
63
65
  /**
@@ -84,6 +86,7 @@ export function GivensPanel({
84
86
  optionSearch,
85
87
  apply,
86
88
  title,
89
+ onControlOpen,
87
90
  }: GivensPanelProps) {
88
91
  // In the builder the bar is also where filters are added, so it draws with
89
92
  // none: an empty row is the "+ Filter" button alone.
@@ -99,13 +102,15 @@ export function GivensPanel({
99
102
  // nothing when pressed.
100
103
  const offerReset = canReset ?? hasValues;
101
104
 
102
- // A cut-off list, and the search that finds past it, for one control.
105
+ // A cut-off list, and the search that finds past it, for one control;
106
+ // and its opening, for options fetched only when wanted.
103
107
  const searchProps = (name: string | undefined) => {
104
108
  if (name === undefined) return {};
105
109
  const search = optionSearch?.get(name);
106
110
  return {
107
111
  ...(optionsTruncated?.has(name) ? { optionsTruncated: true } : {}),
108
112
  ...(search ? { optionSearch: search } : {}),
113
+ ...(onControlOpen ? { onOpen: () => onControlOpen(name) } : {}),
109
114
  };
110
115
  };
111
116
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
5
  import type { Given } from "../../client";
6
- import { summarizeGivenValue } from "./filterSummary";
6
+ import { describeGivenValue, summarizeGivenValue } from "./filterSummary";
7
7
  import {
8
8
  encodeAtLeast,
9
9
  encodeBetween,
@@ -106,3 +106,33 @@ describe("summarizeGivenValue", () => {
106
106
  expect(shown.endsWith("…")).toBe(true);
107
107
  });
108
108
  });
109
+
110
+ describe("describeGivenValue", () => {
111
+ // A run's note is the record of what produced the result, with no popover
112
+ // to hold the rest: the same words, never cut short.
113
+ it("words a value as the button does, but whole", () => {
114
+ const list = encodeFilterList([
115
+ "Outerwear",
116
+ "Footwear",
117
+ "Dresses",
118
+ "Swimwear",
119
+ ]);
120
+ expect(describeGivenValue(given({ type: "filter<string>" }), list)).toBe(
121
+ "Outerwear, Footwear, Dresses, Swimwear",
122
+ );
123
+ const text = "a".repeat(60);
124
+ expect(describeGivenValue(given({ type: "string" }), text)).toBe(text);
125
+ expect(
126
+ describeGivenValue(
127
+ given({ type: "filter<string>", control: "select" }),
128
+ undefined,
129
+ ),
130
+ ).toBe("All");
131
+ expect(
132
+ describeGivenValue(
133
+ given({ type: "date", default: "@2023-01-01" }),
134
+ undefined,
135
+ ),
136
+ ).toBe("Jan 1, 2023");
137
+ });
138
+ });
@@ -36,28 +36,30 @@ function formatDay(text: string): string {
36
36
  return Number.isNaN(date.getTime()) ? text : dayFormat.format(date);
37
37
  }
38
38
 
39
- /** A list of picked values, shortened to fit a button: `Outerwear +2`. */
40
- function summarizeList(values: string[]): string {
39
+ /** A list of picked values, shortened to fit a button: `Outerwear +2`. In full, every one. */
40
+ function summarizeList(values: string[], full: boolean): string {
41
41
  if (values.length === 0) return "";
42
42
  const joined = values.join(", ");
43
+ if (full) return joined;
43
44
  if (joined.length <= MAX_SUMMARY_CHARS || values.length === 1)
44
- return truncate(joined);
45
- return `${truncate(values[0] ?? "")} +${values.length - 1}`;
45
+ return truncate(joined, full);
46
+ return `${truncate(values[0] ?? "", full)} +${values.length - 1}`;
46
47
  }
47
48
 
48
- function truncate(text: string): string {
49
- return text.length > MAX_SUMMARY_CHARS
49
+ function truncate(text: string, full: boolean): string {
50
+ return !full && text.length > MAX_SUMMARY_CHARS
50
51
  ? `${text.slice(0, MAX_SUMMARY_CHARS - 1)}…`
51
52
  : text;
52
53
  }
53
54
 
54
55
  /** What a given with no value of its own shows: its default, or that it does not narrow. */
55
- function unsetSummary(given: Given): string {
56
+ function unsetSummary(given: Given, full: boolean): string {
56
57
  // No default: nothing runs until it is set, so it does not read as "Any".
57
58
  if (isRequiredGiven(given)) return "Required";
58
59
  const type = given.type ?? "string";
59
60
  const shown = renderGivenDefault(type, given.default);
60
- if (shown !== undefined && shown !== "") return summarizeText(type, shown);
61
+ if (shown !== undefined && shown !== "")
62
+ return summarizeText(type, shown, full);
61
63
  const inner = filterInnerType(type) ?? type;
62
64
  return given.control === "select" ||
63
65
  given.control === "multiselect" ||
@@ -67,11 +69,11 @@ function unsetSummary(given: Given): string {
67
69
  }
68
70
 
69
71
  /** A value written as text, read the way its type reads. */
70
- function summarizeText(type: string, text: string): string {
71
- if (!isFilterType(type)) return truncate(formatDay(text));
72
+ function summarizeText(type: string, text: string, full: boolean): string {
73
+ if (!isFilterType(type)) return truncate(formatDay(text), full);
72
74
  const inner = filterInnerType(type);
73
75
  if (inner === "string" && isPlainFilterList(text))
74
- return summarizeList(decodeFilterList(text));
76
+ return summarizeList(decodeFilterList(text), full);
75
77
  if (inner === "number") {
76
78
  const between = decodeBetween(text);
77
79
  if (between) return `${between[0]}–${between[1]}`;
@@ -86,7 +88,21 @@ function summarizeText(type: string, text: string): string {
86
88
  if (days)
87
89
  return `${formatDay(days.firstDay)} – ${formatDay(days.lastDay)}`;
88
90
  }
89
- return truncate(text);
91
+ return truncate(text, full);
92
+ }
93
+
94
+ function wordValue(
95
+ given: Given,
96
+ value: GivenValue | undefined,
97
+ full: boolean,
98
+ ): string {
99
+ if (value === null || value === undefined) return unsetSummary(given, full);
100
+ if (value instanceof Date)
101
+ return Number.isNaN(value.getTime()) ? "" : dayFormat.format(value);
102
+ if (typeof value === "boolean") return value ? "Yes" : "No";
103
+ if (typeof value === "number") return String(value);
104
+ if (value === "") return "(empty)";
105
+ return summarizeText(given.type ?? "string", value, full);
90
106
  }
91
107
 
92
108
  /**
@@ -99,11 +115,17 @@ export function summarizeGivenValue(
99
115
  given: Given,
100
116
  value: GivenValue | undefined,
101
117
  ): string {
102
- if (value === null || value === undefined) return unsetSummary(given);
103
- if (value instanceof Date)
104
- return Number.isNaN(value.getTime()) ? "" : dayFormat.format(value);
105
- if (typeof value === "boolean") return value ? "Yes" : "No";
106
- if (typeof value === "number") return String(value);
107
- if (value === "") return "(empty)";
108
- return summarizeText(given.type ?? "string", value);
118
+ return wordValue(given, value, false);
119
+ }
120
+
121
+ /**
122
+ * A given's value in the same words, but whole: every picked value and no
123
+ * cut-off text. For a record of what produced a result, where nothing else
124
+ * holds the full value.
125
+ */
126
+ export function describeGivenValue(
127
+ given: Given,
128
+ value: GivenValue | undefined,
129
+ ): string {
130
+ return wordValue(given, value, true);
109
131
  }
@@ -28,6 +28,21 @@ function mount(initialEntry: string) {
28
28
  change(next: Record<string, string>, managed: string[]) {
29
29
  act(() => view.result.current.hook.onGivensChange(next, managed));
30
30
  },
31
+ /** Both writes in one tick, before the router commits either. */
32
+ setThenChange(
33
+ name: string,
34
+ value: string,
35
+ next: Record<string, string>,
36
+ managed: string[],
37
+ ) {
38
+ act(() => {
39
+ view.result.current.hook.setParam(name, value);
40
+ view.result.current.hook.onGivensChange(next, managed);
41
+ });
42
+ },
43
+ setParam(name: string, value: string | undefined) {
44
+ act(() => view.result.current.hook.setParam(name, value));
45
+ },
31
46
  };
32
47
  }
33
48
 
@@ -66,6 +81,23 @@ describe("useGivenUrlParams", () => {
66
81
  expect(host.hash).toBe("#trend");
67
82
  });
68
83
 
84
+ it("writes a host's own parameter the same way, keeping the fragment", () => {
85
+ const host = mount("/d?REGION=West#trend");
86
+ host.setParam("source", "orders");
87
+ expect(host.search.get("source")).toBe("orders");
88
+ expect(host.search.get("REGION")).toBe("West");
89
+ expect(host.hash).toBe("#trend");
90
+ host.setParam("source", undefined);
91
+ expect(host.search.has("source")).toBe(false);
92
+ });
93
+
94
+ it("keeps both of two writes made in one tick", () => {
95
+ const host = mount("/d?source=items");
96
+ host.setThenChange("source", "orders", { REGION: "West" }, ["REGION"]);
97
+ expect(host.search.get("source")).toBe("orders");
98
+ expect(host.search.get("REGION")).toBe("West");
99
+ });
100
+
69
101
  it("is not fooled by a given named like an Object.prototype member", () => {
70
102
  const host = mount("/d?constructor=1");
71
103
  host.change({}, ["constructor"]);
@@ -15,6 +15,12 @@ export interface UseGivenUrlParamsResult {
15
15
  next: Record<string, string>,
16
16
  managed: readonly string[],
17
17
  ) => void;
18
+ /**
19
+ * One parameter of the host's own (the source on screen, say), written the
20
+ * same way: merged into the query string, in place, keeping the fragment;
21
+ * `undefined` removes it.
22
+ */
23
+ setParam: (name: string, value: string | undefined) => void;
18
24
  }
19
25
 
20
26
  /**
@@ -45,6 +51,11 @@ export interface UseGivenUrlParamsResult {
45
51
  * every value tried. And a navigation that names only `search` resolves to an
46
52
  * empty fragment, which dropped whatever anchor the reader arrived on;
47
53
  * `setSearchParams` has that problem, which is why this navigates itself.
54
+ * A host's own parameter goes through the same write (`setParam`).
55
+ * - **Writes in one tick build on each other.** Each starts from the query
56
+ * string the last one wrote while the router has yet to commit it, not from
57
+ * the location this render saw, so a given's report beside a source pick
58
+ * keeps both.
48
59
  */
49
60
  export function useGivenUrlParams(): UseGivenUrlParamsResult {
50
61
  const [searchParams] = useSearchParams();
@@ -57,6 +68,24 @@ export function useGivenUrlParams(): UseGivenUrlParamsResult {
57
68
  );
58
69
 
59
70
  const writtenRef = useRef<Set<string>>(new Set());
71
+ // The query string last written, and the location it was written over: a
72
+ // write while that location is still current builds on it, not on a search
73
+ // the write before it has already replaced.
74
+ const pendingRef = useRef<{ key: string; search: string } | null>(null);
75
+
76
+ const write = useCallback(
77
+ (change: (merged: URLSearchParams) => void) => {
78
+ const pending = pendingRef.current;
79
+ const merged = new URLSearchParams(
80
+ pending?.key === location.key ? pending.search : location.search,
81
+ );
82
+ change(merged);
83
+ const search = merged.toString();
84
+ pendingRef.current = { key: location.key, search };
85
+ navigate({ search, hash: location.hash }, { replace: true });
86
+ },
87
+ [navigate, location],
88
+ );
60
89
 
61
90
  const onGivensChange = useCallback(
62
91
  (next: Record<string, string>, managed: readonly string[]) => {
@@ -66,22 +95,28 @@ export function useGivenUrlParams(): UseGivenUrlParamsResult {
66
95
  ...Object.keys(next),
67
96
  ...managed,
68
97
  ]);
69
- const merged = new URLSearchParams(location.search);
70
- for (const name of ours) {
71
- if (!Object.prototype.hasOwnProperty.call(next, name)) {
72
- merged.delete(name);
98
+ write((merged) => {
99
+ for (const name of ours) {
100
+ if (!Object.prototype.hasOwnProperty.call(next, name)) {
101
+ merged.delete(name);
102
+ }
73
103
  }
74
- }
75
- for (const [name, value] of Object.entries(next)) {
76
- merged.set(name, value);
77
- }
78
- navigate(
79
- { search: merged.toString(), hash: location.hash },
80
- { replace: true },
81
- );
104
+ for (const [name, value] of Object.entries(next)) {
105
+ merged.set(name, value);
106
+ }
107
+ });
82
108
  },
83
- [navigate, location],
109
+ [write],
110
+ );
111
+
112
+ const setParam = useCallback(
113
+ (name: string, value: string | undefined) =>
114
+ write((merged) => {
115
+ if (value === undefined) merged.delete(name);
116
+ else merged.set(name, value);
117
+ }),
118
+ [write],
84
119
  );
85
120
 
86
- return { params, onGivensChange };
121
+ return { params, onGivensChange, setParam };
87
122
  }
@@ -36,6 +36,7 @@ export * from "./Home";
36
36
  export * from "./Loading";
37
37
  export * from "./Materializations";
38
38
  export * from "./Model";
39
+ export * from "./ModelViewer";
39
40
  export * from "./Package";
40
41
  export {
41
42
  Prose,
@@ -48,5 +49,9 @@ export * from "./RenderedResult";
48
49
  export * from "./Report";
49
50
  export * from "./legacy";
50
51
  export { ServerProvider, useServer } from "./ServerProvider";
51
- export type { ServerContextValue, ServerProviderProps } from "./ServerProvider";
52
+ export type {
53
+ ModelPage,
54
+ ServerContextValue,
55
+ ServerProviderProps,
56
+ } from "./ServerProvider";
52
57
  export * from "./DocumentStorage";
@@ -102,10 +102,15 @@ mock.module("../../Model/ModelExplorerDialog", () => ({
102
102
  },
103
103
  }));
104
104
 
105
- mockServerProvider({
106
- notebooks: { getNotebook, executeNotebookCell },
107
- models: { executeQueryModel },
108
- });
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
+ );
109
114
 
110
115
  const { default: Notebook } = await import("./Notebook");
111
116
 
@@ -163,6 +168,35 @@ it("opens a cell's 'Data sources' dialog with the notebook's current values", as
163
168
  );
164
169
  });
165
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
+
166
200
  // DEPRECATED FEATURE COVERAGE — delete together with
167
201
  // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
168
202
  describe("deprecated: .malloynb notebooks", () => {
@@ -27,6 +27,7 @@ import { AppDialog } from "../../AppDialog";
27
27
  import { highlight } from "../../highlighter";
28
28
  import { ModelExplorerDialog } from "../../Model/ModelExplorerDialog";
29
29
  import { FloatingIconButton } from "../../FloatingIconButton";
30
+ import { useServer } from "../../ServerProvider";
30
31
  import { Prose } from "../../Prose";
31
32
  import type { NavigationClick } from "../../click_helper";
32
33
  import { useDrill, type DrillNavigation } from "../../drill";
@@ -114,6 +115,11 @@ export function NotebookCell({
114
115
  React.useState<string>();
115
116
  const [sourcesDialogOpen, setSourcesDialogOpen] =
116
117
  React.useState<boolean>(false);
118
+ // The "Data sources" dialog is the Malloy Explorer, which a server with
119
+ // `PUBLISHER_MODEL_PAGE=viewer` takes out of the Console; it waits on
120
+ // `/status` so such a server never offers it.
121
+ const { modelPage, isLoadingStatus } = useServer();
122
+ const explorerAllowed = !isLoadingStatus && modelPage !== "viewer";
117
123
 
118
124
  const [copyMessage, setCopyMessage] = useState("");
119
125
 
@@ -342,7 +348,7 @@ export function NotebookCell({
342
348
  }}
343
349
  />
344
350
  )}
345
- {hasValidImport && (
351
+ {hasValidImport && explorerAllowed && (
346
352
  <FloatingIconButton
347
353
  aria-label="Data sources"
348
354
  sx={{ flexShrink: 0 }}
@@ -358,7 +364,7 @@ export function NotebookCell({
358
364
 
359
365
  {/* Data Sources Dialog */}
360
366
  <ModelExplorerDialog
361
- open={sourcesDialogOpen}
367
+ open={sourcesDialogOpen && explorerAllowed}
362
368
  onClose={() => setSourcesDialogOpen(false)}
363
369
  title="Data Sources"
364
370
  hasValidImport={hasValidImport}
@@ -0,0 +1,79 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import {
5
+ focusManager,
6
+ QueryClient,
7
+ QueryObserver,
8
+ type QueryObserverResult,
9
+ } from "@tanstack/react-query";
10
+ import { describe, expect, it } from "bun:test";
11
+ import { modelPageOf, modelPageState } from "./modelPage";
12
+
13
+ describe("modelPageOf", () => {
14
+ it("is the page /status names, the Explorer unless it says viewer", () => {
15
+ expect(modelPageOf({ modelPage: "viewer" }, false)).toBe("viewer");
16
+ expect(modelPageOf({ modelPage: "explorer" }, false)).toBe("explorer");
17
+ // A server that predates the setting sends no field.
18
+ expect(modelPageOf({}, false)).toBe("explorer");
19
+ expect(modelPageOf({ modelPage: "something new" }, false)).toBe(
20
+ "explorer",
21
+ );
22
+ });
23
+
24
+ // A deployment that chose viewer has chosen not to show the Explorer, and
25
+ // the viewer writes no value into Malloy on any server.
26
+ it("is the viewer when /status could not be read", () => {
27
+ expect(modelPageOf(undefined, true)).toBe("viewer");
28
+ });
29
+
30
+ it("is the Explorer while /status has not answered", () => {
31
+ expect(modelPageOf(undefined, false)).toBe("explorer");
32
+ });
33
+ });
34
+
35
+ describe("modelPageState", () => {
36
+ it("settles once /status answers or fails", () => {
37
+ expect(
38
+ modelPageState({
39
+ data: { modelPage: "viewer" },
40
+ isPending: false,
41
+ isError: false,
42
+ }),
43
+ ).toEqual({ modelPage: "viewer", isLoadingStatus: false });
44
+ expect(
45
+ modelPageState({ data: undefined, isPending: false, isError: true }),
46
+ ).toEqual({ modelPage: "viewer", isLoadingStatus: false });
47
+ });
48
+
49
+ // The first /status fails and its retry pauses, as it does in a hidden tab
50
+ // or offline: nothing has answered, yet react-query's isLoading is false,
51
+ // so a page that waited on it would draw the Explorer on a viewer server.
52
+ it("waits while a retry is paused", async () => {
53
+ const client = new QueryClient();
54
+ focusManager.setFocused(false);
55
+ try {
56
+ const observer = new QueryObserver(client, {
57
+ queryKey: ["status"],
58
+ queryFn: () => Promise.reject(new Error("500")),
59
+ retry: 3,
60
+ retryDelay: 0,
61
+ });
62
+ const paused = await new Promise<QueryObserverResult>((resolve) => {
63
+ const unsubscribe = observer.subscribe((result) => {
64
+ if (result.fetchStatus !== "paused") return;
65
+ unsubscribe();
66
+ resolve(result);
67
+ });
68
+ });
69
+ expect(paused.isLoading).toBe(false);
70
+ expect(modelPageState(paused)).toEqual({
71
+ modelPage: "explorer",
72
+ isLoadingStatus: true,
73
+ });
74
+ } finally {
75
+ focusManager.setFocused(undefined);
76
+ client.clear();
77
+ }
78
+ });
79
+ });