@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
|
@@ -7,12 +7,13 @@ import {
|
|
|
7
7
|
render,
|
|
8
8
|
screen,
|
|
9
9
|
waitFor,
|
|
10
|
+
within,
|
|
10
11
|
} from "@testing-library/react";
|
|
11
12
|
import { describe, expect, it, mock } from "bun:test";
|
|
12
13
|
import { BuilderBar } from "./BuilderBar";
|
|
13
14
|
import type { BuilderControls } from "./builderControls";
|
|
14
15
|
import { ReportBuilder } from "./ReportBuilder";
|
|
15
|
-
import { draftStore } from "./useReportDraft";
|
|
16
|
+
import { draftStore, textFingerprint } from "./useReportDraft";
|
|
16
17
|
import { openDocument } from "./testing/fixtures";
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -29,6 +30,10 @@ source: a is scoped_orders extend {
|
|
|
29
30
|
view: by_cat is by_category
|
|
30
31
|
}`;
|
|
31
32
|
|
|
33
|
+
/** Whether the text tile the controls' `add.text` appends is on the page. */
|
|
34
|
+
const textTileShown = () =>
|
|
35
|
+
screen.queryByRole("group", { name: "Tile text_1", hidden: true }) !== null;
|
|
36
|
+
|
|
32
37
|
const mount = async (
|
|
33
38
|
onControlsChange: (controls: BuilderControls | undefined) => void,
|
|
34
39
|
onSave: (source: string) => Promise<void> | void = () => {},
|
|
@@ -53,7 +58,6 @@ describe("ReportBuilder: a host that takes the controls", () => {
|
|
|
53
58
|
const controls = handed.mock.calls.at(-1)?.[0];
|
|
54
59
|
expect(controls?.status).toBe("saved");
|
|
55
60
|
expect(controls?.canUndo).toBe(false);
|
|
56
|
-
expect(controls?.layout?.value).toBe("grid");
|
|
57
61
|
expect(controls?.save).toBeDefined();
|
|
58
62
|
expect(controls?.add.text).toBeDefined();
|
|
59
63
|
expect(controls?.add.filter).toBeDefined();
|
|
@@ -66,19 +70,19 @@ describe("ReportBuilder: a host that takes the controls", () => {
|
|
|
66
70
|
const saved = mock((_source: string) => {});
|
|
67
71
|
await mount(handed, saved);
|
|
68
72
|
const first = handed.mock.calls.at(-1)?.[0];
|
|
69
|
-
act(() => first?.
|
|
73
|
+
act(() => first?.add.text?.());
|
|
70
74
|
await waitFor(() =>
|
|
71
75
|
expect(handed.mock.calls.at(-1)?.[0]?.status).toBe("unsaved"),
|
|
72
76
|
);
|
|
73
77
|
const now = handed.mock.calls.at(-1)?.[0];
|
|
74
|
-
expect(
|
|
78
|
+
expect(textTileShown()).toBe(true);
|
|
75
79
|
expect(now?.canUndo).toBe(true);
|
|
76
80
|
expect(now?.save).toBe(first?.save);
|
|
77
81
|
await act(async () => {
|
|
78
82
|
first?.save?.();
|
|
79
83
|
});
|
|
80
84
|
await waitFor(() => expect(saved).toHaveBeenCalledTimes(1));
|
|
81
|
-
expect(saved.mock.calls[0]?.[0]).toContain("
|
|
85
|
+
expect(saved.mock.calls[0]?.[0]).toContain("##|(markdown) text_1");
|
|
82
86
|
});
|
|
83
87
|
|
|
84
88
|
it("hands over undefined when the builder goes, so the host stops drawing them", async () => {
|
|
@@ -255,30 +259,34 @@ describe("a draft kept in this browser, and Done", () => {
|
|
|
255
259
|
it("keeps an edit, puts it back on the next open, and says so", async () => {
|
|
256
260
|
window.localStorage.removeItem(`malloy-publisher.report-draft:${KEY}`);
|
|
257
261
|
const first = await mountWithDraft();
|
|
258
|
-
act(() => first.last()?.
|
|
259
|
-
await waitFor(() => expect(stored()).toContain('"
|
|
262
|
+
act(() => first.last()?.add.text?.());
|
|
263
|
+
await waitFor(() => expect(stored()).toContain('"name":"text_1"'));
|
|
260
264
|
expect(first.last()?.draftKeptAt).toBeNumber();
|
|
261
265
|
first.view.unmount();
|
|
262
266
|
|
|
263
267
|
const second = await mountWithDraft();
|
|
264
|
-
await waitFor(() => expect(
|
|
268
|
+
await waitFor(() => expect(textTileShown()).toBe(true));
|
|
265
269
|
expect(second.last()?.status).toBe("unsaved");
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
270
|
+
// Said in the status, not in a banner over the page.
|
|
271
|
+
expect(second.last()?.restored).toMatchObject({
|
|
272
|
+
stale: false,
|
|
273
|
+
pending: false,
|
|
274
|
+
});
|
|
275
|
+
expect(screen.queryByRole("alert")).toBeNull();
|
|
276
|
+
expect(screen.queryByText(/Restored your unsaved edits/)).toBeNull();
|
|
269
277
|
// Undo takes the restore back.
|
|
270
278
|
act(() => second.last()?.undo());
|
|
271
|
-
await waitFor(() => expect(
|
|
279
|
+
await waitFor(() => expect(textTileShown()).toBe(false));
|
|
272
280
|
await waitFor(() => expect(stored()).toBeNull());
|
|
273
281
|
});
|
|
274
282
|
|
|
275
283
|
it("Discard puts the saved report back and drops the draft", async () => {
|
|
276
284
|
window.localStorage.removeItem(`malloy-publisher.report-draft:${KEY}`);
|
|
277
285
|
const { last } = await mountWithDraft();
|
|
278
|
-
act(() => last()?.
|
|
286
|
+
act(() => last()?.add.text?.());
|
|
279
287
|
await waitFor(() => expect(last()?.discard).toBeDefined());
|
|
280
288
|
act(() => last()?.discard?.());
|
|
281
|
-
await waitFor(() => expect(
|
|
289
|
+
await waitFor(() => expect(textTileShown()).toBe(false));
|
|
282
290
|
await waitFor(() => expect(stored()).toBeNull());
|
|
283
291
|
});
|
|
284
292
|
|
|
@@ -287,13 +295,13 @@ describe("a draft kept in this browser, and Done", () => {
|
|
|
287
295
|
const exited = mock(() => {});
|
|
288
296
|
const saved = mock((_source: string) => {});
|
|
289
297
|
const { last } = await mountWithDraft(exited, saved);
|
|
290
|
-
act(() => last()?.
|
|
298
|
+
act(() => last()?.add.text?.());
|
|
291
299
|
await waitFor(() => expect(last()?.status).toBe("unsaved"));
|
|
292
300
|
await act(async () => {
|
|
293
301
|
last()?.done?.();
|
|
294
302
|
});
|
|
295
303
|
await waitFor(() => expect(exited).toHaveBeenCalledTimes(1));
|
|
296
|
-
expect(saved.mock.calls[0]?.[0]).toContain("
|
|
304
|
+
expect(saved.mock.calls[0]?.[0]).toContain("##|(markdown) text_1");
|
|
297
305
|
await waitFor(() => expect(stored()).toBeNull());
|
|
298
306
|
});
|
|
299
307
|
|
|
@@ -303,14 +311,14 @@ describe("a draft kept in this browser, and Done", () => {
|
|
|
303
311
|
const { last } = await mountWithDraft(exited, () =>
|
|
304
312
|
Promise.reject(new Error("The file changed underneath")),
|
|
305
313
|
);
|
|
306
|
-
act(() => last()?.
|
|
314
|
+
act(() => last()?.add.text?.());
|
|
307
315
|
await waitFor(() => expect(last()?.status).toBe("unsaved"));
|
|
308
316
|
await act(async () => {
|
|
309
317
|
last()?.done?.();
|
|
310
318
|
});
|
|
311
319
|
await waitFor(() => expect(last()?.status).toBe("unsaved"));
|
|
312
320
|
expect(exited).not.toHaveBeenCalled();
|
|
313
|
-
expect(stored()).toContain('"
|
|
321
|
+
expect(stored()).toContain('"name":"text_1"');
|
|
314
322
|
});
|
|
315
323
|
});
|
|
316
324
|
|
|
@@ -326,7 +334,13 @@ describe("a draft made before the report changed", () => {
|
|
|
326
334
|
// Made over another file: the fingerprint does not match.
|
|
327
335
|
base: "0:other",
|
|
328
336
|
savedAt: Date.now(),
|
|
329
|
-
document: {
|
|
337
|
+
document: {
|
|
338
|
+
...opened,
|
|
339
|
+
tiles: [
|
|
340
|
+
...opened.tiles,
|
|
341
|
+
{ kind: "text", name: "text_1", markdown: "", colspan: 12 },
|
|
342
|
+
],
|
|
343
|
+
},
|
|
330
344
|
}),
|
|
331
345
|
);
|
|
332
346
|
};
|
|
@@ -351,20 +365,148 @@ describe("a draft made before the report changed", () => {
|
|
|
351
365
|
expect(
|
|
352
366
|
await screen.findByText(/made before this report changed/),
|
|
353
367
|
).toBeDefined();
|
|
354
|
-
expect(
|
|
368
|
+
expect(textTileShown()).toBe(false);
|
|
355
369
|
expect(last()?.status).toBe("saved");
|
|
356
370
|
expect(window.localStorage.getItem(slot)).not.toBeNull();
|
|
371
|
+
// A choice the author has to make: no close, and both answers handed
|
|
372
|
+
// to a host drawing its own status.
|
|
373
|
+
expect(screen.queryByRole("button", { name: /close/i })).toBeNull();
|
|
374
|
+
expect(last()?.restored?.pending).toBe(true);
|
|
375
|
+
expect(last()?.restore).toBeDefined();
|
|
376
|
+
expect(last()?.discard).toBeDefined();
|
|
377
|
+
expect(last()?.dismissRestored).toBeUndefined();
|
|
357
378
|
fireEvent.click(screen.getByRole("button", { name: "Restore them" }));
|
|
358
|
-
await waitFor(() => expect(
|
|
379
|
+
await waitFor(() => expect(textTileShown()).toBe(true));
|
|
380
|
+
expect(screen.queryByText(/made before this report changed/)).toBeNull();
|
|
359
381
|
});
|
|
360
382
|
|
|
361
|
-
it("
|
|
383
|
+
it("is answered by a host's restore as well as the page's button", async () => {
|
|
362
384
|
await keepStale();
|
|
363
385
|
const last = await mountIt();
|
|
364
386
|
await screen.findByText(/made before this report changed/);
|
|
387
|
+
act(() => last()?.restore?.());
|
|
388
|
+
await waitFor(() => expect(textTileShown()).toBe(true));
|
|
389
|
+
expect(last()?.restored?.pending).toBe(false);
|
|
390
|
+
expect(last()?.restore).toBeUndefined();
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("goes when the author edits over it instead, since the edits replace it", async () => {
|
|
394
|
+
await keepStale();
|
|
395
|
+
const last = await mountIt();
|
|
396
|
+
await screen.findByText(/made before this report changed/);
|
|
397
|
+
act(() => last()?.add.text?.());
|
|
398
|
+
await waitFor(() =>
|
|
399
|
+
expect(
|
|
400
|
+
screen.queryByText(/made before this report changed/),
|
|
401
|
+
).toBeNull(),
|
|
402
|
+
);
|
|
403
|
+
expect(last()?.restored).toBeUndefined();
|
|
404
|
+
// What is kept now is the edit, made over the current file.
|
|
405
|
+
expect(window.localStorage.getItem(slot)).not.toContain(
|
|
406
|
+
'"base":"0:other"',
|
|
407
|
+
);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("Discard drops it without touching the report", async () => {
|
|
411
|
+
await keepStale();
|
|
412
|
+
await mountIt();
|
|
413
|
+
await screen.findByText(/made before this report changed/);
|
|
365
414
|
fireEvent.click(screen.getByRole("button", { name: "Discard" }));
|
|
366
415
|
expect(window.localStorage.getItem(slot)).toBeNull();
|
|
367
|
-
expect(
|
|
416
|
+
expect(textTileShown()).toBe(false);
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
describe("edits put back on opening", () => {
|
|
421
|
+
const KEY = "examples/storefront/spec-restored";
|
|
422
|
+
const slot = `malloy-publisher.report-draft:${KEY}`;
|
|
423
|
+
/** A draft kept over this very file, so it is put back, not offered. */
|
|
424
|
+
const keepFresh = async () => {
|
|
425
|
+
const opened = await openDocument(GRID);
|
|
426
|
+
window.localStorage.setItem(
|
|
427
|
+
slot,
|
|
428
|
+
JSON.stringify({
|
|
429
|
+
v: 1,
|
|
430
|
+
base: textFingerprint(GRID),
|
|
431
|
+
savedAt: Date.now(),
|
|
432
|
+
document: { ...opened, title: "Kept title" },
|
|
433
|
+
}),
|
|
434
|
+
);
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
it("in a host's bar: no banner, Draft saved, and the menu says they were restored until it is seen", async () => {
|
|
438
|
+
await keepFresh();
|
|
439
|
+
const handed = mock((_controls: BuilderControls | undefined) => {});
|
|
440
|
+
const page = render(
|
|
441
|
+
<ReportBuilder
|
|
442
|
+
source={GRID}
|
|
443
|
+
document={await openDocument(GRID)}
|
|
444
|
+
onSave={() => {}}
|
|
445
|
+
onExit={() => {}}
|
|
446
|
+
draftKey={KEY}
|
|
447
|
+
onControlsChange={handed}
|
|
448
|
+
/>,
|
|
449
|
+
);
|
|
450
|
+
const last = () => handed.mock.calls.at(-1)?.[0];
|
|
451
|
+
await waitFor(() => expect(last()?.draftKeptAt).toBeNumber());
|
|
452
|
+
expect(screen.queryByRole("alert")).toBeNull();
|
|
453
|
+
expect(last()?.restored?.pending).toBe(false);
|
|
454
|
+
expect(last()?.dismissRestored).toBeDefined();
|
|
455
|
+
expect(last()?.restore).toBeUndefined();
|
|
456
|
+
|
|
457
|
+
// The host draws the SDK's bar with what it was handed.
|
|
458
|
+
const bar = render(<BuilderBar controls={last()} />);
|
|
459
|
+
const chip = bar.getByRole("button", { name: "Draft saved" });
|
|
460
|
+
expect(chip.querySelector('[data-restored="true"]')).not.toBeNull();
|
|
461
|
+
fireEvent.click(chip);
|
|
462
|
+
within(await bar.findByRole("menu")).getByText(
|
|
463
|
+
/Restored your unsaved edits from/,
|
|
464
|
+
);
|
|
465
|
+
bar.getByRole("menuitem", { name: /Discard edits/ });
|
|
466
|
+
fireEvent.keyDown(bar.getByRole("menu"), { key: "Escape" });
|
|
467
|
+
await waitFor(() => expect(last()?.restored).toBeUndefined());
|
|
468
|
+
bar.unmount();
|
|
469
|
+
page.unmount();
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("in the page's own toolbar: no banner, and the status says it", async () => {
|
|
473
|
+
await keepFresh();
|
|
474
|
+
render(
|
|
475
|
+
<ReportBuilder
|
|
476
|
+
source={GRID}
|
|
477
|
+
document={await openDocument(GRID)}
|
|
478
|
+
onSave={() => {}}
|
|
479
|
+
draftKey={KEY}
|
|
480
|
+
/>,
|
|
481
|
+
);
|
|
482
|
+
const chip = await screen.findByRole("button", { name: "Draft saved" });
|
|
483
|
+
expect(screen.queryByRole("alert")).toBeNull();
|
|
484
|
+
fireEvent.click(chip);
|
|
485
|
+
within(await screen.findByRole("menu")).getByText(
|
|
486
|
+
/Restored your unsaved edits from/,
|
|
487
|
+
);
|
|
488
|
+
fireEvent.click(screen.getByRole("menuitem", { name: /Discard edits/ }));
|
|
489
|
+
await waitFor(() => expect(window.localStorage.getItem(slot)).toBeNull());
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it("is old news after the next edit", async () => {
|
|
493
|
+
await keepFresh();
|
|
494
|
+
const handed = mock((_controls: BuilderControls | undefined) => {});
|
|
495
|
+
render(
|
|
496
|
+
<ReportBuilder
|
|
497
|
+
source={GRID}
|
|
498
|
+
document={await openDocument(GRID)}
|
|
499
|
+
onSave={() => {}}
|
|
500
|
+
onExit={() => {}}
|
|
501
|
+
draftKey={KEY}
|
|
502
|
+
onControlsChange={handed}
|
|
503
|
+
/>,
|
|
504
|
+
);
|
|
505
|
+
const last = () => handed.mock.calls.at(-1)?.[0];
|
|
506
|
+
await waitFor(() => expect(last()?.restored).toBeDefined());
|
|
507
|
+
act(() => last()?.add.text?.());
|
|
508
|
+
await waitFor(() => expect(last()?.restored).toBeUndefined());
|
|
509
|
+
expect(last()?.status).toBe("unsaved");
|
|
368
510
|
});
|
|
369
511
|
});
|
|
370
512
|
|
|
@@ -393,7 +535,7 @@ describe("a draft the browser will not keep", () => {
|
|
|
393
535
|
onControlsChange={handed}
|
|
394
536
|
/>,
|
|
395
537
|
);
|
|
396
|
-
act(() => handed.mock.calls.at(-1)?.[0]?.
|
|
538
|
+
act(() => handed.mock.calls.at(-1)?.[0]?.add.text?.());
|
|
397
539
|
await waitFor(() =>
|
|
398
540
|
expect(handed.mock.calls.at(-1)?.[0]?.status).toBe("unsaved"),
|
|
399
541
|
);
|
|
@@ -449,6 +591,50 @@ describe("BuilderBar with Done that saves", () => {
|
|
|
449
591
|
screen.getByRole("menuitem", { name: /Discard edits/ }).click();
|
|
450
592
|
expect(discard).toHaveBeenCalledTimes(1);
|
|
451
593
|
});
|
|
594
|
+
|
|
595
|
+
it("says edits were restored in its menu, and hands back that they were seen", async () => {
|
|
596
|
+
const dismissRestored = mock(() => {});
|
|
597
|
+
render(
|
|
598
|
+
<BuilderBar
|
|
599
|
+
controls={{
|
|
600
|
+
...base,
|
|
601
|
+
done: () => {},
|
|
602
|
+
draftKeptAt: Date.now(),
|
|
603
|
+
discard: () => {},
|
|
604
|
+
restored: { savedAt: Date.now(), stale: false, pending: false },
|
|
605
|
+
dismissRestored,
|
|
606
|
+
}}
|
|
607
|
+
/>,
|
|
608
|
+
);
|
|
609
|
+
expect(screen.queryByRole("alert")).toBeNull();
|
|
610
|
+
screen.getByRole("button", { name: "Draft saved" }).click();
|
|
611
|
+
const menu = await screen.findByRole("menu");
|
|
612
|
+
within(menu).getByText(/Restored your unsaved edits from/);
|
|
613
|
+
expect(within(menu).queryByText(/Kept in this browser/)).toBeNull();
|
|
614
|
+
// Said aloud too, as the banner was.
|
|
615
|
+
// (The open menu hides the rest of the page from the tree.)
|
|
616
|
+
expect(screen.getByRole("status", { hidden: true }).textContent).toMatch(
|
|
617
|
+
/^Draft saved\. Restored your unsaved edits from/,
|
|
618
|
+
);
|
|
619
|
+
fireEvent.keyDown(screen.getByRole("menu"), { key: "Escape" });
|
|
620
|
+
await waitFor(() => expect(dismissRestored).toHaveBeenCalledTimes(1));
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
it("says only that the draft is kept once there is no news", async () => {
|
|
624
|
+
render(
|
|
625
|
+
<BuilderBar
|
|
626
|
+
controls={{
|
|
627
|
+
...base,
|
|
628
|
+
done: () => {},
|
|
629
|
+
draftKeptAt: Date.now(),
|
|
630
|
+
discard: () => {},
|
|
631
|
+
}}
|
|
632
|
+
/>,
|
|
633
|
+
);
|
|
634
|
+
screen.getByRole("button", { name: "Draft saved" }).click();
|
|
635
|
+
expect(await screen.findByText(/Kept in this browser at/)).toBeDefined();
|
|
636
|
+
expect(screen.queryByText(/Restored your unsaved edits/)).toBeNull();
|
|
637
|
+
});
|
|
452
638
|
});
|
|
453
639
|
|
|
454
640
|
describe("selection", () => {
|
|
@@ -7,9 +7,8 @@ import { Alert, Button, Stack, Typography } from "@mui/material";
|
|
|
7
7
|
import { useMemo, useRef, useState, type ReactNode } from "react";
|
|
8
8
|
import { nudgedSpan, useDefaultTileSpan } from "../Dashboard/DashboardGrid";
|
|
9
9
|
import type { TileChrome, TileHeadingSlots } from "../Dashboard/TileCard";
|
|
10
|
-
import type { ReportLayout } from "../Package/documentLocation";
|
|
11
10
|
import type { SavesTo } from "./documentSession";
|
|
12
|
-
import {
|
|
11
|
+
import type { ReportEventHandler } from "../Report/telemetry";
|
|
13
12
|
import type { BuilderGiven } from "./controls";
|
|
14
13
|
import { BuilderDialogs } from "./BuilderDialogs";
|
|
15
14
|
import type { ViewPreview } from "./AddTileDialog";
|
|
@@ -29,6 +28,7 @@ import {
|
|
|
29
28
|
type QueryTile,
|
|
30
29
|
} from "./document";
|
|
31
30
|
import { FilterStrip, type FixedFilter } from "./FilterStrip";
|
|
31
|
+
import { clockTime, type SaveStatusProps } from "./SaveStatus";
|
|
32
32
|
import { SELECTION_RING_PX } from "./TileFrame";
|
|
33
33
|
import { useBuilderSelection } from "./useBuilderSelection";
|
|
34
34
|
import { useBuilderSession } from "./useBuilderSession";
|
|
@@ -155,7 +155,7 @@ export interface ReportBuilderProps {
|
|
|
155
155
|
*/
|
|
156
156
|
dashboards?: string[];
|
|
157
157
|
/**
|
|
158
|
-
*
|
|
158
|
+
* Opens, saves and refusals, for the host to log; see
|
|
159
159
|
* `ReportEvent`. Each is stamped with `modelPath` (empty when the builder
|
|
160
160
|
* was given none) and the document's layout as it stands.
|
|
161
161
|
*/
|
|
@@ -224,7 +224,7 @@ export interface ReportBuilderProps {
|
|
|
224
224
|
onExit?: () => void;
|
|
225
225
|
/**
|
|
226
226
|
* Take over the page-level controls (save status and Save, undo and redo,
|
|
227
|
-
*
|
|
227
|
+
* and adding a tile, text or filter): the builder hands
|
|
228
228
|
* them over as `BuilderControls` whenever they change, and draws no
|
|
229
229
|
* toolbar of its own. Draw them with `BuilderBar`, or place each in
|
|
230
230
|
* the host's own chrome. `undefined` is handed over when the builder goes.
|
|
@@ -240,13 +240,6 @@ export interface ReportBuilderProps {
|
|
|
240
240
|
* One key per report and place it is saved to. Absent, nothing is kept.
|
|
241
241
|
*/
|
|
242
242
|
draftKey?: string;
|
|
243
|
-
/**
|
|
244
|
-
* Whether the toolbar offers the Linear / Grid layout switch. Default
|
|
245
|
-
* true. A host that files a report by its layout passes false, so an
|
|
246
|
-
* author cannot change a layout the host files by. A document held as text
|
|
247
|
-
* never gets the switch.
|
|
248
|
-
*/
|
|
249
|
-
allowLayoutChange?: boolean;
|
|
250
243
|
}
|
|
251
244
|
|
|
252
245
|
export function ReportBuilder({
|
|
@@ -256,7 +249,6 @@ export function ReportBuilder({
|
|
|
256
249
|
onChange,
|
|
257
250
|
onDirtyChange,
|
|
258
251
|
onExit,
|
|
259
|
-
allowLayoutChange = true,
|
|
260
252
|
renderTile,
|
|
261
253
|
renderViewPreview,
|
|
262
254
|
controls,
|
|
@@ -434,46 +426,35 @@ export function ReportBuilder({
|
|
|
434
426
|
});
|
|
435
427
|
|
|
436
428
|
const empty = editor.document.tiles.length === 0;
|
|
437
|
-
// A text-held document's layout is the host's record, so only a file gets
|
|
438
|
-
// the switch, and only when the host allows it.
|
|
439
|
-
const layoutSwitch =
|
|
440
|
-
visibleSources === undefined && allowLayoutChange
|
|
441
|
-
? {
|
|
442
|
-
layout: editor.document.layout,
|
|
443
|
-
onLayoutChange: (next: ReportLayout) => {
|
|
444
|
-
const from = editor.document.layout;
|
|
445
|
-
if (next === from) return;
|
|
446
|
-
editor.update((draft) => {
|
|
447
|
-
draft.layout = next;
|
|
448
|
-
});
|
|
449
|
-
reportEmitter(
|
|
450
|
-
{ path: modelPath ?? "", layout: next },
|
|
451
|
-
onEvent,
|
|
452
|
-
).emit({ type: "report.layout_changed", from, to: next });
|
|
453
|
-
},
|
|
454
|
-
}
|
|
455
|
-
: undefined;
|
|
456
429
|
const { toolbarProps } = session;
|
|
457
|
-
|
|
430
|
+
const restored = draft.restored;
|
|
431
|
+
// Where the edits stand, for the status on either surface: the host's bar
|
|
432
|
+
// or the page's own toolbar.
|
|
433
|
+
const saveStatus: SaveStatusProps = {
|
|
458
434
|
status: session.saving
|
|
459
435
|
? "saving"
|
|
460
436
|
: toolbarProps.dirty
|
|
461
437
|
? "unsaved"
|
|
462
438
|
: "saved",
|
|
463
439
|
saveTarget: saveLabel ?? SAVE_TARGET[savesTo],
|
|
440
|
+
...(draft.keptAt !== undefined ? { draftKeptAt: draft.keptAt } : {}),
|
|
441
|
+
// An offered draft is discarded without being applied, so Discard is
|
|
442
|
+
// an answer before there is anything unsaved.
|
|
443
|
+
...((toolbarProps.dirty || restored?.pending) && draftKey !== undefined
|
|
444
|
+
? { discard: draft.discard }
|
|
445
|
+
: {}),
|
|
446
|
+
...(restored ? { restored } : {}),
|
|
447
|
+
...(restored && !restored.pending
|
|
448
|
+
? { dismissRestored: draft.dismissRestored }
|
|
449
|
+
: {}),
|
|
450
|
+
};
|
|
451
|
+
useReportControls(onControlsChange, {
|
|
452
|
+
...saveStatus,
|
|
464
453
|
...(toolbarProps.onSave ? { save: toolbarProps.onSave } : {}),
|
|
465
454
|
canUndo: toolbarProps.canUndo,
|
|
466
455
|
undo: toolbarProps.onUndo,
|
|
467
456
|
canRedo: toolbarProps.canRedo,
|
|
468
457
|
redo: toolbarProps.onRedo,
|
|
469
|
-
...(layoutSwitch
|
|
470
|
-
? {
|
|
471
|
-
layout: {
|
|
472
|
-
value: layoutSwitch.layout,
|
|
473
|
-
set: layoutSwitch.onLayoutChange,
|
|
474
|
-
},
|
|
475
|
-
}
|
|
476
|
-
: {}),
|
|
477
458
|
add: {
|
|
478
459
|
...(catalog ? { tile: () => tiles.openAdd() } : {}),
|
|
479
460
|
text: tiles.appendText,
|
|
@@ -486,10 +467,7 @@ export function ReportBuilder({
|
|
|
486
467
|
},
|
|
487
468
|
...(toolbarProps.onExit ? { exit: toolbarProps.onExit } : {}),
|
|
488
469
|
...(session.done ? { done: session.done } : {}),
|
|
489
|
-
...(
|
|
490
|
-
...(toolbarProps.dirty && draftKey !== undefined
|
|
491
|
-
? { discard: draft.discard }
|
|
492
|
-
: {}),
|
|
470
|
+
...(restored?.pending ? { restore: draft.restoreOffered } : {}),
|
|
493
471
|
});
|
|
494
472
|
// The builder's actions: on the title's line, at the right, above the
|
|
495
473
|
// description.
|
|
@@ -500,7 +478,9 @@ export function ReportBuilder({
|
|
|
500
478
|
{...(catalog ? { onAddTile: () => openAdd() } : {})}
|
|
501
479
|
savesTo={savesTo}
|
|
502
480
|
{...(saveLabel ? { saveLabel } : {})}
|
|
503
|
-
{...(
|
|
481
|
+
{...(draftKey !== undefined && toolbarProps.onSave
|
|
482
|
+
? { saveStatus }
|
|
483
|
+
: {})}
|
|
504
484
|
/>
|
|
505
485
|
);
|
|
506
486
|
return (
|
|
@@ -601,42 +581,34 @@ export function ReportBuilder({
|
|
|
601
581
|
</Stack>
|
|
602
582
|
)}
|
|
603
583
|
|
|
604
|
-
{
|
|
584
|
+
{/* Edits put back on opening are said in the save status, so
|
|
585
|
+
the page does not move. A stale draft is a choice: put back,
|
|
586
|
+
it replaces the newer version; dropped, the edits are gone.
|
|
587
|
+
So it is asked here, with no close, until it is answered (or
|
|
588
|
+
an edit answers it). */}
|
|
589
|
+
{restored?.pending && (
|
|
605
590
|
<Alert
|
|
606
|
-
severity=
|
|
607
|
-
onClose={draft.dismissRestored}
|
|
591
|
+
severity="warning"
|
|
608
592
|
action={
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
</Button>
|
|
618
|
-
<Button
|
|
619
|
-
color="inherit"
|
|
620
|
-
size="small"
|
|
621
|
-
onClick={draft.discard}
|
|
622
|
-
>
|
|
623
|
-
Discard
|
|
624
|
-
</Button>
|
|
625
|
-
</>
|
|
626
|
-
) : (
|
|
593
|
+
<>
|
|
594
|
+
<Button
|
|
595
|
+
color="inherit"
|
|
596
|
+
size="small"
|
|
597
|
+
onClick={draft.restoreOffered}
|
|
598
|
+
>
|
|
599
|
+
Restore them
|
|
600
|
+
</Button>
|
|
627
601
|
<Button
|
|
628
602
|
color="inherit"
|
|
629
603
|
size="small"
|
|
630
604
|
onClick={draft.discard}
|
|
631
605
|
>
|
|
632
|
-
Discard
|
|
606
|
+
Discard
|
|
633
607
|
</Button>
|
|
634
|
-
|
|
608
|
+
</>
|
|
635
609
|
}
|
|
636
610
|
>
|
|
637
|
-
{
|
|
638
|
-
? `You have unsaved edits from ${clockTime(draft.restored.savedAt)}, made before this report changed. Restoring them replaces the current version.`
|
|
639
|
-
: `Restored your unsaved edits from ${clockTime(draft.restored.savedAt)}.`}
|
|
611
|
+
{`You have unsaved edits from ${clockTime(restored.savedAt)}, made before this report changed. Restoring them replaces the current version.`}
|
|
640
612
|
</Alert>
|
|
641
613
|
)}
|
|
642
614
|
|
|
@@ -692,17 +664,3 @@ export function ReportBuilder({
|
|
|
692
664
|
</OpenDraftContext.Provider>
|
|
693
665
|
);
|
|
694
666
|
}
|
|
695
|
-
|
|
696
|
-
/** A time of day, or a date and time when not today: when a draft was kept. */
|
|
697
|
-
function clockTime(at: number): string {
|
|
698
|
-
const when = new Date(at);
|
|
699
|
-
const today = new Date().toDateString() === when.toDateString();
|
|
700
|
-
return today
|
|
701
|
-
? when.toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })
|
|
702
|
-
: when.toLocaleString([], {
|
|
703
|
-
month: "short",
|
|
704
|
-
day: "numeric",
|
|
705
|
-
hour: "numeric",
|
|
706
|
-
minute: "2-digit",
|
|
707
|
-
});
|
|
708
|
-
}
|
|
@@ -199,39 +199,3 @@ describe("ReportEditor, when the server takes writes", () => {
|
|
|
199
199
|
).toBe(false);
|
|
200
200
|
});
|
|
201
201
|
});
|
|
202
|
-
|
|
203
|
-
describe("ReportEditor's layout switch", () => {
|
|
204
|
-
const mountWith = (allowLayoutChange?: boolean) =>
|
|
205
|
-
render(
|
|
206
|
-
<DocumentStorageProvider
|
|
207
|
-
documentStorage={new BrowserDocumentStorage()}
|
|
208
|
-
>
|
|
209
|
-
<ReportEditor
|
|
210
|
-
environmentName="env"
|
|
211
|
-
packageName="pkg"
|
|
212
|
-
dashboardName="overview"
|
|
213
|
-
{...(allowLayoutChange !== undefined
|
|
214
|
-
? { allowLayoutChange }
|
|
215
|
-
: {})}
|
|
216
|
-
/>
|
|
217
|
-
</DocumentStorageProvider>,
|
|
218
|
-
{ wrapper: serverWrapper },
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
it("is offered for a file by default", async () => {
|
|
222
|
-
mountWith();
|
|
223
|
-
await screen.findByText("Storefront");
|
|
224
|
-
expect(button("Grid layout")).toBeDefined();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("is hidden when the host passes allowLayoutChange={false}", async () => {
|
|
228
|
-
mountWith(false);
|
|
229
|
-
await screen.findByText("Storefront");
|
|
230
|
-
expect(
|
|
231
|
-
screen.queryByRole("button", { name: "Grid layout", hidden: true }),
|
|
232
|
-
).toBeNull();
|
|
233
|
-
expect(
|
|
234
|
-
screen.queryByRole("button", { name: "Linear layout", hidden: true }),
|
|
235
|
-
).toBeNull();
|
|
236
|
-
});
|
|
237
|
-
});
|
|
@@ -108,7 +108,7 @@ export type ReportEditorProps = (
|
|
|
108
108
|
* report's copy is read back only from an authoritative store) and is what
|
|
109
109
|
* a save records until the text says otherwise; once open, the document's
|
|
110
110
|
* own tag decides how it is drawn, what a save records and which events it
|
|
111
|
-
* reports
|
|
111
|
+
* reports.
|
|
112
112
|
*/
|
|
113
113
|
layout?: ReportLayout;
|
|
114
114
|
/** @deprecated Pass `layout`: `dashboard` is grid, `notebook` linear. */
|
|
@@ -141,7 +141,7 @@ export type ReportEditorProps = (
|
|
|
141
141
|
onOpenModel?: (modelPath: string) => void;
|
|
142
142
|
/**
|
|
143
143
|
* Take over the builder's page-level controls (save status and Save, undo
|
|
144
|
-
* and redo,
|
|
144
|
+
* and redo, Add): handed over as `BuilderControls`
|
|
145
145
|
* whenever they change, with no toolbar drawn on the page. Draw them with
|
|
146
146
|
* `BuilderBar` in the host's header, or place each in its own chrome.
|
|
147
147
|
*/
|
|
@@ -155,13 +155,6 @@ export type ReportEditorProps = (
|
|
|
155
155
|
keepDraft?: boolean;
|
|
156
156
|
/** Edit a document held as text; see {@link TextSourceOptions}. */
|
|
157
157
|
textSource?: TextSourceOptions;
|
|
158
|
-
/**
|
|
159
|
-
* Whether the toolbar offers the Linear / Grid layout switch. Default
|
|
160
|
-
* true. A host that files a report by its layout passes false, so an
|
|
161
|
-
* author cannot change a layout the host files by. A document held as text
|
|
162
|
-
* never gets the switch.
|
|
163
|
-
*/
|
|
164
|
-
allowLayoutChange?: boolean;
|
|
165
158
|
};
|
|
166
159
|
|
|
167
160
|
/**
|
|
@@ -217,7 +210,6 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
217
210
|
kind,
|
|
218
211
|
path,
|
|
219
212
|
textSource,
|
|
220
|
-
allowLayoutChange,
|
|
221
213
|
} = props;
|
|
222
214
|
const layout: ReportLayout =
|
|
223
215
|
props.layout ?? (kind ? layoutOfKind(kind) : "grid");
|
|
@@ -556,9 +548,6 @@ export function ReportEditor(props: ReportEditorProps) {
|
|
|
556
548
|
{...(onOpenModel ? { onOpenModel } : {})}
|
|
557
549
|
{...(onControlsChange ? { onControlsChange } : {})}
|
|
558
550
|
{...(draftKey !== undefined ? { draftKey } : {})}
|
|
559
|
-
{...(allowLayoutChange !== undefined
|
|
560
|
-
? { allowLayoutChange }
|
|
561
|
-
: {})}
|
|
562
551
|
savesTo={savesTo}
|
|
563
552
|
{...(saveLabel ? { saveLabel } : {})}
|
|
564
553
|
{...(onEvent ? { onEvent: reportEvent } : {})}
|