@malloy-publisher/sdk 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
- package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
- package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
- package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
- package/dist/builder/index.cjs.js +146 -58
- package/dist/builder/index.es.js +9076 -6479
- package/dist/builder-entry.d.ts +4 -0
- package/dist/client/api.d.ts +77 -47
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +84 -82
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
- package/dist/components/Dashboard/DashboardView.d.ts +36 -0
- package/dist/components/Dashboard/TileCard.d.ts +15 -4
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/index.d.ts +3 -0
- package/dist/components/Dashboard/telemetry.d.ts +15 -3
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +1 -0
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +4 -0
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9714 -7072
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CbbBcZl8.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/utils/clock.d.ts +2 -0
- package/package.json +10 -1
- package/src/builder-entry.ts +35 -0
- package/src/components/Dashboard/Dashboard.tsx +27 -278
- package/src/components/Dashboard/DashboardGrid.tsx +68 -7
- package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
- package/src/components/Dashboard/DashboardTile.tsx +31 -4
- package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
- package/src/components/Dashboard/DashboardView.tsx +352 -0
- package/src/components/Dashboard/RowsDialog.tsx +1 -1
- package/src/components/Dashboard/TileCard.tsx +44 -10
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/index.ts +3 -0
- package/src/components/Dashboard/telemetry.ts +16 -5
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
- package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
- package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
- package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
- package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
- package/src/components/DashboardBuilder/InlineText.tsx +106 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
- package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
- package/src/components/DashboardBuilder/catalog.ts +61 -21
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +257 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
- package/src/components/DashboardBuilder/malloyText.ts +181 -27
- package/src/components/DashboardBuilder/malloyTree.ts +155 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
- package/src/components/DashboardBuilder/readDocument.ts +130 -44
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +47 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
- package/src/components/DashboardBuilder/sortable.tsx +2 -12
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +66 -27
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +190 -0
- package/src/components/Package/Package.create.spec.tsx +380 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +366 -171
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +13 -0
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +18 -1
- package/src/components/RenderedResult/ResultContainer.tsx +44 -11
- package/src/components/RenderedResult/ResultPanel.tsx +4 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +3 -3
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useQueryResult.ts +16 -0
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +118 -0
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
- package/src/components/DashboardBuilder/useTileResize.ts +0 -110
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { render, screen } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it } from "bun:test";
|
|
6
|
+
import { DiffDialog } from "./DiffDialog";
|
|
7
|
+
|
|
8
|
+
describe("DiffDialog", () => {
|
|
9
|
+
it("marks a removed line with its sign and no strikethrough", () => {
|
|
10
|
+
render(
|
|
11
|
+
<DiffDialog
|
|
12
|
+
open
|
|
13
|
+
before={"keep\nold line\n"}
|
|
14
|
+
after={"keep\nnew line\n"}
|
|
15
|
+
onClose={() => {}}
|
|
16
|
+
/>,
|
|
17
|
+
);
|
|
18
|
+
const removed = screen.getByText(/old line/);
|
|
19
|
+
expect(removed.textContent).toContain("− old line");
|
|
20
|
+
expect(getComputedStyle(removed).textDecorationLine).not.toBe(
|
|
21
|
+
"line-through",
|
|
22
|
+
);
|
|
23
|
+
expect(screen.getByText(/new line/).textContent).toContain("+ new line");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -7,25 +7,16 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
|
7
7
|
import { foldUnchanged, lineDiff } from "./diff";
|
|
8
8
|
import { AppDialog } from "../AppDialog";
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* What a save will do to the file, before it does it.
|
|
12
|
-
*
|
|
13
|
-
* Shown for a STRUCTURAL save — a tile added or removed — because those move
|
|
14
|
-
* declarations and the comments beside them, and the file is git-native: a
|
|
15
|
-
* diff is the idiom its authors already read. A property edit never needs
|
|
16
|
-
* this; it changes one tag on one line.
|
|
17
|
-
*/
|
|
10
|
+
/** What the last save changed in the file, read-only: the file is git-native, and a diff is the idiom its authors already read. */
|
|
18
11
|
export function DiffDialog({
|
|
19
12
|
open,
|
|
20
13
|
before,
|
|
21
14
|
after,
|
|
22
|
-
onConfirm,
|
|
23
15
|
onClose,
|
|
24
16
|
}: {
|
|
25
17
|
open: boolean;
|
|
26
18
|
before: string;
|
|
27
19
|
after: string;
|
|
28
|
-
onConfirm: () => void;
|
|
29
20
|
onClose: () => void;
|
|
30
21
|
}) {
|
|
31
22
|
const { theme } = usePublisherTheme();
|
|
@@ -40,12 +31,11 @@ export function DiffDialog({
|
|
|
40
31
|
open={open}
|
|
41
32
|
onClose={onClose}
|
|
42
33
|
maxWidth="md"
|
|
43
|
-
title="
|
|
34
|
+
title="The change to the file"
|
|
44
35
|
description={
|
|
45
36
|
<>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
they were; check they still read right.{" "}
|
|
37
|
+
What the last save wrote. Lines the builder does not own, such as
|
|
38
|
+
comments and other Malloy, are left where they were.{" "}
|
|
49
39
|
<Box
|
|
50
40
|
component="span"
|
|
51
41
|
sx={{ fontVariantNumeric: "tabular-nums" }}
|
|
@@ -54,14 +44,7 @@ export function DiffDialog({
|
|
|
54
44
|
</Box>
|
|
55
45
|
</>
|
|
56
46
|
}
|
|
57
|
-
actions={
|
|
58
|
-
<>
|
|
59
|
-
<Button onClick={onClose}>Keep editing</Button>
|
|
60
|
-
<Button variant="contained" onClick={onConfirm}>
|
|
61
|
-
Save this
|
|
62
|
-
</Button>
|
|
63
|
-
</>
|
|
64
|
-
}
|
|
47
|
+
actions={<Button onClick={onClose}>Close</Button>}
|
|
65
48
|
>
|
|
66
49
|
<Box
|
|
67
50
|
component="pre"
|
|
@@ -102,8 +85,6 @@ export function DiffDialog({
|
|
|
102
85
|
: line.kind === "del"
|
|
103
86
|
? "rgba(168, 41, 31, 0.14)"
|
|
104
87
|
: "transparent",
|
|
105
|
-
textDecoration:
|
|
106
|
-
line.kind === "del" ? "line-through" : "none",
|
|
107
88
|
opacity: line.kind === "del" ? 0.8 : 1,
|
|
108
89
|
}}
|
|
109
90
|
>
|
|
@@ -120,7 +120,7 @@ export function DrillDialog({
|
|
|
120
120
|
<AppDialog
|
|
121
121
|
open={open}
|
|
122
122
|
onClose={onClose}
|
|
123
|
-
title="
|
|
123
|
+
title="Drill-through"
|
|
124
124
|
description="A cell in a column that groups by one of these dimensions becomes a link. Clicking it writes the value into a control — here, or on the dashboard it opens."
|
|
125
125
|
actions={
|
|
126
126
|
<>
|
|
@@ -27,7 +27,13 @@ import {
|
|
|
27
27
|
type ControlKind,
|
|
28
28
|
type MappingRow,
|
|
29
29
|
} from "./controls";
|
|
30
|
-
import
|
|
30
|
+
import {
|
|
31
|
+
isQueryTile,
|
|
32
|
+
type DashboardDocument,
|
|
33
|
+
type DashboardTile,
|
|
34
|
+
type LocalGiven,
|
|
35
|
+
type QueryTile,
|
|
36
|
+
} from "./document";
|
|
31
37
|
import { AppDialog } from "../AppDialog";
|
|
32
38
|
|
|
33
39
|
/**
|
|
@@ -70,7 +76,7 @@ export interface FilterDialogProps {
|
|
|
70
76
|
* source the host has no catalog for, in which case any name is accepted
|
|
71
77
|
* for it and nothing is searched.
|
|
72
78
|
*/
|
|
73
|
-
fieldsFor?: (tile:
|
|
79
|
+
fieldsFor?: (tile: QueryTile) => readonly CatalogField[] | undefined;
|
|
74
80
|
onClose: () => void;
|
|
75
81
|
/**
|
|
76
82
|
* Bind a control. `declare` is set when the control is new to this file, or
|
|
@@ -170,7 +176,7 @@ function FieldPicker({
|
|
|
170
176
|
* situations, and saying "from the model" about the second one is untrue.
|
|
171
177
|
*/
|
|
172
178
|
const unbindable = (tile: DashboardTile | undefined) =>
|
|
173
|
-
tile
|
|
179
|
+
tile && isQueryTile(tile) && tile.declaration.kind === "opaque"
|
|
174
180
|
? {
|
|
175
181
|
label: "Not bindable",
|
|
176
182
|
reason: `Its body is ${tile.declaration.why}, so a filter has no single place to go.`,
|
|
@@ -477,6 +483,7 @@ export function FilterDialog({
|
|
|
477
483
|
</Stack>
|
|
478
484
|
<Stack sx={{ gap: perTile ? 1 : 0 }}>
|
|
479
485
|
{document.tiles.map((tile, index) => {
|
|
486
|
+
if (!isQueryTile(tile)) return null;
|
|
480
487
|
const row = rows[index];
|
|
481
488
|
const title = tile.label ?? tile.name;
|
|
482
489
|
const problem = perTile ? rowProblems[index] : undefined;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import AddIcon from "@mui/icons-material/Add";
|
|
5
|
+
import CancelIcon from "@mui/icons-material/Cancel";
|
|
5
6
|
import FilterListIcon from "@mui/icons-material/FilterList";
|
|
6
7
|
import { Box, Chip, Stack, Tooltip, Typography } from "@mui/material";
|
|
7
8
|
import type { ReactNode } from "react";
|
|
@@ -9,6 +10,9 @@ import { SecondaryButton } from "../buttons";
|
|
|
9
10
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
10
11
|
import type { BuilderControl } from "./controls";
|
|
11
12
|
|
|
13
|
+
/** The `DashboardBar` is this tall and sticky; the strip pins just below it. */
|
|
14
|
+
const TOOLBAR_HEIGHT_PX = 49;
|
|
15
|
+
|
|
12
16
|
/**
|
|
13
17
|
* The strip under the header where the dashboard's controls are configured —
|
|
14
18
|
* the ONE place: a chip per control opens its window, and "Add filter"
|
|
@@ -20,6 +24,7 @@ export function FilterStrip({
|
|
|
20
24
|
unknownFieldsOf,
|
|
21
25
|
onEdit,
|
|
22
26
|
onAdd,
|
|
27
|
+
onRemove,
|
|
23
28
|
children,
|
|
24
29
|
}: {
|
|
25
30
|
controls: BuilderControl[];
|
|
@@ -28,6 +33,8 @@ export function FilterStrip({
|
|
|
28
33
|
unknownFieldsOf: (name: string, type: string | undefined) => string[];
|
|
29
34
|
onEdit: (control: BuilderControl) => void;
|
|
30
35
|
onAdd: () => void;
|
|
36
|
+
/** Take a control off the dashboard, as its window's Remove does. */
|
|
37
|
+
onRemove: (name: string) => void;
|
|
31
38
|
/** The host's live control row. */
|
|
32
39
|
children?: ReactNode;
|
|
33
40
|
}) {
|
|
@@ -36,12 +43,21 @@ export function FilterStrip({
|
|
|
36
43
|
<>
|
|
37
44
|
{/* The filter band, as every dashboard builder has one. The header is the
|
|
38
45
|
dashboard's controls as this FILE has them: a chip per control,
|
|
39
|
-
which opens its window
|
|
40
|
-
|
|
41
|
-
on the chip was a second place, with none of them. The live control row the caller
|
|
46
|
+
which opens its window; the × on a chip removes it, as the window's
|
|
47
|
+
Remove does. The live control row the caller
|
|
42
48
|
passes in sits directly under, showing the same controls as a
|
|
43
49
|
reader gets them — from the saved file. */}
|
|
44
|
-
<Stack
|
|
50
|
+
<Stack
|
|
51
|
+
sx={{
|
|
52
|
+
gap: 1,
|
|
53
|
+
position: "sticky",
|
|
54
|
+
// Under the toolbar, which pins at the top of the same scroller.
|
|
55
|
+
top: TOOLBAR_HEIGHT_PX,
|
|
56
|
+
zIndex: 4,
|
|
57
|
+
bgcolor: theme.background,
|
|
58
|
+
pb: 1,
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
45
61
|
<Stack
|
|
46
62
|
direction="row"
|
|
47
63
|
aria-label="Filters"
|
|
@@ -97,6 +113,12 @@ export function FilterStrip({
|
|
|
97
113
|
: "outlined"
|
|
98
114
|
}
|
|
99
115
|
onClick={() => onEdit(control)}
|
|
116
|
+
onDelete={() => onRemove(control.name)}
|
|
117
|
+
deleteIcon={
|
|
118
|
+
<CancelIcon
|
|
119
|
+
aria-label={`Remove filter ${control.name}`}
|
|
120
|
+
/>
|
|
121
|
+
}
|
|
100
122
|
sx={{
|
|
101
123
|
// Faint when nothing binds it: declared, but not yet a
|
|
102
124
|
// control a reader would see.
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, Button, Stack, TextField, Typography } from "@mui/material";
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
7
|
+
import { Prose, type ProseVariant } from "../Prose";
|
|
8
|
+
import { useReportOpenDraft } from "./openDraft";
|
|
9
|
+
import { markdownProblem } from "./spliceDocument";
|
|
10
|
+
import { useDraft } from "./useDraft";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Markdown that is edited where it is read: it draws as prose, a click on it
|
|
14
|
+
* opens a textarea, and what was typed commits once, when the field closes.
|
|
15
|
+
*
|
|
16
|
+
* Escape and Cmd or Ctrl+Enter are Done, which holds on a draft the writer
|
|
17
|
+
* would refuse and says why; leaving the field commits, so the closed prose
|
|
18
|
+
* keeps saying what Save will refuse. Links stay inert: a click on one is not
|
|
19
|
+
* a way out of the builder, and not an edit either.
|
|
20
|
+
*/
|
|
21
|
+
export function InlineMarkdown({
|
|
22
|
+
markdown,
|
|
23
|
+
placeholder,
|
|
24
|
+
onCommit,
|
|
25
|
+
variant = "document",
|
|
26
|
+
}: {
|
|
27
|
+
markdown: string;
|
|
28
|
+
/** Shown in place of empty prose. */
|
|
29
|
+
placeholder: string;
|
|
30
|
+
/** Called once per edit, with the new text, only when it differs from `markdown`. */
|
|
31
|
+
onCommit: (next: string) => void;
|
|
32
|
+
variant?: ProseVariant;
|
|
33
|
+
}) {
|
|
34
|
+
const { theme } = usePublisherTheme();
|
|
35
|
+
const [editing, setEditing] = useState(false);
|
|
36
|
+
// One object per value, or the draft would reset on every render while open.
|
|
37
|
+
const value = useMemo(
|
|
38
|
+
() => (editing ? { text: markdown } : undefined),
|
|
39
|
+
[editing, markdown],
|
|
40
|
+
);
|
|
41
|
+
const { draft, patch, close, discard } = useDraft<{ text: string }>(
|
|
42
|
+
value,
|
|
43
|
+
editing,
|
|
44
|
+
(next) => onCommit(next.text),
|
|
45
|
+
() => setEditing(false),
|
|
46
|
+
);
|
|
47
|
+
const draftDirty = editing && draft !== undefined && draft.text !== markdown;
|
|
48
|
+
const refused =
|
|
49
|
+
draft !== undefined && draft.text !== markdown
|
|
50
|
+
? markdownProblem(draft.text)
|
|
51
|
+
: undefined;
|
|
52
|
+
useReportOpenDraft(draftDirty, () => {
|
|
53
|
+
if (refused !== undefined) return false;
|
|
54
|
+
close();
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
const actions = useRef<HTMLDivElement>(null);
|
|
58
|
+
const caretPlaced = useRef(false);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!editing) caretPlaced.current = false;
|
|
61
|
+
}, [editing]);
|
|
62
|
+
const placeCaret = useCallback((field: HTMLTextAreaElement | null) => {
|
|
63
|
+
if (!field || caretPlaced.current) return;
|
|
64
|
+
caretPlaced.current = true;
|
|
65
|
+
field.setSelectionRange(field.value.length, field.value.length);
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
if (!editing || draft === undefined) {
|
|
69
|
+
// A blur commits an invalid draft, so the closed prose keeps saying what the writer will refuse at Save.
|
|
70
|
+
const closedProblem = markdown.trim()
|
|
71
|
+
? markdownProblem(markdown)
|
|
72
|
+
: undefined;
|
|
73
|
+
return (
|
|
74
|
+
<Box
|
|
75
|
+
role="button"
|
|
76
|
+
tabIndex={0}
|
|
77
|
+
onClick={(event) => {
|
|
78
|
+
if ((event.target as Element).closest("a"))
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
else setEditing(true);
|
|
81
|
+
}}
|
|
82
|
+
onKeyDown={(event) => {
|
|
83
|
+
if (event.target !== event.currentTarget) return;
|
|
84
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
setEditing(true);
|
|
87
|
+
}}
|
|
88
|
+
sx={{
|
|
89
|
+
cursor: "text",
|
|
90
|
+
minHeight: 24,
|
|
91
|
+
borderRadius: "2px",
|
|
92
|
+
"&:hover, &:focus-visible": {
|
|
93
|
+
outline: "1px dashed currentColor",
|
|
94
|
+
},
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
{markdown.trim() ? (
|
|
98
|
+
<Prose variant={variant}>{markdown}</Prose>
|
|
99
|
+
) : (
|
|
100
|
+
<Typography
|
|
101
|
+
variant="body2"
|
|
102
|
+
sx={{ color: theme.tileTitle, opacity: 0.6 }}
|
|
103
|
+
>
|
|
104
|
+
{placeholder}
|
|
105
|
+
</Typography>
|
|
106
|
+
)}
|
|
107
|
+
{closedProblem && (
|
|
108
|
+
<Typography variant="caption" color="error" role="alert">
|
|
109
|
+
{closedProblem}
|
|
110
|
+
</Typography>
|
|
111
|
+
)}
|
|
112
|
+
</Box>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// An untouched text is left as it was, so only a changed draft is held to the writer's rules.
|
|
117
|
+
const problem =
|
|
118
|
+
draft.text !== markdown ? markdownProblem(draft.text) : undefined;
|
|
119
|
+
const finish = () => {
|
|
120
|
+
if (problem === undefined) close();
|
|
121
|
+
};
|
|
122
|
+
return (
|
|
123
|
+
<Stack spacing={1}>
|
|
124
|
+
<TextField
|
|
125
|
+
multiline
|
|
126
|
+
autoFocus
|
|
127
|
+
minRows={3}
|
|
128
|
+
maxRows={14}
|
|
129
|
+
fullWidth
|
|
130
|
+
value={draft.text}
|
|
131
|
+
placeholder={placeholder}
|
|
132
|
+
error={problem !== undefined}
|
|
133
|
+
helperText={problem}
|
|
134
|
+
inputRef={placeCaret}
|
|
135
|
+
inputProps={{ "aria-label": "Markdown" }}
|
|
136
|
+
onChange={(event) =>
|
|
137
|
+
patch((next) => {
|
|
138
|
+
next.text = event.target.value;
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
onKeyDown={(event) => {
|
|
142
|
+
if (event.key === "Escape") finish();
|
|
143
|
+
else if (
|
|
144
|
+
event.key === "Enter" &&
|
|
145
|
+
(event.metaKey || event.ctrlKey)
|
|
146
|
+
) {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
finish();
|
|
149
|
+
}
|
|
150
|
+
}}
|
|
151
|
+
// Moving to Done or Cancel is not leaving the edit.
|
|
152
|
+
onBlur={(event) => {
|
|
153
|
+
if (
|
|
154
|
+
event.relatedTarget instanceof Node &&
|
|
155
|
+
actions.current?.contains(event.relatedTarget)
|
|
156
|
+
)
|
|
157
|
+
return;
|
|
158
|
+
close();
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
<Stack ref={actions} direction="row" spacing={1}>
|
|
162
|
+
<Button
|
|
163
|
+
size="small"
|
|
164
|
+
variant="outlined"
|
|
165
|
+
disabled={problem !== undefined}
|
|
166
|
+
onClick={finish}
|
|
167
|
+
>
|
|
168
|
+
Done
|
|
169
|
+
</Button>
|
|
170
|
+
<Button
|
|
171
|
+
size="small"
|
|
172
|
+
// Keeps focus in the field, whose blur would otherwise commit the draft Cancel is dropping.
|
|
173
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
174
|
+
onClick={() => {
|
|
175
|
+
discard();
|
|
176
|
+
setEditing(false);
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
Cancel
|
|
180
|
+
</Button>
|
|
181
|
+
</Stack>
|
|
182
|
+
</Stack>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, InputBase } from "@mui/material";
|
|
5
|
+
import { useRef, useState, type KeyboardEvent } from "react";
|
|
6
|
+
import { useReportOpenDraft } from "./openDraft";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A single line of text that is edited where it is read: a click opens a field,
|
|
10
|
+
* Enter or leaving it commits, Escape puts the old text back.
|
|
11
|
+
*
|
|
12
|
+
* The display is a real button, so it is a tab stop that Enter and Space open,
|
|
13
|
+
* and the drag sensor refuses a press that starts on one: opening an editor can
|
|
14
|
+
* never be the start of a move.
|
|
15
|
+
*/
|
|
16
|
+
export function InlineText({
|
|
17
|
+
value,
|
|
18
|
+
placeholder,
|
|
19
|
+
ariaLabel,
|
|
20
|
+
onCommit,
|
|
21
|
+
faintWhenEmpty = false,
|
|
22
|
+
}: {
|
|
23
|
+
value: string;
|
|
24
|
+
/** Shown in place of an empty value. */
|
|
25
|
+
placeholder: string;
|
|
26
|
+
/** Names the field while it is open. */
|
|
27
|
+
ariaLabel: string;
|
|
28
|
+
/** Called once per edit, with the new text, only when it differs from `value`. */
|
|
29
|
+
onCommit: (next: string) => void;
|
|
30
|
+
/** Draws an empty value faintly, and only while its tile is hovered or focused. */
|
|
31
|
+
faintWhenEmpty?: boolean;
|
|
32
|
+
}) {
|
|
33
|
+
const [draft, setDraft] = useState<string | undefined>(undefined);
|
|
34
|
+
// A cancelled edit unmounts the field, and a browser may report that as a blur.
|
|
35
|
+
const cancelled = useRef(false);
|
|
36
|
+
|
|
37
|
+
const commit = () => {
|
|
38
|
+
if (cancelled.current || draft === undefined) return;
|
|
39
|
+
setDraft(undefined);
|
|
40
|
+
if (draft !== value) onCommit(draft);
|
|
41
|
+
};
|
|
42
|
+
useReportOpenDraft(draft !== undefined && draft !== value, () => {
|
|
43
|
+
commit();
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
const open = () => {
|
|
47
|
+
cancelled.current = false;
|
|
48
|
+
setDraft(value);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
if (draft === undefined) {
|
|
52
|
+
const faint = value === "" && faintWhenEmpty;
|
|
53
|
+
return (
|
|
54
|
+
<Box
|
|
55
|
+
component="button"
|
|
56
|
+
type="button"
|
|
57
|
+
className={faint ? "builder-affordance" : undefined}
|
|
58
|
+
onClick={open}
|
|
59
|
+
onKeyDown={(event: KeyboardEvent) => {
|
|
60
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
open();
|
|
63
|
+
}}
|
|
64
|
+
sx={{
|
|
65
|
+
all: "unset",
|
|
66
|
+
boxSizing: "border-box",
|
|
67
|
+
font: "inherit",
|
|
68
|
+
color: "inherit",
|
|
69
|
+
cursor: "text",
|
|
70
|
+
display: "inline-block",
|
|
71
|
+
maxWidth: "100%",
|
|
72
|
+
borderRadius: "2px",
|
|
73
|
+
opacity: faint ? 0 : 1,
|
|
74
|
+
fontStyle: faint ? "italic" : undefined,
|
|
75
|
+
"&:hover, &:focus-visible": {
|
|
76
|
+
outline: "1px dashed currentColor",
|
|
77
|
+
},
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
{value === "" ? placeholder : value}
|
|
81
|
+
</Box>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return (
|
|
85
|
+
<InputBase
|
|
86
|
+
autoFocus
|
|
87
|
+
fullWidth
|
|
88
|
+
value={draft}
|
|
89
|
+
placeholder={placeholder}
|
|
90
|
+
inputProps={{ "aria-label": ariaLabel }}
|
|
91
|
+
onFocus={(event) => event.target.select()}
|
|
92
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
93
|
+
onKeyDown={(event) => {
|
|
94
|
+
if (event.key === "Enter" && !event.nativeEvent.isComposing)
|
|
95
|
+
commit();
|
|
96
|
+
else if (event.key === "Escape") {
|
|
97
|
+
cancelled.current = true;
|
|
98
|
+
setDraft(undefined);
|
|
99
|
+
}
|
|
100
|
+
}}
|
|
101
|
+
onBlur={commit}
|
|
102
|
+
// The field takes its type from the line it replaces.
|
|
103
|
+
sx={{ font: "inherit", color: "inherit", p: 0, "& input": { p: 0 } }}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { DashboardEditor, type DashboardEditorProps } from "./DashboardEditor";
|
|
5
|
+
|
|
6
|
+
/** The props a host passed the notebook editor before notebooks opened in the one builder. */
|
|
7
|
+
export type NotebookEditorProps = (
|
|
8
|
+
| {
|
|
9
|
+
/** `publisher://environments/{env}/packages/{pkg}`, optionally `?versionId=`. */
|
|
10
|
+
resourceUri: string;
|
|
11
|
+
/** The notebook's slug: `overview` for `notebooks/overview.malloy`. */
|
|
12
|
+
notebook: string;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
environmentName: string;
|
|
16
|
+
packageName: string;
|
|
17
|
+
/** The notebook's slug: `overview` for `notebooks/overview.malloy`. */
|
|
18
|
+
notebookName: string;
|
|
19
|
+
}
|
|
20
|
+
) &
|
|
21
|
+
Pick<DashboardEditorProps, "onExit" | "onEvent" | "onDirtyChange" | "path">;
|
|
22
|
+
|
|
23
|
+
/** `DashboardEditor` opened on a notebook, under the name hosts already import. */
|
|
24
|
+
export function NotebookEditor(props: NotebookEditorProps) {
|
|
25
|
+
const { onExit, onEvent, onDirtyChange, path } = props;
|
|
26
|
+
const target =
|
|
27
|
+
"resourceUri" in props
|
|
28
|
+
? { resourceUri: props.resourceUri, dashboard: props.notebook }
|
|
29
|
+
: {
|
|
30
|
+
environmentName: props.environmentName,
|
|
31
|
+
packageName: props.packageName,
|
|
32
|
+
dashboardName: props.notebookName,
|
|
33
|
+
};
|
|
34
|
+
return (
|
|
35
|
+
<DashboardEditor
|
|
36
|
+
{...target}
|
|
37
|
+
kind="notebook"
|
|
38
|
+
{...(onExit ? { onExit } : {})}
|
|
39
|
+
{...(onEvent ? { onEvent } : {})}
|
|
40
|
+
{...(onDirtyChange ? { onDirtyChange } : {})}
|
|
41
|
+
{...(path !== undefined ? { path } : {})}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Alert, Box, Button } from "@mui/material";
|
|
5
|
+
import { DiffDialog } from "./DiffDialog";
|
|
6
|
+
import type { LastSave } from "./useDocumentEditor";
|
|
7
|
+
|
|
8
|
+
export interface SaveNoticeProps {
|
|
9
|
+
/** The save the notice offers to take back; absent once that offer is withdrawn. */
|
|
10
|
+
lastSave?: LastSave & { removedComments?: string[] };
|
|
11
|
+
/** What the document's parts are called, singular: "tile" or "cell". */
|
|
12
|
+
unit: string;
|
|
13
|
+
/** How many parts the document had before the save and after it. */
|
|
14
|
+
moved: { before: number; after: number } | undefined;
|
|
15
|
+
canUndoSave: boolean;
|
|
16
|
+
/** An Undo save just landed and the offer is gone. */
|
|
17
|
+
undone: boolean;
|
|
18
|
+
/** The read-only viewer of the saved change is open. */
|
|
19
|
+
viewing: boolean;
|
|
20
|
+
onView: (open: boolean) => void;
|
|
21
|
+
onUndoSave: () => Promise<void> | void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const plural = (count: number, unit: string) =>
|
|
25
|
+
`${count} ${unit}${count === 1 ? "" : "s"}`;
|
|
26
|
+
|
|
27
|
+
/** What the save did to the file, as facts the author can check before moving on. */
|
|
28
|
+
function facts(
|
|
29
|
+
{ lastSave, unit, moved }: SaveNoticeProps,
|
|
30
|
+
comments: string[],
|
|
31
|
+
): string[] {
|
|
32
|
+
if (!lastSave) return [];
|
|
33
|
+
const lines: string[] = [];
|
|
34
|
+
const change = moved ? moved.after - moved.before : 0;
|
|
35
|
+
if (change === 1) lines.push(`Added a ${unit}`);
|
|
36
|
+
else if (change > 1) lines.push(`Added ${plural(change, unit)}`);
|
|
37
|
+
else if (change < 0) lines.push(`Removed ${plural(-change, unit)}`);
|
|
38
|
+
else if (lastSave.structural) lines.push(`Changed the ${unit}s in the file`);
|
|
39
|
+
else lines.push("Saved your edits");
|
|
40
|
+
if (comments.length > 0)
|
|
41
|
+
lines.push(
|
|
42
|
+
`Removed ${plural(comments.length, "comment")} with their ${unit}s`,
|
|
43
|
+
);
|
|
44
|
+
if (lastSave.clearsHistory) lines.push("Undo history was cleared");
|
|
45
|
+
return lines;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* What a save just did, with the way back: View change shows the file's diff
|
|
50
|
+
* read-only, Undo save writes the file back as it was. Stays until an edit
|
|
51
|
+
* withdraws the offer or the next save replaces it; nothing else hides it.
|
|
52
|
+
*/
|
|
53
|
+
export function SaveNotice(props: SaveNoticeProps) {
|
|
54
|
+
const { lastSave, canUndoSave, undone, viewing, onView, onUndoSave } = props;
|
|
55
|
+
if (undone)
|
|
56
|
+
return (
|
|
57
|
+
<Alert severity="info" role="status">
|
|
58
|
+
Save undone. Your edits are back and unsaved.
|
|
59
|
+
</Alert>
|
|
60
|
+
);
|
|
61
|
+
if (!lastSave) return null;
|
|
62
|
+
const comments = lastSave.removedComments ?? [];
|
|
63
|
+
return (
|
|
64
|
+
<>
|
|
65
|
+
<Alert
|
|
66
|
+
severity="success"
|
|
67
|
+
role="status"
|
|
68
|
+
action={
|
|
69
|
+
<>
|
|
70
|
+
<Button
|
|
71
|
+
color="inherit"
|
|
72
|
+
size="small"
|
|
73
|
+
onClick={() => onView(true)}
|
|
74
|
+
>
|
|
75
|
+
View change
|
|
76
|
+
</Button>
|
|
77
|
+
<Button
|
|
78
|
+
color="inherit"
|
|
79
|
+
size="small"
|
|
80
|
+
disabled={!canUndoSave}
|
|
81
|
+
onClick={() => void onUndoSave()}
|
|
82
|
+
>
|
|
83
|
+
Undo save
|
|
84
|
+
</Button>
|
|
85
|
+
</>
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
{facts(props, comments).join(". ")}.
|
|
89
|
+
{comments.length > 0 && (
|
|
90
|
+
<Box
|
|
91
|
+
component="span"
|
|
92
|
+
aria-label="Comments removed with their cell"
|
|
93
|
+
sx={{
|
|
94
|
+
display: "block",
|
|
95
|
+
whiteSpace: "pre",
|
|
96
|
+
fontFamily: "monospace",
|
|
97
|
+
fontSize: 12,
|
|
98
|
+
mt: 0.5,
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{comments.join("\n")}
|
|
102
|
+
</Box>
|
|
103
|
+
)}
|
|
104
|
+
</Alert>
|
|
105
|
+
<DiffDialog
|
|
106
|
+
open={viewing}
|
|
107
|
+
before={lastSave.before}
|
|
108
|
+
after={lastSave.after}
|
|
109
|
+
onClose={() => onView(false)}
|
|
110
|
+
/>
|
|
111
|
+
</>
|
|
112
|
+
);
|
|
113
|
+
}
|