@malloy-publisher/sdk 0.9.16 → 0.10.0

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 (41) hide show
  1. package/dist/{RenderedResult-5hOs5XnV.cjs.js → RenderedResult-B5f4qOjp.cjs.js} +1 -1
  2. package/dist/{RenderedResult-DxmHGZNQ.es.js → RenderedResult-DiDsN6JE.es.js} +1 -1
  3. package/dist/builder/index.cjs.js +17 -17
  4. package/dist/builder/index.es.js +277 -265
  5. package/dist/components/ReportBuilder/TextTileBody.d.ts +9 -2
  6. package/dist/components/legacy/malloynb/CellRunnerView.d.ts +6 -6
  7. package/dist/hooks/useSettled.d.ts +5 -8
  8. package/dist/hooks/useSettledDraft.d.ts +33 -0
  9. package/dist/index.cjs.js +10 -10
  10. package/dist/index.es.js +3769 -3779
  11. package/dist/useCompiledDocument-C995sQ3j.cjs.js +142 -0
  12. package/dist/{useCompiledDocument-CaYP_OYG.es.js → useCompiledDocument-CRmmbUza.es.js} +5449 -5294
  13. package/dist/utils/malloyLiteral.d.ts +2 -0
  14. package/package.json +11 -16
  15. package/src/components/ReportBuilder/BuilderGrid.tsx +1 -0
  16. package/src/components/ReportBuilder/TextTileBody.tsx +24 -4
  17. package/src/components/ReportBuilder/placement.spec.ts +27 -0
  18. package/src/components/ReportBuilder/placement.ts +8 -4
  19. package/src/components/given/GivenInput.spec.tsx +447 -2
  20. package/src/components/given/GivenInput.tsx +192 -80
  21. package/src/components/given/GivensPanel.spec.tsx +59 -0
  22. package/src/components/given/GivensPanel.tsx +14 -2
  23. package/src/components/legacy/malloynb/CellRunnerView.tsx +6 -6
  24. package/src/hooks/useDimensionFilters.ts +1 -35
  25. package/src/hooks/useDimensionFiltersQuery.ts +2 -36
  26. package/src/hooks/useDimensionalFilterRangeData.ts +1 -35
  27. package/src/hooks/useGivensState.spec.ts +106 -1
  28. package/src/hooks/useGivensState.ts +48 -13
  29. package/src/hooks/useSettled.ts +5 -8
  30. package/src/hooks/useSettledDraft.ts +127 -0
  31. package/src/utils/malloyLiteral.spec.ts +12 -1
  32. package/src/utils/malloyLiteral.ts +32 -0
  33. package/vite.config.ts +0 -2
  34. package/.eslintrc +0 -36
  35. package/dist/components/DOMElement/DOMElement.d.ts +0 -5
  36. package/dist/components/DOMElement/index.d.ts +0 -1
  37. package/dist/components/Package/FileTreeView.d.ts +0 -9
  38. package/dist/useCompiledDocument-zYEfLogf.cjs.js +0 -142
  39. package/src/components/DOMElement/DOMElement.tsx +0 -22
  40. package/src/components/DOMElement/index.ts +0 -4
  41. package/src/components/Package/FileTreeView.tsx +0 -244
@@ -25,7 +25,7 @@ import {
25
25
  import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
26
26
  import { DatePicker } from "@mui/x-date-pickers/DatePicker";
27
27
  import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
28
- import dayjs from "dayjs";
28
+ import dayjs, { type Dayjs } from "dayjs";
29
29
  import utc from "dayjs/plugin/utc";
30
30
  import {
31
31
  createContext,
@@ -33,11 +33,13 @@ import {
33
33
  type ReactNode,
34
34
  useContext,
35
35
  useEffect,
36
+ useRef,
36
37
  useState,
37
38
  } from "react";
38
39
  import { Given } from "../../client";
39
40
  import { paramToGiven, pickedDayToUtc } from "./paramCodec";
40
41
  import { GivenValue } from "../../hooks/givenValue";
42
+ import { useSettledDraft } from "../../hooks/useSettledDraft";
41
43
  import {
42
44
  type OptionSearch,
43
45
  SUGGEST_OPTION_LIMIT,
@@ -286,6 +288,9 @@ export function GivenInput({
286
288
  // that was cut off. Called for every given, as hooks must be; inert unless
287
289
  // the picker below renders with a search to run.
288
290
  const [typed, setTyped] = useState("");
291
+ // The thumb(s) while the reader holds them; the value commits on release.
292
+ const [drag, setDrag] = useState<number | number[] | null>(null);
293
+ const gesture = useRef<number | number[] | null>(null);
289
294
  const search = useOptionSearch(
290
295
  pickerControl ? optionSearch : undefined,
291
296
  typed,
@@ -529,9 +534,16 @@ export function GivenInput({
529
534
  return unrepresentable("number");
530
535
  }
531
536
  // An unset control rests at the low end, which is the no-op threshold.
532
- const position = current ?? rangeMin;
537
+ const dragged = drag !== null;
538
+ const position = dragged
539
+ ? Array.isArray(drag)
540
+ ? drag[0]
541
+ : drag
542
+ : (current ?? rangeMin);
533
543
  // And an unset range spans the whole track, which selects everything.
534
- const thumbs: [number, number] = handles ?? [rangeMin, rangeMax];
544
+ const thumbs: [number, number] = Array.isArray(drag)
545
+ ? [drag[0], drag[1]]
546
+ : (handles ?? [rangeMin, rangeMax]);
535
547
  // A range reads as `lo to hi`, and as `≥ lo` once the upper handle is at
536
548
  // the ceiling, which is also what the value on the wire says.
537
549
  const rangeReadout =
@@ -547,8 +559,9 @@ export function GivenInput({
547
559
  // third state: not unset, and not `≥ position` either. Printing
548
560
  // `≥ rangeMin` for it asserted a lower bound nobody had chosen, just as
549
561
  // counting it unset had hidden that an override was in force at all.
550
- const emptyFilterOverride = numericFilter && value === "";
551
- const isOverridden = current !== undefined || emptyFilterOverride;
562
+ const emptyFilterOverride = numericFilter && value === "" && !dragged;
563
+ const isOverridden =
564
+ current !== undefined || emptyFilterOverride || dragged;
552
565
  // TWO LIMITATIONS here, both reachable as soon as a given carries
553
566
  // `rangeMin`/`rangeMax`, and both about the plain `number` arm rather than
554
567
  // the filter arm. Written when no server populated those fields; slice 6
@@ -651,6 +664,16 @@ export function GivenInput({
651
664
  // gives the thumb somewhere to be.
652
665
  sx={{ py: 0, mt: 0.5 }}
653
666
  onChange={(_event, next) => {
667
+ gesture.current = next;
668
+ setDrag(next);
669
+ }}
670
+ // MUI repeats the previous gesture's value for a click that
671
+ // moved nothing, which would bring a cleared value back.
672
+ onChangeCommitted={() => {
673
+ const next = gesture.current;
674
+ gesture.current = null;
675
+ setDrag(null);
676
+ if (next === null) return;
654
677
  if (numericFilter) {
655
678
  const [lo, hi] = Array.isArray(next)
656
679
  ? [next[0], next[1]]
@@ -750,28 +773,18 @@ export function GivenInput({
750
773
  // was in force. The text box shows the filter as written, and editable.
751
774
  if (isDateFilter && dateIsPickable) {
752
775
  const parsed = bareDate ? dayjs.utc(value as string) : null;
776
+ // Cleared means UNSET, `null`, not an empty filter expression. `""` is a
777
+ // value for a filter given (the empty string is meaningful there), so it
778
+ // reached the wire as a filter of no characters instead of dropping the
779
+ // override.
753
780
  return (
754
- <LocalizationProvider dateAdapter={AdapterDayjs}>
755
- <DatePicker
756
- label={label}
757
- value={parsed?.isValid() ? parsed : null}
758
- // Cleared means UNSET, `null`, not an empty filter expression.
759
- // `""` is a value for a filter given (the empty string is
760
- // meaningful there), so it reached the wire as a filter of no
761
- // characters instead of dropping the override.
762
- onChange={(next) =>
763
- onChange(next ? next.format("YYYY-MM-DD") : null)
764
- }
765
- slotProps={{
766
- textField: {
767
- fullWidth: true,
768
- size: "small",
769
- helperText: helperNode,
770
- },
771
- field: { clearable: true, onClear: () => onChange(null) },
772
- }}
773
- />
774
- </LocalizationProvider>
781
+ <SettledDatePicker
782
+ label={label}
783
+ committed={parsed?.isValid() ? parsed : null}
784
+ toValue={(next) => next.format("YYYY-MM-DD")}
785
+ onChange={onChange}
786
+ helperText={helperNode}
787
+ />
775
788
  );
776
789
  }
777
790
 
@@ -842,11 +855,10 @@ export function GivenInput({
842
855
  }
843
856
 
844
857
  if (type === "number") {
845
- const num = typeof value === "number" ? value : "";
846
858
  // Track whether a value is OVERRIDDEN, the way the string branch below
847
859
  // does, rather than whether the box happens to render non-empty. A
848
- // non-number renders blank (see `num` above), and keying the revert off
849
- // that blank left the user no way to clear it.
860
+ // non-number renders blank, and keying the revert off that blank left
861
+ // the user no way to clear it.
850
862
  const isOverridden = value !== undefined && value !== null;
851
863
  // `""` is an empty box, not an unreadable value. `paramToGiven` now reads
852
864
  // `?N=` as UNSET so it no longer arrives here at all, but a host passing
@@ -856,25 +868,15 @@ export function GivenInput({
856
868
  return unrepresentable("number");
857
869
  }
858
870
  return (
859
- <TextField
871
+ <SettledTextField
860
872
  label={label}
861
873
  type="number"
862
- value={num}
863
- onChange={(e) => {
864
- const v = e.target.value;
865
- onChange(v === "" ? null : Number(v));
866
- }}
874
+ committed={typeof value === "number" ? String(value) : ""}
875
+ onCommit={(text) => onChange(text === "" ? null : Number(text))}
867
876
  placeholder={defaultDisplay}
868
877
  helperText={helperNode}
869
- slotProps={{
870
- input: {
871
- endAdornment: isOverridden && (
872
- <ClearAdornment onClear={() => onChange(null)} />
873
- ),
874
- },
875
- }}
876
- fullWidth
877
- size="small"
878
+ isOverridden={isOverridden}
879
+ onClear={() => onChange(null)}
878
880
  />
879
881
  );
880
882
  }
@@ -918,27 +920,15 @@ export function GivenInput({
918
920
  // The date picker shows a format mask, not a placeholder, so the default
919
921
  // rides on the shared helper line.
920
922
  return (
921
- <LocalizationProvider dateAdapter={AdapterDayjs}>
922
- <DatePicker
923
- label={label}
924
- value={dateValue}
925
- // The clicked day rebuilt in UTC, never `next.toDate()`, which
926
- // is local-mode and lands a day out. See `pickedDayToUtc`.
927
- onChange={(next) =>
928
- onChange(
929
- next ? pickedDayToUtc(next, asDate ?? undefined) : null,
930
- )
931
- }
932
- slotProps={{
933
- textField: {
934
- fullWidth: true,
935
- size: "small",
936
- helperText: helperNode,
937
- },
938
- field: { clearable: true, onClear: () => onChange(null) },
939
- }}
940
- />
941
- </LocalizationProvider>
923
+ <SettledDatePicker
924
+ label={label}
925
+ committed={dateValue}
926
+ // The picked day rebuilt in UTC, never `next.toDate()`, which is
927
+ // local-mode and lands a day out. See `pickedDayToUtc`.
928
+ toValue={(next) => pickedDayToUtc(next, asDate ?? undefined)}
929
+ onChange={onChange}
930
+ helperText={helperNode}
931
+ />
942
932
  );
943
933
  }
944
934
 
@@ -956,10 +946,10 @@ export function GivenInput({
956
946
  const str = typeof value === "string" ? value : "";
957
947
  const isOverridden = value !== undefined && value !== null;
958
948
  return (
959
- <TextField
949
+ <SettledTextField
960
950
  label={label}
961
- value={str}
962
- onChange={(e) => onChange(e.target.value)}
951
+ committed={str}
952
+ onCommit={onChange}
963
953
  placeholder={
964
954
  isOverridden
965
955
  ? undefined
@@ -967,19 +957,139 @@ export function GivenInput({
967
957
  (type.startsWith("filter<") ? type : undefined))
968
958
  }
969
959
  helperText={helperNode}
960
+ isOverridden={isOverridden}
961
+ emptyOverrides
962
+ onClear={() => onChange(null)}
963
+ />
964
+ );
965
+ }
966
+
967
+ /**
968
+ * A text box that applies what is typed once the reader pauses, tabs away or
969
+ * presses Enter, rather than on every keystroke: under autorun each applied
970
+ * value is a wave of queries, and one wave per keystroke floods the workers.
971
+ */
972
+ function SettledTextField({
973
+ label,
974
+ type,
975
+ committed,
976
+ onCommit,
977
+ placeholder,
978
+ helperText,
979
+ isOverridden,
980
+ emptyOverrides = false,
981
+ onClear,
982
+ }: {
983
+ label: string;
984
+ type?: "number";
985
+ committed: string;
986
+ onCommit: (text: string) => void;
987
+ placeholder: string | undefined;
988
+ helperText: ReactNode;
989
+ isOverridden: boolean;
990
+ /** An emptied box is a deliberate `""` override, not a revert to the default. */
991
+ emptyOverrides?: boolean;
992
+ onClear: () => void;
993
+ }) {
994
+ const { draft, change, reset, bind } = useSettledDraft(committed, onCommit, {
995
+ unset: emptyOverrides && !isOverridden,
996
+ });
997
+ return (
998
+ <TextField
999
+ label={label}
1000
+ type={type}
1001
+ value={draft}
1002
+ onChange={(e) => change(e.target.value)}
1003
+ placeholder={placeholder}
1004
+ helperText={helperText}
970
1005
  slotProps={{
971
1006
  input: {
972
1007
  endAdornment: isOverridden && (
973
- <ClearAdornment onClear={() => onChange(null)} />
1008
+ <ClearAdornment
1009
+ onClear={() => {
1010
+ // Before the revert, so the blur it provokes finds
1011
+ // nothing left to commit.
1012
+ reset("");
1013
+ onClear();
1014
+ }}
1015
+ />
974
1016
  ),
975
1017
  },
976
1018
  }}
1019
+ {...bind}
977
1020
  fullWidth
978
1021
  size="small"
979
1022
  />
980
1023
  );
981
1024
  }
982
1025
 
1026
+ // Calendar parts, not instants: a typed day is local midnight and the committed
1027
+ // one is UTC, which are equal days but different instants outside UTC.
1028
+ const sameDay = (a: Dayjs | null, b: Dayjs | null) =>
1029
+ a === null || b === null
1030
+ ? a === b
1031
+ : a.year() === b.year() &&
1032
+ a.month() === b.month() &&
1033
+ a.date() === b.date();
1034
+
1035
+ /**
1036
+ * A day picker that applies a typed date once the reader pauses or tabs away,
1037
+ * for the same reason as `SettledTextField`: each section typed into the field
1038
+ * is a valid date of its own. A day clicked in the calendar applies at once.
1039
+ */
1040
+ function SettledDatePicker({
1041
+ label,
1042
+ committed,
1043
+ toValue,
1044
+ onChange,
1045
+ helperText,
1046
+ minDate,
1047
+ }: {
1048
+ label: string;
1049
+ committed: Dayjs | null;
1050
+ toValue: (picked: Dayjs) => GivenValue;
1051
+ onChange: (next: GivenValue) => void;
1052
+ helperText?: ReactNode;
1053
+ minDate?: Dayjs;
1054
+ }) {
1055
+ const { draft, change, reset, bind } = useSettledDraft<Dayjs | null>(
1056
+ committed,
1057
+ // A half-typed date is an invalid Dayjs, which is not a value yet.
1058
+ (next) => {
1059
+ if (next === null) onChange(null);
1060
+ else if (next.isValid()) onChange(toValue(next));
1061
+ },
1062
+ { same: sameDay },
1063
+ );
1064
+ return (
1065
+ <LocalizationProvider dateAdapter={AdapterDayjs}>
1066
+ <DatePicker
1067
+ label={label}
1068
+ value={draft}
1069
+ minDate={minDate}
1070
+ onChange={change}
1071
+ slotProps={{
1072
+ textField: {
1073
+ fullWidth: true,
1074
+ size: "small",
1075
+ helperText,
1076
+ ...bind,
1077
+ },
1078
+ field: {
1079
+ clearable: true,
1080
+ onClear: () => {
1081
+ reset(null);
1082
+ onChange(null);
1083
+ },
1084
+ },
1085
+ // Keeps the click from blurring, and so committing, the field first.
1086
+ clearButton: { onMouseDown: (e) => e.preventDefault() },
1087
+ }}
1088
+ />
1089
+ </LocalizationProvider>
1090
+ );
1091
+ }
1092
+
983
1093
  /**
984
1094
  * The × that reverts a control to its default: one button, so every control
985
1095
  * says the same thing to a screen reader and offers the same 24px target.
@@ -1011,7 +1121,9 @@ function ClearButton({
1011
1121
 
1012
1122
  function ClearAdornment({ onClear }: { onClear: () => void }) {
1013
1123
  return (
1014
- <InputAdornment position="end">
1124
+ // Keeps focus in the field, so the click does not first blur it into a
1125
+ // commit of whatever was typed.
1126
+ <InputAdornment position="end" onMouseDown={(e) => e.preventDefault()}>
1015
1127
  <ClearButton onClear={onClear} edge="end" />
1016
1128
  </InputAdornment>
1017
1129
  );
@@ -1249,31 +1361,31 @@ function TimeRangeControl({
1249
1361
  <MenuItem value={CUSTOM_RANGE}>Custom range</MenuItem>
1250
1362
  </TextField>
1251
1363
  {custom && (
1252
- <LocalizationProvider dateAdapter={AdapterDayjs}>
1253
- <DatePicker
1364
+ <>
1365
+ <SettledDatePicker
1254
1366
  label="From"
1255
- value={day(draft.from)}
1367
+ committed={day(draft.from)}
1368
+ toValue={(d) => d.format("YYYY-MM-DD")}
1256
1369
  onChange={(next) =>
1257
1370
  commitDays({
1258
1371
  ...draft,
1259
- from: next ? next.format("YYYY-MM-DD") : undefined,
1372
+ from: next === null ? undefined : String(next),
1260
1373
  })
1261
1374
  }
1262
- slotProps={{ textField: { size: "small" } }}
1263
1375
  />
1264
- <DatePicker
1376
+ <SettledDatePicker
1265
1377
  label="To"
1266
- value={day(draft.to)}
1378
+ committed={day(draft.to)}
1267
1379
  minDate={day(draft.from) ?? undefined}
1380
+ toValue={(d) => d.format("YYYY-MM-DD")}
1268
1381
  onChange={(next) =>
1269
1382
  commitDays({
1270
1383
  ...draft,
1271
- to: next ? next.format("YYYY-MM-DD") : undefined,
1384
+ to: next === null ? undefined : String(next),
1272
1385
  })
1273
1386
  }
1274
- slotProps={{ textField: { size: "small" } }}
1275
1387
  />
1276
- </LocalizationProvider>
1388
+ </>
1277
1389
  )}
1278
1390
  </Stack>
1279
1391
  );
@@ -200,3 +200,62 @@ describe("layout and title", () => {
200
200
  expect(screen.getByRole("button", { name: "Reset" })).toBeDefined();
201
201
  });
202
202
  });
203
+
204
+ describe("GivensPanel: Apply with autorun off", () => {
205
+ const TEXT: Given = { name: "REGION", type: "string" };
206
+
207
+ function ApplyHarness({ onApplied }: { onApplied: () => void }) {
208
+ const [params, setParams] = useState<Record<string, string>>({});
209
+ const { draft, setGiven, apply, pending } = useGivensState({
210
+ declaredTypes: new Map([["REGION", "string"]]),
211
+ params,
212
+ onParamsChange: setParams,
213
+ autorun: false,
214
+ });
215
+ return (
216
+ <GivensPanel
217
+ givens={[TEXT]}
218
+ values={draft}
219
+ onChange={setGiven}
220
+ onReset={() => {}}
221
+ apply={{
222
+ onApply: () => {
223
+ onApplied();
224
+ apply();
225
+ },
226
+ pending,
227
+ }}
228
+ />
229
+ );
230
+ }
231
+
232
+ it("applies a click that lands right after typing, before the draft settles", () => {
233
+ let applied = 0;
234
+ render(<ApplyHarness onApplied={() => applied++} />);
235
+ const field = screen.getByRole("textbox");
236
+ const button = screen.getByRole("button", { name: "Apply" });
237
+
238
+ field.focus();
239
+ fireEvent.change(field, { target: { value: "CA" } });
240
+ // The browser's order: mousedown on the button blurs the field, which
241
+ // flushes the draft, and only then does the click fire.
242
+ fireEvent.mouseDown(button);
243
+ fireEvent.blur(field);
244
+ fireEvent.mouseUp(button);
245
+ fireEvent.click(button);
246
+
247
+ expect(applied).toBe(1);
248
+ expect(button.getAttribute("aria-disabled")).toBe("true");
249
+ });
250
+
251
+ it("does nothing on a click while nothing is pending", () => {
252
+ let applied = 0;
253
+ render(<ApplyHarness onApplied={() => applied++} />);
254
+ const button = screen.getByRole("button", { name: "Apply" });
255
+
256
+ fireEvent.click(button);
257
+
258
+ expect(applied).toBe(0);
259
+ expect(button.getAttribute("aria-disabled")).toBe("true");
260
+ });
261
+ });
@@ -132,8 +132,20 @@ export function GivensPanel({
132
132
  variant="contained"
133
133
  size="small"
134
134
  disableElevation
135
- onClick={apply.onApply}
136
- disabled={!apply.pending}
135
+ onClick={() => apply.pending && apply.onApply()}
136
+ // Not `disabled`: a disabled button swallows the mousedown, so a
137
+ // click right after typing lands on the panel once blur enables it.
138
+ aria-disabled={!apply.pending}
139
+ sx={{
140
+ "&[aria-disabled='true']": {
141
+ cursor: "default",
142
+ color: "action.disabled",
143
+ backgroundColor: "action.disabledBackground",
144
+ "&:hover": {
145
+ backgroundColor: "action.disabledBackground",
146
+ },
147
+ },
148
+ }}
137
149
  >
138
150
  Apply
139
151
  </Button>
@@ -92,12 +92,12 @@ export interface CellReportProps {
92
92
  *
93
93
  * That is every committed change. Under `## autorun=false` a change is
94
94
  * committed on Apply, so reports are batched; otherwise every change is
95
- * committed and typing in a text control reports per keystroke. It does NOT
96
- * run per keystroke: a changed value waits `GIVEN_SETTLE_MS` before
97
- * anything is dispatched, so a burst of typing produces one run. A run that
98
- * does start supersedes and aborts the one before it. The REPORTS are still
99
- * per keystroke, so a host doing something expensive per call should
100
- * debounce.
95
+ * committed. A changed value waits `GIVEN_SETTLE_MS` before anything is
96
+ * dispatched, so a burst of changes produces one run. A run that
97
+ * does start supersedes and aborts the one before it. A text, number, date
98
+ * or slider control commits once it settles, so typed text runs after both
99
+ * waits; the wait here still covers pickers, keyboard slider steps, drill
100
+ * and Reset, which commit at once.
101
101
  *
102
102
  * `managed` names every given this report declares, set or not. A host
103
103
  * writing to a shared query string needs it: `givens` alone says which
@@ -6,6 +6,7 @@ import {
6
6
  DimensionSpec,
7
7
  getDimensionKey,
8
8
  } from "./useDimensionalFilterRangeData";
9
+ import { formatMalloyValue } from "../utils/malloyLiteral";
9
10
  import { escapeMalloyString } from "../utils/malloyString";
10
11
 
11
12
  /**
@@ -79,41 +80,6 @@ export interface UseDimensionFiltersResult {
79
80
  generateWhereClause: () => string;
80
81
  }
81
82
 
82
- /**
83
- * Formats a value for use in Malloy query
84
- */
85
- function formatMalloyValue(
86
- value: FilterValuePrimitive | null | undefined,
87
- isDate: boolean = false,
88
- ): string {
89
- if (value === null || value === undefined) {
90
- return "null";
91
- }
92
-
93
- if (isDate) {
94
- if (value instanceof Date) {
95
- // Format as YYYY-MM-DD
96
- return `@${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, "0")}-${String(value.getDate()).padStart(2, "0")}`;
97
- }
98
- // If it's a string, assume it's already in ISO format
99
- return `@${value}`;
100
- }
101
-
102
- if (typeof value === "string") {
103
- return `'${escapeMalloyString(value)}'`;
104
- }
105
-
106
- if (typeof value === "number") {
107
- return String(value);
108
- }
109
-
110
- if (typeof value === "boolean") {
111
- return value ? "true" : "false";
112
- }
113
-
114
- return String(value);
115
- }
116
-
117
83
  /**
118
84
  * Generates a Malloy filter condition for a single filter selection
119
85
  */
@@ -4,7 +4,8 @@
4
4
  import { useCallback, useMemo, useState } from "react";
5
5
  import { createEmbeddedQueryResult } from "../components/QueryResult";
6
6
  import { encodeResourceUri } from "../utils/formatting";
7
- import { FilterSelection, FilterValuePrimitive } from "./useDimensionFilters";
7
+ import { FilterSelection } from "./useDimensionFilters";
8
+ import { formatMalloyValue } from "../utils/malloyLiteral";
8
9
  import { escapeMalloyString } from "../utils/malloyString";
9
10
 
10
11
  /**
@@ -43,41 +44,6 @@ export interface DimensionFiltersQueryResult {
43
44
  canExecute: boolean;
44
45
  }
45
46
 
46
- /**
47
- * Formats a value for use in Malloy query
48
- */
49
- function formatMalloyValue(
50
- value: FilterValuePrimitive | null | undefined,
51
- isDate: boolean = false,
52
- ): string {
53
- if (value === null || value === undefined) {
54
- return "null";
55
- }
56
-
57
- if (isDate) {
58
- if (value instanceof Date) {
59
- // Format as YYYY-MM-DD
60
- return `@${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, "0")}-${String(value.getDate()).padStart(2, "0")}`;
61
- }
62
- // If it's a string, assume it's already in ISO format
63
- return `@${value}`;
64
- }
65
-
66
- if (typeof value === "string") {
67
- return `'${escapeMalloyString(value)}'`;
68
- }
69
-
70
- if (typeof value === "number") {
71
- return String(value);
72
- }
73
-
74
- if (typeof value === "boolean") {
75
- return value ? "true" : "false";
76
- }
77
-
78
- return String(value);
79
- }
80
-
81
47
  /**
82
48
  * Generates a Malloy filter condition for a single filter selection
83
49
  */
@@ -5,6 +5,7 @@ import { useMemo } from "react";
5
5
  import { useServer } from "../components/ServerProvider";
6
6
  import { FilterSelection, FilterValuePrimitive } from "./useDimensionFilters";
7
7
  import { useQueryWithApiError } from "./useQueryWithApiError";
8
+ import { formatMalloyValue } from "../utils/malloyLiteral";
8
9
  import { escapeMalloyString } from "../utils/malloyString";
9
10
 
10
11
  /**
@@ -118,41 +119,6 @@ export interface DimensionalFilterRangeDataResult {
118
119
  refetch: () => void;
119
120
  }
120
121
 
121
- /**
122
- * Formats a value for use in Malloy query
123
- */
124
- function formatMalloyValue(
125
- value: FilterValuePrimitive | null | undefined,
126
- isDate: boolean = false,
127
- ): string {
128
- if (value === null || value === undefined) {
129
- return "null";
130
- }
131
-
132
- if (isDate) {
133
- if (value instanceof Date) {
134
- // Format as YYYY-MM-DD
135
- return `@${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, "0")}-${String(value.getDate()).padStart(2, "0")}`;
136
- }
137
- // If it's a string, assume it's already in ISO format
138
- return `@${value}`;
139
- }
140
-
141
- if (typeof value === "string") {
142
- return `'${escapeMalloyString(value)}'`;
143
- }
144
-
145
- if (typeof value === "number") {
146
- return String(value);
147
- }
148
-
149
- if (typeof value === "boolean") {
150
- return value ? "true" : "false";
151
- }
152
-
153
- return String(value);
154
- }
155
-
156
122
  /**
157
123
  * Generates a Malloy filter condition for a single filter selection
158
124
  */