@malloy-publisher/sdk 0.9.15 → 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.
- package/dist/{RenderedResult-BClN_PG6.cjs.js → RenderedResult-B5f4qOjp.cjs.js} +21 -4
- package/dist/{RenderedResult-YBzVMVH2.es.js → RenderedResult-DiDsN6JE.es.js} +204 -187
- package/dist/builder/index.cjs.js +75 -75
- package/dist/builder/index.es.js +5304 -5156
- package/dist/builder-entry.d.ts +1 -1
- package/dist/client/api.d.ts +1 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +2 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +5 -0
- package/dist/components/ReportBuilder/ArrangeMenu.d.ts +9 -0
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +5 -7
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +3 -1
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +1 -1
- package/dist/components/ReportBuilder/TextTileBody.d.ts +9 -2
- package/dist/components/ReportBuilder/TileFrame.d.ts +34 -22
- package/dist/components/ReportBuilder/builderControls.d.ts +19 -0
- package/dist/components/ReportBuilder/placement.d.ts +48 -2
- package/dist/components/ReportBuilder/sortable.d.ts +9 -0
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
- package/dist/components/ReportBuilder/useBuilderShortcuts.d.ts +9 -1
- package/dist/components/ReportBuilder/useEdgeResize.d.ts +84 -0
- package/dist/components/ReportBuilder/useTileReorder.d.ts +3 -0
- package/dist/components/legacy/malloynb/CellRunnerView.d.ts +6 -6
- package/dist/hooks/useSettled.d.ts +5 -8
- package/dist/hooks/useSettledDraft.d.ts +33 -0
- package/dist/index.cjs.js +10 -10
- package/dist/index.es.js +3861 -3870
- package/dist/theme/classes.d.ts +1 -1
- package/dist/useCompiledDocument-C995sQ3j.cjs.js +142 -0
- package/dist/{useCompiledDocument-BGk38oaW.es.js → useCompiledDocument-CRmmbUza.es.js} +6426 -6257
- package/dist/utils/malloyLiteral.d.ts +2 -0
- package/package.json +11 -16
- package/src/builder-entry.ts +1 -0
- package/src/components/Dashboard/DashboardGrid.tsx +2 -0
- package/src/components/Dashboard/DashboardTile.tsx +4 -0
- package/src/components/Dashboard/DashboardView.tsx +1 -0
- package/src/components/RenderedResult/RenderedResult.tsx +18 -0
- package/src/components/RenderedResult/ResultContainer.tsx +39 -3
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.ts +6 -0
- package/src/components/ReportBuilder/ArrangeMenu.tsx +80 -0
- package/src/components/ReportBuilder/BuilderBar.tsx +4 -0
- package/src/components/ReportBuilder/BuilderDialogs.tsx +8 -1
- package/src/components/ReportBuilder/BuilderGrid.tsx +62 -60
- package/src/components/ReportBuilder/BuilderToolbar.tsx +4 -0
- package/src/components/ReportBuilder/EditorSurface.tsx +9 -2
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +99 -0
- package/src/components/ReportBuilder/ReportBuilder.tsx +110 -30
- package/src/components/ReportBuilder/TextTileBody.tsx +24 -4
- package/src/components/ReportBuilder/TileFrame.tsx +261 -310
- package/src/components/ReportBuilder/builderControls.ts +34 -0
- package/src/components/ReportBuilder/placement.spec.ts +235 -0
- package/src/components/ReportBuilder/placement.ts +179 -9
- package/src/components/ReportBuilder/readDocument.spec.ts +7 -17
- package/src/components/ReportBuilder/readDocument.ts +3 -6
- package/src/components/ReportBuilder/sortable.tsx +26 -2
- package/src/components/ReportBuilder/spliceDocument.spec.ts +0 -40
- package/src/components/ReportBuilder/spliceDocument.ts +0 -39
- package/src/components/ReportBuilder/useBuilderSession.ts +7 -2
- package/src/components/ReportBuilder/useBuilderShortcuts.ts +25 -1
- package/src/components/ReportBuilder/useEdgeResize.spec.tsx +324 -0
- package/src/components/ReportBuilder/useEdgeResize.ts +397 -0
- package/src/components/ReportBuilder/useTileReorder.ts +1 -1
- package/src/components/given/GivenInput.spec.tsx +447 -2
- package/src/components/given/GivenInput.tsx +192 -80
- package/src/components/given/GivensPanel.spec.tsx +59 -0
- package/src/components/given/GivensPanel.tsx +14 -2
- package/src/components/legacy/malloynb/CellRunnerView.tsx +6 -6
- package/src/hooks/useDimensionFilters.ts +1 -35
- package/src/hooks/useDimensionFiltersQuery.ts +2 -36
- package/src/hooks/useDimensionalFilterRangeData.ts +1 -35
- package/src/hooks/useGivensState.spec.ts +106 -1
- package/src/hooks/useGivensState.ts +48 -13
- package/src/hooks/useSettled.ts +5 -8
- package/src/hooks/useSettledDraft.ts +127 -0
- package/src/theme/classes.ts +1 -1
- package/src/utils/malloyLiteral.spec.ts +12 -1
- package/src/utils/malloyLiteral.ts +32 -0
- package/vite.config.ts +0 -2
- package/.eslintrc +0 -36
- package/dist/components/DOMElement/DOMElement.d.ts +0 -5
- package/dist/components/DOMElement/index.d.ts +0 -1
- package/dist/components/Package/FileTreeView.d.ts +0 -9
- package/dist/components/ReportBuilder/useTileHeight.d.ts +0 -39
- package/dist/components/ReportBuilder/useTileResize.d.ts +0 -40
- package/dist/useCompiledDocument-D9t5ry_t.cjs.js +0 -142
- package/src/components/DOMElement/DOMElement.tsx +0 -22
- package/src/components/DOMElement/index.ts +0 -4
- package/src/components/Package/FileTreeView.tsx +0 -244
- package/src/components/ReportBuilder/useTileHeight.ts +0 -149
- package/src/components/ReportBuilder/useTileResize.spec.tsx +0 -146
- package/src/components/ReportBuilder/useTileResize.ts +0 -148
|
@@ -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
|
|
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] =
|
|
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 =
|
|
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
|
-
<
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
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
|
|
849
|
-
//
|
|
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
|
-
<
|
|
871
|
+
<SettledTextField
|
|
860
872
|
label={label}
|
|
861
873
|
type="number"
|
|
862
|
-
|
|
863
|
-
|
|
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
|
-
|
|
870
|
-
|
|
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
|
-
<
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
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
|
-
<
|
|
949
|
+
<SettledTextField
|
|
960
950
|
label={label}
|
|
961
|
-
|
|
962
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1253
|
-
<
|
|
1364
|
+
<>
|
|
1365
|
+
<SettledDatePicker
|
|
1254
1366
|
label="From"
|
|
1255
|
-
|
|
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 ?
|
|
1372
|
+
from: next === null ? undefined : String(next),
|
|
1260
1373
|
})
|
|
1261
1374
|
}
|
|
1262
|
-
slotProps={{ textField: { size: "small" } }}
|
|
1263
1375
|
/>
|
|
1264
|
-
<
|
|
1376
|
+
<SettledDatePicker
|
|
1265
1377
|
label="To"
|
|
1266
|
-
|
|
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 ?
|
|
1384
|
+
to: next === null ? undefined : String(next),
|
|
1272
1385
|
})
|
|
1273
1386
|
}
|
|
1274
|
-
slotProps={{ textField: { size: "small" } }}
|
|
1275
1387
|
/>
|
|
1276
|
-
|
|
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
|
|
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
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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
|
|
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
|
*/
|