@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
@@ -4,14 +4,20 @@
4
4
  import { Box, Button, Paper, Stack, Typography } from "@mui/material";
5
5
  import { Given } from "../../client";
6
6
  import { GivenValue } from "../../hooks/givenValue";
7
+ import { useFilterEditing } from "./filterEditing";
8
+ import {
9
+ AddFilterButton,
10
+ FilterButton,
11
+ FilterSettingsButton,
12
+ } from "./FilterButton";
7
13
  import { GivenInput } from "./GivenInput";
8
- import { usePublisherTheme } from "../../theme/ThemeContext";
9
14
 
10
15
  /**
11
16
  * How the control row is laid out.
12
17
  *
13
18
  * - `panel`: the vertical "Filters" block a notebook shows above its cells.
14
- * - `bar`: a horizontal filter bar above a dashboard grid.
19
+ * - `bar`: a report's row of filter buttons, one per control, each opening
20
+ * its control in a popover (`FilterButton`). Both report layouts use it.
15
21
  *
16
22
  * Two presentations of one control implementation, rather than two
17
23
  * implementations: a control gains a behavior (a suggest dropdown, an Apply
@@ -65,11 +71,10 @@ export function GivensPanel({
65
71
  apply,
66
72
  title,
67
73
  }: GivensPanelProps) {
68
- // Above the early return below, not down at its use site: the bar layout is
69
- // the only branch that paints a border, but a hook called conditionally is
70
- // a hook called on some renders and not others.
71
- const { theme } = usePublisherTheme();
72
- if (givens.length === 0) return null;
74
+ // In the builder the bar is also where filters are added, so it draws with
75
+ // none: an empty row is the "+ Filter" button alone.
76
+ const editing = useFilterEditing();
77
+ if (givens.length === 0 && !(editing && layout === "bar")) return null;
73
78
  // Some value actually SET, not merely some entry present. `paramsToGivens`
74
79
  // records `?X=` as a null entry, so counting entries offered Reset for a
75
80
  // control that is unset, and pressing it changed nothing and left the empty
@@ -77,14 +82,7 @@ export function GivensPanel({
77
82
  const hasValues = Array.from(values.values()).some((v) => v !== null);
78
83
 
79
84
  const inputs = givens.map((given) => (
80
- <Box
81
- key={given.name}
82
- sx={
83
- layout === "bar"
84
- ? { minWidth: 200, flex: "1 1 200px", maxWidth: 320 }
85
- : undefined
86
- }
87
- >
85
+ <Box key={given.name}>
88
86
  <GivenInput
89
87
  given={given}
90
88
  value={given.name ? values.get(given.name) : undefined}
@@ -120,37 +118,40 @@ export function GivensPanel({
120
118
  );
121
119
 
122
120
  if (layout === "bar") {
121
+ // A row of filter buttons with no box of its own: the controls are the
122
+ // edges, and a card around them was the one box on the page drawn around
123
+ // other boxes.
123
124
  return (
124
- <Paper
125
- elevation={0}
126
- sx={{
127
- p: 2,
128
- // The card edge, not MUI's `divider`: this row IS one of the
129
- // page's cards as far as a reader is concerned, and on
130
- // `divider` it stayed at the old hairline weight while the
131
- // cards under it darkened — the one box on the page outlined
132
- // differently from everything it sits above.
133
- border: theme.cardBorder,
134
- borderRadius: 1,
135
- // Border only, no raised fill — the same construction the
136
- // dashboard's cards use, so the control row reads as part of
137
- // the page rather than as a panel floating above it.
138
- backgroundColor: "transparent",
139
- }}
125
+ <Stack
126
+ direction="row"
127
+ role="group"
128
+ aria-label={title ?? "Filters"}
129
+ useFlexGap
130
+ sx={{ flexWrap: "wrap", alignItems: "center", gap: 1 }}
140
131
  >
141
- <Stack
142
- direction="row"
143
- alignItems="flex-start"
144
- spacing={2}
145
- useFlexGap
146
- sx={{ flexWrap: "wrap" }}
147
- >
148
- {inputs}
149
- <Box sx={{ flex: "0 0 auto", ml: "auto", pt: 0.5 }}>
150
- {actions}
151
- </Box>
152
- </Stack>
153
- </Paper>
132
+ {givens.map((given) => (
133
+ <FilterButton
134
+ key={given.name}
135
+ given={given}
136
+ value={given.name ? values.get(given.name) : undefined}
137
+ onChange={(next) => given.name && onChange(given.name, next)}
138
+ options={given.name ? options?.get(given.name) : undefined}
139
+ optionsLoading={optionsLoading}
140
+ optionsFailed={
141
+ given.name ? optionsFailed?.has(given.name) : undefined
142
+ }
143
+ />
144
+ ))}
145
+ {editing?.unrendered.map((filter) => (
146
+ <FilterSettingsButton
147
+ key={filter.name}
148
+ name={filter.name}
149
+ label={filter.label}
150
+ />
151
+ ))}
152
+ <AddFilterButton />
153
+ <Box sx={{ ml: "auto" }}>{actions}</Box>
154
+ </Stack>
154
155
  );
155
156
  }
156
157
 
@@ -0,0 +1,60 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { createContext, useContext } from "react";
5
+
6
+ /**
7
+ * What the report builder adds to a report's row of filter buttons, so the
8
+ * row a reader uses is also the one place a filter is configured: no second
9
+ * row of chips naming the same filters again.
10
+ *
11
+ * Provided by the builder around the host's control row; absent everywhere
12
+ * else, where the row is the reader's and offers no editing at all.
13
+ */
14
+ export interface FilterEditing {
15
+ /** The builder's word on one filter, by given name; undefined when it does not know the name. */
16
+ stateOf: (name: string) => FilterEditState | undefined;
17
+ /**
18
+ * Filters the file declares that the row has no control for (no tile reads
19
+ * them yet), shown after the row's own so they can still be configured or
20
+ * removed.
21
+ */
22
+ unrendered: { name: string; label: string }[];
23
+ /** Open a filter's settings: which tiles it applies to, its label and kind. */
24
+ onEdit: (name: string) => void;
25
+ /** Take a filter off the report. */
26
+ onRemove: (name: string) => void;
27
+ /** Declare a new filter, or bind one the model offers. */
28
+ onAdd: () => void;
29
+ /** Why adding is off; set, the add button is disabled and says why. */
30
+ addDisabledReason?: string;
31
+ /**
32
+ * Where the report opens each filter (`## artifact { givens { … } }`), as
33
+ * written in the file; undefined when it opens at the declared default.
34
+ * Any filter has one, the model's included: it is the report's to say.
35
+ */
36
+ startingValueOf?: (name: string) => string | undefined;
37
+ /** Open the report with this filter at `text` (as the file spells it), or at its default when undefined. */
38
+ setStartingValue?: (name: string, text: string | undefined) => void;
39
+ }
40
+
41
+ export interface FilterEditState {
42
+ /** Why a tile cannot take this filter's binding, when one cannot. */
43
+ problem?: string;
44
+ /** Where the filter is declared: this file, or the model it imports. */
45
+ origin: "dashboard" | "model";
46
+ /**
47
+ * Set when a tile reads the filter through the model rather than a binding
48
+ * in this file: why it can be set but not removed or configured here.
49
+ */
50
+ fixed?: string;
51
+ /** Open the model that sets it, when the host can. */
52
+ openModel?: () => void;
53
+ }
54
+
55
+ export const FilterEditingContext = createContext<FilterEditing | undefined>(
56
+ undefined,
57
+ );
58
+
59
+ /** The builder's filter editing, when the row is drawn inside the builder. */
60
+ export const useFilterEditing = () => useContext(FilterEditingContext);
@@ -0,0 +1,108 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import type { Given } from "../../client";
6
+ import { summarizeGivenValue } from "./filterSummary";
7
+ import {
8
+ encodeAtLeast,
9
+ encodeBetween,
10
+ encodeDayRange,
11
+ encodeFilterList,
12
+ encodeTimePreset,
13
+ } from "./filterValue";
14
+
15
+ const given = (over: Partial<Given>): Given => ({ name: "g", ...over });
16
+
17
+ describe("summarizeGivenValue", () => {
18
+ it("reads an unset picker as All, and an unset range as Any", () => {
19
+ expect(
20
+ summarizeGivenValue(
21
+ given({ type: "filter<string>", control: "multiselect" }),
22
+ null,
23
+ ),
24
+ ).toBe("All");
25
+ expect(summarizeGivenValue(given({ type: "filter<number>" }), null)).toBe(
26
+ "Any",
27
+ );
28
+ expect(summarizeGivenValue(given({ type: "boolean" }), undefined)).toBe(
29
+ "Any",
30
+ );
31
+ });
32
+
33
+ it("shows an unset given's default as its value, read the way its type reads", () => {
34
+ expect(
35
+ summarizeGivenValue(
36
+ given({ type: "date", default: "@2023-01-01" }),
37
+ null,
38
+ ),
39
+ ).toBe("Jan 1, 2023");
40
+ expect(
41
+ summarizeGivenValue(given({ type: "string", default: "'WN'" }), null),
42
+ ).toBe("WN");
43
+ });
44
+
45
+ it("lists picked values, shortening a long list to the first and a count", () => {
46
+ const type = "filter<string>";
47
+ expect(
48
+ summarizeGivenValue(
49
+ given({ type }),
50
+ encodeFilterList(["Outerwear", "Footwear"]),
51
+ ),
52
+ ).toBe("Outerwear, Footwear");
53
+ expect(
54
+ summarizeGivenValue(
55
+ given({ type }),
56
+ encodeFilterList(["Outerwear", "Footwear", "Dresses", "Swimwear"]),
57
+ ),
58
+ ).toBe("Outerwear +3");
59
+ });
60
+
61
+ it("reads number ranges and time presets", () => {
62
+ expect(
63
+ summarizeGivenValue(
64
+ given({ type: "filter<number>" }),
65
+ encodeAtLeast(50),
66
+ ),
67
+ ).toBe("≥ 50");
68
+ expect(
69
+ summarizeGivenValue(
70
+ given({ type: "filter<number>" }),
71
+ encodeBetween(10, 90),
72
+ ),
73
+ ).toBe("10–90");
74
+ expect(
75
+ summarizeGivenValue(
76
+ given({ type: "filter<date>" }),
77
+ encodeTimePreset("30d"),
78
+ ),
79
+ ).toBe("Last 30 days");
80
+ expect(
81
+ summarizeGivenValue(
82
+ given({ type: "filter<date>" }),
83
+ encodeDayRange("2024-01-01", "2024-03-31"),
84
+ ),
85
+ ).toBe("Jan 1, 2024 – Mar 31, 2024");
86
+ });
87
+
88
+ it("reads scalars plainly, and an explicit empty string as (empty)", () => {
89
+ expect(summarizeGivenValue(given({ type: "boolean" }), true)).toBe("Yes");
90
+ expect(summarizeGivenValue(given({ type: "number" }), 7)).toBe("7");
91
+ expect(
92
+ summarizeGivenValue(
93
+ given({ type: "date" }),
94
+ new Date("2023-01-01T00:00:00Z"),
95
+ ),
96
+ ).toBe("Jan 1, 2023");
97
+ expect(summarizeGivenValue(given({ type: "string" }), "")).toBe(
98
+ "(empty)",
99
+ );
100
+ });
101
+
102
+ it("truncates a long free-text value", () => {
103
+ const text = "a".repeat(60);
104
+ const shown = summarizeGivenValue(given({ type: "string" }), text);
105
+ expect(shown.length).toBe(28);
106
+ expect(shown.endsWith("…")).toBe(true);
107
+ });
108
+ });
@@ -0,0 +1,109 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { isRequiredGiven } from "./required";
5
+ import type { Given } from "../../client";
6
+ import type { GivenValue } from "../../hooks/givenValue";
7
+ import {
8
+ decodeAtLeast,
9
+ decodeBetween,
10
+ decodeDayRange,
11
+ decodeFilterList,
12
+ decodeTimePreset,
13
+ filterInnerType,
14
+ isFilterType,
15
+ isPlainFilterList,
16
+ TIME_PRESETS,
17
+ } from "./filterValue";
18
+ import { renderGivenDefault } from "./utils";
19
+
20
+ /** Longest summary a filter button shows before it shortens to "first +N". */
21
+ const MAX_SUMMARY_CHARS = 28;
22
+
23
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
24
+
25
+ const dayFormat = new Intl.DateTimeFormat("en-US", {
26
+ month: "short",
27
+ day: "numeric",
28
+ year: "numeric",
29
+ timeZone: "UTC",
30
+ });
31
+
32
+ /** `2023-01-01` → `Jan 1, 2023`; anything else unchanged. */
33
+ function formatDay(text: string): string {
34
+ if (!DAY.test(text)) return text;
35
+ const date = new Date(`${text}T00:00:00Z`);
36
+ return Number.isNaN(date.getTime()) ? text : dayFormat.format(date);
37
+ }
38
+
39
+ /** A list of picked values, shortened to fit a button: `Outerwear +2`. */
40
+ function summarizeList(values: string[]): string {
41
+ if (values.length === 0) return "";
42
+ const joined = values.join(", ");
43
+ if (joined.length <= MAX_SUMMARY_CHARS || values.length === 1)
44
+ return truncate(joined);
45
+ return `${truncate(values[0] ?? "")} +${values.length - 1}`;
46
+ }
47
+
48
+ function truncate(text: string): string {
49
+ return text.length > MAX_SUMMARY_CHARS
50
+ ? `${text.slice(0, MAX_SUMMARY_CHARS - 1)}…`
51
+ : text;
52
+ }
53
+
54
+ /** 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
+ // No default: nothing runs until it is set, so it does not read as "Any".
57
+ if (isRequiredGiven(given)) return "Required";
58
+ const type = given.type ?? "string";
59
+ const shown = renderGivenDefault(type, given.default);
60
+ if (shown !== undefined && shown !== "") return summarizeText(type, shown);
61
+ const inner = filterInnerType(type) ?? type;
62
+ return given.control === "select" ||
63
+ given.control === "multiselect" ||
64
+ inner === "string"
65
+ ? "All"
66
+ : "Any";
67
+ }
68
+
69
+ /** 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
+ const inner = filterInnerType(type);
73
+ if (inner === "string" && isPlainFilterList(text))
74
+ return summarizeList(decodeFilterList(text));
75
+ if (inner === "number") {
76
+ const between = decodeBetween(text);
77
+ if (between) return `${between[0]}–${between[1]}`;
78
+ const atLeast = decodeAtLeast(text);
79
+ if (atLeast !== undefined) return `≥ ${atLeast}`;
80
+ }
81
+ if (inner === "date" || inner === "timestamp" || inner === "timestamptz") {
82
+ const preset = decodeTimePreset(text);
83
+ if (preset)
84
+ return TIME_PRESETS.find((p) => p.key === preset)?.label ?? text;
85
+ const days = decodeDayRange(text);
86
+ if (days)
87
+ return `${formatDay(days.firstDay)} – ${formatDay(days.lastDay)}`;
88
+ }
89
+ return truncate(text);
90
+ }
91
+
92
+ /**
93
+ * The few words a filter button shows for its given's current value: `All`,
94
+ * `Outerwear +2`, `Jan 1, 2023`, `≥ 50`, `Last 30 days`. Unset, the model
95
+ * default stands in, read the same way, so a default looks like the value it
96
+ * is rather than a hint under the control. The full value is the popover's.
97
+ */
98
+ export function summarizeGivenValue(
99
+ given: Given,
100
+ value: GivenValue | undefined,
101
+ ): 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);
109
+ }
@@ -295,7 +295,7 @@ function zoneOffsetMinutes(zone: string | undefined): number | undefined {
295
295
  * back as unset. Naming the types that cannot hold an empty value keeps the two
296
296
  * in step as new types arrive.
297
297
  */
298
- function isEmptyStringMeaningful(type: string | undefined): boolean {
298
+ export function isEmptyStringMeaningful(type: string | undefined): boolean {
299
299
  return !EMPTY_MEANS_UNSET.has(type ?? "");
300
300
  }
301
301
 
@@ -0,0 +1,60 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import type { Given } from "../../client";
6
+ import {
7
+ missingRequiredGivens,
8
+ requiredPrompt,
9
+ waitingOn,
10
+ waitingText,
11
+ } from "./required";
12
+
13
+ const YEAR: Given = {
14
+ name: "YEAR",
15
+ label: "Recall Year",
16
+ type: "number",
17
+ required: true,
18
+ };
19
+ const MAKER: Given = {
20
+ name: "MAKER",
21
+ label: "Maker",
22
+ type: "filter<string>",
23
+ required: true,
24
+ };
25
+ const REGION: Given = { name: "REGION", type: "filter<string>", default: "" };
26
+
27
+ describe("required givens", () => {
28
+ it("are missing until set; an optional one never is", () => {
29
+ const missing = missingRequiredGivens([YEAR, MAKER, REGION], new Map());
30
+ expect(missing.map((g) => g.name)).toEqual(["YEAR", "MAKER"]);
31
+ });
32
+
33
+ it("count an empty filter as a value (All), but not an empty number", () => {
34
+ const missing = missingRequiredGivens(
35
+ [YEAR, MAKER],
36
+ new Map<string, string>([
37
+ ["YEAR", ""],
38
+ ["MAKER", ""],
39
+ ]),
40
+ );
41
+ expect(missing.map((g) => g.name)).toEqual(["YEAR"]);
42
+ });
43
+
44
+ it("count a value the host sets", () => {
45
+ expect(missingRequiredGivens([YEAR], new Map(), { YEAR: 2020 })).toEqual(
46
+ [],
47
+ );
48
+ });
49
+
50
+ it("say what to set, and which tiles wait", () => {
51
+ expect(requiredPrompt([YEAR, MAKER])).toBe(
52
+ "Pick a value for Recall Year and Maker to see this report.",
53
+ );
54
+ expect(waitingOn([YEAR, MAKER], ["MAKER"]).map((g) => g.name)).toEqual([
55
+ "MAKER",
56
+ ]);
57
+ expect(waitingOn([YEAR], undefined)).toEqual([]);
58
+ expect(waitingText([YEAR])).toBe("Waiting for Recall Year.");
59
+ });
60
+ });
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { Given } from "../../client";
5
+ import type { GivenValue } from "../../hooks/givenValue";
6
+ import { isEmptyStringMeaningful } from "./paramCodec";
7
+
8
+ /**
9
+ * Whether a given must be set before anything that reads it can run: the
10
+ * server says it declares no default (`required`), and Malloy then refuses
11
+ * the query ("Given 'X' has no value and no default").
12
+ *
13
+ * The explicit flag, not an absent `default`: a server or proxy that does not
14
+ * send `required` leaves every tile running as before, where reading absence
15
+ * would make every given look required on one that drops `default`.
16
+ */
17
+ export const isRequiredGiven = (given: Given): boolean =>
18
+ given.required === true;
19
+
20
+ /**
21
+ * No value yet. An empty string is a value only where the codec says it means
22
+ * something: for a `filter<…>` or a string it is "All", which a reader can
23
+ * pick on a required filter and must then see run; for a number or a date it
24
+ * is nothing.
25
+ */
26
+ const unset = (value: GivenValue | undefined, type: string | undefined) =>
27
+ value === undefined ||
28
+ value === null ||
29
+ (value === "" && !isEmptyStringMeaningful(type));
30
+
31
+ /**
32
+ * The page's required controls that have no value yet, in row order. A tile
33
+ * that reads one is not run; the page asks for them instead.
34
+ */
35
+ export function missingRequiredGivens(
36
+ specs: readonly Given[],
37
+ values: ReadonlyMap<string, GivenValue>,
38
+ /** Values the host sets itself, which count as set. */
39
+ hostGivens?: Readonly<Record<string, unknown>>,
40
+ ): Given[] {
41
+ return specs.filter(
42
+ (spec) =>
43
+ spec.name !== undefined &&
44
+ isRequiredGiven(spec) &&
45
+ unset(values.get(spec.name), spec.type) &&
46
+ (hostGivens?.[spec.name] === undefined ||
47
+ hostGivens[spec.name] === null),
48
+ );
49
+ }
50
+
51
+ /** The required givens among `missing` that a tile reading `reads` waits on. */
52
+ export function waitingOn(
53
+ missing: readonly Given[],
54
+ reads: readonly string[] | undefined,
55
+ ): Given[] {
56
+ if (!reads || missing.length === 0) return [];
57
+ const names = new Set(reads);
58
+ return missing.filter((spec) => spec.name && names.has(spec.name));
59
+ }
60
+
61
+ const labelOf = (given: Given) => given.label ?? given.name ?? "";
62
+
63
+ function joinAnd(labels: readonly string[]): string {
64
+ return labels.length < 2
65
+ ? labels.join("")
66
+ : `${labels.slice(0, -1).join(", ")} and ${labels[labels.length - 1]}`;
67
+ }
68
+
69
+ /** What the page says while a required filter is unset: "Pick a value for Recall Year to see this report." */
70
+ export function requiredPrompt(missing: readonly Given[]): string {
71
+ const labels = missing.map(labelOf);
72
+ return `Pick a value for ${joinAnd(labels)} to see this report.`;
73
+ }
74
+
75
+ /** What a tile waiting on required filters says in place of its result. */
76
+ export function waitingText(waiting: readonly Given[]): string {
77
+ return `Waiting for ${joinAnd(waiting.map(labelOf))}.`;
78
+ }
@@ -12,6 +12,15 @@ export { AppDialog } from "./AppDialog";
12
12
  export { UnsavedChangesDialog } from "./UnsavedChangesDialog";
13
13
  export { BackLink } from "./BackLink";
14
14
  export { NarrowEditGate } from "./NarrowEditGate";
15
+ // For a host that holds a report as text and resolves its own givens.
16
+ export { localGivenSpec } from "./ReportBuilder/localGiven";
17
+ export { malloyLiteral } from "../utils/malloyLiteral";
18
+ export {
19
+ clearReportDraft,
20
+ draftStorageAvailable,
21
+ reportDraftKey,
22
+ type ReportDraftTarget,
23
+ } from "./ReportBuilder/useReportDraft";
15
24
  // The Console's palette, and the two maps drawn from it. Exported so a host
16
25
  // paints its own chrome — the Publisher app's theme included — from the same
17
26
  // hues rather than picking a near-miss beside them.
@@ -206,6 +206,8 @@ describe("the version reaches what the manifest drives", () => {
206
206
  });
207
207
  await waitFor(() => expect(cacheKeys("queryResult").length).toBe(1));
208
208
 
209
+ // The control sits in its filter button's popover.
210
+ fireEvent.click(await screen.findByRole("button", { name: /^REGION: / }));
209
211
  fireEvent.change(await screen.findByLabelText("REGION"), {
210
212
  target: { value: "CA" },
211
213
  });
@@ -234,7 +236,7 @@ describe("the version reaches what the manifest drives", () => {
234
236
 
235
237
  render(dashboardAt(), { wrapper: serverWrapper });
236
238
 
237
- await screen.findByLabelText("REGION");
239
+ await screen.findByRole("button", { name: /^REGION: / });
238
240
  expect(screen.queryByRole("button", { name: /^Explore / })).toBeNull();
239
241
  });
240
242
  });
@@ -9,7 +9,7 @@
9
9
  * and its line below.
10
10
  */
11
11
  export { Dashboard, type DashboardProps } from "./Dashboard";
12
- export { default as Notebook } from "./Notebook";
12
+ export { default as Notebook } from "./malloynb/Notebook";
13
13
  export { type DocumentKind } from "./kindAdapter";
14
14
  export {
15
15
  documentRoute,