@malloy-publisher/sdk 0.9.10 → 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 (257) hide show
  1. package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
  2. package/dist/{RenderedResult-Dp1Qdajz.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 +7493 -6769
  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 -34
  15. package/dist/components/Dashboard/TileCard.d.ts +10 -3
  16. package/dist/components/Dashboard/useStuck.d.ts +15 -7
  17. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
  18. package/dist/components/Package/PackageProblems.d.ts +14 -0
  19. package/dist/components/RemoveBadge.d.ts +40 -0
  20. package/dist/components/Report/Report.d.ts +13 -4
  21. package/dist/components/Report/ReportPage.d.ts +60 -0
  22. package/dist/components/Report/layoutRules.d.ts +32 -0
  23. package/dist/components/Report/reportQuery.d.ts +30 -0
  24. package/dist/components/Report/telemetry.d.ts +0 -2
  25. package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
  26. package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
  27. package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
  28. package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
  29. package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
  30. package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
  31. package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
  32. package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
  33. package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
  34. package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -8
  35. package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
  36. package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
  37. package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
  38. package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
  39. package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
  40. package/dist/components/ReportBuilder/TileMenu.d.ts +12 -9
  41. package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
  42. package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
  43. package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
  44. package/dist/components/ReportBuilder/catalog.d.ts +2 -4
  45. package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
  46. package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
  47. package/dist/components/ReportBuilder/preview.d.ts +17 -2
  48. package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
  49. package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
  50. package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
  51. package/dist/components/ReportBuilder/sortable.d.ts +4 -3
  52. package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
  53. package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
  54. package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
  55. package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
  56. package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
  57. package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
  58. package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
  59. package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
  60. package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
  61. package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
  62. package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
  63. package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
  64. package/dist/components/ServerProvider.d.ts +9 -0
  65. package/dist/components/controlTokens.d.ts +45 -0
  66. package/dist/components/drill/markDrillableCells.d.ts +1 -1
  67. package/dist/components/given/FilterButton.d.ts +35 -0
  68. package/dist/components/given/GivensPanel.d.ts +2 -1
  69. package/dist/components/given/filterEditing.d.ts +54 -0
  70. package/dist/components/given/filterSummary.d.ts +9 -0
  71. package/dist/components/given/paramCodec.d.ts +11 -0
  72. package/dist/components/given/required.d.ts +25 -0
  73. package/dist/components/index.d.ts +3 -0
  74. package/dist/components/legacy/index.d.ts +1 -1
  75. package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
  76. package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
  77. package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
  78. package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
  79. package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
  80. package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
  81. package/dist/components/styles.d.ts +0 -2
  82. package/dist/hooks/useQueryResult.d.ts +7 -0
  83. package/dist/index.cjs.js +16 -19
  84. package/dist/index.es.js +8324 -7769
  85. package/dist/theme/ThemeContext.d.ts +8 -1
  86. package/dist/theme/classes.d.ts +49 -0
  87. package/dist/theme/index.d.ts +2 -0
  88. package/dist/theme/types.d.ts +7 -0
  89. package/dist/theme/ui.d.ts +75 -0
  90. package/dist/{useCompiledDocument-BMPDvdFx.es.js → useCompiledDocument-7j5cBjQd.es.js} +8669 -7851
  91. package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
  92. package/package.json +2 -2
  93. package/src/builder-entry.ts +9 -0
  94. package/src/components/AppDialog.tsx +23 -0
  95. package/src/components/Dashboard/DashboardGrid.tsx +39 -17
  96. package/src/components/Dashboard/DashboardTile.tsx +19 -2
  97. package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
  98. package/src/components/Dashboard/DashboardView.tsx +137 -155
  99. package/src/components/Dashboard/RowsDialog.tsx +1 -2
  100. package/src/components/Dashboard/TileCard.tsx +28 -10
  101. package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
  102. package/src/components/Dashboard/useStuck.ts +28 -17
  103. package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
  104. package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
  105. package/src/components/Package/NewDocumentDialog.tsx +383 -119
  106. package/src/components/Package/Package.artifacts.spec.tsx +1 -1
  107. package/src/components/Package/Package.create.spec.tsx +7 -6
  108. package/src/components/Package/Package.tsx +10 -7
  109. package/src/components/Package/PackageProblems.spec.tsx +41 -0
  110. package/src/components/Package/PackageProblems.tsx +95 -0
  111. package/src/components/Prose.tsx +12 -7
  112. package/src/components/RemoveBadge.tsx +94 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +5 -9
  114. package/src/components/RenderedResult/ResultPanel.tsx +59 -3
  115. package/src/components/Report/Report.spec.tsx +50 -32
  116. package/src/components/Report/Report.telemetry.spec.tsx +0 -45
  117. package/src/components/Report/Report.tsx +45 -77
  118. package/src/components/Report/ReportPage.tsx +168 -0
  119. package/src/components/Report/layoutRules.spec.ts +35 -0
  120. package/src/components/Report/layoutRules.ts +55 -0
  121. package/src/components/Report/reportQuery.ts +53 -0
  122. package/src/components/Report/telemetry.ts +0 -2
  123. package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
  124. package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
  125. package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
  126. package/src/components/ReportBuilder/BuilderDialogs.tsx +28 -39
  127. package/src/components/ReportBuilder/BuilderGrid.tsx +31 -29
  128. package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
  129. package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
  130. package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
  131. package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
  132. package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
  133. package/src/components/ReportBuilder/FilterStrip.tsx +130 -151
  134. package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
  135. package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
  136. package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
  137. package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
  138. package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -15
  139. package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
  140. package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
  141. package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
  142. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +37 -31
  143. package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
  144. package/src/components/ReportBuilder/ReportBuilder.tsx +292 -117
  145. package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
  146. package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
  147. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
  148. package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
  149. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
  150. package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
  151. package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
  152. package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
  153. package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
  154. package/src/components/ReportBuilder/TileFrame.tsx +212 -75
  155. package/src/components/ReportBuilder/TileMenu.tsx +241 -140
  156. package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
  157. package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
  158. package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
  159. package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
  160. package/src/components/ReportBuilder/builderControls.ts +164 -0
  161. package/src/components/ReportBuilder/builderReport.ts +1 -2
  162. package/src/components/ReportBuilder/catalog.ts +10 -26
  163. package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
  164. package/src/components/ReportBuilder/localGiven.ts +56 -0
  165. package/src/components/ReportBuilder/preview.spec.ts +125 -5
  166. package/src/components/ReportBuilder/preview.ts +60 -44
  167. package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
  168. package/src/components/ReportBuilder/readDocument.ts +14 -11
  169. package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
  170. package/src/components/ReportBuilder/readForEditor.ts +4 -26
  171. package/src/components/ReportBuilder/reportTag.ts +28 -7
  172. package/src/components/ReportBuilder/sortable.tsx +15 -7
  173. package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
  174. package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
  175. package/src/components/ReportBuilder/testing/inline.ts +25 -5
  176. package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
  177. package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
  178. package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
  179. package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
  180. package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
  181. package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
  182. package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
  183. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
  184. package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
  185. package/src/components/ReportBuilder/useExitGuard.ts +16 -0
  186. package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
  187. package/src/components/ReportBuilder/useFilterForm.ts +5 -1
  188. package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
  189. package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
  190. package/src/components/ReportBuilder/useReportDraft.ts +292 -0
  191. package/src/components/ReportBuilder/useReportEditor.ts +3 -12
  192. package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
  193. package/src/components/ReportBuilder/useTileEditing.ts +43 -12
  194. package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
  195. package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
  196. package/src/components/ReportBuilder/widthLabel.ts +26 -0
  197. package/src/components/ServerProvider.tsx +11 -0
  198. package/src/components/controlTokens.ts +47 -0
  199. package/src/components/drill/markDrillableCells.ts +2 -1
  200. package/src/components/given/FilterButton.spec.tsx +143 -0
  201. package/src/components/given/FilterButton.tsx +478 -0
  202. package/src/components/given/GivenInput.spec.tsx +47 -0
  203. package/src/components/given/GivenInput.tsx +20 -2
  204. package/src/components/given/GivensPanel.spec.tsx +11 -3
  205. package/src/components/given/GivensPanel.tsx +45 -44
  206. package/src/components/given/filterEditing.ts +60 -0
  207. package/src/components/given/filterSummary.spec.ts +108 -0
  208. package/src/components/given/filterSummary.ts +109 -0
  209. package/src/components/given/paramCodec.ts +1 -1
  210. package/src/components/given/required.spec.ts +60 -0
  211. package/src/components/given/required.ts +78 -0
  212. package/src/components/index.ts +9 -0
  213. package/src/components/legacy/Dashboard.spec.tsx +3 -1
  214. package/src/components/legacy/index.ts +1 -1
  215. package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
  216. package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
  217. package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
  218. package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
  219. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
  220. package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
  221. package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
  222. package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
  223. package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
  224. package/src/components/legacy/malloynb/cellKind.ts +24 -0
  225. package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
  226. package/src/components/styles.ts +0 -18
  227. package/src/hooks/useGivensState.ts +7 -3
  228. package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
  229. package/src/hooks/useQueryResult.ts +26 -1
  230. package/src/theme/ThemeContext.tsx +21 -1
  231. package/src/theme/classes.ts +52 -0
  232. package/src/theme/index.ts +8 -0
  233. package/src/theme/resolveTheme.ts +3 -0
  234. package/src/theme/types.ts +7 -0
  235. package/src/theme/ui.spec.tsx +91 -0
  236. package/src/theme/ui.ts +115 -0
  237. package/dist/RenderedResult-BcgYjkZ0.cjs.js +0 -153
  238. package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
  239. package/dist/components/Notebook/cellKind.d.ts +0 -20
  240. package/dist/components/Report/LinearReport.d.ts +0 -18
  241. package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
  242. package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
  243. package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
  244. package/dist/useCompiledDocument-UY28ITET.cjs.js +0 -141
  245. package/src/components/Notebook/cellKind.spec.ts +0 -199
  246. package/src/components/Notebook/cellKind.ts +0 -74
  247. package/src/components/Report/LinearReport.tsx +0 -71
  248. package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
  249. package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
  250. package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
  251. package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
  252. package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
  253. package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
  254. package/src/components/legacy/Notebook.served.spec.tsx +0 -183
  255. /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
  256. /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
  257. /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
@@ -0,0 +1,478 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { reportClasses } from "../../theme/classes";
5
+ import AddIcon from "@mui/icons-material/Add";
6
+ import CloseIcon from "@mui/icons-material/Close";
7
+ import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
8
+ import {
9
+ Box,
10
+ Button,
11
+ ButtonBase,
12
+ IconButton,
13
+ Popover,
14
+ Tooltip,
15
+ Typography,
16
+ } from "@mui/material";
17
+ import type { ReactNode } from "react";
18
+ import { useState } from "react";
19
+ import { MOTION_FAST, reducedMotionSx } from "../../theme/motion";
20
+ import { usePublisherTheme } from "../../theme/ThemeContext";
21
+ import { edgeColor, hoverEdgeColor } from "../controlTokens";
22
+ import { RemoveBadge, removeBadgeRevealSx } from "../RemoveBadge";
23
+ import { useFilterEditing } from "./filterEditing";
24
+ import { isRequiredGiven } from "./required";
25
+ import { summarizeGivenValue } from "./filterSummary";
26
+ import { GivenInput, type GivenInputProps } from "./GivenInput";
27
+ import { givenToParam } from "./paramCodec";
28
+
29
+ /**
30
+ * One filter in a report's control row: a 32px button that names the filter
31
+ * and says what it is set to (`Category All`, `Ordered since Jan 1, 2023`),
32
+ * and opens the filter's full control in a popover.
33
+ *
34
+ * The row reads at a glance and costs one line, where a form field per filter
35
+ * cost two (the field, then a `Default:` caption under it) and wrapped. Every
36
+ * kind of control (picker, range, time range, date, boolean, text) opens the
37
+ * same way, so the row has one shape whatever the filters are.
38
+ *
39
+ * Set to a value of its own, the button is tinted in the accent and carries a
40
+ * clear (×), which drops the value back to the model default, as the control's
41
+ * own × does. The default itself reads as a value, not as a hint.
42
+ *
43
+ * Inside the builder ({@link useFilterEditing}) the same button is where the
44
+ * filter is configured: a remove badge on its corner while it is hovered or
45
+ * focused, and its settings from the popover. Distinct from the clear (×):
46
+ * that one empties the value, the badge takes the filter off the report.
47
+ */
48
+ export function FilterButton(props: GivenInputProps) {
49
+ const { given, value, onChange } = props;
50
+ const { theme } = usePublisherTheme();
51
+ const ui = theme.ui;
52
+ const editing = useFilterEditing();
53
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
54
+ const name = given.name ?? "";
55
+ const label = given.label ?? name;
56
+ const set = value !== null && value !== undefined;
57
+ const summary = summarizeGivenValue(given, value);
58
+ const open = anchor !== null;
59
+ const state = editing?.stateOf(name);
60
+ const problem = state?.problem;
61
+ // Read through the model: set here as in the reader, changed only there.
62
+ const fixed = state?.fixed;
63
+ const button = (
64
+ <FilterShell
65
+ name={name}
66
+ set={set}
67
+ open={open}
68
+ problem={problem}
69
+ fixed={fixed !== undefined}
70
+ required={!set && isRequiredGiven(given)}
71
+ >
72
+ <ButtonBase
73
+ aria-haspopup="dialog"
74
+ aria-expanded={open}
75
+ aria-label={`${label}: ${summary}`}
76
+ onClick={(event) => setAnchor(event.currentTarget)}
77
+ sx={(mui) => ({
78
+ height: "100%",
79
+ borderRadius: ui.radius.control,
80
+ pl: "10px",
81
+ pr: set ? "4px" : "8px",
82
+ gap: "6px",
83
+ fontFamily: "inherit",
84
+ fontSize: ui.type.control.fontSize,
85
+ lineHeight: 1,
86
+ minWidth: 0,
87
+ color: mui.palette.text.primary,
88
+ })}
89
+ >
90
+ <Box
91
+ component="span"
92
+ sx={(mui) => ({
93
+ color: set ? theme.accent : mui.palette.text.secondary,
94
+ whiteSpace: "nowrap",
95
+ })}
96
+ >
97
+ {label}
98
+ </Box>
99
+ <Box
100
+ component="span"
101
+ sx={{
102
+ fontWeight: ui.type.control.fontWeight,
103
+ whiteSpace: "nowrap",
104
+ overflow: "hidden",
105
+ textOverflow: "ellipsis",
106
+ }}
107
+ >
108
+ {summary}
109
+ </Box>
110
+ {!set && (
111
+ <ExpandMoreIcon
112
+ aria-hidden
113
+ sx={(mui) => ({
114
+ fontSize: 16,
115
+ color: mui.palette.text.secondary,
116
+ transform: open ? "rotate(180deg)" : "none",
117
+ })}
118
+ />
119
+ )}
120
+ </ButtonBase>
121
+ {set && (
122
+ <IconButton
123
+ aria-label={`Clear ${label}`}
124
+ onClick={() => onChange(null)}
125
+ sx={{
126
+ width: 22,
127
+ height: 22,
128
+ mr: "4px",
129
+ borderRadius: "4px",
130
+ color: theme.accent,
131
+ }}
132
+ >
133
+ <CloseIcon sx={{ fontSize: 14 }} />
134
+ </IconButton>
135
+ )}
136
+ </FilterShell>
137
+ );
138
+ return (
139
+ <>
140
+ {problem ? <Tooltip title={problem}>{button}</Tooltip> : button}
141
+ <Popover
142
+ className={reportClasses.filterPopover}
143
+ open={open}
144
+ anchorEl={anchor}
145
+ onClose={() => setAnchor(null)}
146
+ anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
147
+ transformOrigin={{ vertical: "top", horizontal: "left" }}
148
+ slotProps={{
149
+ paper: {
150
+ role: "dialog",
151
+ "aria-label": `${label} filter`,
152
+ sx: {
153
+ mt: 0.75,
154
+ p: 1.5,
155
+ width: 300,
156
+ maxWidth: "calc(100vw - 32px)",
157
+ boxSizing: "border-box",
158
+ borderRadius: ui.radius.tile,
159
+ border: theme.cardBorder,
160
+ boxShadow: theme.shadow.lift,
161
+ },
162
+ },
163
+ }}
164
+ >
165
+ <GivenInput {...props} />
166
+ {editing && (
167
+ <Box
168
+ sx={(mui) => ({
169
+ mt: 1.5,
170
+ pt: 1,
171
+ borderTop: `1px solid ${mui.palette.divider}`,
172
+ display: "flex",
173
+ flexDirection: "column",
174
+ alignItems: "flex-start",
175
+ gap: 0.5,
176
+ })}
177
+ >
178
+ {problem && (
179
+ <Typography
180
+ sx={{ ...ui.type.caption, color: "warning.main" }}
181
+ >
182
+ {problem}
183
+ </Typography>
184
+ )}
185
+ {fixed !== undefined && (
186
+ <Typography
187
+ sx={(mui) => ({
188
+ ...ui.type.caption,
189
+ color: mui.palette.text.secondary,
190
+ })}
191
+ >
192
+ {fixed}
193
+ </Typography>
194
+ )}
195
+ <StartingValue
196
+ name={name}
197
+ type={given.type}
198
+ text={startingTextOf(value, given.type)}
199
+ />
200
+ {fixed === undefined ? (
201
+ <Button
202
+ size="small"
203
+ aria-label={`Edit filter ${name}`}
204
+ aria-haspopup="dialog"
205
+ onClick={() => {
206
+ setAnchor(null);
207
+ editing.onEdit(name);
208
+ }}
209
+ sx={{ px: 0.75, minWidth: 0, ...ui.type.control }}
210
+ >
211
+ Filter settings…
212
+ </Button>
213
+ ) : (
214
+ state?.openModel && (
215
+ <Button
216
+ size="small"
217
+ onClick={() => {
218
+ setAnchor(null);
219
+ state.openModel?.();
220
+ }}
221
+ sx={{ px: 0.75, minWidth: 0, ...ui.type.control }}
222
+ >
223
+ Open the model
224
+ </Button>
225
+ )
226
+ )}
227
+ </Box>
228
+ )}
229
+ </Popover>
230
+ </>
231
+ );
232
+ }
233
+
234
+ /**
235
+ * A filter's value as the report's `givens { … }` writes it: as the query
236
+ * endpoint spells it, the URL's spelling. For a `filter<…>` that is the filter
237
+ * text itself, not an `f'…'` literal: the server unwraps a literal without
238
+ * un-escaping it, so `f'O\'Brien'` would start the report at `O\'Brien`.
239
+ * Undefined when there is no value to start from.
240
+ */
241
+ function startingTextOf(
242
+ value: GivenInputProps["value"],
243
+ type: string | undefined,
244
+ ): string | undefined {
245
+ if (value === undefined || value === null) return undefined;
246
+ return givenToParam(value, type);
247
+ }
248
+
249
+ /** A starting value as it compares: a filter's `f'…'` literal, as a file may write it, unwrapped. */
250
+ function startingComparable(
251
+ text: string | undefined,
252
+ type: string | undefined,
253
+ ): string | undefined {
254
+ if (text === undefined || !type?.startsWith("filter<")) return text;
255
+ return /^f(['"])([\s\S]*)\1$/.exec(text)?.[2] ?? text;
256
+ }
257
+
258
+ /**
259
+ * Where the report opens this filter, in the builder: "Open the report with
260
+ * this value", or back to its default. Any filter has one, the model's
261
+ * included, since where a report opens is the report's to say.
262
+ */
263
+ function StartingValue({
264
+ name,
265
+ type,
266
+ text,
267
+ }: {
268
+ name: string;
269
+ type: string | undefined;
270
+ /** The current value as the file would spell it; undefined when unset. */
271
+ text: string | undefined;
272
+ }) {
273
+ const editing = useFilterEditing();
274
+ const ui = usePublisherTheme().theme.ui;
275
+ if (!editing?.setStartingValue) return null;
276
+ const set = editing.setStartingValue;
277
+ const start = startingComparable(editing.startingValueOf?.(name), type);
278
+ const buttonSx = { px: 0.75, minWidth: 0, ...ui.type.control };
279
+ return (
280
+ <>
281
+ {start !== undefined && start === text && (
282
+ <Typography
283
+ sx={(mui) => ({
284
+ ...ui.type.caption,
285
+ color: mui.palette.text.secondary,
286
+ px: 0.75,
287
+ })}
288
+ >
289
+ The report opens with this value.
290
+ </Typography>
291
+ )}
292
+ {text !== undefined && text !== start && (
293
+ <Button size="small" onClick={() => set(name, text)} sx={buttonSx}>
294
+ Open the report with this value
295
+ </Button>
296
+ )}
297
+ {start !== undefined && (
298
+ <Button
299
+ size="small"
300
+ onClick={() => set(name, undefined)}
301
+ sx={buttonSx}
302
+ >
303
+ Open at the default instead
304
+ </Button>
305
+ )}
306
+ </>
307
+ );
308
+ }
309
+
310
+ /**
311
+ * The button's box: its edge, its tint when set, and in the builder the
312
+ * remove badge on its corner. Shared with {@link UnusedFilterButton} so a
313
+ * filter no tile reads yet sits in the row in the same shape.
314
+ */
315
+ function FilterShell({
316
+ name,
317
+ set = false,
318
+ open = false,
319
+ unused = false,
320
+ problem,
321
+ fixed = false,
322
+ required = false,
323
+ children,
324
+ }: {
325
+ name: string;
326
+ set?: boolean;
327
+ open?: boolean;
328
+ unused?: boolean;
329
+ problem?: string;
330
+ /** The model's filter: no remove badge, since the builder cannot take it off. */
331
+ fixed?: boolean;
332
+ /** Required and unset: edged in the warning colour, since nothing that reads it runs. */
333
+ required?: boolean;
334
+ children: ReactNode;
335
+ }) {
336
+ const { theme } = usePublisherTheme();
337
+ const ui = theme.ui;
338
+ const editing = useFilterEditing();
339
+ return (
340
+ <Box
341
+ className={reportClasses.filter}
342
+ data-filter={name}
343
+ data-set={set || undefined}
344
+ data-problem={problem ? true : undefined}
345
+ data-required={required || undefined}
346
+ sx={(mui) => ({
347
+ position: "relative",
348
+ display: "inline-flex",
349
+ alignItems: "center",
350
+ height: ui.size.control,
351
+ boxSizing: "border-box",
352
+ borderRadius: ui.radius.control,
353
+ border: "1px solid",
354
+ borderStyle: unused ? "dashed" : "solid",
355
+ borderColor:
356
+ problem || required
357
+ ? mui.palette.warning.main
358
+ : set
359
+ ? `color-mix(in srgb, ${theme.accent} 45%, transparent)`
360
+ : open
361
+ ? theme.accent
362
+ : edgeColor(theme.cardBorder),
363
+ bgcolor: set
364
+ ? `color-mix(in srgb, ${theme.accent} 8%, ${mui.palette.background.paper})`
365
+ : mui.palette.background.paper,
366
+ opacity: unused ? 0.75 : 1,
367
+ transition: `border-color ${MOTION_FAST}`,
368
+ ...reducedMotionSx,
369
+ "&:hover": {
370
+ borderColor:
371
+ set || open || problem
372
+ ? undefined
373
+ : hoverEdgeColor(theme.cardBorder, theme.tileTitle),
374
+ },
375
+ maxWidth: "100%",
376
+ ...removeBadgeRevealSx,
377
+ })}
378
+ >
379
+ {children}
380
+ {editing && !fixed && (
381
+ <RemoveBadge
382
+ label={`Remove filter ${name}`}
383
+ onRemove={() => editing.onRemove(name)}
384
+ />
385
+ )}
386
+ </Box>
387
+ );
388
+ }
389
+
390
+ /**
391
+ * A filter the row has no live control for, as a button that opens its
392
+ * settings. Mostly a filter the file declares that no tile reads yet
393
+ * (`unused`): dashed and faint, saying so in words, and its settings are where
394
+ * it is bound to tiles. Also every filter when the builder has no live row to
395
+ * draw (no server to run one), so filters can still be edited.
396
+ */
397
+ export function FilterSettingsButton({
398
+ name,
399
+ label,
400
+ unused = true,
401
+ }: {
402
+ name: string;
403
+ label: string;
404
+ unused?: boolean;
405
+ }) {
406
+ const editing = useFilterEditing();
407
+ const ui = usePublisherTheme().theme.ui;
408
+ if (!editing) return null;
409
+ const problem = editing.stateOf(name)?.problem;
410
+ const shell = (
411
+ <FilterShell name={name} unused={unused} problem={problem}>
412
+ <ButtonBase
413
+ aria-label={`Edit filter ${name}`}
414
+ aria-haspopup="dialog"
415
+ onClick={() => editing.onEdit(name)}
416
+ sx={(mui) => ({
417
+ height: "100%",
418
+ borderRadius: ui.radius.control,
419
+ px: "10px",
420
+ gap: "6px",
421
+ fontFamily: "inherit",
422
+ fontSize: ui.type.control.fontSize,
423
+ lineHeight: 1,
424
+ color: mui.palette.text.secondary,
425
+ whiteSpace: "nowrap",
426
+ })}
427
+ >
428
+ <span>{label}</span>
429
+ {unused && (
430
+ <Box component="span" sx={{ fontStyle: "italic" }}>
431
+ Unused
432
+ </Box>
433
+ )}
434
+ </ButtonBase>
435
+ </FilterShell>
436
+ );
437
+ return problem ? <Tooltip title={problem}>{shell}</Tooltip> : shell;
438
+ }
439
+
440
+ /** The row's last slot in the builder: declare or bind another filter. */
441
+ export function AddFilterButton() {
442
+ const { theme } = usePublisherTheme();
443
+ const ui = theme.ui;
444
+ const editing = useFilterEditing();
445
+ if (!editing) return null;
446
+ const disabled = editing.addDisabledReason !== undefined;
447
+ return (
448
+ // A disabled button takes no pointer events, so the tooltip saying why
449
+ // sits on a wrapper.
450
+ <Tooltip title={editing.addDisabledReason ?? ""}>
451
+ <span>
452
+ <Button
453
+ variant="outlined"
454
+ startIcon={<AddIcon />}
455
+ aria-label="Add filter"
456
+ aria-haspopup="dialog"
457
+ disabled={disabled}
458
+ onClick={() => editing.onAdd()}
459
+ sx={(mui) => ({
460
+ height: ui.size.control,
461
+ minHeight: ui.size.control,
462
+ px: 1.25,
463
+ borderRadius: ui.radius.control,
464
+ borderStyle: "dashed",
465
+ borderColor: edgeColor(theme.cardBorder),
466
+ color: mui.palette.text.secondary,
467
+ boxShadow: "none",
468
+ ...ui.type.control,
469
+ "& .MuiButton-startIcon": { mr: 0.5 },
470
+ "& .MuiButton-startIcon svg": { fontSize: 16 },
471
+ })}
472
+ >
473
+ Filter
474
+ </Button>
475
+ </span>
476
+ </Tooltip>
477
+ );
478
+ }
@@ -373,6 +373,53 @@ describe("GivenInput: multi-pick needs a type that can carry several values", ()
373
373
  });
374
374
  });
375
375
 
376
+ describe("GivenInput: a multi-pick keeps its picks when the reader clicks away", () => {
377
+ const given: Given = {
378
+ name: "BRAND",
379
+ type: "filter<string>",
380
+ control: "multiselect",
381
+ };
382
+
383
+ it("does not take back the option just picked", () => {
384
+ // The list stays open after a pick with that option highlighted, and
385
+ // MUI's blur used to pick it again, which in a multi-pick removes it.
386
+ const onChange = mock((_next: GivenValue) => {});
387
+ render(
388
+ <GivenInput
389
+ given={given}
390
+ value={undefined}
391
+ onChange={onChange}
392
+ options={["Aurora", "Levi"]}
393
+ />,
394
+ );
395
+ const input = screen.getByRole("combobox");
396
+ fireEvent.mouseDown(input);
397
+ // A pointer hovers an option before it clicks it, which highlights it.
398
+ const aurora = screen.getByRole("option", { name: "Aurora" });
399
+ fireEvent.mouseMove(aurora);
400
+ fireEvent.click(aurora);
401
+ expect(onChange).toHaveBeenLastCalledWith("Aurora");
402
+ fireEvent.blur(input);
403
+ expect(onChange).toHaveBeenCalledTimes(1);
404
+ });
405
+
406
+ it("still keeps text typed but not picked", () => {
407
+ const onChange = mock((_next: GivenValue) => {});
408
+ render(
409
+ <GivenInput
410
+ given={given}
411
+ value={undefined}
412
+ onChange={onChange}
413
+ options={["Aurora"]}
414
+ />,
415
+ );
416
+ const input = screen.getByRole("combobox");
417
+ fireEvent.change(input, { target: { value: "Zephyr" } });
418
+ fireEvent.blur(input);
419
+ expect(onChange).toHaveBeenLastCalledWith("Zephyr");
420
+ });
421
+ });
422
+
376
423
  describe("GivenInput: the whole type x control matrix", () => {
377
424
  // Six guards decide which widget a given gets (`pickableType`,
378
425
  // `multiplePickable`, `filterIsPickable`, `bareDate`, `dateIsPickable`,
@@ -25,7 +25,7 @@ import { DatePicker } from "@mui/x-date-pickers/DatePicker";
25
25
  import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
26
26
  import dayjs from "dayjs";
27
27
  import utc from "dayjs/plugin/utc";
28
- import { type ReactNode, useEffect, useState } from "react";
28
+ import { type FocusEvent, type ReactNode, useEffect, useState } from "react";
29
29
  import { Given } from "../../client";
30
30
  import { paramToGiven, pickedDayToUtc } from "./paramCodec";
31
31
  import { GivenValue } from "../../hooks/givenValue";
@@ -329,7 +329,15 @@ export function GivenInput({
329
329
  // `freeSolo` Autocomplete without this discards it on blur, so a
330
330
  // value that is legal but absent from `suggest` could be typed and
331
331
  // then silently vanish.
332
- autoSelect
332
+ //
333
+ // Single-pick only. On blur MUI's `autoSelect` also picks the
334
+ // HIGHLIGHTED option while the list is open, and a multi-pick
335
+ // keeps its list open after a pick with that option still
336
+ // highlighted, so clicking away picked it a second time, which in
337
+ // a multi-pick takes it back out: choose Aurora, click the page,
338
+ // and the filter was gone. A multi-pick keeps typed text itself,
339
+ // in the input's blur below.
340
+ autoSelect={!multiple}
333
341
  options={options ?? []}
334
342
  loading={optionsLoading}
335
343
  noOptionsText={
@@ -389,6 +397,16 @@ export function GivenInput({
389
397
  </>
390
398
  ),
391
399
  },
400
+ htmlInput: {
401
+ ...params.inputProps,
402
+ onBlur: (event: FocusEvent<HTMLInputElement>) => {
403
+ params.inputProps.onBlur?.(event);
404
+ if (!multiple) return;
405
+ const typed = event.target.value.trim();
406
+ if (typed !== "" && !selected.includes(typed))
407
+ commit([...selected, typed]);
408
+ },
409
+ },
392
410
  }}
393
411
  />
394
412
  )}
@@ -149,14 +149,22 @@ describe("layout and title", () => {
149
149
  expect(screen.queryAllByText("Filters")).toHaveLength(0);
150
150
  });
151
151
 
152
- it("renders the bar layout with its controls and no heading", () => {
152
+ it("renders the bar layout as filter buttons that open their controls, with no heading", () => {
153
153
  render(<GivensPanel {...props} layout="bar" />);
154
- // The bar is meant to sit inline above a dashboard, so it carries the
155
- // controls but drops the heading the panel layout shows.
154
+ // The bar sits inline above a report: a button per control, naming it
155
+ // and its value, and no heading. The control is in its popover.
156
+ expect(screen.queryByRole("combobox")).toBeNull();
157
+ fireEvent.click(screen.getByRole("button", { name: /^BRAND: / }));
156
158
  expect(screen.getByRole("combobox")).toBeDefined();
157
159
  expect(screen.queryAllByText("Filters")).toHaveLength(0);
158
160
  });
159
161
 
162
+ it("offers no editing outside the builder", () => {
163
+ render(<GivensPanel {...props} layout="bar" />);
164
+ expect(screen.queryByLabelText(/^Remove filter/)).toBeNull();
165
+ expect(screen.queryByLabelText("Add filter")).toBeNull();
166
+ });
167
+
160
168
  it("still offers Reset from the bar layout", () => {
161
169
  let reset = 0;
162
170
  render(