@malloy-publisher/sdk 0.9.11 → 0.9.13
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/README.md +5 -7
- package/dist/{RenderedResult-Cmx8sX8d.es.js → RenderedResult-DnBtf-cI.es.js} +2 -2
- package/dist/{RenderedResult-BlNoIiSi.cjs.js → RenderedResult-DtQtNV0d.cjs.js} +1 -1
- package/dist/ServerProvider-BIFPCzTD.cjs.js +1 -0
- package/dist/{ServerProvider-azXLkk1q.es.js → ServerProvider-BV7IoDMR.es.js} +808 -607
- package/dist/builder/index.cjs.js +72 -72
- package/dist/builder/index.es.js +4156 -4219
- package/dist/builder-entry.d.ts +1 -0
- package/dist/client/api.d.ts +224 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +41 -37
- package/dist/components/Connections/common.d.ts +11 -3
- package/dist/components/Report/telemetry.d.ts +0 -5
- package/dist/components/ReportBuilder/BuilderBar.d.ts +1 -1
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +14 -10
- package/dist/components/ReportBuilder/EditorSurface.d.ts +1 -2
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +3 -10
- package/dist/components/ReportBuilder/ReportEditor.d.ts +2 -9
- package/dist/components/ReportBuilder/SaveStatus.d.ts +16 -0
- package/dist/components/ReportBuilder/TileFrame.d.ts +9 -2
- package/dist/components/ReportBuilder/builderControls.d.ts +14 -6
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +1 -1
- package/dist/components/ReportBuilder/useReportDraft.d.ts +6 -2
- package/dist/components/given/GivenInput.d.ts +18 -1
- package/dist/components/given/GivensPanel.d.ts +12 -1
- package/dist/components/given/useOptionSearch.d.ts +30 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/useDocumentControls.d.ts +5 -0
- package/dist/hooks/useGivensState.d.ts +7 -0
- package/dist/hooks/useSuggestOptions.d.ts +60 -4
- package/dist/index.cjs.js +9 -9
- package/dist/index.es.js +2541 -2400
- package/dist/{useCompiledDocument-7j5cBjQd.es.js → useCompiledDocument-B4QF1mIl.es.js} +6912 -6759
- package/dist/useCompiledDocument-D0OAMejE.cjs.js +142 -0
- package/package.json +1 -1
- package/src/builder-entry.ts +1 -0
- package/src/components/Connections/AddConnectionDialog.tsx +34 -2
- package/src/components/Connections/EditConnectionDialog.tsx +45 -3
- package/src/components/Connections/common.spec.ts +69 -0
- package/src/components/Connections/common.ts +132 -0
- package/src/components/Environment/Connections.tsx +1 -0
- package/src/components/Report/ReportPage.tsx +5 -1
- package/src/components/Report/telemetry.ts +0 -6
- package/src/components/ReportBuilder/AddTileDialog.tsx +2 -2
- package/src/components/ReportBuilder/BuilderBar.tsx +5 -256
- package/src/components/ReportBuilder/BuilderHeader.tsx +9 -3
- package/src/components/ReportBuilder/BuilderToolbar.tsx +15 -38
- package/src/components/ReportBuilder/EditorSurface.tsx +0 -3
- package/src/components/ReportBuilder/FilterDialog.tsx +1 -1
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +210 -24
- package/src/components/ReportBuilder/ReportBuilder.tsx +43 -85
- package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +0 -36
- package/src/components/ReportBuilder/ReportEditor.tsx +2 -13
- package/src/components/ReportBuilder/SaveStatus.tsx +271 -0
- package/src/components/ReportBuilder/TileFrame.spec.ts +34 -0
- package/src/components/ReportBuilder/TileFrame.tsx +10 -3
- package/src/components/ReportBuilder/builderControls.ts +39 -13
- package/src/components/ReportBuilder/emptyStart.spec.ts +1 -1
- package/src/components/ReportBuilder/useReportDraft.ts +38 -4
- package/src/components/given/GivenInput.tsx +219 -104
- package/src/components/given/GivensPanel.spec.tsx +19 -0
- package/src/components/given/GivensPanel.tsx +31 -1
- package/src/components/given/useOptionSearch.spec.tsx +218 -0
- package/src/components/given/useOptionSearch.ts +100 -0
- package/src/hooks/index.ts +5 -1
- package/src/hooks/useDocumentControls.ts +12 -1
- package/src/hooks/useGivensState.spec.ts +54 -0
- package/src/hooks/useGivensState.ts +21 -1
- package/src/hooks/useSuggestOptions.dom.spec.ts +125 -4
- package/src/hooks/useSuggestOptions.spec.ts +73 -2
- package/src/hooks/useSuggestOptions.ts +234 -62
- package/dist/ServerProvider-BOgiW8MX.cjs.js +0 -1
- package/dist/useCompiledDocument-B21sVbb4.cjs.js +0 -141
- package/src/components/ReportBuilder/ReportBuilder.layoutSwitch.spec.tsx +0 -145
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
IconButton,
|
|
14
14
|
InputAdornment,
|
|
15
15
|
MenuItem,
|
|
16
|
+
Paper,
|
|
17
|
+
type PaperProps,
|
|
16
18
|
Slider,
|
|
17
19
|
Stack,
|
|
18
20
|
TextField,
|
|
@@ -25,10 +27,23 @@ import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
|
|
25
27
|
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
|
|
26
28
|
import dayjs from "dayjs";
|
|
27
29
|
import utc from "dayjs/plugin/utc";
|
|
28
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
createContext,
|
|
32
|
+
type FocusEvent,
|
|
33
|
+
type ReactNode,
|
|
34
|
+
useContext,
|
|
35
|
+
useEffect,
|
|
36
|
+
useState,
|
|
37
|
+
} from "react";
|
|
29
38
|
import { Given } from "../../client";
|
|
30
39
|
import { paramToGiven, pickedDayToUtc } from "./paramCodec";
|
|
31
40
|
import { GivenValue } from "../../hooks/givenValue";
|
|
41
|
+
import {
|
|
42
|
+
type OptionSearch,
|
|
43
|
+
SUGGEST_OPTION_LIMIT,
|
|
44
|
+
SUGGEST_SEARCH_LIMIT,
|
|
45
|
+
} from "../../hooks/useSuggestOptions";
|
|
46
|
+
import { type OptionSearchState, useOptionSearch } from "./useOptionSearch";
|
|
32
47
|
import {
|
|
33
48
|
decodeAtLeast,
|
|
34
49
|
decodeBetween,
|
|
@@ -87,6 +102,16 @@ export interface GivenInputProps {
|
|
|
87
102
|
* Free text still works, so the control degrades rather than locking up.
|
|
88
103
|
*/
|
|
89
104
|
optionsFailed?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* The option list was cut off: more values exist than `options` holds. The
|
|
107
|
+
* dropdown says so, since a value missing from it may still be in the data.
|
|
108
|
+
*/
|
|
109
|
+
optionsTruncated?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Search the whole dimension on the server as the reader types, for a list
|
|
112
|
+
* that was cut off. Absent, typing filters `options` in the browser.
|
|
113
|
+
*/
|
|
114
|
+
optionSearch?: OptionSearch;
|
|
90
115
|
}
|
|
91
116
|
|
|
92
117
|
/**
|
|
@@ -147,6 +172,8 @@ export function GivenInput({
|
|
|
147
172
|
options,
|
|
148
173
|
optionsLoading,
|
|
149
174
|
optionsFailed,
|
|
175
|
+
optionsTruncated,
|
|
176
|
+
optionSearch,
|
|
150
177
|
}: GivenInputProps) {
|
|
151
178
|
const label = given.label ?? given.name ?? "";
|
|
152
179
|
const { theme: publisherTheme } = usePublisherTheme();
|
|
@@ -255,6 +282,15 @@ export function GivenInput({
|
|
|
255
282
|
? [value]
|
|
256
283
|
: [];
|
|
257
284
|
|
|
285
|
+
// What the reader is typing into the picker, for a server search of a list
|
|
286
|
+
// that was cut off. Called for every given, as hooks must be; inert unless
|
|
287
|
+
// the picker below renders with a search to run.
|
|
288
|
+
const [typed, setTyped] = useState("");
|
|
289
|
+
const search = useOptionSearch(
|
|
290
|
+
pickerControl ? optionSearch : undefined,
|
|
291
|
+
typed,
|
|
292
|
+
);
|
|
293
|
+
|
|
258
294
|
if (
|
|
259
295
|
pickerControl &&
|
|
260
296
|
pickableType &&
|
|
@@ -305,113 +341,133 @@ export function GivenInput({
|
|
|
305
341
|
onChange(filtered ? (encoded as string) : next[0]);
|
|
306
342
|
};
|
|
307
343
|
|
|
344
|
+
const hint = optionHint(search, optionsTruncated, optionSearch);
|
|
308
345
|
return (
|
|
309
|
-
<
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
346
|
+
<OptionHint.Provider value={hint}>
|
|
347
|
+
<Autocomplete
|
|
348
|
+
multiple={multiple}
|
|
349
|
+
// Picking one value out of several should not put the list away;
|
|
350
|
+
// MUI closes on select by default, which makes "and also Aurora"
|
|
351
|
+
// cost a second click to reopen.
|
|
352
|
+
disableCloseOnSelect={multiple}
|
|
353
|
+
// Free text keeps the control from being a cage: the suggest query
|
|
354
|
+
// returns the common values, not necessarily every legal one.
|
|
355
|
+
freeSolo
|
|
356
|
+
// MUI hides the dropdown arrow whenever `freeSolo` is set, which
|
|
357
|
+
// left a control that HAS a list of values looking exactly like a
|
|
358
|
+
// plain text box: nothing on it said the list existed, so the only
|
|
359
|
+
// way to find the options was to guess that clicking would reveal
|
|
360
|
+
// them. Reported independently by a reader as "the controls render
|
|
361
|
+
// as text boxes rather than dropdowns"; the options were being
|
|
362
|
+
// fetched and offered correctly the whole time, and only the
|
|
363
|
+
// affordance was missing. Same principle as `markDrillableCells`:
|
|
364
|
+
// something you can act on has to look like it.
|
|
365
|
+
forcePopupIcon
|
|
366
|
+
// Keeps text the reader typed but did not pick from the list. A
|
|
367
|
+
// `freeSolo` Autocomplete without this discards it on blur, so a
|
|
368
|
+
// value that is legal but absent from `suggest` could be typed and
|
|
369
|
+
// then silently vanish.
|
|
370
|
+
//
|
|
371
|
+
// Single-pick only. On blur MUI's `autoSelect` also picks the
|
|
372
|
+
// HIGHLIGHTED option while the list is open, and a multi-pick
|
|
373
|
+
// keeps its list open after a pick with that option still
|
|
374
|
+
// highlighted, so clicking away picked it a second time, which in
|
|
375
|
+
// a multi-pick takes it back out: choose Aurora, click the page,
|
|
376
|
+
// and the filter was gone. A multi-pick keeps typed text itself,
|
|
377
|
+
// in the input's blur below.
|
|
378
|
+
autoSelect={!multiple}
|
|
379
|
+
// The server's matches once it has answered for exactly what is
|
|
380
|
+
// typed; until then the list in hand, filtered here as usual.
|
|
381
|
+
options={search.page?.values ?? options ?? []}
|
|
382
|
+
// Already matched on the server, case and all: filtering them
|
|
383
|
+
// again here could only hide a match.
|
|
384
|
+
{...(search.page
|
|
385
|
+
? { filterOptions: (found: string[]) => found }
|
|
386
|
+
: {})}
|
|
387
|
+
onInputChange={(_event, text, reason) =>
|
|
388
|
+
// Only typing searches. MUI also sets the text on a pick and
|
|
389
|
+
// on a reset to the value, and searching for the value just
|
|
390
|
+
// picked would replace the list with that one value.
|
|
391
|
+
setTyped(reason === "input" ? text : "")
|
|
392
|
+
}
|
|
393
|
+
loading={optionsLoading || search.searching}
|
|
394
|
+
loadingText={search.searching ? "Searching…" : "Loading…"}
|
|
395
|
+
noOptionsText={
|
|
396
|
+
optionsFailed ? "Options unavailable" : "No matching values"
|
|
397
|
+
}
|
|
398
|
+
slots={{ paper: HintPaper }}
|
|
399
|
+
value={multiple ? selected : (selected[0] ?? null)}
|
|
400
|
+
onChange={(_event, next) =>
|
|
401
|
+
commit(
|
|
402
|
+
next === null
|
|
403
|
+
? []
|
|
404
|
+
: Array.isArray(next)
|
|
405
|
+
? (next as string[])
|
|
406
|
+
: [next as string],
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
renderInput={(params) => (
|
|
410
|
+
<TextField
|
|
411
|
+
{...params}
|
|
412
|
+
label={label}
|
|
413
|
+
size="small"
|
|
414
|
+
// The model's own default when it has one, as a ghost, the
|
|
415
|
+
// way every other unset control shows it. A hardcoded "All"
|
|
416
|
+
// told the reader nothing would be filtered while the query
|
|
417
|
+
// was about to run on the declared default.
|
|
418
|
+
//
|
|
419
|
+
// Except when an explicit `""` is in force. That is the EMPTY
|
|
420
|
+
// filter, so the default is precisely what is NOT running,
|
|
421
|
+
// and showing it as a ghost made the control assert one
|
|
422
|
+
// filter while the query used another.
|
|
423
|
+
placeholder={
|
|
424
|
+
selected.length !== 0
|
|
425
|
+
? undefined
|
|
426
|
+
: value === ""
|
|
427
|
+
? "All"
|
|
428
|
+
: (defaultDisplay ?? "All")
|
|
429
|
+
}
|
|
430
|
+
error={optionsFailed}
|
|
431
|
+
helperText={
|
|
432
|
+
optionsFailed ? (
|
|
394
433
|
<>
|
|
395
|
-
|
|
396
|
-
|
|
434
|
+
Could not load the options for this control. Type
|
|
435
|
+
a value to filter anyway.
|
|
436
|
+
{helperNode ? <br /> : null}
|
|
437
|
+
{helperNode}
|
|
397
438
|
</>
|
|
398
|
-
)
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
439
|
+
) : (
|
|
440
|
+
helperNode
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
slotProps={{
|
|
444
|
+
input: {
|
|
445
|
+
...params.InputProps,
|
|
446
|
+
endAdornment: (
|
|
447
|
+
<>
|
|
448
|
+
{optionsLoading && (
|
|
449
|
+
<CircularProgress size={16} />
|
|
450
|
+
)}
|
|
451
|
+
{params.InputProps.endAdornment}
|
|
452
|
+
</>
|
|
453
|
+
),
|
|
408
454
|
},
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
455
|
+
htmlInput: {
|
|
456
|
+
...params.inputProps,
|
|
457
|
+
onBlur: (event: FocusEvent<HTMLInputElement>) => {
|
|
458
|
+
params.inputProps.onBlur?.(event);
|
|
459
|
+
if (!multiple) return;
|
|
460
|
+
const typed = event.target.value.trim();
|
|
461
|
+
if (typed !== "" && !selected.includes(typed))
|
|
462
|
+
commit([...selected, typed]);
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
}}
|
|
466
|
+
/>
|
|
467
|
+
)}
|
|
468
|
+
fullWidth
|
|
469
|
+
/>
|
|
470
|
+
</OptionHint.Provider>
|
|
415
471
|
);
|
|
416
472
|
}
|
|
417
473
|
|
|
@@ -1222,3 +1278,62 @@ function TimeRangeControl({
|
|
|
1222
1278
|
</Stack>
|
|
1223
1279
|
);
|
|
1224
1280
|
}
|
|
1281
|
+
|
|
1282
|
+
/** The line under a picker's options that says the list is partial, or being searched. */
|
|
1283
|
+
const OptionHint = createContext<string | undefined>(undefined);
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* The picker's dropdown, with a line under its options when there is
|
|
1287
|
+
* something to say about them. Read from context rather than props: MUI
|
|
1288
|
+
* renders the slot itself and passes it only its own props.
|
|
1289
|
+
*/
|
|
1290
|
+
function HintPaper({ children, ...props }: PaperProps) {
|
|
1291
|
+
const hint = useContext(OptionHint);
|
|
1292
|
+
return (
|
|
1293
|
+
<Paper {...props}>
|
|
1294
|
+
{children}
|
|
1295
|
+
{hint && (
|
|
1296
|
+
<Box
|
|
1297
|
+
role="note"
|
|
1298
|
+
sx={{
|
|
1299
|
+
px: 2,
|
|
1300
|
+
py: 1,
|
|
1301
|
+
borderTop: 1,
|
|
1302
|
+
borderColor: "divider",
|
|
1303
|
+
color: "text.secondary",
|
|
1304
|
+
typography: "caption",
|
|
1305
|
+
}}
|
|
1306
|
+
>
|
|
1307
|
+
{hint}
|
|
1308
|
+
</Box>
|
|
1309
|
+
)}
|
|
1310
|
+
</Paper>
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
const count = (n: number) => n.toLocaleString("en-US");
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* What the dropdown says about its options, if anything. Only a cut-off list
|
|
1318
|
+
* has something to say: a whole list needs no footnote.
|
|
1319
|
+
*/
|
|
1320
|
+
export function optionHint(
|
|
1321
|
+
search: OptionSearchState,
|
|
1322
|
+
truncated: boolean | undefined,
|
|
1323
|
+
searchable: OptionSearch | undefined,
|
|
1324
|
+
): string | undefined {
|
|
1325
|
+
if (search.active) {
|
|
1326
|
+
if (search.searching) return "Searching all values…";
|
|
1327
|
+
if (search.failed)
|
|
1328
|
+
return `Could not search all values. Showing matches in the first ${count(SUGGEST_OPTION_LIMIT)}.`;
|
|
1329
|
+
if (search.page?.truncated)
|
|
1330
|
+
return `Showing the first ${count(SUGGEST_SEARCH_LIMIT)} matches. Keep typing to narrow them.`;
|
|
1331
|
+
return undefined;
|
|
1332
|
+
}
|
|
1333
|
+
if (!truncated) return undefined;
|
|
1334
|
+
// A named suggest query cannot be searched on the server, so the list in
|
|
1335
|
+
// hand is all there is to filter; a value past it can still be typed in.
|
|
1336
|
+
return searchable
|
|
1337
|
+
? `Showing the first ${count(SUGGEST_OPTION_LIMIT)} values. Type to search them all.`
|
|
1338
|
+
: `Showing the first ${count(SUGGEST_OPTION_LIMIT)} values. A value not listed can still be typed.`;
|
|
1339
|
+
}
|
|
@@ -180,4 +180,23 @@ describe("layout and title", () => {
|
|
|
180
180
|
fireEvent.click(screen.getByRole("button", { name: "Reset" }));
|
|
181
181
|
expect(reset).toBe(1);
|
|
182
182
|
});
|
|
183
|
+
|
|
184
|
+
it("offers no Reset when the values are already where it would put them", () => {
|
|
185
|
+
// A value the document starts with is set, but Reset would change
|
|
186
|
+
// nothing: offered anyway, it was a button that did nothing.
|
|
187
|
+
render(
|
|
188
|
+
<GivensPanel
|
|
189
|
+
{...props}
|
|
190
|
+
layout="bar"
|
|
191
|
+
values={new Map([["BRAND", "Nike"]])}
|
|
192
|
+
canReset={false}
|
|
193
|
+
/>,
|
|
194
|
+
);
|
|
195
|
+
expect(screen.queryByRole("button", { name: "Reset" })).toBeNull();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("offers Reset when the values have moved off the start, even to empty", () => {
|
|
199
|
+
render(<GivensPanel {...props} layout="bar" canReset />);
|
|
200
|
+
expect(screen.getByRole("button", { name: "Reset" })).toBeDefined();
|
|
201
|
+
});
|
|
183
202
|
});
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Box, Button, Paper, Stack, Typography } from "@mui/material";
|
|
5
5
|
import { Given } from "../../client";
|
|
6
6
|
import { GivenValue } from "../../hooks/givenValue";
|
|
7
|
+
import type { OptionSearch } from "../../hooks/useSuggestOptions";
|
|
7
8
|
import { useFilterEditing } from "./filterEditing";
|
|
8
9
|
import {
|
|
9
10
|
AddFilterButton,
|
|
@@ -30,12 +31,22 @@ export interface GivensPanelProps {
|
|
|
30
31
|
values: Map<string, GivenValue>;
|
|
31
32
|
onChange: (name: string, value: GivenValue) => void;
|
|
32
33
|
onReset: () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Whether Reset would change anything: the controls differ from where the
|
|
36
|
+
* document starts them (`useGivensState`'s `atStart`). Absent, Reset is
|
|
37
|
+
* offered whenever a value is set, as before.
|
|
38
|
+
*/
|
|
39
|
+
canReset?: boolean;
|
|
33
40
|
layout?: GivensLayout;
|
|
34
41
|
/** Resolved `suggest` options per given name. */
|
|
35
42
|
options?: Map<string, string[]>;
|
|
36
43
|
optionsLoading?: boolean;
|
|
37
44
|
/** Givens whose `suggest` query failed, from `useSuggestOptions.failed`. */
|
|
38
45
|
optionsFailed?: ReadonlySet<string>;
|
|
46
|
+
/** Givens whose option list was cut off, from `useSuggestOptions.truncated`. */
|
|
47
|
+
optionsTruncated?: ReadonlySet<string>;
|
|
48
|
+
/** Server search for a cut-off list, per given, from `useSuggestOptions.search`. */
|
|
49
|
+
optionSearch?: ReadonlyMap<string, OptionSearch>;
|
|
39
50
|
/**
|
|
40
51
|
* Set to render an Apply button, for `autorun=false`. Absent means controls
|
|
41
52
|
* take effect as they change, which is the default everywhere.
|
|
@@ -64,10 +75,13 @@ export function GivensPanel({
|
|
|
64
75
|
values,
|
|
65
76
|
onChange,
|
|
66
77
|
onReset,
|
|
78
|
+
canReset,
|
|
67
79
|
layout = "panel",
|
|
68
80
|
options,
|
|
69
81
|
optionsLoading,
|
|
70
82
|
optionsFailed,
|
|
83
|
+
optionsTruncated,
|
|
84
|
+
optionSearch,
|
|
71
85
|
apply,
|
|
72
86
|
title,
|
|
73
87
|
}: GivensPanelProps) {
|
|
@@ -80,6 +94,20 @@ export function GivensPanel({
|
|
|
80
94
|
// control that is unset, and pressing it changed nothing and left the empty
|
|
81
95
|
// parameter in the URL.
|
|
82
96
|
const hasValues = Array.from(values.values()).some((v) => v !== null);
|
|
97
|
+
// Only when pressing it would change something. A value the document starts
|
|
98
|
+
// with is set but is already the reset state, and Reset beside it did
|
|
99
|
+
// nothing when pressed.
|
|
100
|
+
const offerReset = canReset ?? hasValues;
|
|
101
|
+
|
|
102
|
+
// A cut-off list, and the search that finds past it, for one control.
|
|
103
|
+
const searchProps = (name: string | undefined) => {
|
|
104
|
+
if (name === undefined) return {};
|
|
105
|
+
const search = optionSearch?.get(name);
|
|
106
|
+
return {
|
|
107
|
+
...(optionsTruncated?.has(name) ? { optionsTruncated: true } : {}),
|
|
108
|
+
...(search ? { optionSearch: search } : {}),
|
|
109
|
+
};
|
|
110
|
+
};
|
|
83
111
|
|
|
84
112
|
const inputs = givens.map((given) => (
|
|
85
113
|
<Box key={given.name}>
|
|
@@ -92,6 +120,7 @@ export function GivensPanel({
|
|
|
92
120
|
optionsFailed={
|
|
93
121
|
given.name ? optionsFailed?.has(given.name) : undefined
|
|
94
122
|
}
|
|
123
|
+
{...searchProps(given.name)}
|
|
95
124
|
/>
|
|
96
125
|
</Box>
|
|
97
126
|
));
|
|
@@ -109,7 +138,7 @@ export function GivensPanel({
|
|
|
109
138
|
Apply
|
|
110
139
|
</Button>
|
|
111
140
|
)}
|
|
112
|
-
{
|
|
141
|
+
{offerReset && (
|
|
113
142
|
<Button variant="text" size="small" onClick={onReset}>
|
|
114
143
|
Reset
|
|
115
144
|
</Button>
|
|
@@ -140,6 +169,7 @@ export function GivensPanel({
|
|
|
140
169
|
optionsFailed={
|
|
141
170
|
given.name ? optionsFailed?.has(given.name) : undefined
|
|
142
171
|
}
|
|
172
|
+
{...searchProps(given.name)}
|
|
143
173
|
/>
|
|
144
174
|
))}
|
|
145
175
|
{editing?.unrendered.map((filter) => (
|