@malloy-publisher/sdk 0.2.7 → 0.3.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/README.md +180 -204
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
- package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
- package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
- package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
- package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
- package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9561 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/api.d.ts +13 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/ApiErrorDisplay.d.ts +1 -2
- package/dist/components/Dashboard/Dashboard.d.ts +23 -16
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
- package/dist/components/Dashboard/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
- package/dist/components/DocumentStorage/index.d.ts +3 -0
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/Model/index.d.ts +0 -1
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +2 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
- package/dist/components/drill/index.d.ts +2 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/drill/useDrillSelf.d.ts +46 -0
- package/dist/components/given/filterValue.d.ts +63 -0
- package/dist/components/given/index.d.ts +1 -0
- package/dist/components/given/useGivenUrlParams.d.ts +39 -0
- package/dist/components/index.d.ts +3 -3
- package/dist/components/styles.d.ts +3 -7
- package/dist/core-8NVBCLZh.cjs.js +148 -0
- package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/hooks/useSuggestOptions.d.ts +28 -12
- package/dist/index.cjs.js +34 -1
- package/dist/index.es.js +21487 -79
- package/dist/sdk.css +1 -1
- package/dist/styles.css +0 -1
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/package.json +25 -14
- package/src/builder-entry.ts +55 -0
- package/src/components/ApiErrorDisplay.tsx +1 -1
- package/src/components/Connections/EditConnectionDialog.tsx +96 -86
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +184 -229
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +67 -101
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
- package/src/components/Dashboard/telemetry.ts +44 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
- package/src/components/DocumentStorage/index.ts +16 -0
- package/src/components/Environment/About.tsx +4 -36
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +34 -72
- package/src/components/Model/index.ts +0 -1
- package/src/components/Notebook/Notebook.tsx +27 -156
- package/src/components/Notebook/NotebookCell.tsx +37 -191
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/RenderedResult.tsx +86 -76
- package/src/components/RenderedResult/ResultContainer.tsx +25 -36
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +16 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
- package/src/components/RenderedResult/resultSizing.ts +308 -0
- package/src/components/ResultsDialog.tsx +2 -1
- package/src/components/drill/index.ts +6 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/drill/useDrillSelf.spec.tsx +64 -0
- package/src/components/drill/useDrillSelf.ts +110 -0
- package/src/components/given/GivenInput.spec.tsx +196 -2
- package/src/components/given/GivenInput.tsx +300 -25
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/given/filterValue.spec.ts +112 -0
- package/src/components/given/filterValue.ts +188 -0
- package/src/components/given/index.ts +4 -0
- package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
- package/src/components/given/useGivenUrlParams.ts +87 -0
- package/src/components/index.ts +11 -3
- package/src/components/styles.ts +0 -37
- package/src/hooks/index.ts +13 -1
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useGivensState.spec.ts +158 -0
- package/src/hooks/useGivensState.ts +114 -23
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
- package/src/hooks/useSuggestOptions.ts +94 -51
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/vite.config.ts +5 -1
- package/dist/components/AnalyzePackageButton.d.ts +0 -6
- package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
- package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
- package/dist/components/Workbook/ModelPicker.d.ts +0 -11
- package/dist/components/Workbook/MutableCell.d.ts +0 -17
- package/dist/components/Workbook/Workbook.d.ts +0 -7
- package/dist/components/Workbook/WorkbookList.d.ts +0 -7
- package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
- package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
- package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
- package/dist/components/Workbook/index.d.ts +0 -7
- package/dist/core-CWKmWEg2.cjs.js +0 -148
- package/dist/index-B0WyZAUA.es.js +0 -66412
- package/dist/index-kxVD1RjY.cjs.js +0 -356
- package/dist/markdown-editor.css +0 -341
- package/src/components/AnalyzePackageButton.tsx +0 -319
- package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
- package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
- package/src/components/Workbook/ModelPicker.tsx +0 -134
- package/src/components/Workbook/MutableCell.tsx +0 -458
- package/src/components/Workbook/Workbook.tsx +0 -501
- package/src/components/Workbook/WorkbookList.tsx +0 -110
- package/src/components/Workbook/WorkbookManager.ts +0 -214
- package/src/components/Workbook/WorkbookStorage.ts +0 -35
- package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
- package/src/components/Workbook/index.ts +0 -10
|
@@ -26,9 +26,16 @@ import {
|
|
|
26
26
|
isStringCondition,
|
|
27
27
|
NumberFilterExpression,
|
|
28
28
|
StringFilterExpression,
|
|
29
|
+
TemporalFilterExpression,
|
|
30
|
+
type Moment,
|
|
29
31
|
type StringCondition,
|
|
30
32
|
type StringFilter,
|
|
33
|
+
type TemporalFilter,
|
|
31
34
|
} from "@malloydata/malloy-filter";
|
|
35
|
+
import dayjs from "dayjs";
|
|
36
|
+
import utc from "dayjs/plugin/utc";
|
|
37
|
+
|
|
38
|
+
dayjs.extend(utc);
|
|
32
39
|
|
|
33
40
|
/** True for the `filter<…>` family, whose values are filter syntax, not plain. */
|
|
34
41
|
export function isFilterType(type: string | undefined): boolean {
|
|
@@ -205,3 +212,184 @@ export function decodeAtLeast(value: string): number | undefined {
|
|
|
205
212
|
const bound = Number(parsed.values[0]);
|
|
206
213
|
return Number.isFinite(bound) ? bound : undefined;
|
|
207
214
|
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* An inclusive number range, which is what a two-handled slider means:
|
|
218
|
+
* `encodeBetween(10, 20)` is `[10 to 20]`, Malloy's `>= 10 and <= 20`. The same
|
|
219
|
+
* spelling Malloyyo's `filters.between` writes, so a value set on either host
|
|
220
|
+
* reads back on the other.
|
|
221
|
+
*/
|
|
222
|
+
export function encodeBetween(lo: number, hi: number): string {
|
|
223
|
+
return NumberFilterExpression.unparse({
|
|
224
|
+
operator: "range",
|
|
225
|
+
startOperator: ">=",
|
|
226
|
+
startValue: String(lo),
|
|
227
|
+
endOperator: "<=",
|
|
228
|
+
endValue: String(hi),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The bounds back out of {@link encodeBetween}, or undefined for any other
|
|
234
|
+
* filter. Only the closed range round-trips: `(10 to 20]` and its kin exclude an
|
|
235
|
+
* end the slider's thumbs cannot express, and a negated range is not a range at
|
|
236
|
+
* all, so both fall through to the text box rather than being redrawn as
|
|
237
|
+
* something else.
|
|
238
|
+
*/
|
|
239
|
+
export function decodeBetween(value: string): [number, number] | undefined {
|
|
240
|
+
const text = value.trim();
|
|
241
|
+
if (text === "") return undefined;
|
|
242
|
+
const { parsed } = NumberFilterExpression.parse(text);
|
|
243
|
+
if (
|
|
244
|
+
parsed === null ||
|
|
245
|
+
parsed.operator !== "range" ||
|
|
246
|
+
parsed.not === true ||
|
|
247
|
+
parsed.startOperator !== ">=" ||
|
|
248
|
+
parsed.endOperator !== "<="
|
|
249
|
+
) {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
const lo = Number(parsed.startValue);
|
|
253
|
+
const hi = Number(parsed.endValue);
|
|
254
|
+
return Number.isFinite(lo) && Number.isFinite(hi) && lo <= hi
|
|
255
|
+
? [lo, hi]
|
|
256
|
+
: undefined;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The preset windows a time-range control offers for a `filter<date>` or
|
|
261
|
+
* `filter<timestamp>` given. The same six Malloyyo's `TimeRange` widget ships,
|
|
262
|
+
* spelled in Malloy's filter grammar: `today` is the current day, `7 days` is
|
|
263
|
+
* Malloy's "in the last 7 days", a rolling window ending now.
|
|
264
|
+
*
|
|
265
|
+
* Structured clauses rather than strings so the spelling on the wire is the
|
|
266
|
+
* filter package's own, and {@link decodeTimePreset} compares against the same
|
|
267
|
+
* structure the parser returns rather than against text that may be spelled
|
|
268
|
+
* `7 day`, `7 days` or `7 days` by whoever wrote the URL.
|
|
269
|
+
*/
|
|
270
|
+
export const TIME_PRESETS: readonly {
|
|
271
|
+
key: string;
|
|
272
|
+
label: string;
|
|
273
|
+
clause: TemporalFilter;
|
|
274
|
+
}[] = [
|
|
275
|
+
{
|
|
276
|
+
key: "today",
|
|
277
|
+
label: "Today",
|
|
278
|
+
clause: { operator: "in", in: { moment: "today" } },
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
key: "7d",
|
|
282
|
+
label: "Last 7 days",
|
|
283
|
+
clause: { operator: "in_last", units: "day", n: "7" },
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
key: "30d",
|
|
287
|
+
label: "Last 30 days",
|
|
288
|
+
clause: { operator: "in_last", units: "day", n: "30" },
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
key: "90d",
|
|
292
|
+
label: "Last 90 days",
|
|
293
|
+
clause: { operator: "in_last", units: "day", n: "90" },
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
key: "12m",
|
|
297
|
+
label: "Last 12 months",
|
|
298
|
+
clause: { operator: "in_last", units: "month", n: "12" },
|
|
299
|
+
},
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
/** The filter text for one of {@link TIME_PRESETS}, by key. */
|
|
303
|
+
export function encodeTimePreset(key: string): string | undefined {
|
|
304
|
+
const preset = TIME_PRESETS.find((p) => p.key === key);
|
|
305
|
+
return preset ? TemporalFilterExpression.unparse(preset.clause) : undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Which preset a filter is, or undefined when it is none of them. Matched on the
|
|
310
|
+
* parsed clause, so `7 day` and `7 days` are the same window, and a negated or
|
|
311
|
+
* compound filter is not a preset however it is spelled.
|
|
312
|
+
*/
|
|
313
|
+
export function decodeTimePreset(value: string): string | undefined {
|
|
314
|
+
const text = value.trim();
|
|
315
|
+
if (text === "") return undefined;
|
|
316
|
+
const { parsed } = TemporalFilterExpression.parse(text);
|
|
317
|
+
if (parsed === null) return undefined;
|
|
318
|
+
for (const preset of TIME_PRESETS) {
|
|
319
|
+
const want = preset.clause;
|
|
320
|
+
if (want.operator !== parsed.operator) continue;
|
|
321
|
+
if (want.operator === "in" && parsed.operator === "in") {
|
|
322
|
+
if (parsed.not !== true && parsed.in.moment === want.in.moment) {
|
|
323
|
+
return preset.key;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (want.operator === "in_last" && parsed.operator === "in_last") {
|
|
327
|
+
if (
|
|
328
|
+
parsed.not !== true &&
|
|
329
|
+
parsed.units === want.units &&
|
|
330
|
+
Number(parsed.n) === Number(want.n)
|
|
331
|
+
) {
|
|
332
|
+
return preset.key;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* An inclusive range of whole days, as two `YYYY-MM-DD` strings, in Malloy's
|
|
343
|
+
* filter grammar.
|
|
344
|
+
*
|
|
345
|
+
* Malloy's `A to B` runs from the start of A up to but NOT including the start
|
|
346
|
+
* of B (`filter_compilers.ts`, `case 'to'`), while a reader picking "January
|
|
347
|
+
* 1st to January 31st" means both days. So the end is encoded as the day AFTER
|
|
348
|
+
* the last day picked: `encodeDayRange("2024-01-01", "2024-01-31")` is
|
|
349
|
+
* `2024-01-01 to 2024-02-01`. {@link decodeDayRange} undoes exactly that, so a
|
|
350
|
+
* range written by Malloyyo (which encodes the picked day verbatim) displays
|
|
351
|
+
* here as the days it actually selects.
|
|
352
|
+
*/
|
|
353
|
+
export function encodeDayRange(firstDay: string, lastDay: string): string {
|
|
354
|
+
const end = dayjs.utc(lastDay, "YYYY-MM-DD").add(1, "day");
|
|
355
|
+
return TemporalFilterExpression.unparse({
|
|
356
|
+
operator: "to",
|
|
357
|
+
fromMoment: { moment: "literal", literal: firstDay, units: "day" },
|
|
358
|
+
toMoment: {
|
|
359
|
+
moment: "literal",
|
|
360
|
+
literal: end.format("YYYY-MM-DD"),
|
|
361
|
+
units: "day",
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* The inclusive days back out of {@link encodeDayRange}, or undefined for any
|
|
368
|
+
* other filter. Both ends must be whole-day literals: a range with a time of
|
|
369
|
+
* day, a relative end (`2024-01-01 to now`), or a negation is not something two
|
|
370
|
+
* day pickers can show, and falls through to the text box.
|
|
371
|
+
*/
|
|
372
|
+
export function decodeDayRange(
|
|
373
|
+
value: string,
|
|
374
|
+
): { firstDay: string; lastDay: string } | undefined {
|
|
375
|
+
const text = value.trim();
|
|
376
|
+
if (text === "") return undefined;
|
|
377
|
+
const { parsed } = TemporalFilterExpression.parse(text);
|
|
378
|
+
if (parsed === null || parsed.operator !== "to" || parsed.not === true) {
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
const from = dayLiteral(parsed.fromMoment);
|
|
382
|
+
const to = dayLiteral(parsed.toMoment);
|
|
383
|
+
if (from === undefined || to === undefined) return undefined;
|
|
384
|
+
const lastDay = dayjs.utc(to, "YYYY-MM-DD").subtract(1, "day");
|
|
385
|
+
if (!lastDay.isValid() || lastDay.isBefore(dayjs.utc(from, "YYYY-MM-DD"))) {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
return { firstDay: from, lastDay: lastDay.format("YYYY-MM-DD") };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function dayLiteral(moment: Moment): string | undefined {
|
|
392
|
+
return moment.moment === "literal" && DAY.test(moment.literal)
|
|
393
|
+
? moment.literal
|
|
394
|
+
: undefined;
|
|
395
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { act, renderHook } from "@testing-library/react";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
import { MemoryRouter, useLocation } from "react-router-dom";
|
|
8
|
+
import { useGivenUrlParams } from "./useGivenUrlParams";
|
|
9
|
+
|
|
10
|
+
function mount(initialEntry: string) {
|
|
11
|
+
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
12
|
+
<MemoryRouter initialEntries={[initialEntry]}>{children}</MemoryRouter>
|
|
13
|
+
);
|
|
14
|
+
const view = renderHook(
|
|
15
|
+
() => ({ hook: useGivenUrlParams(), location: useLocation() }),
|
|
16
|
+
{ wrapper },
|
|
17
|
+
);
|
|
18
|
+
return {
|
|
19
|
+
get params() {
|
|
20
|
+
return view.result.current.hook.params;
|
|
21
|
+
},
|
|
22
|
+
get search() {
|
|
23
|
+
return new URLSearchParams(view.result.current.location.search);
|
|
24
|
+
},
|
|
25
|
+
get hash() {
|
|
26
|
+
return view.result.current.location.hash;
|
|
27
|
+
},
|
|
28
|
+
change(next: Record<string, string>, managed: string[]) {
|
|
29
|
+
act(() => view.result.current.hook.onGivensChange(next, managed));
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("useGivenUrlParams", () => {
|
|
35
|
+
it("reads the query string as a flat record", () => {
|
|
36
|
+
const host = mount("/d?REGION=West&utm=x");
|
|
37
|
+
expect(host.params).toEqual({ REGION: "West", utm: "x" });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("merges into the query string, leaving parameters that are not ours", () => {
|
|
41
|
+
const host = mount("/d?utm=x");
|
|
42
|
+
host.change({ REGION: "West" }, ["REGION"]);
|
|
43
|
+
expect(host.search.get("REGION")).toBe("West");
|
|
44
|
+
expect(host.search.get("utm")).toBe("x");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("removes a managed name that was cleared, and only that", () => {
|
|
48
|
+
const host = mount("/d?REGION=West&STATUS=open&utm=x");
|
|
49
|
+
host.change({ STATUS: "open" }, ["REGION", "STATUS"]);
|
|
50
|
+
expect(host.search.has("REGION")).toBe(false);
|
|
51
|
+
expect(host.search.get("STATUS")).toBe("open");
|
|
52
|
+
expect(host.search.get("utm")).toBe("x");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("remembers what it wrote, so a given the model stopped declaring is still cleaned up", () => {
|
|
56
|
+
const host = mount("/d");
|
|
57
|
+
host.change({ REGION: "West" }, ["REGION"]);
|
|
58
|
+
// The model reloads without REGION; the report no longer manages it.
|
|
59
|
+
host.change({}, []);
|
|
60
|
+
expect(host.search.has("REGION")).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("keeps the fragment the reader arrived on", () => {
|
|
64
|
+
const host = mount("/d?utm=x#trend");
|
|
65
|
+
host.change({ REGION: "West" }, ["REGION"]);
|
|
66
|
+
expect(host.hash).toBe("#trend");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("is not fooled by a given named like an Object.prototype member", () => {
|
|
70
|
+
const host = mount("/d?constructor=1");
|
|
71
|
+
host.change({}, ["constructor"]);
|
|
72
|
+
expect(host.search.has("constructor")).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
5
|
+
import { useLocation, useNavigate, useSearchParams } from "react-router-dom";
|
|
6
|
+
|
|
7
|
+
export interface UseGivenUrlParamsResult {
|
|
8
|
+
/** The query string as a flat record: what a document reads its givens from. */
|
|
9
|
+
params: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* For a document's `onGivensChange`: writes the applied values into the
|
|
12
|
+
* query string, in place, leaving every parameter that is not a given alone.
|
|
13
|
+
*/
|
|
14
|
+
onGivensChange: (
|
|
15
|
+
next: Record<string, string>,
|
|
16
|
+
managed: readonly string[],
|
|
17
|
+
) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Keep a document's control values in the page's query string, so a filtered
|
|
22
|
+
* dashboard or a parameterized notebook is a shareable link.
|
|
23
|
+
*
|
|
24
|
+
* This is the host side of `useGivensState`: the document reports its applied
|
|
25
|
+
* values and the names it manages, this writes them into the URL and feeds the
|
|
26
|
+
* URL back in as `params`. The two Console pages carried a copy each; they
|
|
27
|
+
* agreed line for line, so this is that code once, for any host on
|
|
28
|
+
* react-router.
|
|
29
|
+
*
|
|
30
|
+
* Three things it is careful about, each of which was a bug once:
|
|
31
|
+
*
|
|
32
|
+
* - **Merge, never replace.** The query string is not the document's alone: a
|
|
33
|
+
* tracking tag or any other unrelated parameter shares it, and replacing the
|
|
34
|
+
* whole string dropped those on LOAD, as soon as the first report arrived.
|
|
35
|
+
* Only names that are ours are touched: what the document manages now, plus
|
|
36
|
+
* anything this hook wrote earlier, so a control cleared after a model reload
|
|
37
|
+
* stopped declaring it still gets its parameter removed. That memory outlives
|
|
38
|
+
* a document swap on purpose: the parameter written for the previous
|
|
39
|
+
* document is the stale one the next should clear.
|
|
40
|
+
* - **`hasOwnProperty`, not `in`.** `next` is a plain object literal, so `in`
|
|
41
|
+
* walks its prototype and reports `constructor`, `toString` and friends as
|
|
42
|
+
* present; a given with one of those names could never be cleared.
|
|
43
|
+
* - **Replace, and keep the hash.** Changing a control is not a navigation
|
|
44
|
+
* step, so Back should leave the document rather than walk back through
|
|
45
|
+
* every value tried. And a navigation that names only `search` resolves to an
|
|
46
|
+
* empty fragment, which dropped whatever anchor the reader arrived on;
|
|
47
|
+
* `setSearchParams` has that problem, which is why this navigates itself.
|
|
48
|
+
*/
|
|
49
|
+
export function useGivenUrlParams(): UseGivenUrlParamsResult {
|
|
50
|
+
const [searchParams] = useSearchParams();
|
|
51
|
+
const navigate = useNavigate();
|
|
52
|
+
const location = useLocation();
|
|
53
|
+
|
|
54
|
+
const params = useMemo(
|
|
55
|
+
() => Object.fromEntries(searchParams.entries()),
|
|
56
|
+
[searchParams],
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const writtenRef = useRef<Set<string>>(new Set());
|
|
60
|
+
|
|
61
|
+
const onGivensChange = useCallback(
|
|
62
|
+
(next: Record<string, string>, managed: readonly string[]) => {
|
|
63
|
+
const ours = new Set([...managed, ...writtenRef.current]);
|
|
64
|
+
writtenRef.current = new Set([
|
|
65
|
+
...writtenRef.current,
|
|
66
|
+
...Object.keys(next),
|
|
67
|
+
...managed,
|
|
68
|
+
]);
|
|
69
|
+
const merged = new URLSearchParams(location.search);
|
|
70
|
+
for (const name of ours) {
|
|
71
|
+
if (!Object.prototype.hasOwnProperty.call(next, name)) {
|
|
72
|
+
merged.delete(name);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const [name, value] of Object.entries(next)) {
|
|
76
|
+
merged.set(name, value);
|
|
77
|
+
}
|
|
78
|
+
navigate(
|
|
79
|
+
{ search: merged.toString(), hash: location.hash },
|
|
80
|
+
{ replace: true },
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
[navigate, location],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return { params, onGivensChange };
|
|
87
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Exported because Dashboard, DashboardTile and Notebook all present request
|
|
5
|
+
// failures through it; a host composing those needs the same presentation for
|
|
6
|
+
// its own.
|
|
7
|
+
export { ApiErrorDisplay, type ApiErrorDisplayProps } from "./ApiErrorDisplay";
|
|
5
8
|
export { useRouterClickHandler, type NavigationClick } from "./click_helper";
|
|
6
9
|
export * from "./Dashboard";
|
|
7
10
|
export * from "./DataAppViewer";
|
|
@@ -15,9 +18,14 @@ export * from "./Materializations";
|
|
|
15
18
|
export * from "./Model";
|
|
16
19
|
export * from "./Notebook";
|
|
17
20
|
export * from "./Package";
|
|
21
|
+
export {
|
|
22
|
+
Prose,
|
|
23
|
+
type ProseLinkContext,
|
|
24
|
+
type ProseProps,
|
|
25
|
+
type ProseVariant,
|
|
26
|
+
} from "./Prose";
|
|
18
27
|
export * from "./QueryResult";
|
|
19
28
|
export * from "./RenderedResult";
|
|
20
29
|
export { ServerProvider, useServer } from "./ServerProvider";
|
|
21
30
|
export type { ServerContextValue, ServerProviderProps } from "./ServerProvider";
|
|
22
|
-
export * from "./
|
|
23
|
-
export type { WorkbookStorage } from "./Workbook";
|
|
31
|
+
export * from "./DocumentStorage";
|
package/src/components/styles.ts
CHANGED
|
@@ -85,12 +85,6 @@ export const CleanNotebookContainer = styled("div")(({ theme }) => ({
|
|
|
85
85
|
margin: "0 auto",
|
|
86
86
|
}));
|
|
87
87
|
|
|
88
|
-
export const CleanNotebookHeader = styled("div")(({ theme }) => ({
|
|
89
|
-
marginBottom: "40px",
|
|
90
|
-
paddingBottom: "24px",
|
|
91
|
-
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
88
|
export const CleanNotebookSection = styled("div")({
|
|
95
89
|
marginBottom: "48px",
|
|
96
90
|
padding: "0",
|
|
@@ -99,14 +93,6 @@ export const CleanNotebookSection = styled("div")({
|
|
|
99
93
|
boxShadow: "none",
|
|
100
94
|
});
|
|
101
95
|
|
|
102
|
-
export const CleanNotebookCell = styled("div")({
|
|
103
|
-
marginBottom: "0",
|
|
104
|
-
padding: "0",
|
|
105
|
-
backgroundColor: "transparent",
|
|
106
|
-
border: "none",
|
|
107
|
-
boxShadow: "none",
|
|
108
|
-
});
|
|
109
|
-
|
|
110
96
|
export const CleanMetricCard = styled("div")({
|
|
111
97
|
backgroundColor: "transparent",
|
|
112
98
|
paddingTop: "12px",
|
|
@@ -117,29 +103,6 @@ export const CleanMetricCard = styled("div")({
|
|
|
117
103
|
marginBottom: "0",
|
|
118
104
|
});
|
|
119
105
|
|
|
120
|
-
export const CleanCodeBlock = styled("div")(({ theme }) => ({
|
|
121
|
-
backgroundColor: theme.palette.mode === "dark" ? "#1e293b" : "#f8f9fa",
|
|
122
|
-
padding: "16px",
|
|
123
|
-
borderRadius: "8px",
|
|
124
|
-
border: `1px solid ${theme.palette.divider}`,
|
|
125
|
-
fontFamily: "'Monaco', 'Menlo', 'Ubuntu Mono', monospace",
|
|
126
|
-
fontSize: "13px",
|
|
127
|
-
lineHeight: "1.5",
|
|
128
|
-
overflowX: "auto",
|
|
129
|
-
color: theme.palette.text.primary,
|
|
130
|
-
}));
|
|
131
|
-
|
|
132
|
-
export const CleanActionBar = styled("div")(({ theme }) => ({
|
|
133
|
-
backgroundColor: theme.palette.mode === "dark" ? "#1e293b" : "#f8f9fa",
|
|
134
|
-
padding: "12px 16px",
|
|
135
|
-
borderRadius: "8px",
|
|
136
|
-
border: `1px solid ${theme.palette.divider}`,
|
|
137
|
-
marginBottom: "16px",
|
|
138
|
-
display: "flex",
|
|
139
|
-
justifyContent: "space-between",
|
|
140
|
-
alignItems: "center",
|
|
141
|
-
}));
|
|
142
|
-
|
|
143
106
|
export const StyledExplorerPage = styled("div")({
|
|
144
107
|
height: "100%",
|
|
145
108
|
});
|
package/src/hooks/index.ts
CHANGED
|
@@ -26,7 +26,6 @@ export {
|
|
|
26
26
|
export {
|
|
27
27
|
useDimensionalFilterRangeData,
|
|
28
28
|
getDimensionKey,
|
|
29
|
-
makeDimensionKey,
|
|
30
29
|
type DimensionalFilterRangeDataResult,
|
|
31
30
|
type DimensionSpec,
|
|
32
31
|
type DimensionValue,
|
|
@@ -44,3 +43,16 @@ export {
|
|
|
44
43
|
type UseGivensStateResult,
|
|
45
44
|
} from "./useGivensState";
|
|
46
45
|
export { useSuggestOptions } from "./useSuggestOptions";
|
|
46
|
+
|
|
47
|
+
// One query, and one control row, as every surface asks for them
|
|
48
|
+
export {
|
|
49
|
+
queryResultKey,
|
|
50
|
+
useQueryResult,
|
|
51
|
+
type QueryRequestSpec,
|
|
52
|
+
type QueryResultState,
|
|
53
|
+
} from "./useQueryResult";
|
|
54
|
+
export {
|
|
55
|
+
useDocumentControls,
|
|
56
|
+
type DocumentControls,
|
|
57
|
+
type UseDocumentControlsOptions,
|
|
58
|
+
} from "./useDocumentControls";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useCallback, useMemo } from "react";
|
|
5
|
+
import type { Given } from "../client";
|
|
6
|
+
import { useDrillSelf } from "../components/drill/useDrillSelf";
|
|
7
|
+
import type { GivensPanelProps } from "../components/given/GivensPanel";
|
|
8
|
+
import { useGivensState, type UseGivensStateResult } from "./useGivensState";
|
|
9
|
+
import { useSuggestOptions } from "./useSuggestOptions";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Everything a document's control row needs, from what the document declares.
|
|
13
|
+
*
|
|
14
|
+
* A dashboard, a notebook and the builder's harness each wired this by hand:
|
|
15
|
+
* the declared types read off the givens, the report to the host guarded on the
|
|
16
|
+
* document having loaded, `useGivensState`, `useSuggestOptions` for the pickers'
|
|
17
|
+
* options, `useDrillSelf` for `to=self`, and the same nine props into
|
|
18
|
+
* `GivensPanel`. Sixty lines each, with the same reasoning in the comments of
|
|
19
|
+
* each. This is that wiring once, so a control gains a behaviour on every
|
|
20
|
+
* surface at the same time.
|
|
21
|
+
*/
|
|
22
|
+
export interface UseDocumentControlsOptions {
|
|
23
|
+
/** The document's declared givens. Empty until it has loaded. */
|
|
24
|
+
specs: Given[];
|
|
25
|
+
/**
|
|
26
|
+
* Whether the document has loaded. Reports to the host are WITHHELD until
|
|
27
|
+
* it has: before then the declared set is empty, so a report would say "no
|
|
28
|
+
* values, and I manage nothing", which a host reasonably reads as "clear
|
|
29
|
+
* what you wrote" — and during an in-app move from one document to the next
|
|
30
|
+
* that window sits between the two, so the parameters it would clear belong
|
|
31
|
+
* to the document now arriving. A document that genuinely declares no givens
|
|
32
|
+
* still reports, because by then the empty set is the answer rather than
|
|
33
|
+
* the absence of one.
|
|
34
|
+
*/
|
|
35
|
+
loaded: boolean;
|
|
36
|
+
/** Where the controls start, from the file. A URL beats them. */
|
|
37
|
+
startingValues?: Record<string, string>;
|
|
38
|
+
/** Control values from the host, typically its URL query parameters. */
|
|
39
|
+
params?: Record<string, string>;
|
|
40
|
+
/**
|
|
41
|
+
* Applied values, for a host that wants them in its URL, with every name
|
|
42
|
+
* this document manages — `givens` alone says which parameters to write but
|
|
43
|
+
* not which to remove.
|
|
44
|
+
*/
|
|
45
|
+
onGivensChange?: (
|
|
46
|
+
givens: Record<string, string>,
|
|
47
|
+
managed: readonly string[],
|
|
48
|
+
) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Which document the edits belong to. Without it the edits are keyed by
|
|
51
|
+
* their starting VALUES alone, so two documents whose starting values
|
|
52
|
+
* coincide (the common case: both empty) look like one, and the one you came
|
|
53
|
+
* from keeps filtering the one you moved to. The version belongs in it too,
|
|
54
|
+
* so a swap between versions drops the edits made to the other.
|
|
55
|
+
*/
|
|
56
|
+
documentKey: string;
|
|
57
|
+
/** False batches changes behind Apply. */
|
|
58
|
+
autorun: boolean;
|
|
59
|
+
/** Where `suggest` queries run: the document's own model. */
|
|
60
|
+
environmentName: string;
|
|
61
|
+
packageName: string;
|
|
62
|
+
modelPath: string | undefined;
|
|
63
|
+
versionId?: string;
|
|
64
|
+
/** How the document names itself in a refused-drill warning. */
|
|
65
|
+
documentName: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface DocumentControls extends UseGivensStateResult {
|
|
69
|
+
/** Declared type per given name: what this document can set and how a value is encoded. */
|
|
70
|
+
declaredTypes: ReadonlyMap<string, string | undefined>;
|
|
71
|
+
options: Map<string, string[]>;
|
|
72
|
+
optionsLoading: boolean;
|
|
73
|
+
optionsFailed: ReadonlySet<string>;
|
|
74
|
+
/** For `useDrill`: whether a `to=self` on this given can be honoured. */
|
|
75
|
+
canSelf: (given: string) => boolean;
|
|
76
|
+
/** For `useDrill`: set the given to the clicked value, encoded for its type. */
|
|
77
|
+
onSelf: (given: string, rawValue: unknown) => void;
|
|
78
|
+
/** Everything `GivensPanel` takes except its layout: spread it in. */
|
|
79
|
+
panel: Omit<GivensPanelProps, "layout" | "title">;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function useDocumentControls({
|
|
83
|
+
specs,
|
|
84
|
+
loaded,
|
|
85
|
+
startingValues,
|
|
86
|
+
params,
|
|
87
|
+
onGivensChange,
|
|
88
|
+
documentKey,
|
|
89
|
+
autorun,
|
|
90
|
+
environmentName,
|
|
91
|
+
packageName,
|
|
92
|
+
modelPath,
|
|
93
|
+
versionId,
|
|
94
|
+
documentName,
|
|
95
|
+
}: UseDocumentControlsOptions): DocumentControls {
|
|
96
|
+
const declaredTypes = useMemo(
|
|
97
|
+
() =>
|
|
98
|
+
new Map(
|
|
99
|
+
specs
|
|
100
|
+
.filter((spec) => spec.name !== undefined)
|
|
101
|
+
.map((spec) => [spec.name as string, spec.type]),
|
|
102
|
+
),
|
|
103
|
+
[specs],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const report = useCallback(
|
|
107
|
+
(next: Record<string, string>) => {
|
|
108
|
+
if (!loaded) return;
|
|
109
|
+
onGivensChange?.(next, Array.from(declaredTypes.keys()));
|
|
110
|
+
},
|
|
111
|
+
[loaded, onGivensChange, declaredTypes],
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const state = useGivensState({
|
|
115
|
+
declaredTypes,
|
|
116
|
+
startingValues,
|
|
117
|
+
params,
|
|
118
|
+
// Withheld, not accepted and dropped: `useGivensState` records what it
|
|
119
|
+
// last reported BEFORE calling out, so a report the callback threw away
|
|
120
|
+
// would be remembered as delivered and never retried, leaving a parameter
|
|
121
|
+
// stranded in the host's URL. Passing undefined skips the report and
|
|
122
|
+
// leaves its record untouched.
|
|
123
|
+
onParamsChange: loaded ? report : undefined,
|
|
124
|
+
documentKey,
|
|
125
|
+
autorun,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const {
|
|
129
|
+
options,
|
|
130
|
+
isLoading: optionsLoading,
|
|
131
|
+
failed: optionsFailed,
|
|
132
|
+
} = useSuggestOptions(
|
|
133
|
+
environmentName,
|
|
134
|
+
packageName,
|
|
135
|
+
modelPath,
|
|
136
|
+
specs,
|
|
137
|
+
versionId,
|
|
138
|
+
// So a suggest over a gated or scoped source carries the givens it needs.
|
|
139
|
+
{ values: state.applied, declaredTypes },
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const { canSelf, onSelf } = useDrillSelf({
|
|
143
|
+
declaredTypes,
|
|
144
|
+
setGiven: state.setGiven,
|
|
145
|
+
documentName,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
...state,
|
|
150
|
+
declaredTypes,
|
|
151
|
+
options,
|
|
152
|
+
optionsLoading,
|
|
153
|
+
optionsFailed,
|
|
154
|
+
canSelf,
|
|
155
|
+
onSelf,
|
|
156
|
+
panel: {
|
|
157
|
+
givens: specs,
|
|
158
|
+
values: state.draft,
|
|
159
|
+
onChange: state.setGiven,
|
|
160
|
+
onReset: state.reset,
|
|
161
|
+
options,
|
|
162
|
+
optionsLoading,
|
|
163
|
+
optionsFailed,
|
|
164
|
+
// Absent means autorun; only an explicit `false` batches behind Apply.
|
|
165
|
+
apply: autorun
|
|
166
|
+
? undefined
|
|
167
|
+
: { onApply: state.apply, pending: state.pending },
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|