@malloy-publisher/sdk 0.9.9 → 0.9.11

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 (261) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-BHuJpdSn.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
  3. package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
  4. package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
  5. package/dist/builder/index.cjs.js +78 -130
  6. package/dist/builder/index.es.js +7440 -6727
  7. package/dist/builder-entry.d.ts +3 -0
  8. package/dist/client/api.d.ts +26 -22
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +1 -1
  11. package/dist/components/AppDialog.d.ts +9 -1
  12. package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
  13. package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
  14. package/dist/components/Dashboard/DashboardView.d.ts +22 -23
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +22 -0
  17. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -5
  18. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  19. package/dist/components/Package/PackageProblems.d.ts +14 -0
  20. package/dist/components/RemoveBadge.d.ts +40 -0
  21. package/dist/components/Report/Report.d.ts +13 -4
  22. package/dist/components/Report/ReportPage.d.ts +60 -0
  23. package/dist/components/Report/layoutRules.d.ts +32 -0
  24. package/dist/components/Report/reportQuery.d.ts +30 -0
  25. package/dist/components/Report/telemetry.d.ts +0 -2
  26. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  27. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  28. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  29. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  30. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  31. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  32. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  33. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  34. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  35. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -6
  36. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  37. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  38. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  39. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  40. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  41. package/dist/components/ReportBuilder/TileMenu.d.ts +19 -11
  42. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  43. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  44. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  45. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  46. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  47. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  48. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  49. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  50. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  51. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  52. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  53. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  54. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  55. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  56. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  57. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  58. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  59. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  60. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  61. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  62. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  63. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  64. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  65. package/dist/components/ServerProvider.d.ts +9 -0
  66. package/dist/components/controlTokens.d.ts +45 -0
  67. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  68. package/dist/components/given/FilterButton.d.ts +35 -0
  69. package/dist/components/given/GivensPanel.d.ts +2 -1
  70. package/dist/components/given/filterEditing.d.ts +54 -0
  71. package/dist/components/given/filterSummary.d.ts +9 -0
  72. package/dist/components/given/paramCodec.d.ts +11 -0
  73. package/dist/components/given/required.d.ts +25 -0
  74. package/dist/components/index.d.ts +3 -0
  75. package/dist/components/legacy/index.d.ts +1 -1
  76. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  77. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  78. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  79. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  80. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  81. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  82. package/dist/components/styles.d.ts +0 -2
  83. package/dist/hooks/useQueryResult.d.ts +7 -0
  84. package/dist/index.cjs.js +16 -19
  85. package/dist/index.es.js +8324 -7769
  86. package/dist/theme/ThemeContext.d.ts +8 -1
  87. package/dist/theme/classes.d.ts +49 -0
  88. package/dist/theme/index.d.ts +2 -0
  89. package/dist/theme/types.d.ts +7 -0
  90. package/dist/theme/ui.d.ts +75 -0
  91. package/dist/{useCompiledDocument-1dgF5CC9.es.js → useCompiledDocument-7j5cBjQd.es.js} +8768 -7912
  92. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  93. package/package.json +2 -2
  94. package/src/builder-entry.ts +9 -0
  95. package/src/components/AppDialog.tsx +23 -0
  96. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  97. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  98. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  99. package/src/components/Dashboard/DashboardView.tsx +136 -105
  100. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  101. package/src/components/Dashboard/TileCard.tsx +28 -10
  102. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  103. package/src/components/Dashboard/useStuck.ts +49 -0
  104. package/src/components/DocumentCreate/newNotebook.spec.ts +8 -6
  105. package/src/components/DocumentCreate/newNotebook.ts +26 -12
  106. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  107. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  108. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  109. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  110. package/src/components/Package/Package.create.spec.tsx +7 -6
  111. package/src/components/Package/Package.tsx +10 -7
  112. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  113. package/src/components/Package/PackageProblems.tsx +95 -0
  114. package/src/components/Prose.tsx +12 -7
  115. package/src/components/RemoveBadge.tsx +94 -0
  116. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  117. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  118. package/src/components/Report/Report.spec.tsx +50 -32
  119. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  120. package/src/components/Report/Report.tsx +45 -77
  121. package/src/components/Report/ReportPage.tsx +168 -0
  122. package/src/components/Report/layoutRules.spec.ts +35 -0
  123. package/src/components/Report/layoutRules.ts +55 -0
  124. package/src/components/Report/reportQuery.ts +53 -0
  125. package/src/components/Report/telemetry.ts +0 -2
  126. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  127. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  128. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  129. package/src/components/ReportBuilder/BuilderDialogs.tsx +30 -39
  130. package/src/components/ReportBuilder/BuilderGrid.tsx +43 -31
  131. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  132. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  133. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  134. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  135. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  136. package/src/components/ReportBuilder/FilterStrip.tsx +129 -150
  137. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  138. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  139. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  140. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  141. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -16
  142. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  143. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  144. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  145. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +41 -36
  146. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  147. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -116
  148. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  149. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  150. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  151. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  152. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  153. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  154. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  155. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  156. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  157. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  158. package/src/components/ReportBuilder/TileMenu.tsx +248 -142
  159. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  160. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  161. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  162. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  163. package/src/components/ReportBuilder/builderControls.ts +164 -0
  164. package/src/components/ReportBuilder/builderReport.ts +1 -2
  165. package/src/components/ReportBuilder/catalog.ts +10 -26
  166. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  167. package/src/components/ReportBuilder/localGiven.ts +56 -0
  168. package/src/components/ReportBuilder/newDashboard.spec.ts +2 -3
  169. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  170. package/src/components/ReportBuilder/preview.ts +60 -44
  171. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  172. package/src/components/ReportBuilder/readDocument.ts +14 -11
  173. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  174. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  175. package/src/components/ReportBuilder/reportTag.ts +28 -7
  176. package/src/components/ReportBuilder/sortable.tsx +15 -7
  177. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  178. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  179. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  180. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  181. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  182. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  183. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  184. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  185. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  186. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  187. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  188. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  189. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  190. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  191. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  192. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  193. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  194. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  195. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  196. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  197. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  198. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  199. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  200. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  201. package/src/components/ServerProvider.tsx +11 -0
  202. package/src/components/controlTokens.ts +47 -0
  203. package/src/components/drill/markDrillableCells.ts +2 -1
  204. package/src/components/given/FilterButton.spec.tsx +143 -0
  205. package/src/components/given/FilterButton.tsx +478 -0
  206. package/src/components/given/GivenInput.spec.tsx +47 -0
  207. package/src/components/given/GivenInput.tsx +20 -2
  208. package/src/components/given/GivensPanel.spec.tsx +11 -3
  209. package/src/components/given/GivensPanel.tsx +45 -44
  210. package/src/components/given/filterEditing.ts +60 -0
  211. package/src/components/given/filterSummary.spec.ts +108 -0
  212. package/src/components/given/filterSummary.ts +109 -0
  213. package/src/components/given/paramCodec.ts +1 -1
  214. package/src/components/given/required.spec.ts +60 -0
  215. package/src/components/given/required.ts +78 -0
  216. package/src/components/index.ts +9 -0
  217. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  218. package/src/components/legacy/index.ts +1 -1
  219. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  220. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  221. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  222. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  223. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  224. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  225. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  226. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  227. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  228. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  229. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  230. package/src/components/styles.ts +0 -18
  231. package/src/hooks/useGivensState.ts +7 -3
  232. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  233. package/src/hooks/useQueryResult.ts +26 -1
  234. package/src/theme/ThemeContext.tsx +21 -1
  235. package/src/theme/classes.ts +52 -0
  236. package/src/theme/index.ts +8 -0
  237. package/src/theme/resolveTheme.ts +3 -0
  238. package/src/theme/types.ts +7 -0
  239. package/src/theme/ui.spec.tsx +91 -0
  240. package/src/theme/ui.ts +115 -0
  241. package/dist/RenderedResult-Bw7EQc42.cjs.js +0 -153
  242. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  243. package/dist/components/Notebook/cellKind.d.ts +0 -20
  244. package/dist/components/Report/LinearReport.d.ts +0 -18
  245. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  246. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  247. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  248. package/dist/useCompiledDocument-BKyRnXmA.cjs.js +0 -141
  249. package/src/components/Notebook/cellKind.spec.ts +0 -199
  250. package/src/components/Notebook/cellKind.ts +0 -74
  251. package/src/components/Report/LinearReport.tsx +0 -71
  252. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  253. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  254. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  255. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  256. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  257. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  258. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  259. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  260. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  261. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -3,13 +3,25 @@
3
3
 
4
4
  import {
5
5
  Alert,
6
+ Box,
6
7
  Button,
7
- MenuItem,
8
+ ButtonBase,
8
9
  Stack,
9
10
  TextField,
10
11
  Tooltip,
12
+ Typography,
11
13
  } from "@mui/material";
12
- import { useEffect, useMemo, useState } from "react";
14
+ import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
15
+ import type { GivenValue } from "../../hooks/givenValue";
16
+ import { reportClasses } from "../../theme/classes";
17
+ import { usePublisherTheme } from "../../theme/ThemeContext";
18
+ import { edgeColor } from "../controlTokens";
19
+ import { DashboardTile } from "../Dashboard/DashboardTile";
20
+ import {
21
+ readableName,
22
+ ViewPicker,
23
+ type PickerGroup,
24
+ } from "../ReportBuilder/ViewPicker";
13
25
  import {
14
26
  createDocument,
15
27
  reportPathForTitle,
@@ -26,11 +38,6 @@ import { AppDialog } from "../AppDialog";
26
38
  import { layoutOfKind, type DocumentKind } from "../legacy/kindAdapter";
27
39
  import type { ReportLayout } from "./documentLocation";
28
40
 
29
- const LAYOUT_LABEL: Record<ReportLayout, string> = {
30
- linear: "Linear: read top to bottom",
31
- grid: "Grid: tiles side by side",
32
- };
33
-
34
41
  export interface NewDocumentDialogProps {
35
42
  open: boolean;
36
43
  /** Which layout the dialog opens on. Default linear. */
@@ -97,6 +104,8 @@ export function NewDocumentDialog({
97
104
  const [modelPath, setModelPath] = useState("");
98
105
  /** The chosen view, as `source::view` — one value, so the pair is always valid. */
99
106
  const [tile, setTile] = useState("");
107
+ const [query, setQuery] = useState("");
108
+ const searchRef = useRef<HTMLInputElement>(null);
100
109
  const [title, setTitle] = useState("");
101
110
  const [touchedTitle, setTouchedTitle] = useState(false);
102
111
  const [attempted, setAttempted] = useState(false);
@@ -120,7 +129,70 @@ export function NewDocumentDialog({
120
129
  () => choices.get(modelPath) ?? [],
121
130
  [choices, modelPath],
122
131
  );
132
+ // Every model's views in one list, grouped by source; a key names the
133
+ // model too, so picking a view picks its model.
134
+ // What each picker key names, so a key is looked up, never split: a model
135
+ // path or a name could hold the separator.
136
+ const picks = useMemo(
137
+ () =>
138
+ new Map(
139
+ [...choices.entries()].flatMap(([model, pairs]) =>
140
+ pairs.map(
141
+ (pair) =>
142
+ [
143
+ pickKey(model, pair.source, pair.view),
144
+ { model, source: pair.source, view: pair.view },
145
+ ] as const,
146
+ ),
147
+ ),
148
+ ),
149
+ [choices],
150
+ );
151
+ const groups = useMemo<PickerGroup[]>(() => {
152
+ const several = choices.size > 1;
153
+ return [...choices.entries()].flatMap(([model, pairs]) => {
154
+ const bySource = new Map<string, typeof pairs>();
155
+ for (const pair of pairs)
156
+ bySource.set(pair.source, [
157
+ ...(bySource.get(pair.source) ?? []),
158
+ pair,
159
+ ]);
160
+ return [...bySource.entries()].map(([source, views]) => ({
161
+ key: `${model}::${source}`,
162
+ label: source,
163
+ ariaLabel: `${source} in ${model}`,
164
+ ...(several || views[0]?.sourceDescription
165
+ ? {
166
+ detail: [
167
+ several ? model : undefined,
168
+ views[0]?.sourceDescription,
169
+ ]
170
+ .filter(Boolean)
171
+ .join(" · "),
172
+ }
173
+ : {}),
174
+ entries: views.map((pair) => ({
175
+ key: pickKey(model, pair.source, pair.view),
176
+ name: pair.view,
177
+ title: pair.description ?? readableName(pair.view),
178
+ ...(pair.chart ? { chart: pair.chart } : {}),
179
+ })),
180
+ }));
181
+ });
182
+ }, [choices]);
183
+ const pickView = (key: string) => {
184
+ const pick = picks.get(key);
185
+ if (!pick) return;
186
+ setModelPath(pick.model);
187
+ setTile(`${pick.source}::${pick.view}`);
188
+ };
123
189
  const chosen = tiles.find((t) => `${t.source}::${t.view}` === tile);
190
+ const pickedKey = chosen
191
+ ? pickKey(modelPath, chosen.source, chosen.view)
192
+ : undefined;
193
+ // The preview follows the pick once it settles: arrowing through the list
194
+ // ran a query for every view passed on the way.
195
+ const previewed = useSettled(chosen, 250);
124
196
 
125
197
  useEffect(() => {
126
198
  if (open) setLayout(initialLayout);
@@ -142,7 +214,7 @@ export function NewDocumentDialog({
142
214
 
143
215
  useEffect(() => {
144
216
  if (!open || touchedTitle || chosen === undefined) return;
145
- setTitle(chosen.view.replace(/_/g, " "));
217
+ setTitle(readableName(chosen.view));
146
218
  }, [open, touchedTitle, chosen]);
147
219
 
148
220
  useEffect(() => {
@@ -150,6 +222,7 @@ export function NewDocumentDialog({
150
222
  // Reset on close, so the next open starts from the package again.
151
223
  setModelPath("");
152
224
  setTile("");
225
+ setQuery("");
153
226
  setTitle("");
154
227
  setTouchedTitle(false);
155
228
  setLocation(undefined);
@@ -202,6 +275,9 @@ export function NewDocumentDialog({
202
275
  titleProblem !== undefined && (attempted || title.trim() !== "");
203
276
 
204
277
  const loading = modelsLoading || isLoading;
278
+ const { theme } = usePublisherTheme();
279
+ const ui = theme.ui;
280
+ const edge = edgeColor(theme.cardBorder);
205
281
  const unread = choices.size === 0 && (modelsFailed || failed.length > 0);
206
282
  // Create is off only when nothing typed could make it succeed; the title is checked on press.
207
283
  const blocked = loading
@@ -215,7 +291,6 @@ export function NewDocumentDialog({
215
291
  : undefined;
216
292
  const label = "report";
217
293
  const createLabel = busy ? `Creating ${label}…` : `Create ${label}`;
218
- const first = "First query";
219
294
  const picked = tile !== "" && chosen === undefined && tiles.length > 0;
220
295
 
221
296
  const create = async () => {
@@ -260,11 +335,14 @@ export function NewDocumentDialog({
260
335
 
261
336
  return (
262
337
  <AppDialog
338
+ className={`${reportClasses.dialog} ${reportClasses.newReportDialog}`}
339
+ maxWidth="md"
340
+ initialFocus={searchRef}
263
341
  open={open}
264
342
  // A write in flight is not abandoned by Escape or a backdrop click.
265
343
  onClose={busy ? () => {} : onClose}
266
344
  title={`New ${label}`}
267
- description="A report is a Malloy file in the package that lays out text and queries, as a grid or top to bottom. Pick what its first query shows; the rest is the builder."
345
+ description="A report is a Malloy file in the package that lays out text and queries. Pick the view its first query shows; the rest is the builder."
268
346
  actions={
269
347
  <>
270
348
  <Button onClick={onClose} disabled={busy}>
@@ -290,7 +368,7 @@ export function NewDocumentDialog({
290
368
  </>
291
369
  }
292
370
  >
293
- <Stack sx={{ gap: 2, pt: 1 }}>
371
+ <Stack sx={{ gap: 1.5 }}>
294
372
  {modelsFailed ? (
295
373
  <Alert
296
374
  severity="error"
@@ -330,117 +408,303 @@ export function NewDocumentDialog({
330
408
  </Alert>
331
409
  )
332
410
  )}
333
- {canChangeLayout && (
334
- <TextField
335
- select
336
- size="small"
337
- label="Layout"
338
- value={layout}
339
- disabled={busy}
340
- onChange={(event) =>
341
- setLayout(event.target.value as ReportLayout)
342
- }
343
- inputProps={{ "aria-label": "Layout" }}
344
- helperText="Switch it any time in the builder."
345
- >
346
- {(["linear", "grid"] as const).map((l) => (
347
- <MenuItem key={l} value={l}>
348
- {LAYOUT_LABEL[l]}
349
- </MenuItem>
350
- ))}
351
- </TextField>
352
- )}
353
- <TextField
354
- select
355
- size="small"
356
- label="Model"
357
- value={choices.has(modelPath) ? modelPath : ""}
358
- disabled={choices.size === 0 || busy}
359
- onChange={(event) => {
360
- setModelPath(event.target.value);
361
- setTile("");
411
+ <Box
412
+ sx={{
413
+ // Edge to edge inside the window: two panes, as Add a tile.
414
+ mx: -3,
415
+ mb: -1,
416
+ borderTop: `1px solid ${edge}`,
417
+ borderBottom: `1px solid ${edge}`,
418
+ display: "grid",
419
+ gridTemplateColumns: {
420
+ xs: "1fr",
421
+ md: "320px minmax(0, 1fr)",
422
+ },
423
+ height: { md: 500 },
362
424
  }}
363
- inputProps={{ "aria-label": "Model" }}
364
- helperText={
365
- loading
366
- ? "Reading the package's models…"
367
- : choices.size === 1
368
- ? "The only model with a view to start from."
369
- : "Models with a view to start from."
370
- }
371
425
  >
372
- {[...choices.keys()].map((modelFile) => (
373
- <MenuItem key={modelFile} value={modelFile}>
374
- {modelFile}
375
- </MenuItem>
376
- ))}
377
- </TextField>
378
- {/* One field, not two: the file needs a view OF a source, so the
379
- pair is the thing being chosen. */}
380
- <TextField
381
- select
382
- size="small"
383
- label={first}
384
- value={chosen ? tile : ""}
385
- disabled={tiles.length === 0 || busy}
386
- onChange={(event) => setTile(event.target.value)}
387
- inputProps={{ "aria-label": first }}
388
- error={picked}
389
- helperText={
390
- picked
391
- ? "The view you picked is no longer in this model; pick another."
392
- : tiles.length === 1
393
- ? "The only view this model offers; more are added in the builder."
394
- : "A view of a source; more are added in the builder."
395
- }
396
- >
397
- {tiles.map((option) => (
398
- <MenuItem
399
- key={`${option.source}::${option.view}`}
400
- value={`${option.source}::${option.view}`}
401
- >
402
- {option.source} → {option.view}
403
- </MenuItem>
404
- ))}
405
- </TextField>
406
- <TextField
407
- size="small"
408
- label="Title"
409
- value={title}
410
- disabled={busy}
411
- onChange={(event) => {
412
- setTouchedTitle(true);
413
- setTitle(event.target.value);
414
- }}
415
- inputProps={{ "aria-label": "Report title" }}
416
- error={showTitleProblem}
417
- helperText={
418
- showTitleProblem
419
- ? titleProblem
420
- : target.route === "package"
421
- ? "Names the file too, unless you type a location."
422
- : (savedAs ??
423
- `Saved as a new ${label} in the host's store, and opened in the builder.`)
424
- }
425
- />
426
- <TextField
427
- size="small"
428
- label="Location"
429
- value={location ?? suggested ?? ""}
430
- placeholder="report.malloy"
431
- disabled={busy}
432
- onChange={(event) => setLocation(event.target.value)}
433
- inputProps={{ "aria-label": "Location" }}
434
- error={locationProblem !== undefined}
435
- helperText={
436
- locationProblem ??
437
- (path
438
- ? `Written as ${path} in the package, and opened in the builder.`
439
- : "A path in the package; the package root by default.")
440
- }
441
- />
442
- {failure && <Alert severity="error">{failure}</Alert>}
426
+ <Box
427
+ sx={{
428
+ display: "flex",
429
+ flexDirection: "column",
430
+ minHeight: 0,
431
+ borderRight: { md: `1px solid ${edge}` },
432
+ maxHeight: { xs: 280, md: "none" },
433
+ }}
434
+ >
435
+ <ViewPicker
436
+ groups={groups}
437
+ query={query}
438
+ onQuery={setQuery}
439
+ picked={pickedKey}
440
+ onPick={pickView}
441
+ onTake={(key) => {
442
+ pickView(key);
443
+ }}
444
+ searchRef={searchRef}
445
+ disabled={busy}
446
+ empty={
447
+ <Typography
448
+ variant="body2"
449
+ sx={{ color: "text.secondary", p: 2 }}
450
+ >
451
+ {loading
452
+ ? "Reading the package's models…"
453
+ : "No view to start from."}
454
+ </Typography>
455
+ }
456
+ />
457
+ </Box>
458
+ <Box
459
+ sx={(mui) => ({
460
+ p: 2.5,
461
+ display: "flex",
462
+ flexDirection: "column",
463
+ gap: 2,
464
+ minHeight: 0,
465
+ overflowY: "auto",
466
+ bgcolor: `color-mix(in srgb, ${mui.palette.text.primary} 3%, ${mui.palette.background.paper})`,
467
+ })}
468
+ >
469
+ {canChangeLayout && (
470
+ <Box>
471
+ <PaneLabel>Layout</PaneLabel>
472
+ <Box
473
+ role="radiogroup"
474
+ aria-label="Layout"
475
+ sx={{
476
+ display: "grid",
477
+ gridTemplateColumns: "1fr 1fr",
478
+ gap: 1,
479
+ }}
480
+ >
481
+ {(["linear", "grid"] as const).map((l) => (
482
+ <LayoutCard
483
+ key={l}
484
+ layout={l}
485
+ checked={layout === l}
486
+ disabled={busy}
487
+ onPick={() => setLayout(l)}
488
+ />
489
+ ))}
490
+ </Box>
491
+ <Typography
492
+ variant="caption"
493
+ component="p"
494
+ sx={{ color: "text.secondary", mt: 0.75 }}
495
+ >
496
+ Switch it any time in the builder.
497
+ </Typography>
498
+ </Box>
499
+ )}
500
+ <Box>
501
+ <PaneLabel>First query</PaneLabel>
502
+ <Box
503
+ role="region"
504
+ aria-label="Preview"
505
+ sx={(mui) => ({
506
+ height: 200,
507
+ display: "flex",
508
+ position: "relative",
509
+ overflow: "hidden",
510
+ borderRadius: ui.radius.tile,
511
+ border: `1px solid ${edge}`,
512
+ bgcolor: mui.palette.background.paper,
513
+ "&::after": {
514
+ content: '""',
515
+ position: "absolute",
516
+ left: 0,
517
+ right: 0,
518
+ bottom: 0,
519
+ height: 40,
520
+ pointerEvents: "none",
521
+ background: `linear-gradient(to bottom, transparent, ${mui.palette.background.paper})`,
522
+ },
523
+ })}
524
+ >
525
+ {chosen && previewed ? (
526
+ <Box sx={{ flex: 1, minWidth: 0, px: 2, pt: 1.5 }}>
527
+ <DashboardTile
528
+ environmentName={environmentName}
529
+ packageName={packageName}
530
+ {...(versionId !== undefined
531
+ ? { versionId }
532
+ : {})}
533
+ modelPath={modelPath}
534
+ tile={`${previewed.source} -> ${previewed.view}`}
535
+ label={
536
+ title.trim() || readableName(previewed.view)
537
+ }
538
+ borderless
539
+ givens={NO_GIVENS}
540
+ declaredTypes={NO_TYPES}
541
+ height={180}
542
+ />
543
+ </Box>
544
+ ) : (
545
+ <Typography
546
+ variant="body2"
547
+ sx={{ color: "text.secondary", m: "auto" }}
548
+ >
549
+ {picked
550
+ ? "The view you picked is no longer in this model; pick another."
551
+ : "Pick a view to start from."}
552
+ </Typography>
553
+ )}
554
+ </Box>
555
+ <Typography
556
+ variant="caption"
557
+ component="p"
558
+ sx={{ color: "text.secondary", mt: 0.75 }}
559
+ >
560
+ More are added in the builder.
561
+ </Typography>
562
+ </Box>
563
+ <TextField
564
+ size="small"
565
+ label="Title"
566
+ value={title}
567
+ disabled={busy}
568
+ onChange={(event) => {
569
+ setTouchedTitle(true);
570
+ setTitle(event.target.value);
571
+ }}
572
+ InputLabelProps={{ shrink: true }}
573
+ inputProps={{ "aria-label": "Report title" }}
574
+ error={showTitleProblem}
575
+ helperText={
576
+ showTitleProblem
577
+ ? titleProblem
578
+ : target.route === "package"
579
+ ? "Names the file too, unless you type a location."
580
+ : (savedAs ??
581
+ `Saved as a new ${label} in the host's store, and opened in the builder.`)
582
+ }
583
+ />
584
+ <TextField
585
+ size="small"
586
+ label="Location"
587
+ value={location ?? suggested ?? ""}
588
+ placeholder="report.malloy"
589
+ disabled={busy}
590
+ onChange={(event) => setLocation(event.target.value)}
591
+ InputLabelProps={{ shrink: true }}
592
+ inputProps={{ "aria-label": "Location" }}
593
+ error={locationProblem !== undefined}
594
+ helperText={
595
+ locationProblem ??
596
+ (path
597
+ ? `Written as ${path} in the package, and opened in the builder.`
598
+ : "A path in the package; the package root by default.")
599
+ }
600
+ />
601
+ {failure && <Alert severity="error">{failure}</Alert>}
602
+ </Box>
603
+ </Box>
443
604
  </Stack>
444
605
  </AppDialog>
445
606
  );
446
607
  }
608
+
609
+ /** `value` once it has held still for `ms`; undefined until then. */
610
+ function useSettled<T>(value: T, ms: number): T | undefined {
611
+ const [settled, setSettled] = useState<T | undefined>(undefined);
612
+ useEffect(() => {
613
+ const timer = window.setTimeout(() => setSettled(value), ms);
614
+ return () => window.clearTimeout(timer);
615
+ }, [value, ms]);
616
+ return settled;
617
+ }
618
+ /** A picker key: the model, the source and the view, so the pick names all three. */
619
+ const pickKey = (model: string, source: string, view: string) =>
620
+ `${model}::${source}::${view}`;
621
+
622
+ /** A preview runs with no filter values: the model's own defaults. */
623
+ const NO_GIVENS = new Map<string, GivenValue>();
624
+ const NO_TYPES = new Map<string, string | undefined>();
625
+
626
+ /** A small heading over a part of the window. */
627
+ function PaneLabel({ children }: { children: ReactNode }) {
628
+ const ui = usePublisherTheme().theme.ui;
629
+ return (
630
+ <Typography
631
+ component="div"
632
+ sx={{ ...ui.type.label, color: "text.secondary", mb: 0.75 }}
633
+ >
634
+ {children}
635
+ </Typography>
636
+ );
637
+ }
638
+
639
+ /** A layout as a card: its picture and its name, as the filter kinds are. */
640
+ function LayoutCard({
641
+ layout,
642
+ checked,
643
+ disabled,
644
+ onPick,
645
+ }: {
646
+ layout: ReportLayout;
647
+ checked: boolean;
648
+ disabled: boolean;
649
+ onPick: () => void;
650
+ }) {
651
+ const { theme } = usePublisherTheme();
652
+ const ui = theme.ui;
653
+ const edge = edgeColor(theme.cardBorder);
654
+ const ink = checked ? theme.accent : "currentColor";
655
+ return (
656
+ <ButtonBase
657
+ role="radio"
658
+ aria-checked={checked}
659
+ aria-label={layout === "linear" ? "Linear" : "Grid"}
660
+ disabled={disabled}
661
+ onClick={onPick}
662
+ sx={(mui) => ({
663
+ justifyContent: "flex-start",
664
+ gap: 1.25,
665
+ px: 1.25,
666
+ py: 1,
667
+ borderRadius: ui.radius.tile,
668
+ border: `1px solid ${checked ? theme.accent : edge}`,
669
+ boxShadow: checked ? `0 0 0 1px ${theme.accent}` : "none",
670
+ bgcolor: checked
671
+ ? `color-mix(in srgb, ${theme.accent} 6%, ${mui.palette.background.paper})`
672
+ : mui.palette.background.paper,
673
+ color: mui.palette.text.secondary,
674
+ textAlign: "left",
675
+ })}
676
+ >
677
+ <svg width="34" height="26" viewBox="0 0 34 26" aria-hidden>
678
+ {layout === "linear" ? (
679
+ <g fill="none" stroke={ink} strokeWidth="1.5">
680
+ <rect x="3" y="2" width="28" height="7" rx="1.5" />
681
+ <rect x="3" y="12" width="28" height="5" rx="1.5" />
682
+ <path d="M5 21.5h20" strokeLinecap="round" />
683
+ </g>
684
+ ) : (
685
+ <g fill="none" stroke={ink} strokeWidth="1.5">
686
+ <rect x="2" y="2" width="14" height="10" rx="1.5" />
687
+ <rect x="18" y="2" width="14" height="10" rx="1.5" />
688
+ <rect x="2" y="14" width="30" height="10" rx="1.5" />
689
+ </g>
690
+ )}
691
+ </svg>
692
+ <Box>
693
+ <Box
694
+ sx={{
695
+ ...ui.type.control,
696
+ fontWeight: checked ? ui.type.label.fontWeight : 500,
697
+ color: checked ? theme.accent : "text.primary",
698
+ }}
699
+ >
700
+ {layout === "linear" ? "Linear" : "Grid"}
701
+ </Box>
702
+ <Box sx={{ ...ui.type.caption, color: "text.secondary" }}>
703
+ {layout === "linear"
704
+ ? "Read top to bottom"
705
+ : "Tiles side by side"}
706
+ </Box>
707
+ </Box>
708
+ </ButtonBase>
709
+ );
710
+ }
@@ -66,7 +66,7 @@ const rows = async () => {
66
66
  const section = screen.getByRole("region", { name: "Reports" });
67
67
  return Array.from(section.querySelectorAll('[role="button"]'))
68
68
  .map((row) => row.textContent ?? "")
69
- .filter((text) => text !== "New report");
69
+ .filter((text) => text !== "Report");
70
70
  };
71
71
 
72
72
  beforeEach(() => {
@@ -141,7 +141,7 @@ function mount(
141
141
  }
142
142
 
143
143
  const settled = () => screen.findByText("old");
144
- const NEW = { name: "New report" } as const;
144
+ const NEW = { name: "Add report" } as const;
145
145
 
146
146
  beforeEach(() => {
147
147
  clearCache();
@@ -254,12 +254,11 @@ const openNew = async (layout: "linear" | "grid" = "linear") => {
254
254
  await waitFor(() =>
255
255
  expect(screen.getByLabelText("Report title")).toHaveProperty(
256
256
  "value",
257
- "by category",
257
+ "By category",
258
258
  ),
259
259
  );
260
260
  if (layout === "grid") {
261
- fireEvent.mouseDown(screen.getByRole("combobox", { name: /Layout/ }));
262
- fireEvent.click(screen.getByRole("option", { name: /^Grid/ }));
261
+ fireEvent.click(screen.getByRole("radio", { name: "Grid" }));
263
262
  }
264
263
  };
265
264
 
@@ -284,8 +283,10 @@ describe("creating", () => {
284
283
  expect(screen.getByLabelText("Report title")).toBeDefined(),
285
284
  );
286
285
  expect(
287
- screen.getByRole("combobox", { name: /Layout/ }).textContent,
288
- ).toMatch(/^Linear/);
286
+ screen
287
+ .getByRole("radio", { name: "Linear" })
288
+ .getAttribute("aria-checked"),
289
+ ).toBe("true");
289
290
  });
290
291
 
291
292
  it("writes a linear report at the package root, refreshes the listings, and opens its editor", async () => {