@malloy-publisher/sdk 0.8.2 → 0.8.3

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.
package/dist/index.es.js CHANGED
@@ -2,14 +2,14 @@ import { jsx as r, jsxs as T, Fragment as se } from "react/jsx-runtime";
2
2
  import { Link as nc, Box as te, Typography as K, Stack as Ie, Tooltip as Mt, IconButton as ct, TextField as $t, Button as ut, Grid as un, Paper as oa, FormControlLabel as $s, Switch as Ns, Divider as hn, List as Fs, ListItemButton as As, ListItemText as _t, TableContainer as rc, Table as Zn, TableHead as Yn, TableRow as bt, TableCell as ce, TableBody as Gn, Snackbar as Sr, Menu as Xn, MenuItem as Nt, ListItemIcon as mn, Container as Sa, FormGroup as ac, Dialog as la, DialogTitle as ca, Chip as ic, DialogContent as ua, Alert as gr, CircularProgress as sc, LinearProgress as oc } from "@mui/material";
3
3
  import * as ye from "react";
4
4
  import ge, { useMemo as Ze, useRef as st, useCallback as gt, useState as j, useEffect as We, useId as lc } from "react";
5
- import { e as Ae, q as Oe, p as $e, L as vt, P as da, S as Kn, v as Qe, E as cc, F as ha, H as Vi, I as _s, J as uc, K as Yr, M as Lt, N as wt, O as Pt, Q as Ye, R as Ft, U as Rt, V as dc, W as jt, X as Ui, Y as hc, Z as lt, _ as fc, $ as dt, a0 as Ct, a1 as Jn, g as Pe, a2 as mc, a3 as pc, a4 as yc, a5 as br, a6 as ve, a7 as Bi, a8 as gc, a9 as Ls, aa as Ca, ab as ue, A as Ps, ac as Rs, ad as Fe, ae as Cr, af as St, ag as ji, ah as Zi, ai as Yi, aj as Gi, ak as bc, al as Xi, am as Ki, an as Gr, ao as vc, ap as At, aq as wc, ar as kc, as as fa, at as Sc, au as qs, av as Cc, aw as Ji, ax as xc, ay as Tc, C as Mc, az as Ws, aA as Oc, aB as zs, aC as Un, aD as Hs, aE as Dc, aF as Ec, aG as Ic, aH as Vs, aI as $c, aJ as Nc, w as Fc, aK as Ac, aL as _c, B as Lc, aM as Pc, u as Rc, aN as qc } from "./DocumentStorage-BZqn0x5r.es.js";
6
- import { aP as $f, aO as Nf, f as Ff, x as Af, b0 as _f, aW as Lf, aY as Pf, aX as Rf, y as qf, T as Wf, h as zf, a$ as Hf, b as Vf, d as Uf, aQ as Bf, aR as jf, aS as Zf, aT as Yf, aZ as Gf, s as Xf, m as Kf, b4 as Jf, a as Qf, aU as em, a_ as tm, r as nm, b1 as rm, aV as am, b2 as im, b3 as sm } from "./DocumentStorage-BZqn0x5r.es.js";
5
+ import { e as Ae, q as Oe, p as $e, L as vt, P as da, S as Kn, v as Qe, E as cc, F as ha, H as Vi, I as _s, J as uc, K as Yr, M as Lt, N as wt, O as Pt, Q as Ye, R as Ft, U as Rt, V as dc, W as jt, X as Ui, Y as hc, Z as lt, _ as fc, $ as dt, a0 as Ct, a1 as Jn, g as Pe, a2 as mc, a3 as pc, a4 as yc, a5 as br, a6 as ve, a7 as Bi, a8 as gc, a9 as Ls, aa as Ca, ab as ue, A as Ps, ac as Rs, ad as Fe, ae as Cr, af as St, ag as ji, ah as Zi, ai as Yi, aj as Gi, ak as bc, al as Xi, am as Ki, an as Gr, ao as vc, ap as At, aq as wc, ar as kc, as as fa, at as Sc, au as qs, av as Cc, aw as Ji, ax as xc, ay as Tc, C as Mc, az as Ws, aA as Oc, aB as zs, aC as Un, aD as Hs, aE as Dc, aF as Ec, aG as Ic, aH as Vs, aI as $c, aJ as Nc, w as Fc, aK as Ac, aL as _c, B as Lc, aM as Pc, u as Rc, aN as qc } from "./DocumentStorage-CigwNjz4.es.js";
6
+ import { aP as $f, aO as Nf, f as Ff, x as Af, b0 as _f, aW as Lf, aY as Pf, aX as Rf, y as qf, T as Wf, h as zf, a$ as Hf, b as Vf, d as Uf, aQ as Bf, aR as jf, aS as Zf, aT as Yf, aZ as Gf, s as Xf, m as Kf, b4 as Jf, a as Qf, aU as em, a_ as tm, r as nm, b1 as rm, aV as am, b2 as im, b3 as sm } from "./DocumentStorage-CigwNjz4.es.js";
7
7
  import { u as xe, aG as je, d as Qi, A as Us, aH as xa, m as qe, P as fr, ag as Wc, aE as Bs, aI as Wn, aJ as zc, aK as Hc, aL as on } from "./ServerProvider-CfUFleYe.es.js";
8
8
  import { aM as lm, S as cm, aO as um, aN as dm, aF as hm } from "./ServerProvider-CfUFleYe.es.js";
9
9
  import { useQueryClient as xr } from "@tanstack/react-query";
10
10
  import { createBox as Vc, createStack as Uc } from "@mui/system";
11
11
  import { Delete as Tr, Edit as Ta, MoreVert as Mr } from "@mui/icons-material";
12
- import { D as mm, R as pm, b as ym, a as gm, d as bm, m as vm, r as wm } from "./RenderedResult-DKOl0FQ8.es.js";
12
+ import { D as mm, R as pm, b as ym, a as gm, d as bm, m as vm, r as wm } from "./RenderedResult-BfayOSk1.es.js";
13
13
  import { useNavigate as js, useSearchParams as Bc, useLocation as jc } from "react-router-dom";
14
14
  const Zc = Ae(/* @__PURE__ */ r("path", {
15
15
  d: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20z"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.8.2",
4
+ "version": "0.8.3",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -383,6 +383,7 @@ describe("GivenInput: the whole type x control matrix", () => {
383
383
  // through every branch and renders nothing at all.
384
384
  const widget = () => {
385
385
  if (screen.queryAllByTestId("time-range").length) return "timerange";
386
+ if (screen.queryAllByTestId("boolean-filter").length) return "boolfilter";
386
387
  if (screen.queryAllByRole("combobox").length) return "picker";
387
388
  if (screen.queryAllByRole("slider").length) return "slider";
388
389
  if (screen.queryAllByRole("checkbox").length) return "checkbox";
@@ -432,6 +433,7 @@ describe("GivenInput: the whole type x control matrix", () => {
432
433
  "timestamptz",
433
434
  "filter<number>",
434
435
  "filter<date>",
436
+ "filter<boolean>",
435
437
  ]) {
436
438
  expect(show(type, "select")).not.toBe("picker");
437
439
  }
@@ -503,6 +505,7 @@ describe("GivenInput: the whole type x control matrix", () => {
503
505
  "filter<number>",
504
506
  "filter<date>",
505
507
  "filter<timestamp>",
508
+ "filter<boolean>",
506
509
  "array<string>",
507
510
  "record",
508
511
  undefined,
@@ -763,6 +766,69 @@ describe("GivenInput: a date renders its UTC day, whatever zone the runner is in
763
766
  );
764
767
  });
765
768
 
769
+ describe("GivenInput: the true/false dropdown for a boolean filter", () => {
770
+ const given: Given = { name: "FLAG", type: "filter<boolean>" };
771
+ const dropdown = () =>
772
+ screen
773
+ .getAllByRole("combobox")
774
+ .find((el) => el.tagName !== "INPUT") as HTMLElement;
775
+ const widget = (value: GivenValue | undefined) => {
776
+ cleanup();
777
+ render(<GivenInput given={given} value={value} onChange={() => {}} />);
778
+ return screen.queryAllByTestId("boolean-filter").length
779
+ ? "dropdown"
780
+ : "text";
781
+ };
782
+
783
+ it("offers true and false, and commits the one picked", () => {
784
+ const onChange = mock((_next: GivenValue) => {});
785
+ render(
786
+ <GivenInput given={given} value={undefined} onChange={onChange} />,
787
+ );
788
+ fireEvent.mouseDown(dropdown());
789
+ expect(
790
+ screen.getAllByRole("option").map((option) => option.textContent),
791
+ ).toEqual(["true", "false"]);
792
+ fireEvent.click(screen.getByRole("option", { name: "false" }));
793
+ expect(onChange).toHaveBeenCalledWith("false");
794
+ });
795
+
796
+ it("shows an unset given as its default, with no revert", () => {
797
+ render(
798
+ <GivenInput
799
+ given={{ ...given, default: "f'true'" }}
800
+ value={undefined}
801
+ onChange={() => {}}
802
+ />,
803
+ );
804
+ expect(dropdown().textContent).toBe("true");
805
+ expect(clearButtons()).toHaveLength(0);
806
+ });
807
+
808
+ it("shows a picked value, however it is spelled, and reverts it", () => {
809
+ const onChange = mock((_next: GivenValue) => {});
810
+ render(<GivenInput given={given} value=" TRUE " onChange={onChange} />);
811
+ expect(dropdown().textContent).toBe("true");
812
+ fireEvent.click(clearButtons()[0]);
813
+ expect(onChange).toHaveBeenCalledWith(null);
814
+ });
815
+
816
+ it("shows the empty filter as Any, an override it can revert", () => {
817
+ render(<GivenInput given={given} value="" onChange={() => {}} />);
818
+ expect(dropdown().textContent).toBe("Any");
819
+ expect(clearButtons()).toHaveLength(1);
820
+ });
821
+
822
+ it("leaves any other filter in the text box, as written", () => {
823
+ // `=false` leaves null rows out and `false` keeps them, so showing it as
824
+ // "false" would claim a filter that is not running.
825
+ for (const value of ["=false", "not true", "null", "asdf"]) {
826
+ expect(widget(value)).toBe("text");
827
+ }
828
+ expect(widget("false")).toBe("dropdown");
829
+ });
830
+ });
831
+
766
832
  describe("GivenInput: the time-range control for a date filter", () => {
767
833
  const given: Given = { name: "PERIOD", type: "filter<timestamp>" };
768
834
  const dropdown = () =>
@@ -30,6 +30,7 @@ import { GivenValue } from "../../hooks/givenValue";
30
30
  import {
31
31
  decodeAtLeast,
32
32
  decodeBetween,
33
+ decodeBooleanFilter,
33
34
  decodeDayRange,
34
35
  decodeFilterList,
35
36
  decodeTimePreset,
@@ -676,6 +677,31 @@ export function GivenInput({
676
677
  );
677
678
  }
678
679
 
680
+ // A `filter<boolean>` gets a dropdown of its two values. Unset and the empty
681
+ // filter both mean no filtering; any other spelling (`=false`, `not true`,
682
+ // `null`) falls through to the text box, where it stays as written.
683
+ if (filterInnerType(type) === "boolean") {
684
+ const picked =
685
+ typeof value === "string" ? decodeBooleanFilter(value) : undefined;
686
+ if (
687
+ value === undefined ||
688
+ value === null ||
689
+ value === "" ||
690
+ picked !== undefined
691
+ ) {
692
+ return (
693
+ <BooleanFilterControl
694
+ label={label}
695
+ picked={picked}
696
+ emptyOverride={value === ""}
697
+ onChange={onChange}
698
+ helperNode={helperNode}
699
+ defaultDisplay={defaultDisplay}
700
+ />
701
+ );
702
+ }
703
+ }
704
+
679
705
  if (type === "boolean") {
680
706
  // Three states for a boolean. When unset, reflect the model DEFAULT so the
681
707
  // box shows what the query will actually run with (not a misleading
@@ -878,6 +904,79 @@ function ClearAdornment({ onClear }: { onClear: () => void }) {
878
904
  );
879
905
  }
880
906
 
907
+ const ANY_BOOLEAN = "__any__";
908
+
909
+ /**
910
+ * A dropdown of `true` and `false` for a `filter<boolean>` given.
911
+ *
912
+ * Unset shows the model's own default, the way every other control does, and
913
+ * picks nothing. An explicit `""` (the empty filter, which a URL can carry) is
914
+ * shown as "Any" and offered only while it is in force: the gesture for "no
915
+ * filter" is the ×, which reverts to the model default, as in the time-range
916
+ * control.
917
+ */
918
+ function BooleanFilterControl({
919
+ label,
920
+ picked,
921
+ emptyOverride,
922
+ onChange,
923
+ helperNode,
924
+ defaultDisplay,
925
+ }: {
926
+ label: string;
927
+ picked: "true" | "false" | undefined;
928
+ emptyOverride: boolean;
929
+ onChange: (next: GivenValue) => void;
930
+ helperNode: ReactNode;
931
+ defaultDisplay: string | undefined;
932
+ }) {
933
+ const selected = picked ?? (emptyOverride ? ANY_BOOLEAN : "");
934
+ const isOverridden = selected !== "";
935
+ return (
936
+ <Box data-testid="boolean-filter">
937
+ <TextField
938
+ select
939
+ label={label}
940
+ value={selected}
941
+ size="small"
942
+ fullWidth
943
+ helperText={helperNode}
944
+ slotProps={{
945
+ select: {
946
+ displayEmpty: true,
947
+ renderValue: (v) =>
948
+ v === "true" || v === "false"
949
+ ? v
950
+ : v === ANY_BOOLEAN
951
+ ? "Any"
952
+ : defaultDisplay || "Any",
953
+ },
954
+ input: {
955
+ endAdornment: isOverridden ? (
956
+ <IconButton
957
+ size="small"
958
+ aria-label="clear value"
959
+ onClick={() => onChange(null)}
960
+ sx={{ mr: 2 }}
961
+ >
962
+ <ClearIcon fontSize="small" />
963
+ </IconButton>
964
+ ) : undefined,
965
+ },
966
+ }}
967
+ onChange={(e) => {
968
+ // "Any" is only listed while it is already in force.
969
+ if (e.target.value !== ANY_BOOLEAN) onChange(e.target.value);
970
+ }}
971
+ >
972
+ {emptyOverride && <MenuItem value={ANY_BOOLEAN}>Any</MenuItem>}
973
+ <MenuItem value="true">true</MenuItem>
974
+ <MenuItem value="false">false</MenuItem>
975
+ </TextField>
976
+ </Box>
977
+ );
978
+ }
979
+
881
980
  /** What a time-range control is showing; undefined means it cannot show it. */
882
981
  type TimeRangeState =
883
982
  | { kind: "unset" }
@@ -23,6 +23,7 @@
23
23
  */
24
24
 
25
25
  import {
26
+ BooleanFilterExpression,
26
27
  isStringCondition,
27
28
  NumberFilterExpression,
28
29
  StringFilterExpression,
@@ -42,6 +43,26 @@ export function isFilterType(type: string | undefined): boolean {
42
43
  return (type ?? "").startsWith("filter<");
43
44
  }
44
45
 
46
+ /**
47
+ * The value a `filter<boolean>` dropdown shows for `value`: `"true"` or
48
+ * `"false"`, however it is spelled (`TRUE`, ` true `). Undefined for anything
49
+ * else the grammar can say (`=false`, `not true`, `null`, and text that does
50
+ * not parse), which the dropdown cannot show and must not rewrite.
51
+ *
52
+ * The plain forms are the ones offered because they are what a reader means:
53
+ * `true` matches true rows, and `false` matches false or null. `=false`, which
54
+ * leaves null out, is a different filter and stays in the text box as written.
55
+ */
56
+ export function decodeBooleanFilter(
57
+ value: string,
58
+ ): "true" | "false" | undefined {
59
+ const { parsed } = BooleanFilterExpression.parse(value);
60
+ if (!parsed || parsed.not) return undefined;
61
+ return parsed.operator === "true" || parsed.operator === "false"
62
+ ? parsed.operator
63
+ : undefined;
64
+ }
65
+
45
66
  /** The `T` of a `filter<T>`, or undefined for any other type. */
46
67
  export function filterInnerType(type: string | undefined): string | undefined {
47
68
  const match = /^filter<(.+)>$/.exec(type ?? "");