@malloy-publisher/sdk 0.0.248 → 0.0.249

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 (98) hide show
  1. package/README.md +32 -17
  2. package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
  3. package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
  4. package/dist/client/api.d.ts +297 -6
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +74 -70
  7. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  9. package/dist/components/Dashboard/index.d.ts +2 -0
  10. package/dist/components/Notebook/Notebook.d.ts +46 -8
  11. package/dist/components/Notebook/NotebookCell.d.ts +37 -3
  12. package/dist/components/Notebook/runPlan.d.ts +29 -0
  13. package/dist/components/Notebook/types.d.ts +10 -0
  14. package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
  15. package/dist/components/Package/Package.d.ts +1 -4
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
  18. package/dist/components/ResultsDialog.d.ts +4 -1
  19. package/dist/components/ServerProvider.d.ts +2 -1
  20. package/dist/components/click_helper.d.ts +10 -1
  21. package/dist/components/drill/index.d.ts +3 -0
  22. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  23. package/dist/components/drill/resolveDrill.d.ts +159 -0
  24. package/dist/components/drill/useDrill.d.ts +63 -0
  25. package/dist/components/given/GivenInput.d.ts +27 -3
  26. package/dist/components/given/GivensPanel.d.ts +36 -7
  27. package/dist/components/given/filterValue.d.ts +117 -0
  28. package/dist/components/given/index.d.ts +1 -1
  29. package/dist/components/given/paramCodec.d.ts +60 -0
  30. package/dist/components/index.d.ts +4 -1
  31. package/dist/components/styles.d.ts +23 -0
  32. package/dist/constants/docLinks.d.ts +6 -0
  33. package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
  34. package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
  35. package/dist/hooks/givenValue.d.ts +10 -0
  36. package/dist/hooks/index.d.ts +3 -1
  37. package/dist/hooks/useGivensState.d.ts +64 -0
  38. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  39. package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
  40. package/dist/index-CWQXhe0D.cjs.js +338 -0
  41. package/dist/index.cjs.js +1 -1
  42. package/dist/index.es.js +77 -62
  43. package/dist/theme/types.d.ts +9 -0
  44. package/package.json +3 -1
  45. package/src/components/Connections/AddConnectionDialog.tsx +10 -1
  46. package/src/components/Dashboard/Dashboard.tsx +395 -0
  47. package/src/components/Dashboard/DashboardTile.tsx +150 -0
  48. package/src/components/Dashboard/index.ts +2 -0
  49. package/src/components/Home/Home.tsx +114 -23
  50. package/src/components/Notebook/Notebook.tsx +444 -390
  51. package/src/components/Notebook/NotebookCell.tsx +117 -3
  52. package/src/components/Notebook/runPlan.spec.ts +152 -0
  53. package/src/components/Notebook/runPlan.ts +64 -0
  54. package/src/components/Notebook/types.ts +11 -0
  55. package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
  56. package/src/components/Package/ContentTypeIcon.tsx +77 -6
  57. package/src/components/Package/Package.tsx +148 -38
  58. package/src/components/RenderedResult/RenderedResult.tsx +309 -19
  59. package/src/components/RenderedResult/ResultContainer.tsx +28 -1
  60. package/src/components/ResultsDialog.tsx +5 -0
  61. package/src/components/ServerProvider.tsx +2 -0
  62. package/src/components/click_helper.ts +14 -1
  63. package/src/components/drill/index.ts +25 -0
  64. package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
  65. package/src/components/drill/markDrillableCells.spec.ts +106 -0
  66. package/src/components/drill/markDrillableCells.ts +311 -0
  67. package/src/components/drill/resolveDrill.spec.ts +446 -0
  68. package/src/components/drill/resolveDrill.ts +372 -0
  69. package/src/components/drill/useDrill.tsx +200 -0
  70. package/src/components/given/GivenInput.spec.tsx +495 -15
  71. package/src/components/given/GivenInput.tsx +562 -30
  72. package/src/components/given/GivensPanel.spec.tsx +172 -0
  73. package/src/components/given/GivensPanel.tsx +139 -32
  74. package/src/components/given/filterValue.spec.ts +361 -0
  75. package/src/components/given/filterValue.ts +204 -0
  76. package/src/components/given/index.ts +5 -1
  77. package/src/components/given/paramCodec.spec.ts +854 -0
  78. package/src/components/given/paramCodec.ts +480 -0
  79. package/src/components/index.ts +4 -1
  80. package/src/components/styles.ts +27 -3
  81. package/src/constants/docLinks.spec.ts +51 -0
  82. package/src/constants/docLinks.ts +26 -0
  83. package/src/hooks/givenValue.ts +10 -0
  84. package/src/hooks/index.ts +6 -4
  85. package/src/hooks/useGivensState.spec.ts +446 -0
  86. package/src/hooks/useGivensState.ts +337 -0
  87. package/src/hooks/useSuggestOptions.spec.ts +109 -0
  88. package/src/hooks/useSuggestOptions.ts +260 -0
  89. package/src/theme/buildTableCssVars.ts +4 -0
  90. package/src/theme/resolveTheme.spec.ts +13 -0
  91. package/src/theme/resolveTheme.ts +3 -0
  92. package/src/theme/types.ts +9 -0
  93. package/test/README.md +16 -10
  94. package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
  95. package/dist/hooks/useGivensForm.d.ts +0 -35
  96. package/dist/index-MES4MGpQ.cjs.js +0 -309
  97. package/src/hooks/useGivensForm.spec.ts +0 -99
  98. package/src/hooks/useGivensForm.ts +0 -107
@@ -1,14 +1,18 @@
1
1
  import ClearIcon from "@mui/icons-material/Clear";
2
2
  import {
3
3
  Autocomplete,
4
+ Box,
4
5
  Checkbox,
6
+ CircularProgress,
5
7
  FormControl,
6
8
  FormControlLabel,
7
9
  FormHelperText,
8
10
  IconButton,
9
11
  InputAdornment,
12
+ Slider,
10
13
  Stack,
11
14
  TextField,
15
+ Typography,
12
16
  } from "@mui/material";
13
17
  import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
14
18
  import { DatePicker } from "@mui/x-date-pickers/DatePicker";
@@ -16,15 +20,57 @@ import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
16
20
  import dayjs from "dayjs";
17
21
  import utc from "dayjs/plugin/utc";
18
22
  import { Given } from "../../client";
19
- import { GivenValue } from "../../hooks/useGivensForm";
23
+ import { paramToGiven, pickedDayToUtc } from "./paramCodec";
24
+ import { GivenValue } from "../../hooks/givenValue";
25
+ import {
26
+ decodeAtLeast,
27
+ decodeFilterList,
28
+ encodeAtLeast,
29
+ encodeFilterList,
30
+ filterInnerType,
31
+ isFilterType,
32
+ isPlainFilterList,
33
+ } from "./filterValue";
20
34
  import { renderGivenDefault } from "./utils";
21
35
 
22
36
  dayjs.extend(utc);
23
37
 
38
+ /**
39
+ * Metrics of MUI's small outlined input, which the box-less controls match so a
40
+ * row of mixed widgets lines up: the horizontal inset of an outlined field's
41
+ * content and helper text, and the height of the field itself.
42
+ */
43
+ const INPUT_CONTENT_INSET = 14;
44
+ const SLIDER_FIELD_HEIGHT = 42;
45
+
24
46
  export interface GivenInputProps {
47
+ /**
48
+ * The declaration, which carries its own presentation (`label`, `control`,
49
+ * `rangeMin`, `rangeMax`) from the control tags on it
50
+ * (`# label="Brand" control=select range_min=0`).
51
+ *
52
+ * Presentation never changes what the given means, just which widget stands
53
+ * in for typing the value by hand. An untagged given falls back to the
54
+ * widget its type implies, which is what notebooks have always rendered.
55
+ */
25
56
  given: Given;
26
57
  value: GivenValue | undefined;
27
58
  onChange: (next: GivenValue) => void;
59
+ /**
60
+ * Options for a `select`/`multiselect`, already resolved from the given's
61
+ * `suggest` query. Resolved by the caller rather than fetched here so this
62
+ * stays a presentational component: the suggest query is an ordinary query
63
+ * against the host's model, which the widget has no business knowing about.
64
+ */
65
+ options?: string[];
66
+ optionsLoading?: boolean;
67
+ /**
68
+ * The `suggest` query for this given failed. Distinguished from an empty
69
+ * `options` because a dropdown looks identical either way, and the two mean
70
+ * opposite things: no values in the data, versus no answer from the server.
71
+ * Free text still works, so the control degrades rather than locking up.
72
+ */
73
+ optionsFailed?: boolean;
28
74
  }
29
75
 
30
76
  /**
@@ -72,14 +118,21 @@ function annotationHelperText(given: Given): string | undefined {
72
118
  * including an empty string — so typing the field empty (a deliberate `""`)
73
119
  * is distinguishable from unset by the × being present.
74
120
  * - revert → the × affordance calls `onChange(null)`, which drops the override
75
- * (useGivensForm deletes the key) and returns the widget to its unset state.
121
+ * (useGivensState deletes the key) and returns the widget to its unset state.
76
122
  *
77
123
  * A given's model default (if any) is also surfaced as an always-visible
78
124
  * `Default: …` helper line on every widget — including the boolean checkbox,
79
125
  * which gets a wrapping FormControl for the slot.
80
126
  */
81
- export function GivenInput({ given, value, onChange }: GivenInputProps) {
82
- const label = given.name ?? "";
127
+ export function GivenInput({
128
+ given,
129
+ value,
130
+ onChange,
131
+ options,
132
+ optionsLoading,
133
+ optionsFailed,
134
+ }: GivenInputProps) {
135
+ const label = given.label ?? given.name ?? "";
83
136
  const type = given.type ?? "string";
84
137
  const helperText = annotationHelperText(given);
85
138
  const defaultDisplay = renderGivenDefault(type, given.default);
@@ -103,12 +156,463 @@ export function GivenInput({ given, value, onChange }: GivenInputProps) {
103
156
  </>
104
157
  ) : undefined;
105
158
 
159
+ // A picker, when the declaration asked for one. Placed ahead of the
160
+ // type branches because `control=` is an explicit instruction and the type
161
+ // is only an inference.
162
+ //
163
+ // But this picker only speaks two languages: plain strings, and the STRING
164
+ // filter grammar. It commits through `encodeFilterList`, which is
165
+ // `StringFilterExpression.unparse`. So `control=select` on anything else is
166
+ // refused rather than honoured, because honouring it corrupts the value:
167
+ // a `filter<date>` or `filter<number>` would receive string-grammar escaping
168
+ // that the temporal and number parsers reject outright, and a `number`,
169
+ // `date` or `boolean` given would receive a string that `givensToRequest`
170
+ // forwards verbatim for Malloy to refuse. Falling through gives the given the
171
+ // widget its type implies, which is the behaviour before `control=` existed.
172
+ // `control=` IS populated now, by `readGivenControlSpec` on the server, so
173
+ // this guard is live rather than pre-emptive.
174
+ const pickableType = type === "string" || filterInnerType(type) === "string";
175
+ const filterIsPickable =
176
+ !isFilterType(type) ||
177
+ typeof value !== "string" ||
178
+ isPlainFilterList(value);
179
+ // And multi-pick only for a `filter<…>`, which is the one type that can carry
180
+ // several values in one string. A plain `string` given cannot hold a list at
181
+ // all: `GivenValue` admits no array, and `givenToParam` refuses one rather
182
+ // than joining it, because the codec cannot read a join back. So a
183
+ // `multiselect` on a plain string given renders as a single-pick instead of
184
+ // emitting something that cannot survive the address bar.
185
+ /**
186
+ * A value that is in force but that this control cannot render.
187
+ *
188
+ * Every typed branch has the same hazard: the control substitutes a blank
189
+ * for a value of the wrong shape, so the value goes on filtering every cell
190
+ * while the box looks empty. Shown here rather than per branch, because
191
+ * handling it three different ways is how the date branch ended up with a
192
+ * revert and the number branch without one.
193
+ *
194
+ * Read-only on purpose: an editable version swapped itself for the real
195
+ * control the moment the typed text first parsed, taking the cursor with it.
196
+ */
197
+ const unrepresentable = (what: string) => (
198
+ <TextField
199
+ label={label}
200
+ value={String(value)}
201
+ error
202
+ inputProps={{ readOnly: true }}
203
+ helperText={
204
+ <>
205
+ {`Not a ${what}. Clear it to pick one.`}
206
+ {helperNode ? <br /> : null}
207
+ {helperNode}
208
+ </>
209
+ }
210
+ slotProps={{
211
+ input: {
212
+ endAdornment: <ClearAdornment onClear={() => onChange(null)} />,
213
+ },
214
+ }}
215
+ fullWidth
216
+ size="small"
217
+ />
218
+ );
219
+
220
+ const multiplePickable = isFilterType(type);
221
+ const multiple = given.control === "multiselect" && multiplePickable;
222
+ const filtered = isFilterType(type);
223
+ const pickerControl =
224
+ given.control === "select" || given.control === "multiselect";
225
+ // A filter carries its selection as one string ("Nike, Levi's"); a plain
226
+ // array-typed given carries a real array.
227
+ //
228
+ // Guarded by `pickerControl` because it is read only by the picker below and
229
+ // by the condition guarding it. Computing it for every given would decode a
230
+ // filter on every render of a control that never shows one.
231
+ const selected: string[] = !pickerControl
232
+ ? []
233
+ : filtered
234
+ ? typeof value === "string"
235
+ ? decodeFilterList(value)
236
+ : []
237
+ : typeof value === "string" && value !== ""
238
+ ? [value]
239
+ : [];
240
+
241
+ if (
242
+ pickerControl &&
243
+ pickableType &&
244
+ // A picker that cannot represent the current filter would silently
245
+ // rewrite it on the next edit: `-Nike` decodes to one opaque chip and
246
+ // re-encodes as a literal, inverting what the filter means. Fall through
247
+ // to the text box instead, where the author's filter stays visible and
248
+ // editable as written.
249
+ filterIsPickable &&
250
+ // Same reasoning, different cause: a single-pick control has room for one
251
+ // value and the model's filter holds several. It rendered the first and
252
+ // dropped the rest as soon as the reader picked anything.
253
+ !(!multiple && selected.length > 1)
254
+ ) {
255
+ const commit = (next: string[]) => {
256
+ // ASK the encoder what survived; do not predict it from `next.length`.
257
+ // `encodeFilterList` drops any value with no non-whitespace character,
258
+ // so a single blank-looking pick (a run of spaces, a tab, an NBSP, all
259
+ // ordinary in scraped data and passed through untouched by
260
+ // `readOptionValues`) has length 1, skipped the revert arm below, and
261
+ // encoded to `""`: the EMPTY filter, sent as an explicit "match
262
+ // everything" override while the control redrew showing the model
263
+ // default as a ghost. This is the identical drift that made a blank
264
+ // cell drill to every row, at a second call site: `drillValueToFilter`
265
+ // was fixed to ask the encoder and this one still predicted it.
266
+ const encoded = filtered ? encodeFilterList(next) : undefined;
267
+ if (next.length === 0 || encoded === "") {
268
+ // `null` for every type, which is what the × means everywhere else
269
+ // in this file: drop the override and let the model's own value
270
+ // stand. This arm used to send `""` for a filter, the empty filter,
271
+ // meaning "match everything" as an explicit override. Same button,
272
+ // same given, opposite result set from the text box's ×, and
273
+ // nothing on screen said which one you were about to get.
274
+ //
275
+ // FORECLOSED by choosing revert: a reader cannot override a
276
+ // DECLARED default with "match everything", because the only
277
+ // gesture for it now means revert. The honest fix is a separate
278
+ // affordance rather than two meanings for one ×. This is now
279
+ // REACHABLE: `control=` is populated server-side and pickers render,
280
+ // so a given with a declared default and a picker hits it.
281
+ onChange(null);
282
+ return;
283
+ }
284
+ // One value for a non-filter given, never the array. `GivenValue`
285
+ // admits no array at all now, and the URL codec could not round-trip
286
+ // one anyway: `givenToParam` refuses it rather than joining on `,`,
287
+ // because reading it back yields the joined string, not the list.
288
+ onChange(filtered ? (encoded as string) : next[0]);
289
+ };
290
+
291
+ return (
292
+ <Autocomplete
293
+ multiple={multiple}
294
+ // Picking one value out of several should not put the list away;
295
+ // MUI closes on select by default, which makes "and also Aurora"
296
+ // cost a second click to reopen.
297
+ disableCloseOnSelect={multiple}
298
+ // Free text keeps the control from being a cage: the suggest query
299
+ // returns the common values, not necessarily every legal one.
300
+ freeSolo
301
+ // MUI hides the dropdown arrow whenever `freeSolo` is set, which
302
+ // left a control that HAS a list of values looking exactly like a
303
+ // plain text box: nothing on it said the list existed, so the only
304
+ // way to find the options was to guess that clicking would reveal
305
+ // them. Reported independently by a reader as "the controls render
306
+ // as text boxes rather than dropdowns"; the options were being
307
+ // fetched and offered correctly the whole time, and only the
308
+ // affordance was missing. Same principle as `markDrillableCells`:
309
+ // something you can act on has to look like it.
310
+ forcePopupIcon
311
+ // Keeps text the reader typed but did not pick from the list. A
312
+ // `freeSolo` Autocomplete without this discards it on blur, so a
313
+ // value that is legal but absent from `suggest` could be typed and
314
+ // then silently vanish.
315
+ autoSelect
316
+ options={options ?? []}
317
+ loading={optionsLoading}
318
+ noOptionsText={
319
+ optionsFailed ? "Options unavailable" : "No matching values"
320
+ }
321
+ value={multiple ? selected : (selected[0] ?? null)}
322
+ onChange={(_event, next) =>
323
+ commit(
324
+ next === null
325
+ ? []
326
+ : Array.isArray(next)
327
+ ? (next as string[])
328
+ : [next as string],
329
+ )
330
+ }
331
+ renderInput={(params) => (
332
+ <TextField
333
+ {...params}
334
+ label={label}
335
+ size="small"
336
+ // The model's own default when it has one, as a ghost, the
337
+ // way every other unset control shows it. A hardcoded "All"
338
+ // told the reader nothing would be filtered while the query
339
+ // was about to run on the declared default.
340
+ //
341
+ // Except when an explicit `""` is in force. That is the EMPTY
342
+ // filter, so the default is precisely what is NOT running,
343
+ // and showing it as a ghost made the control assert one
344
+ // filter while the query used another.
345
+ placeholder={
346
+ selected.length !== 0
347
+ ? undefined
348
+ : value === ""
349
+ ? "All"
350
+ : (defaultDisplay ?? "All")
351
+ }
352
+ error={optionsFailed}
353
+ helperText={
354
+ optionsFailed ? (
355
+ <>
356
+ Could not load the options for this control. Type a
357
+ value to filter anyway.
358
+ {helperNode ? <br /> : null}
359
+ {helperNode}
360
+ </>
361
+ ) : (
362
+ helperNode
363
+ )
364
+ }
365
+ slotProps={{
366
+ input: {
367
+ ...params.InputProps,
368
+ endAdornment: (
369
+ <>
370
+ {optionsLoading && <CircularProgress size={16} />}
371
+ {params.InputProps.endAdornment}
372
+ </>
373
+ ),
374
+ },
375
+ }}
376
+ />
377
+ )}
378
+ fullWidth
379
+ />
380
+ );
381
+ }
382
+
383
+ // A slider, when the declaration bounded the range. Only a lower bound is
384
+ // expressible as a filter here (see `encodeAtLeast`), so this reads as
385
+ // "at least", which is what a threshold control is for.
386
+ const numericFilter =
387
+ isFilterType(type) && filterInnerType(type) === "number";
388
+ const { rangeMin, rangeMax } = given;
389
+ // A slider can only represent `>= N`, so a `filter<number>` carrying anything
390
+ // else (a range, an upper bound, a negation) falls through to the text box.
391
+ // Otherwise `decodeAtLeast` returns undefined, the slider claims "Any" while a
392
+ // filter is in force, and the first drag silently replaces the author's filter
393
+ // with a threshold. Same principle as the picker and the date guards above.
394
+ const sliderIsRepresentable =
395
+ !numericFilter ||
396
+ value === undefined ||
397
+ value === null ||
398
+ value === "" ||
399
+ (typeof value === "string" && decodeAtLeast(value) !== undefined);
400
+ if (
401
+ (numericFilter || type === "number") &&
402
+ rangeMin !== undefined &&
403
+ rangeMax !== undefined &&
404
+ sliderIsRepresentable
405
+ ) {
406
+ const current = numericFilter
407
+ ? typeof value === "string"
408
+ ? decodeAtLeast(value)
409
+ : undefined
410
+ : typeof value === "number"
411
+ ? value
412
+ : undefined;
413
+ // Same hazard as the number and date branches: a value that cannot be
414
+ // placed on the track would otherwise read as "Any" while still being
415
+ // sent. Live rather than latent: `readGivenControlSpec` populates
416
+ // `rangeMin`/`rangeMax` from the declaration's own tags.
417
+ if (
418
+ current === undefined &&
419
+ value !== undefined &&
420
+ value !== null &&
421
+ value !== ""
422
+ ) {
423
+ return unrepresentable("number");
424
+ }
425
+ // An unset control rests at the low end, which is the no-op threshold.
426
+ const position = current ?? rangeMin;
427
+ // `""` on a filter given is an explicit "no threshold" OVERRIDE, not an
428
+ // absence: `paramToGiven` keeps it because the empty string is a value a
429
+ // filter can mean, and `givensToRequest` sends it. Counting it as unset
430
+ // drew "Any" with no clear affordance, so the reader could see neither
431
+ // that an override was in force nor any way back to the model's default.
432
+ // An explicit empty filter is an override with NO threshold, which is a
433
+ // third state: not unset, and not `≥ position` either. Printing
434
+ // `≥ rangeMin` for it asserted a lower bound nobody had chosen, just as
435
+ // counting it unset had hidden that an override was in force at all.
436
+ const emptyFilterOverride = numericFilter && value === "";
437
+ const isOverridden = current !== undefined || emptyFilterOverride;
438
+ // TWO LIMITATIONS here, both reachable as soon as a given carries
439
+ // `rangeMin`/`rangeMax`, and both about the plain `number` arm rather than
440
+ // the filter arm. Written when no server populated those fields; slice 6
441
+ // now does, so treat these as live rather than theoretical.
442
+ // An unset control rests its thumb at `rangeMin` while the
443
+ // readout shows the model default, so the two disagree whenever the
444
+ // default is not the floor; and MUI fires no onChange for a click at the
445
+ // thumb's existing position, so the floor cannot be selected from the
446
+ // resting state. Fixing either means seeding the thumb from the default,
447
+ // which needs a default that parses as a number and a decision about what
448
+ // to show when it does not.
449
+ return (
450
+ <FormControl fullWidth>
451
+ {/* A slider is the one control with no box around it, so it has to
452
+ borrow the outlined inputs' metrics to sit in a row with them:
453
+ their content is inset 14px and their field is 42px tall, and
454
+ a control that matches both puts its helper text on the same
455
+ line as its neighbours'. Left to itself the label started at
456
+ the column edge and the helper sat 10px lower than the rest,
457
+ which is most of what made a mixed control row look crooked. */}
458
+ <Box
459
+ sx={{
460
+ height: SLIDER_FIELD_HEIGHT,
461
+ px: `${INPUT_CONTENT_INSET}px`,
462
+ display: "flex",
463
+ flexDirection: "column",
464
+ justifyContent: "center",
465
+ }}
466
+ >
467
+ <Stack direction="row" alignItems="center" spacing={1}>
468
+ <Typography variant="body2" color="text.secondary" noWrap>
469
+ {label}
470
+ </Typography>
471
+ <Typography variant="body2" sx={{ fontWeight: 600 }}>
472
+ {/* `≥ N` only for a FILTER, whose value IS a lower
473
+ bound. A plain `number` given is an ordinary value, and
474
+ the onChange below says so by committing `picked`
475
+ rather than a threshold, so labelling it `≥` described
476
+ a query nobody was running. */}
477
+ {!isOverridden
478
+ ? numericFilter
479
+ ? "Any"
480
+ : (defaultDisplay ?? "Unset")
481
+ : emptyFilterOverride
482
+ ? "Any"
483
+ : numericFilter
484
+ ? `≥ ${position}`
485
+ : String(position)}
486
+ </Typography>
487
+ {isOverridden && (
488
+ <IconButton
489
+ size="small"
490
+ aria-label="clear value"
491
+ // `null`, like every other × in this file: revert the
492
+ // override. It used to send `""` for a filter, which
493
+ // `decodeAtLeast` reads back as undefined, so the
494
+ // control redrew as "Any" and hid this button while the
495
+ // given was still explicitly set to the empty filter.
496
+ // The reader could neither see the override nor undo it.
497
+ onClick={() => onChange(null)}
498
+ sx={{ p: 0 }}
499
+ >
500
+ <ClearIcon fontSize="small" />
501
+ </IconButton>
502
+ )}
503
+ </Stack>
504
+ <Slider
505
+ size="small"
506
+ min={rangeMin}
507
+ max={rangeMax}
508
+ value={position}
509
+ valueLabelDisplay="auto"
510
+ aria-label={label}
511
+ // MUI pads a slider vertically for a touch target, which is
512
+ // 26px this control cannot spare; the row above already
513
+ // gives the thumb somewhere to be.
514
+ sx={{ py: 0, mt: 0.5 }}
515
+ onChange={(_event, next) => {
516
+ const picked = Array.isArray(next) ? next[0] : next;
517
+ // Back at the floor is no threshold at all for a FILTER,
518
+ // not `>= min`, so dragging left the whole way clears
519
+ // rather than leaving a filter that reads as a constraint.
520
+ //
521
+ // A plain `number` given is not a threshold, so its floor
522
+ // is an ordinary value and clearing there made the minimum
523
+ // the one number on the scale the reader could not pick.
524
+ if (numericFilter && picked <= rangeMin) {
525
+ onChange(null);
526
+ return;
527
+ }
528
+ onChange(numericFilter ? encodeAtLeast(picked) : picked);
529
+ }}
530
+ />
531
+ </Box>
532
+ {helperNode && (
533
+ <FormHelperText sx={{ mx: `${INPUT_CONTENT_INSET}px` }}>
534
+ {helperNode}
535
+ </FormHelperText>
536
+ )}
537
+ </FormControl>
538
+ );
539
+ }
540
+
541
+ // A date-typed filter gets the same picker a plain date given gets. The
542
+ // value is filter syntax, but a bare ISO date is valid filter syntax for
543
+ // "on that day", so the round trip is direct.
544
+ const dateFilterInner = isFilterType(type)
545
+ ? filterInnerType(type)
546
+ : undefined;
547
+ const isDateFilter =
548
+ dateFilterInner === "date" ||
549
+ dateFilterInner === "timestamp" ||
550
+ dateFilterInner === "timestamptz";
551
+ // Only a bare `YYYY-MM-DD` is the picker's own spelling; anything else is a
552
+ // filter expression the picker cannot represent. Unset is fine, since the
553
+ // picker simply shows nothing.
554
+ //
555
+ // An explicit `""` is NOT fine and used to be allowed here. It is the empty
556
+ // filter, a live override that `givensToRequest` sends, and a DatePicker
557
+ // renders it byte-identical to unset: blank field, `Default: …` helper, and
558
+ // no clear button, because MUI emits none for a field with no value. So the
559
+ // screen said the model default was in force while the query matched every
560
+ // row, and there was no way back. Falling through to the text box is the
561
+ // remedy this file already uses for a filter a control cannot represent:
562
+ // there the value is visible as written and the × reverts it.
563
+ const bareDate =
564
+ typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value);
565
+ const dateIsPickable = value === undefined || value === null || bareDate;
566
+ // An unrepresentable date filter falls through to the text box below, for the
567
+ // same reason a non-list string filter does: a range like
568
+ // `2024-01-01 to 2024-02-01` handed whole to `dayjs.utc` parses as its
569
+ // leading date, so the picker would claim a single wrong day while a range
570
+ // was in force. The text box shows the filter as written, and editable.
571
+ if (isDateFilter && dateIsPickable) {
572
+ const parsed = bareDate ? dayjs.utc(value as string) : null;
573
+ return (
574
+ <LocalizationProvider dateAdapter={AdapterDayjs}>
575
+ <DatePicker
576
+ label={label}
577
+ value={parsed?.isValid() ? parsed : null}
578
+ // Cleared means UNSET, `null`, not an empty filter expression.
579
+ // `""` is a value for a filter given (the empty string is
580
+ // meaningful there), so it reached the wire as a filter of no
581
+ // characters instead of dropping the override.
582
+ onChange={(next) =>
583
+ onChange(next ? next.format("YYYY-MM-DD") : null)
584
+ }
585
+ slotProps={{
586
+ textField: {
587
+ fullWidth: true,
588
+ size: "small",
589
+ helperText: helperNode,
590
+ },
591
+ field: { clearable: true, onClear: () => onChange(null) },
592
+ }}
593
+ />
594
+ </LocalizationProvider>
595
+ );
596
+ }
597
+
106
598
  if (type === "boolean") {
107
599
  // Three states for a boolean. When unset, reflect the model DEFAULT so the
108
600
  // box shows what the query will actually run with (not a misleading
109
601
  // unchecked). A toggle is an explicit true/false override; the revert (×)
110
602
  // — shown only when overridden — drops the override back to the default.
111
603
  const isOverridden = typeof value === "boolean";
604
+ // A link carrying `?FLAG=yes` reaches here as a string, which `paramToGiven`
605
+ // passes through on purpose. Without this the checkbox rendered the model
606
+ // DEFAULT for it, so the box said one thing while `givensToRequest` sent
607
+ // "yes" and every cell failed, with nothing on screen to explain why.
608
+ // No `value !== ""` carve-out here, unlike the number branch it was copied
609
+ // from. `paramToGiven` returns null for an empty `boolean` parameter, so
610
+ // `""` cannot reach a checkbox from a URL or a host; if one ever did, a
611
+ // checkbox has no empty state to show it in, and saying so beats drawing
612
+ // the model default over a value that is still being sent.
613
+ if (!isOverridden && value !== undefined && value !== null) {
614
+ return unrepresentable("true or false");
615
+ }
112
616
  const defaultChecked = given.default?.trim() === "true";
113
617
  const checked = isOverridden ? value : defaultChecked;
114
618
  return (
@@ -146,6 +650,13 @@ export function GivenInput({ given, value, onChange }: GivenInputProps) {
146
650
  // non-number renders blank (see `num` above), and keying the revert off
147
651
  // that blank left the user no way to clear it.
148
652
  const isOverridden = value !== undefined && value !== null;
653
+ // `""` is an empty box, not an unreadable value. `paramToGiven` now reads
654
+ // `?N=` as UNSET so it no longer arrives here at all, but a host passing
655
+ // values in directly still can, and calling that "Not a number" would put
656
+ // a red error over a field showing nothing.
657
+ if (isOverridden && value !== "" && typeof value !== "number") {
658
+ return unrepresentable("number");
659
+ }
149
660
  return (
150
661
  <TextField
151
662
  label={label}
@@ -171,7 +682,41 @@ export function GivenInput({ given, value, onChange }: GivenInputProps) {
171
682
  }
172
683
 
173
684
  if (type === "date" || type === "timestamp" || type === "timestamptz") {
174
- const dateValue = value instanceof Date ? dayjs.utc(value) : null;
685
+ // A string is read as a date first. `# drill { to=self }` onto a date
686
+ // given hands over a bare `YYYY-MM-DD` string, not a Date, so treating
687
+ // any non-Date as unreadable painted an error over a value the product
688
+ // itself had just produced.
689
+ const asDate =
690
+ value instanceof Date
691
+ ? value
692
+ : typeof value === "string"
693
+ ? ((parsed) => (parsed instanceof Date ? parsed : null))(
694
+ paramToGiven(type, value),
695
+ )
696
+ : null;
697
+ const dateValue = asDate ? dayjs.utc(asDate) : null;
698
+ // Same lesson as `number` above, and it bit here too. A value the codec
699
+ // cannot read (a shared link carrying `?ORDER_DATE=last month`) is still
700
+ // filtering every cell, but a DatePicker can only render a date, so it
701
+ // showed blank, and the picker's own `clearable` appears only when it
702
+ // holds one: the state was invisible AND had no revert.
703
+ //
704
+ // `""` is an empty control, not an unreadable value; see the number
705
+ // branch above for the same distinction.
706
+ const unreadable =
707
+ value !== undefined &&
708
+ value !== null &&
709
+ value !== "" &&
710
+ asDate === null;
711
+
712
+ // Its own field rather than a badged DatePicker, which was tried twice.
713
+ // Putting the revert in `slotProps.textField.InputProps` REPLACES the
714
+ // picker's own "Choose date" button, because MUI merges that object
715
+ // shallowly and ours wins outright. And passing `error` through the same
716
+ // slot pins it: MUI's `useField` returns any defined `error` ahead of its
717
+ // own validation, so `error: false` suppressed the picker's real errors.
718
+ if (unreadable) return unrepresentable("date");
719
+
175
720
  // The date picker shows a format mask, not a placeholder, so the default
176
721
  // rides on the shared helper line.
177
722
  return (
@@ -179,7 +724,13 @@ export function GivenInput({ given, value, onChange }: GivenInputProps) {
179
724
  <DatePicker
180
725
  label={label}
181
726
  value={dateValue}
182
- onChange={(next) => onChange(next ? next.toDate() : null)}
727
+ // The clicked day rebuilt in UTC, never `next.toDate()`, which
728
+ // is local-mode and lands a day out. See `pickedDayToUtc`.
729
+ onChange={(next) =>
730
+ onChange(
731
+ next ? pickedDayToUtc(next, asDate ?? undefined) : null,
732
+ )
733
+ }
183
734
  slotProps={{
184
735
  textField: {
185
736
  fullWidth: true,
@@ -193,30 +744,11 @@ export function GivenInput({ given, value, onChange }: GivenInputProps) {
193
744
  );
194
745
  }
195
746
 
196
- if (type.startsWith("array<")) {
197
- const list = Array.isArray(value) ? value.map(String) : [];
198
- return (
199
- <Autocomplete
200
- multiple
201
- freeSolo
202
- options={[]}
203
- value={list}
204
- onChange={(_event, next) =>
205
- onChange(next.length === 0 ? null : (next as string[]))
206
- }
207
- renderInput={(params) => (
208
- <TextField
209
- {...params}
210
- label={label}
211
- size="small"
212
- placeholder={list.length === 0 ? defaultDisplay : undefined}
213
- helperText={helperNode}
214
- />
215
- )}
216
- fullWidth
217
- />
218
- );
219
- }
747
+ // No `array<…>` branch on purpose. `malloyGivenToApi` renders a non-filter
748
+ // given as the bare `type.type`, so the widest thing the server could ever
749
+ // send is `"array"`; `"array<…>"` is a spelling nothing produces. Malloy's
750
+ // grammar emits only scalar parameter types for givens today anyway
751
+ // (`service/given.ts`), so the case is doubly unreachable.
220
752
 
221
753
  // Default: string, filter<...>, or unknown types — plain text input.
222
754
  // An empty field is a deliberate `""` override, NOT a revert: typing the