@malloy-publisher/sdk 0.9.16 → 0.10.1
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-5hOs5XnV.cjs.js → RenderedResult-B5f4qOjp.cjs.js} +1 -1
- package/dist/{RenderedResult-DxmHGZNQ.es.js → RenderedResult-vf6tu8tf.es.js} +2 -2
- package/dist/{ServerProvider-D7neZcTk.es.js → ServerProvider-B6RLAbgV.es.js} +48 -24
- package/dist/builder/index.cjs.js +17 -17
- package/dist/builder/index.es.js +278 -266
- package/dist/client/api.d.ts +64 -28
- package/dist/client/index.es.js +1 -1
- package/dist/components/ReportBuilder/TextTileBody.d.ts +9 -2
- 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 +3769 -3779
- package/dist/useCompiledDocument-C995sQ3j.cjs.js +142 -0
- package/dist/{useCompiledDocument-CaYP_OYG.es.js → useCompiledDocument-CLbTFtsJ.es.js} +5449 -5294
- package/dist/utils/malloyLiteral.d.ts +2 -0
- package/package.json +11 -16
- package/src/components/ReportBuilder/BuilderGrid.tsx +1 -0
- package/src/components/ReportBuilder/TextTileBody.tsx +24 -4
- package/src/components/ReportBuilder/placement.spec.ts +27 -0
- package/src/components/ReportBuilder/placement.ts +8 -4
- 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/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/useCompiledDocument-zYEfLogf.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
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { act, renderHook } from "@testing-library/react";
|
|
5
|
-
import {
|
|
5
|
+
import { StrictMode } from "react";
|
|
6
|
+
import { afterEach, describe, expect, it, setSystemTime } from "bun:test";
|
|
6
7
|
import { useGivensState } from "./useGivensState";
|
|
7
8
|
|
|
8
9
|
const TYPES = new Map<string, string | undefined>([
|
|
@@ -645,6 +646,110 @@ describe("useGivensState: clearing a given that has a starting value", () => {
|
|
|
645
646
|
expect(entries(result.current.applied)).toEqual({ REGION: "East" });
|
|
646
647
|
});
|
|
647
648
|
|
|
649
|
+
it("keeps the newest edit when a URL two reports old arrives late", () => {
|
|
650
|
+
let url: Record<string, string> = {};
|
|
651
|
+
const { result, rerender } = renderHook(
|
|
652
|
+
(props: { params: Record<string, string> }) =>
|
|
653
|
+
useGivensState({
|
|
654
|
+
declaredTypes: TYPES,
|
|
655
|
+
params: props.params,
|
|
656
|
+
onParamsChange: (next) => {
|
|
657
|
+
url = next;
|
|
658
|
+
},
|
|
659
|
+
documentKey: "dashboard",
|
|
660
|
+
autorun: true,
|
|
661
|
+
}),
|
|
662
|
+
{ initialProps: { params: url } },
|
|
663
|
+
);
|
|
664
|
+
|
|
665
|
+
const reportedUrls: Record<string, string>[] = [];
|
|
666
|
+
for (const typed of ["F", "Fo", "For"]) {
|
|
667
|
+
act(() => result.current.setGiven("REGION", typed));
|
|
668
|
+
reportedUrls.push(url);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// The host delivers them late and in order, the oldest first.
|
|
672
|
+
for (const arriving of reportedUrls) {
|
|
673
|
+
rerender({ params: arriving });
|
|
674
|
+
expect(entries(result.current.applied)).toEqual({ REGION: "For" });
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
it("keeps the newest edit through repeated renders at a stale URL", () => {
|
|
679
|
+
let url: Record<string, string> = {};
|
|
680
|
+
const { result, rerender } = renderHook(
|
|
681
|
+
(props: { params: Record<string, string> }) =>
|
|
682
|
+
useGivensState({
|
|
683
|
+
declaredTypes: TYPES,
|
|
684
|
+
params: props.params,
|
|
685
|
+
onParamsChange: (next) => {
|
|
686
|
+
url = next;
|
|
687
|
+
},
|
|
688
|
+
documentKey: "dashboard",
|
|
689
|
+
autorun: true,
|
|
690
|
+
}),
|
|
691
|
+
{ initialProps: { params: url }, wrapper: StrictMode },
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
const reportedUrls: Record<string, string>[] = [];
|
|
695
|
+
for (const typed of ["F", "Fo", "For"]) {
|
|
696
|
+
act(() => result.current.setGiven("REGION", typed));
|
|
697
|
+
reportedUrls.push(url);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// The first report lands, and the host re-renders for its own reasons
|
|
701
|
+
// before the next one does.
|
|
702
|
+
for (let i = 0; i < 3; i++) {
|
|
703
|
+
rerender({ params: reportedUrls[0] });
|
|
704
|
+
expect(entries(result.current.applied)).toEqual({ REGION: "For" });
|
|
705
|
+
}
|
|
706
|
+
rerender({ params: reportedUrls[1] });
|
|
707
|
+
rerender({ params: reportedUrls[1] });
|
|
708
|
+
expect(entries(result.current.applied)).toEqual({ REGION: "For" });
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
describe("a report that was replaced before its URL landed", () => {
|
|
712
|
+
afterEach(() => setSystemTime());
|
|
713
|
+
|
|
714
|
+
const mount = (documentKey = "dashboard") => {
|
|
715
|
+
let url: Record<string, string> = {};
|
|
716
|
+
const view = renderHook(
|
|
717
|
+
(props: { params: Record<string, string>; documentKey: string }) =>
|
|
718
|
+
useGivensState({
|
|
719
|
+
declaredTypes: TYPES,
|
|
720
|
+
params: props.params,
|
|
721
|
+
onParamsChange: (next) => {
|
|
722
|
+
url = next;
|
|
723
|
+
},
|
|
724
|
+
documentKey: props.documentKey,
|
|
725
|
+
autorun: true,
|
|
726
|
+
}),
|
|
727
|
+
{ initialProps: { params: url, documentKey } },
|
|
728
|
+
);
|
|
729
|
+
// Set, then cleared, before the URL for the first lands.
|
|
730
|
+
act(() => view.result.current.setGiven("REGION", "F"));
|
|
731
|
+
act(() => view.result.current.setGiven("REGION", null));
|
|
732
|
+
return view;
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
it("stops reading a later push that repeats it as an echo", () => {
|
|
736
|
+
setSystemTime(1_000_000);
|
|
737
|
+
const { result, rerender } = mount();
|
|
738
|
+
rerender({ params: {}, documentKey: "dashboard" });
|
|
739
|
+
setSystemTime(1_005_000);
|
|
740
|
+
rerender({ params: { REGION: "F" }, documentKey: "dashboard" });
|
|
741
|
+
expect(entries(result.current.applied)).toEqual({ REGION: "F" });
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
it("is forgotten when the document changes", () => {
|
|
745
|
+
setSystemTime(1_000_000);
|
|
746
|
+
const { result, rerender } = mount();
|
|
747
|
+
rerender({ params: {}, documentKey: "other" });
|
|
748
|
+
rerender({ params: { REGION: "F" }, documentKey: "other" });
|
|
749
|
+
expect(entries(result.current.applied)).toEqual({ REGION: "F" });
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
|
|
648
753
|
it("Reset after a clear restores the starting value and runs once", () => {
|
|
649
754
|
const host = renderWithUrlHost({
|
|
650
755
|
autorun: true,
|
|
@@ -130,6 +130,11 @@ function sameDeclaredParams(
|
|
|
130
130
|
return true;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/** Bounds the reports remembered as in flight when a host never echoes them. */
|
|
134
|
+
const MAX_IN_FLIGHT_REPORTS = 32;
|
|
135
|
+
// How long a superseded report can still be told apart from a push that repeats it.
|
|
136
|
+
const IN_FLIGHT_REPORT_MS = 1500;
|
|
137
|
+
|
|
133
138
|
/** Same entries, same values: enough for state whose values are primitives. */
|
|
134
139
|
function sameParams(
|
|
135
140
|
a: Record<string, string>,
|
|
@@ -163,7 +168,7 @@ export function useGivensState({
|
|
|
163
168
|
// mount reads as an echo.
|
|
164
169
|
const lastReported = useRef<Record<string, string> | null>(null);
|
|
165
170
|
|
|
166
|
-
// The
|
|
171
|
+
// The reports BEFORE `lastReported`, kept only until the newer one is seen
|
|
167
172
|
// coming back.
|
|
168
173
|
//
|
|
169
174
|
// A report does not reach `params` in the same tick: the host navigates, the
|
|
@@ -175,12 +180,18 @@ export function useGivensState({
|
|
|
175
180
|
// the edits were discarded, and `initial` put the value the reader had just
|
|
176
181
|
// cleared straight back into the control, and into the URL after it.
|
|
177
182
|
//
|
|
178
|
-
// Narrow by construction: it holds
|
|
179
|
-
//
|
|
183
|
+
// Narrow by construction: it holds the reports still in flight (several when
|
|
184
|
+
// a control reports faster than the URL lands), and drops each as the URL
|
|
185
|
+
// moves past it. The cost is
|
|
180
186
|
// that an external push landing in that window whose values happen to equal
|
|
181
|
-
//
|
|
187
|
+
// a report being replaced is taken for the echo — the same values we were
|
|
182
188
|
// just showing, arriving in the few milliseconds before our own URL lands.
|
|
183
|
-
|
|
189
|
+
// A value that repeats while in flight (A, B, A) matches its oldest report,
|
|
190
|
+
// so B stays in flight until the next report lands.
|
|
191
|
+
const priorReported = useRef<
|
|
192
|
+
{ params: Record<string, string>; at: number }[]
|
|
193
|
+
>([]);
|
|
194
|
+
const lastReportedAt = useRef(0);
|
|
184
195
|
|
|
185
196
|
// The URL that defines the current starting point. This is `params` EXCEPT
|
|
186
197
|
// when `params` is our own report arriving back through the host, which is
|
|
@@ -211,17 +222,32 @@ export function useGivensState({
|
|
|
211
222
|
const echoes = (reported: Record<string, string> | null) =>
|
|
212
223
|
reported !== null &&
|
|
213
224
|
sameDeclaredParams(params ?? {}, reported, declaredTypes);
|
|
214
|
-
// The
|
|
215
|
-
//
|
|
216
|
-
|
|
225
|
+
// The oldest report still in flight that `params` matches. Reports are
|
|
226
|
+
// delivered in order, so those before it are gone for good and it stays
|
|
227
|
+
// until the URL moves past it: a re-render at the same URL is idempotent.
|
|
228
|
+
// An entry older than the window is dropped: a URL that repeats it then is
|
|
229
|
+
// a push (Back, a drill), not a straggler.
|
|
230
|
+
const now = Date.now();
|
|
231
|
+
priorReported.current = priorReported.current.filter(
|
|
232
|
+
(r) => now - r.at < IN_FLIGHT_REPORT_MS,
|
|
233
|
+
);
|
|
234
|
+
const inFlight =
|
|
235
|
+
lastReported.current === null
|
|
236
|
+
? priorReported.current.map((r) => r.params)
|
|
237
|
+
: [
|
|
238
|
+
...priorReported.current.map((r) => r.params),
|
|
239
|
+
lastReported.current,
|
|
240
|
+
];
|
|
241
|
+
const arrived = inFlight.findIndex(echoes);
|
|
242
|
+
if (anchor.current.documentKey !== documentKey) priorReported.current = [];
|
|
217
243
|
if (
|
|
218
244
|
anchor.current.documentKey !== documentKey ||
|
|
219
|
-
(!sameParams(params ?? {}, anchor.current.params ?? {}) &&
|
|
220
|
-
!echoes(lastReported.current) &&
|
|
221
|
-
!echoes(priorReported.current))
|
|
245
|
+
(!sameParams(params ?? {}, anchor.current.params ?? {}) && arrived < 0)
|
|
222
246
|
) {
|
|
223
247
|
anchor.current = { documentKey, params };
|
|
224
248
|
}
|
|
249
|
+
if (arrived > 0)
|
|
250
|
+
priorReported.current = priorReported.current.slice(arrived);
|
|
225
251
|
const anchorParams = anchor.current.params;
|
|
226
252
|
const startingValuesKey = JSON.stringify(startingValues);
|
|
227
253
|
const anchorParamsKey = JSON.stringify(anchorParams);
|
|
@@ -363,7 +389,10 @@ export function useGivensState({
|
|
|
363
389
|
() => givensToParams(applied, declaredTypes),
|
|
364
390
|
[applied, declaredTypes],
|
|
365
391
|
);
|
|
366
|
-
if (lastReported.current === null)
|
|
392
|
+
if (lastReported.current === null) {
|
|
393
|
+
lastReported.current = appliedParams;
|
|
394
|
+
lastReportedAt.current = Date.now();
|
|
395
|
+
}
|
|
367
396
|
// Recorded only when the report is actually DELIVERED. A surface withholds
|
|
368
397
|
// the callback while it is still loading — `Notebook` passes undefined until
|
|
369
398
|
// the document has arrived, so that a report made in the window where it
|
|
@@ -384,8 +413,14 @@ export function useGivensState({
|
|
|
384
413
|
useEffect(() => {
|
|
385
414
|
if (!onParamsChange) return;
|
|
386
415
|
if (sameParams(lastReported.current ?? {}, appliedParams)) return;
|
|
387
|
-
|
|
416
|
+
if (lastReported.current !== null) {
|
|
417
|
+
priorReported.current = [
|
|
418
|
+
...priorReported.current.slice(-MAX_IN_FLIGHT_REPORTS + 1),
|
|
419
|
+
{ params: lastReported.current, at: lastReportedAt.current },
|
|
420
|
+
];
|
|
421
|
+
}
|
|
388
422
|
lastReported.current = appliedParams;
|
|
423
|
+
lastReportedAt.current = Date.now();
|
|
389
424
|
onParamsChange(appliedParams);
|
|
390
425
|
}, [appliedParams, onParamsChange]);
|
|
391
426
|
|
package/src/hooks/useSettled.ts
CHANGED
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* How long a changed
|
|
7
|
+
* How long a changed value has to stay changed before it is acted on: a given
|
|
8
|
+
* input commits after it, and the notebook waits it again before running.
|
|
8
9
|
*
|
|
9
|
-
* Aborting
|
|
10
|
-
* HTTP request, but
|
|
11
|
-
*
|
|
12
|
-
* are then thrown away. So autorun on a text control put one wave of doomed
|
|
13
|
-
* queries on that warehouse per keystroke. `origin/main` bounded the load by
|
|
14
|
-
* refusing to start a second run at all, which dropped the newest values;
|
|
15
|
-
* waiting for the value to settle bounds it without making that trade.
|
|
10
|
+
* Aborting a superseded run is not enough on its own: an abort cancels the
|
|
11
|
+
* HTTP request, but cells already dispatched have reached the server and go on
|
|
12
|
+
* running against the customer's warehouse, and their answers are thrown away.
|
|
16
13
|
*/
|
|
17
14
|
export const GIVEN_SETTLE_MS = 400;
|
|
18
15
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type KeyboardEvent,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { GIVEN_SETTLE_MS, useSettled } from "./useSettled";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A control's own copy of a value that is applied the moment it is committed.
|
|
15
|
+
*
|
|
16
|
+
* A draft the reader has edited is the source of truth while the field is
|
|
17
|
+
* focused, so a value echoing back from the URL cannot overwrite keystrokes
|
|
18
|
+
* typed since; a field the reader has not edited follows `committed`. An edited
|
|
19
|
+
* draft commits on blur, on Enter, and once it has settled (not mid-IME
|
|
20
|
+
* composition), each only if it differs from `committed`. A change made while
|
|
21
|
+
* the field is not focused (a calendar pick) commits at once. Mount and an
|
|
22
|
+
* untouched focus never commit.
|
|
23
|
+
*
|
|
24
|
+
* `unset` says `committed` is the empty display of a value that was never
|
|
25
|
+
* set, so an edit that lands back on that display still commits it: the
|
|
26
|
+
* reader emptied the field on purpose.
|
|
27
|
+
*/
|
|
28
|
+
export function useSettledDraft<T>(
|
|
29
|
+
committed: T,
|
|
30
|
+
commit: (draft: T) => void,
|
|
31
|
+
{
|
|
32
|
+
same = Object.is,
|
|
33
|
+
unset = false,
|
|
34
|
+
}: { same?: (a: T, b: T) => boolean; unset?: boolean } = {},
|
|
35
|
+
) {
|
|
36
|
+
const [draft, setDraft] = useState(committed);
|
|
37
|
+
const [focused, setFocused] = useState(false);
|
|
38
|
+
// A ref, set synchronously, so an unmount in the same batch as a reset sees it.
|
|
39
|
+
const edited = useRef(false);
|
|
40
|
+
// What was last committed, until `committed` catches up with it: a draft
|
|
41
|
+
// that equals the stale `committed` meanwhile has still been edited.
|
|
42
|
+
const sent = useRef<{ value: T } | null>(null);
|
|
43
|
+
const composing = useRef(false);
|
|
44
|
+
const latest = useRef({ draft, committed, focused, unset, commit, same });
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
latest.current = { draft, committed, focused, unset, commit, same };
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const due = () => {
|
|
50
|
+
const l = latest.current;
|
|
51
|
+
const shown = sent.current ? sent.current.value : l.committed;
|
|
52
|
+
return edited.current && (l.unset || !l.same(l.draft, shown));
|
|
53
|
+
};
|
|
54
|
+
const send = () => {
|
|
55
|
+
const l = latest.current;
|
|
56
|
+
sent.current = { value: l.draft };
|
|
57
|
+
l.commit(l.draft);
|
|
58
|
+
// The draft is already what is on screen: nothing is left to protect.
|
|
59
|
+
if (l.unset && l.same(l.draft, l.committed)) edited.current = false;
|
|
60
|
+
};
|
|
61
|
+
const flush = () => {
|
|
62
|
+
if (due()) send();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Composition end bumps `gen` so a draft that settled mid-composition is
|
|
66
|
+
// re-armed: the confirming input event repeats the tracked text, so the
|
|
67
|
+
// draft alone would not change.
|
|
68
|
+
const [gen, setGen] = useState(0);
|
|
69
|
+
const pending = useMemo(() => ({ draft, gen }), [draft, gen]);
|
|
70
|
+
const settled = useSettled(pending, GIVEN_SETTLE_MS);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const l = latest.current;
|
|
73
|
+
if (l.same(settled.draft, l.draft) && due() && !composing.current) {
|
|
74
|
+
send();
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `due`/`send` read refs only
|
|
77
|
+
}, [settled]);
|
|
78
|
+
|
|
79
|
+
// A pending draft is committed rather than dropped if the field goes away.
|
|
80
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `flush` reads refs only
|
|
81
|
+
useEffect(() => () => flush(), []);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (sent.current && same(sent.current.value, committed)) {
|
|
85
|
+
sent.current = null;
|
|
86
|
+
}
|
|
87
|
+
if (same(draft, committed)) {
|
|
88
|
+
if (!unset && !sent.current) edited.current = false;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!focused || !edited.current) setDraft(committed);
|
|
92
|
+
}, [committed, focused, draft, unset, same]);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
draft,
|
|
96
|
+
/** Show `next` as typed; applies it now if the field is not focused. */
|
|
97
|
+
change: (next: T) => {
|
|
98
|
+
edited.current = true;
|
|
99
|
+
setDraft(next);
|
|
100
|
+
if (!latest.current.focused && !same(next, committed)) commit(next);
|
|
101
|
+
},
|
|
102
|
+
/** Drop the draft for `next` without committing, for a clear. */
|
|
103
|
+
reset: (next: T) => {
|
|
104
|
+
edited.current = false;
|
|
105
|
+
sent.current = null;
|
|
106
|
+
setDraft(next);
|
|
107
|
+
},
|
|
108
|
+
bind: {
|
|
109
|
+
onFocus: () => setFocused(true),
|
|
110
|
+
onBlur: () => {
|
|
111
|
+
setFocused(false);
|
|
112
|
+
flush();
|
|
113
|
+
sent.current = null;
|
|
114
|
+
},
|
|
115
|
+
onKeyDown: (e: KeyboardEvent) => {
|
|
116
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing) flush();
|
|
117
|
+
},
|
|
118
|
+
onCompositionStart: () => {
|
|
119
|
+
composing.current = true;
|
|
120
|
+
},
|
|
121
|
+
onCompositionEnd: () => {
|
|
122
|
+
composing.current = false;
|
|
123
|
+
setGen((g) => g + 1);
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
|
-
import { malloyLiteral } from "./malloyLiteral";
|
|
5
|
+
import { formatMalloyValue, malloyLiteral } from "./malloyLiteral";
|
|
6
6
|
|
|
7
7
|
describe("malloyLiteral", () => {
|
|
8
8
|
it("spells a value the way its given's type reads it", () => {
|
|
@@ -41,3 +41,14 @@ describe("malloyLiteral", () => {
|
|
|
41
41
|
expect(malloyLiteral(new Date("nope"))).toBeUndefined();
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
|
+
|
|
45
|
+
describe("formatMalloyValue", () => {
|
|
46
|
+
it("spells filter values, dates as local-time days", () => {
|
|
47
|
+
expect(formatMalloyValue(null)).toBe("null");
|
|
48
|
+
expect(formatMalloyValue("O'Neil")).toBe("'O\\'Neil'");
|
|
49
|
+
expect(formatMalloyValue(42)).toBe("42");
|
|
50
|
+
expect(formatMalloyValue(false)).toBe("false");
|
|
51
|
+
expect(formatMalloyValue("2024-01-31", true)).toBe("@2024-01-31");
|
|
52
|
+
expect(formatMalloyValue(new Date(2024, 0, 5), true)).toBe("@2024-01-05");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -74,3 +74,35 @@ function datePart(value: unknown): string | undefined {
|
|
|
74
74
|
: value.toISOString().slice(0, 10);
|
|
75
75
|
return /^(\d{4}-\d{2}-\d{2})/.exec(String(value))?.[1];
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/** A filter value as a Malloy literal; unlike `malloyLiteral`, a Date is spelled as a local-time day. */
|
|
79
|
+
export function formatMalloyValue(
|
|
80
|
+
value: string | number | boolean | Date | null | undefined,
|
|
81
|
+
isDate: boolean = false,
|
|
82
|
+
): string {
|
|
83
|
+
if (value === null || value === undefined) {
|
|
84
|
+
return "null";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isDate) {
|
|
88
|
+
if (value instanceof Date) {
|
|
89
|
+
return `@${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, "0")}-${String(value.getDate()).padStart(2, "0")}`;
|
|
90
|
+
}
|
|
91
|
+
// A string is assumed to already be ISO.
|
|
92
|
+
return `@${value}`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (typeof value === "string") {
|
|
96
|
+
return `'${escapeMalloyString(value)}'`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (typeof value === "number") {
|
|
100
|
+
return String(value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (typeof value === "boolean") {
|
|
104
|
+
return value ? "true" : "false";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return String(value);
|
|
108
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -70,10 +70,8 @@ export default ({ mode }) => {
|
|
|
70
70
|
"@mui/material",
|
|
71
71
|
"@mui/icons-material",
|
|
72
72
|
"@mui/system",
|
|
73
|
-
"@mui/x-tree-view",
|
|
74
73
|
|
|
75
74
|
// Other large React libraries
|
|
76
|
-
"@react-spring/web",
|
|
77
75
|
"@tanstack/react-query",
|
|
78
76
|
|
|
79
77
|
// Malloy dependencies (should be provided by host)
|
package/.eslintrc
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Specify the environments where the code will run
|
|
3
|
-
"env": {
|
|
4
|
-
"jest": true, // Enable Jest for testing
|
|
5
|
-
"browser": true // Enable browser environment
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
// Stop ESLint from searching for configuration in parent folders
|
|
9
|
-
"root": true,
|
|
10
|
-
|
|
11
|
-
// Specify the parser for TypeScript (using @typescript-eslint/parser)
|
|
12
|
-
"parser": "@typescript-eslint/parser", // Leverages TS ESTree to lint TypeScript
|
|
13
|
-
|
|
14
|
-
// Add additional rules and configuration options
|
|
15
|
-
"plugins": ["@typescript-eslint"],
|
|
16
|
-
|
|
17
|
-
// Extend various ESLint configurations and plugins
|
|
18
|
-
"extends": [
|
|
19
|
-
"eslint:recommended", // ESLint recommended rules
|
|
20
|
-
"plugin:react/recommended", // React recommended rules
|
|
21
|
-
"plugin:@typescript-eslint/recommended", // TypeScript recommended rules
|
|
22
|
-
"plugin:@typescript-eslint/eslint-recommended", // ESLint overrides for TypeScript
|
|
23
|
-
"prettier", // Prettier rules
|
|
24
|
-
"plugin:prettier/recommended", // Prettier plugin integration
|
|
25
|
-
"plugin:react-hooks/recommended", // Recommended rules for React hooks
|
|
26
|
-
"plugin:storybook/recommended" // Recommended rules for Storybook
|
|
27
|
-
],
|
|
28
|
-
"settings": {
|
|
29
|
-
"react": {
|
|
30
|
-
"version": "detect"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"rules": {
|
|
34
|
-
"react/react-in-jsx-scope": "off",
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as DOMElement } from './DOMElement';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Database, Model } from '../../client';
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
interface FiieTreeViewProps {
|
|
4
|
-
items: Model[] | Database[];
|
|
5
|
-
defaultExpandedItems: string[];
|
|
6
|
-
onClickTreeNode?: (to: string, event?: React.MouseEvent) => void;
|
|
7
|
-
}
|
|
8
|
-
export declare function FileTreeView({ items, defaultExpandedItems, onClickTreeNode, }: FiieTreeViewProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
export {};
|