@malloy-publisher/sdk 0.9.9 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RenderedResult-BlNoIiSi.cjs.js +153 -0
- package/dist/{RenderedResult-BHuJpdSn.es.js → RenderedResult-Cmx8sX8d.es.js} +102 -102
- package/dist/ServerProvider-BOgiW8MX.cjs.js +1 -0
- package/dist/{ServerProvider-CQy4jVYK.es.js → ServerProvider-azXLkk1q.es.js} +619 -586
- package/dist/builder/index.cjs.js +78 -130
- package/dist/builder/index.es.js +7440 -6727
- package/dist/builder-entry.d.ts +3 -0
- package/dist/client/api.d.ts +26 -22
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/AppDialog.d.ts +9 -1
- package/dist/components/Dashboard/DashboardGrid.d.ts +14 -15
- package/dist/components/Dashboard/DashboardTile.d.ts +8 -1
- package/dist/components/Dashboard/DashboardView.d.ts +22 -23
- package/dist/components/Dashboard/TileCard.d.ts +10 -3
- package/dist/components/Dashboard/useStuck.d.ts +22 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -5
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +6 -0
- package/dist/components/Package/PackageProblems.d.ts +14 -0
- package/dist/components/RemoveBadge.d.ts +40 -0
- package/dist/components/Report/Report.d.ts +13 -4
- package/dist/components/Report/ReportPage.d.ts +60 -0
- package/dist/components/Report/layoutRules.d.ts +32 -0
- package/dist/components/Report/reportQuery.d.ts +30 -0
- package/dist/components/Report/telemetry.d.ts +0 -2
- package/dist/components/ReportBuilder/AddTileDialog.d.ts +22 -3
- package/dist/components/ReportBuilder/BuilderBar.d.ts +17 -0
- package/dist/components/ReportBuilder/BuilderDialogs.d.ts +7 -6
- package/dist/components/ReportBuilder/BuilderGrid.d.ts +10 -4
- package/dist/components/ReportBuilder/BuilderHeader.d.ts +4 -7
- package/dist/components/ReportBuilder/BuilderToolbar.d.ts +88 -0
- package/dist/components/ReportBuilder/DrillDialog.d.ts +3 -1
- package/dist/components/ReportBuilder/EditorSurface.d.ts +7 -9
- package/dist/components/ReportBuilder/FilterDialog.d.ts +3 -1
- package/dist/components/ReportBuilder/FilterStrip.d.ts +30 -6
- package/dist/components/ReportBuilder/InlineMarkdown.d.ts +4 -4
- package/dist/components/ReportBuilder/ReportBuilder.d.ts +49 -12
- package/dist/components/ReportBuilder/ReportEditor.d.ts +53 -3
- package/dist/components/ReportBuilder/TextTileBody.d.ts +2 -5
- package/dist/components/ReportBuilder/TileFrame.d.ts +10 -4
- package/dist/components/ReportBuilder/TileMenu.d.ts +19 -11
- package/dist/components/ReportBuilder/ViewPicker.d.ts +53 -0
- package/dist/components/ReportBuilder/addTileToDocument.d.ts +24 -3
- package/dist/components/ReportBuilder/builderControls.d.ts +60 -0
- package/dist/components/ReportBuilder/catalog.d.ts +2 -4
- package/dist/components/ReportBuilder/inlineEdit.d.ts +9 -10
- package/dist/components/ReportBuilder/localGiven.d.ts +12 -0
- package/dist/components/ReportBuilder/preview.d.ts +17 -2
- package/dist/components/ReportBuilder/readDocument.d.ts +0 -2
- package/dist/components/ReportBuilder/readForEditor.d.ts +2 -7
- package/dist/components/ReportBuilder/reportTag.d.ts +11 -1
- package/dist/components/ReportBuilder/sortable.d.ts +4 -3
- package/dist/components/ReportBuilder/testing/inline.d.ts +5 -1
- package/dist/components/ReportBuilder/useBuilderSelection.d.ts +0 -1
- package/dist/components/ReportBuilder/useBuilderSession.d.ts +21 -12
- package/dist/components/ReportBuilder/useDocumentEditor.d.ts +2 -6
- package/dist/components/ReportBuilder/useExitGuard.d.ts +3 -0
- package/dist/components/ReportBuilder/useFilterForm.d.ts +3 -1
- package/dist/components/ReportBuilder/useOpenedDocument.d.ts +0 -4
- package/dist/components/ReportBuilder/useReportDraft.d.ts +66 -0
- package/dist/components/ReportBuilder/useReportEditor.d.ts +0 -9
- package/dist/components/ReportBuilder/useTileEditing.d.ts +6 -3
- package/dist/components/ReportBuilder/viewAnnotations.d.ts +9 -0
- package/dist/components/ReportBuilder/widthLabel.d.ts +6 -0
- package/dist/components/ServerProvider.d.ts +9 -0
- package/dist/components/controlTokens.d.ts +45 -0
- package/dist/components/drill/markDrillableCells.d.ts +1 -1
- package/dist/components/given/FilterButton.d.ts +35 -0
- package/dist/components/given/GivensPanel.d.ts +2 -1
- package/dist/components/given/filterEditing.d.ts +54 -0
- package/dist/components/given/filterSummary.d.ts +9 -0
- package/dist/components/given/paramCodec.d.ts +11 -0
- package/dist/components/given/required.d.ts +25 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/legacy/index.d.ts +1 -1
- package/dist/components/{Report/CellReport.d.ts → legacy/malloynb/CellRunnerView.d.ts} +9 -17
- package/dist/components/legacy/{MalloynbCells.d.ts → malloynb/MalloynbCells.d.ts} +3 -3
- package/dist/components/legacy/{Notebook.d.ts → malloynb/Notebook.d.ts} +1 -1
- package/dist/components/{Notebook → legacy/malloynb}/NotebookCell.d.ts +3 -3
- package/dist/components/legacy/malloynb/cellKind.d.ts +5 -0
- package/dist/components/{Notebook → legacy/malloynb}/types.d.ts +1 -1
- package/dist/components/styles.d.ts +0 -2
- package/dist/hooks/useQueryResult.d.ts +7 -0
- package/dist/index.cjs.js +16 -19
- package/dist/index.es.js +8324 -7769
- package/dist/theme/ThemeContext.d.ts +8 -1
- package/dist/theme/classes.d.ts +49 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/types.d.ts +7 -0
- package/dist/theme/ui.d.ts +75 -0
- package/dist/{useCompiledDocument-1dgF5CC9.es.js → useCompiledDocument-7j5cBjQd.es.js} +8768 -7912
- package/dist/useCompiledDocument-B21sVbb4.cjs.js +141 -0
- package/package.json +2 -2
- package/src/builder-entry.ts +9 -0
- package/src/components/AppDialog.tsx +23 -0
- package/src/components/Dashboard/DashboardGrid.tsx +39 -17
- package/src/components/Dashboard/DashboardTile.tsx +19 -2
- package/src/components/Dashboard/DashboardView.spec.tsx +216 -15
- package/src/components/Dashboard/DashboardView.tsx +136 -105
- package/src/components/Dashboard/RowsDialog.tsx +1 -2
- package/src/components/Dashboard/TileCard.tsx +28 -10
- package/src/components/Dashboard/defaultTileSpan.spec.ts +24 -0
- package/src/components/Dashboard/useStuck.ts +49 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +8 -6
- package/src/components/DocumentCreate/newNotebook.ts +26 -12
- package/src/components/DocumentCreate/useDocumentChoices.ts +19 -2
- package/src/components/Package/NewDocumentDialog.spec.tsx +76 -59
- package/src/components/Package/NewDocumentDialog.tsx +383 -119
- package/src/components/Package/Package.artifacts.spec.tsx +1 -1
- package/src/components/Package/Package.create.spec.tsx +7 -6
- package/src/components/Package/Package.tsx +10 -7
- package/src/components/Package/PackageProblems.spec.tsx +41 -0
- package/src/components/Package/PackageProblems.tsx +95 -0
- package/src/components/Prose.tsx +12 -7
- package/src/components/RemoveBadge.tsx +94 -0
- package/src/components/RenderedResult/RenderedResult.tsx +5 -9
- package/src/components/RenderedResult/ResultPanel.tsx +59 -3
- package/src/components/Report/Report.spec.tsx +50 -32
- package/src/components/Report/Report.telemetry.spec.tsx +0 -45
- package/src/components/Report/Report.tsx +45 -77
- package/src/components/Report/ReportPage.tsx +168 -0
- package/src/components/Report/layoutRules.spec.ts +35 -0
- package/src/components/Report/layoutRules.ts +55 -0
- package/src/components/Report/reportQuery.ts +53 -0
- package/src/components/Report/telemetry.ts +0 -2
- package/src/components/ReportBuilder/AddTileDialog.spec.tsx +76 -41
- package/src/components/ReportBuilder/AddTileDialog.tsx +368 -133
- package/src/components/ReportBuilder/BuilderBar.tsx +599 -0
- package/src/components/ReportBuilder/BuilderDialogs.tsx +30 -39
- package/src/components/ReportBuilder/BuilderGrid.tsx +43 -31
- package/src/components/ReportBuilder/BuilderHeader.tsx +63 -75
- package/src/components/ReportBuilder/BuilderToolbar.tsx +95 -9
- package/src/components/ReportBuilder/DrillDialog.tsx +240 -128
- package/src/components/ReportBuilder/EditorSurface.tsx +345 -69
- package/src/components/ReportBuilder/FilterDialog.tsx +516 -166
- package/src/components/ReportBuilder/FilterStrip.tsx +129 -150
- package/src/components/ReportBuilder/InlineMarkdown.tsx +71 -45
- package/src/components/ReportBuilder/ReportBuilder.charts.spec.tsx +35 -40
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +491 -0
- package/src/components/ReportBuilder/ReportBuilder.exit.spec.tsx +2 -4
- package/src/components/ReportBuilder/ReportBuilder.inline.spec.tsx +13 -16
- package/src/components/ReportBuilder/ReportBuilder.notebook.spec.tsx +27 -118
- package/src/components/ReportBuilder/ReportBuilder.openDraft.spec.tsx +12 -5
- package/src/components/ReportBuilder/ReportBuilder.sources.spec.tsx +2 -10
- package/src/components/ReportBuilder/ReportBuilder.spec.tsx +41 -36
- package/src/components/ReportBuilder/ReportBuilder.textTiles.spec.tsx +22 -15
- package/src/components/ReportBuilder/ReportBuilder.tsx +292 -116
- package/src/components/ReportBuilder/ReportEditor.emptyStart.spec.tsx +2 -1
- package/src/components/ReportBuilder/ReportEditor.modelFilters.spec.tsx +312 -0
- package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +26 -75
- package/src/components/ReportBuilder/ReportEditor.package.spec.tsx +6 -2
- package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -2
- package/src/components/ReportBuilder/ReportEditor.spec.tsx +2 -4
- package/src/components/ReportBuilder/ReportEditor.textSource.spec.tsx +93 -13
- package/src/components/ReportBuilder/ReportEditor.tsx +104 -14
- package/src/components/ReportBuilder/TextTileBody.tsx +6 -7
- package/src/components/ReportBuilder/TileFrame.tsx +212 -75
- package/src/components/ReportBuilder/TileMenu.tsx +248 -142
- package/src/components/ReportBuilder/ViewPicker.tsx +349 -0
- package/src/components/ReportBuilder/addTile.compile.spec.ts +1 -1
- package/src/components/ReportBuilder/addTileToDocument.spec.ts +102 -3
- package/src/components/ReportBuilder/addTileToDocument.ts +122 -25
- package/src/components/ReportBuilder/builderControls.ts +164 -0
- package/src/components/ReportBuilder/builderReport.ts +1 -2
- package/src/components/ReportBuilder/catalog.ts +10 -26
- package/src/components/ReportBuilder/inlineEdit.tsx +22 -54
- package/src/components/ReportBuilder/localGiven.ts +56 -0
- package/src/components/ReportBuilder/newDashboard.spec.ts +2 -3
- package/src/components/ReportBuilder/preview.spec.ts +125 -5
- package/src/components/ReportBuilder/preview.ts +60 -44
- package/src/components/ReportBuilder/readDocument.spec.ts +16 -22
- package/src/components/ReportBuilder/readDocument.ts +14 -11
- package/src/components/ReportBuilder/readForEditor.spec.ts +12 -41
- package/src/components/ReportBuilder/readForEditor.ts +4 -26
- package/src/components/ReportBuilder/reportTag.ts +28 -7
- package/src/components/ReportBuilder/sortable.tsx +15 -7
- package/src/components/ReportBuilder/spliceDocument.imports.spec.ts +1 -1
- package/src/components/ReportBuilder/tagParse.spec.ts +0 -40
- package/src/components/ReportBuilder/testing/inline.ts +25 -5
- package/src/components/ReportBuilder/testing/reportLayoutParity.json +13 -8
- package/src/components/ReportBuilder/textTiles.spec.ts +7 -6
- package/src/components/ReportBuilder/useBuilderSelection.ts +35 -0
- package/src/components/ReportBuilder/useBuilderSession.spec.ts +2 -2
- package/src/components/ReportBuilder/useBuilderSession.ts +21 -13
- package/src/components/ReportBuilder/useDocumentEditor.spec.ts +0 -58
- package/src/components/ReportBuilder/useDocumentEditor.ts +3 -16
- package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +26 -0
- package/src/components/ReportBuilder/useEditorCatalog.ts +7 -2
- package/src/components/ReportBuilder/useExitGuard.ts +16 -0
- package/src/components/ReportBuilder/useFilterForm.spec.tsx +17 -0
- package/src/components/ReportBuilder/useFilterForm.ts +5 -1
- package/src/components/ReportBuilder/useOpenedDocument.ts +0 -2
- package/src/components/ReportBuilder/useReportDraft.spec.ts +149 -0
- package/src/components/ReportBuilder/useReportDraft.ts +292 -0
- package/src/components/ReportBuilder/useReportEditor.ts +3 -12
- package/src/components/ReportBuilder/useSaveChannel.ts +0 -1
- package/src/components/ReportBuilder/useTileEditing.ts +43 -12
- package/src/components/ReportBuilder/viewAnnotations.ts +29 -0
- package/src/components/ReportBuilder/widthLabel.spec.ts +25 -0
- package/src/components/ReportBuilder/widthLabel.ts +26 -0
- package/src/components/ServerProvider.tsx +11 -0
- package/src/components/controlTokens.ts +47 -0
- package/src/components/drill/markDrillableCells.ts +2 -1
- package/src/components/given/FilterButton.spec.tsx +143 -0
- package/src/components/given/FilterButton.tsx +478 -0
- package/src/components/given/GivenInput.spec.tsx +47 -0
- package/src/components/given/GivenInput.tsx +20 -2
- package/src/components/given/GivensPanel.spec.tsx +11 -3
- package/src/components/given/GivensPanel.tsx +45 -44
- package/src/components/given/filterEditing.ts +60 -0
- package/src/components/given/filterSummary.spec.ts +108 -0
- package/src/components/given/filterSummary.ts +109 -0
- package/src/components/given/paramCodec.ts +1 -1
- package/src/components/given/required.spec.ts +60 -0
- package/src/components/given/required.ts +78 -0
- package/src/components/index.ts +9 -0
- package/src/components/legacy/Dashboard.spec.tsx +3 -1
- package/src/components/legacy/index.ts +1 -1
- package/src/components/{Report/CellReport.spec.tsx → legacy/malloynb/CellRunnerView.spec.tsx} +53 -57
- package/src/components/{Report/CellReport.tsx → legacy/malloynb/CellRunnerView.tsx} +122 -136
- package/src/components/legacy/{MalloynbCells.tsx → malloynb/MalloynbCells.tsx} +6 -6
- package/src/components/legacy/{Notebook.layout.spec.tsx → malloynb/Notebook.layout.spec.tsx} +16 -7
- package/src/components/legacy/malloynb/Notebook.served.spec.tsx +84 -0
- package/src/components/legacy/{Notebook.spec.tsx → malloynb/Notebook.spec.tsx} +5 -3
- package/src/components/legacy/{Notebook.tsx → malloynb/Notebook.tsx} +9 -7
- package/src/components/{Notebook → legacy/malloynb}/NotebookCell.tsx +70 -150
- package/src/components/legacy/malloynb/cellKind.spec.ts +33 -0
- package/src/components/legacy/malloynb/cellKind.ts +24 -0
- package/src/components/{Notebook → legacy/malloynb}/types.ts +1 -1
- package/src/components/styles.ts +0 -18
- package/src/hooks/useGivensState.ts +7 -3
- package/src/hooks/useQueryResult.placeholder.spec.ts +44 -0
- package/src/hooks/useQueryResult.ts +26 -1
- package/src/theme/ThemeContext.tsx +21 -1
- package/src/theme/classes.ts +52 -0
- package/src/theme/index.ts +8 -0
- package/src/theme/resolveTheme.ts +3 -0
- package/src/theme/types.ts +7 -0
- package/src/theme/ui.spec.tsx +91 -0
- package/src/theme/ui.ts +115 -0
- package/dist/RenderedResult-Bw7EQc42.cjs.js +0 -153
- package/dist/ServerProvider-B0dUY8be.cjs.js +0 -1
- package/dist/components/Notebook/cellKind.d.ts +0 -20
- package/dist/components/Report/LinearReport.d.ts +0 -18
- package/dist/components/ReportBuilder/SourceViewPicker.d.ts +0 -9
- package/dist/components/ReportBuilder/legacyNotebook.d.ts +0 -73
- package/dist/components/ReportBuilder/useConversionConfirm.d.ts +0 -20
- package/dist/useCompiledDocument-BKyRnXmA.cjs.js +0 -141
- package/src/components/Notebook/cellKind.spec.ts +0 -199
- package/src/components/Notebook/cellKind.ts +0 -74
- package/src/components/Report/LinearReport.tsx +0 -71
- package/src/components/ReportBuilder/SourceViewPicker.tsx +0 -122
- package/src/components/ReportBuilder/legacyNotebook.chart.spec.ts +0 -77
- package/src/components/ReportBuilder/legacyNotebook.convert.spec.ts +0 -626
- package/src/components/ReportBuilder/legacyNotebook.read.spec.ts +0 -338
- package/src/components/ReportBuilder/legacyNotebook.ts +0 -1122
- package/src/components/ReportBuilder/useConversionConfirm.ts +0 -55
- package/src/components/legacy/Notebook.served.spec.tsx +0 -183
- /package/dist/components/{Notebook → legacy/malloynb}/runPlan.d.ts +0 -0
- /package/src/components/{Notebook → legacy/malloynb}/runPlan.spec.ts +0 -0
- /package/src/components/{Notebook → legacy/malloynb}/runPlan.ts +0 -0
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
+
import { segmentedSx } from "./BuilderToolbar";
|
|
5
|
+
import { reportClasses } from "../../theme/classes";
|
|
4
6
|
import {
|
|
7
|
+
Box,
|
|
5
8
|
Button,
|
|
6
|
-
Stack,
|
|
7
9
|
TextField,
|
|
8
10
|
ToggleButton,
|
|
9
11
|
ToggleButtonGroup,
|
|
10
12
|
Typography,
|
|
11
13
|
} from "@mui/material";
|
|
12
|
-
import { useEffect, useMemo, useState } from "react";
|
|
14
|
+
import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
13
15
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
14
|
-
import type { PackageCatalog } from "./catalog";
|
|
15
|
-
import type { ChartPick } from "./chartLine";
|
|
16
16
|
import { isBareName } from "../../utils/malloyText";
|
|
17
|
-
import type { DashboardDocument } from "./document";
|
|
18
|
-
import { ChartPicker } from "./ChartPicker";
|
|
19
17
|
import { AppDialog } from "../AppDialog";
|
|
20
|
-
import {
|
|
18
|
+
import { edgeColor } from "../controlTokens";
|
|
19
|
+
import type { CatalogSource, CatalogView, PackageCatalog } from "./catalog";
|
|
20
|
+
import { chartChoices } from "./ChartPicker";
|
|
21
|
+
import {
|
|
22
|
+
ChartGlyph,
|
|
23
|
+
readableName,
|
|
24
|
+
ViewPicker,
|
|
25
|
+
type PickerGroup,
|
|
26
|
+
} from "./ViewPicker";
|
|
27
|
+
import type { ChartPick } from "./chartLine";
|
|
28
|
+
import type { DashboardDocument } from "./document";
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* What a new tile is: a view, picked from the package.
|
|
@@ -50,6 +58,21 @@ export interface NewTile {
|
|
|
50
58
|
colspan: number;
|
|
51
59
|
}
|
|
52
60
|
|
|
61
|
+
/** A view the picker shows a preview of, as the tile it would add. */
|
|
62
|
+
export interface ViewPreview {
|
|
63
|
+
base: string;
|
|
64
|
+
/** The model that exports the source: what the preview runs against. */
|
|
65
|
+
modelPath: string;
|
|
66
|
+
view: string;
|
|
67
|
+
/** The title the tile would have. */
|
|
68
|
+
label: string;
|
|
69
|
+
/** A chart for the preview; absent keeps the view's own. */
|
|
70
|
+
chart?: ChartPick | "none";
|
|
71
|
+
chartCarried?: string[];
|
|
72
|
+
/** The givens the source is scoped by, the ones the preview sends. */
|
|
73
|
+
givens: string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
53
76
|
export interface AddTileDialogProps {
|
|
54
77
|
open: boolean;
|
|
55
78
|
document: DashboardDocument;
|
|
@@ -57,10 +80,36 @@ export interface AddTileDialogProps {
|
|
|
57
80
|
columns: number;
|
|
58
81
|
onClose: () => void;
|
|
59
82
|
onAdd: (tile: NewTile) => void;
|
|
60
|
-
/** Add an empty text tile, whose markdown is written on the tile itself. */
|
|
83
|
+
/** Add an empty text tile instead, whose markdown is written on the tile itself. */
|
|
61
84
|
onAddText: () => void;
|
|
85
|
+
/** The picked view run as a tile, with the page's filters. Absent, a card says what will run. */
|
|
86
|
+
renderPreview?: (view: ViewPreview) => ReactNode;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** `by_category` -> `By category`: a view's name, read as words, where it has no doc line. */
|
|
90
|
+
export function viewTitle(view: CatalogView): string {
|
|
91
|
+
return view.description ?? readableName(view.name);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** What a view's own chart tag is, in a sentence. */
|
|
95
|
+
const DECLARED: Record<string, string> = {
|
|
96
|
+
bar_chart: "a bar chart",
|
|
97
|
+
line_chart: "a line chart",
|
|
98
|
+
scatter_chart: "a scatter chart",
|
|
99
|
+
shape_map: "a shape map",
|
|
100
|
+
segment_map: "a segment map",
|
|
101
|
+
big_value: "a big value",
|
|
102
|
+
sparkline: "a sparkline",
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
interface Entry {
|
|
106
|
+
source: CatalogSource;
|
|
107
|
+
view: CatalogView;
|
|
108
|
+
key: string;
|
|
62
109
|
}
|
|
63
110
|
|
|
111
|
+
const entryKey = (source: string, view: string) => `${source}\u0000${view}`;
|
|
112
|
+
|
|
64
113
|
export function AddTileDialog({
|
|
65
114
|
open,
|
|
66
115
|
document,
|
|
@@ -69,170 +118,356 @@ export function AddTileDialog({
|
|
|
69
118
|
onClose,
|
|
70
119
|
onAdd,
|
|
71
120
|
onAddText,
|
|
121
|
+
renderPreview,
|
|
72
122
|
}: AddTileDialogProps) {
|
|
73
123
|
const { theme } = usePublisherTheme();
|
|
124
|
+
const ui = theme.ui;
|
|
125
|
+
const edge = edgeColor(theme.cardBorder);
|
|
74
126
|
const sources = useMemo(() => catalog?.sources ?? [], [catalog]);
|
|
75
|
-
const [
|
|
76
|
-
const [
|
|
77
|
-
const [view, setView] = useState<string>("");
|
|
127
|
+
const [query, setQuery] = useState("");
|
|
128
|
+
const [pickedKey, setPickedKey] = useState<string | undefined>();
|
|
78
129
|
const [label, setLabel] = useState("");
|
|
79
130
|
const [chart, setChart] = useState<ChartPick | "none" | "default">(
|
|
80
131
|
"default",
|
|
81
132
|
);
|
|
82
|
-
const
|
|
133
|
+
const searchRef = useRef<HTMLInputElement>(null);
|
|
134
|
+
|
|
135
|
+
// The source the tiles already read comes first, so the common case is one
|
|
136
|
+
// click on a view near the top.
|
|
137
|
+
const ordered = useMemo(() => {
|
|
138
|
+
const read = new Set(document.sources.map((s) => s.base));
|
|
139
|
+
return [...sources].sort(
|
|
140
|
+
(a, b) => Number(read.has(b.name)) - Number(read.has(a.name)),
|
|
141
|
+
);
|
|
142
|
+
}, [sources, document]);
|
|
143
|
+
const withViews = ordered.filter((s) => s.views.length > 0);
|
|
144
|
+
const withoutViews = ordered.filter((s) => s.views.length === 0);
|
|
145
|
+
|
|
146
|
+
// Every view on offer, by key: the picker's entries and what a key means.
|
|
147
|
+
const entries = useMemo(
|
|
148
|
+
() =>
|
|
149
|
+
new Map(
|
|
150
|
+
withViews.flatMap((source) =>
|
|
151
|
+
source.views.map(
|
|
152
|
+
(view) =>
|
|
153
|
+
[
|
|
154
|
+
entryKey(source.name, view.name),
|
|
155
|
+
{ source, view, key: entryKey(source.name, view.name) },
|
|
156
|
+
] as const,
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
),
|
|
160
|
+
[withViews],
|
|
161
|
+
);
|
|
162
|
+
const groups = useMemo<PickerGroup[]>(
|
|
163
|
+
() =>
|
|
164
|
+
withViews.map((source) => ({
|
|
165
|
+
key: source.name,
|
|
166
|
+
label: source.name,
|
|
167
|
+
...(source.description ? { detail: source.description } : {}),
|
|
168
|
+
entries: source.views.map((view) => ({
|
|
169
|
+
key: entryKey(source.name, view.name),
|
|
170
|
+
name: view.name,
|
|
171
|
+
title: viewTitle(view),
|
|
172
|
+
...(view.chart ? { chart: view.chart } : {}),
|
|
173
|
+
})),
|
|
174
|
+
})),
|
|
175
|
+
[withViews],
|
|
176
|
+
);
|
|
177
|
+
// Kept while a search hides it, so typing does not drop the choice.
|
|
178
|
+
const picked = pickedKey === undefined ? undefined : entries.get(pickedKey);
|
|
83
179
|
|
|
84
180
|
useEffect(() => {
|
|
85
181
|
if (!open) return;
|
|
86
|
-
|
|
87
|
-
// Open on the source the tiles already read, so the common case is one
|
|
88
|
-
// click on a view.
|
|
89
|
-
const withViews = (name: string) =>
|
|
90
|
-
sources.some((s) => s.name === name && s.views.length > 0);
|
|
91
|
-
setBase(
|
|
92
|
-
document.sources.map((s) => s.base).find(withViews) ??
|
|
93
|
-
sources.find((s) => s.views.length > 0)?.name ??
|
|
94
|
-
"",
|
|
95
|
-
);
|
|
96
|
-
setView("");
|
|
182
|
+
setQuery("");
|
|
97
183
|
setLabel("");
|
|
98
184
|
setChart("default");
|
|
99
|
-
|
|
100
|
-
|
|
185
|
+
const first = withViews[0]?.views[0];
|
|
186
|
+
setPickedKey(
|
|
187
|
+
first && withViews[0]
|
|
188
|
+
? entryKey(withViews[0].name, first.name)
|
|
189
|
+
: undefined,
|
|
190
|
+
);
|
|
191
|
+
// Only on opening: the catalog arriving later must not move the pick.
|
|
192
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
193
|
+
}, [open]);
|
|
101
194
|
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
195
|
+
const unwritable = picked
|
|
196
|
+
? [picked.source.name, picked.view.name]
|
|
197
|
+
.filter((name) => !isBareName(name))
|
|
198
|
+
.map(
|
|
199
|
+
(name) =>
|
|
200
|
+
`"${name}" is not a plain Malloy name, so a tile cannot be written for it.`,
|
|
201
|
+
)[0]
|
|
202
|
+
: undefined;
|
|
203
|
+
const canAdd = picked !== undefined && unwritable === undefined;
|
|
204
|
+
const title = picked ? viewTitle(picked.view) : "";
|
|
205
|
+
const chartPart =
|
|
206
|
+
chart !== "default" && picked
|
|
207
|
+
? {
|
|
208
|
+
chart,
|
|
209
|
+
chartCarried: picked.view.chart ? [picked.view.chart] : [],
|
|
210
|
+
}
|
|
211
|
+
: {};
|
|
212
|
+
const add = (entry: Entry | undefined = picked) => {
|
|
213
|
+
if (!entry) return;
|
|
214
|
+
if (![entry.source.name, entry.view.name].every(isBareName)) return;
|
|
215
|
+
const same = entry.key === picked?.key;
|
|
216
|
+
onAdd({
|
|
217
|
+
base: entry.source.name,
|
|
218
|
+
modelPath: entry.source.modelPath,
|
|
219
|
+
...(entry.source.exporters
|
|
220
|
+
? { exporters: entry.source.exporters }
|
|
221
|
+
: {}),
|
|
222
|
+
view: entry.view.name,
|
|
223
|
+
...(same && label.trim() ? { label: label.trim() } : {}),
|
|
224
|
+
...(same ? chartPart : {}),
|
|
225
|
+
colspan: Math.ceil(columns / 2),
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
// Only the charts this view can take: a choice that cannot apply is not a
|
|
229
|
+
// choice here, where the view is still being picked.
|
|
230
|
+
const charts = picked
|
|
231
|
+
? chartChoices(picked.view, chart).filter(
|
|
232
|
+
(choice) => choice.value !== "custom" && choice.disabled !== true,
|
|
233
|
+
)
|
|
234
|
+
: [];
|
|
113
235
|
|
|
114
236
|
return (
|
|
115
237
|
<AppDialog
|
|
238
|
+
className={`${reportClasses.dialog} ${reportClasses.addTileDialog}`}
|
|
116
239
|
open={open}
|
|
117
240
|
onClose={onClose}
|
|
241
|
+
maxWidth="md"
|
|
242
|
+
initialFocus={searchRef}
|
|
118
243
|
title="Add a tile"
|
|
119
|
-
description="
|
|
244
|
+
description="Pick a view from this package. You can change its title and chart now or later."
|
|
120
245
|
actions={
|
|
121
246
|
<>
|
|
247
|
+
<Button onClick={onAddText} sx={{ mr: "auto" }}>
|
|
248
|
+
Add text instead
|
|
249
|
+
</Button>
|
|
122
250
|
<Button onClick={onClose}>Cancel</Button>
|
|
123
251
|
<Button
|
|
124
252
|
variant="contained"
|
|
125
|
-
disabled={
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
onClick={() =>
|
|
129
|
-
mode === "text"
|
|
130
|
-
? onAddText()
|
|
131
|
-
: onAdd({
|
|
132
|
-
base,
|
|
133
|
-
modelPath: pickedSource?.modelPath ?? "",
|
|
134
|
-
...(pickedSource?.exporters
|
|
135
|
-
? { exporters: pickedSource.exporters }
|
|
136
|
-
: {}),
|
|
137
|
-
view,
|
|
138
|
-
...(label.trim() ? { label: label.trim() } : {}),
|
|
139
|
-
...(chart !== "default"
|
|
140
|
-
? {
|
|
141
|
-
chart,
|
|
142
|
-
...(picked
|
|
143
|
-
? {
|
|
144
|
-
chartCarried: picked.chart
|
|
145
|
-
? [picked.chart]
|
|
146
|
-
: [],
|
|
147
|
-
}
|
|
148
|
-
: {}),
|
|
149
|
-
}
|
|
150
|
-
: {}),
|
|
151
|
-
colspan,
|
|
152
|
-
})
|
|
153
|
-
}
|
|
253
|
+
disabled={!canAdd}
|
|
254
|
+
onClick={() => add()}
|
|
154
255
|
>
|
|
155
|
-
|
|
256
|
+
Add tile
|
|
156
257
|
</Button>
|
|
157
258
|
</>
|
|
158
259
|
}
|
|
159
260
|
>
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
261
|
+
<Box
|
|
262
|
+
sx={{
|
|
263
|
+
// Edge to edge inside the window: two panes, not a form.
|
|
264
|
+
mx: -3,
|
|
265
|
+
mb: -1,
|
|
266
|
+
borderTop: `1px solid ${edge}`,
|
|
267
|
+
borderBottom: `1px solid ${edge}`,
|
|
268
|
+
display: "grid",
|
|
269
|
+
gridTemplateColumns: { xs: "1fr", md: "320px minmax(0, 1fr)" },
|
|
270
|
+
height: { md: 460 },
|
|
271
|
+
}}
|
|
272
|
+
>
|
|
273
|
+
<Box
|
|
274
|
+
sx={{
|
|
275
|
+
display: "flex",
|
|
276
|
+
flexDirection: "column",
|
|
277
|
+
minHeight: 0,
|
|
278
|
+
borderRight: { md: `1px solid ${edge}` },
|
|
279
|
+
maxHeight: { xs: 280, md: "none" },
|
|
168
280
|
}}
|
|
169
281
|
>
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
<>
|
|
190
|
-
<SourceViewPicker
|
|
191
|
-
sources={sources}
|
|
192
|
-
source={base}
|
|
193
|
-
view={view}
|
|
194
|
-
onSource={(name) => {
|
|
195
|
-
setBase(name);
|
|
196
|
-
setView("");
|
|
197
|
-
}}
|
|
198
|
-
onView={(name) => {
|
|
199
|
-
setView(name);
|
|
200
|
-
setChart("default");
|
|
201
|
-
}}
|
|
202
|
-
/>
|
|
203
|
-
{unwritable && (
|
|
204
|
-
<Typography variant="body2" color="error">
|
|
205
|
-
{unwritable}
|
|
282
|
+
<ViewPicker
|
|
283
|
+
groups={groups}
|
|
284
|
+
query={query}
|
|
285
|
+
onQuery={setQuery}
|
|
286
|
+
picked={picked?.key}
|
|
287
|
+
onPick={(key) => {
|
|
288
|
+
setPickedKey(key);
|
|
289
|
+
setChart("default");
|
|
290
|
+
}}
|
|
291
|
+
onTake={(key) => add(entries.get(key))}
|
|
292
|
+
searchRef={searchRef}
|
|
293
|
+
empty={
|
|
294
|
+
<Typography
|
|
295
|
+
variant="body2"
|
|
296
|
+
sx={{ color: theme.tileTitle, p: 2 }}
|
|
297
|
+
>
|
|
298
|
+
{catalog
|
|
299
|
+
? "This package publishes no source with a view to put on a tile."
|
|
300
|
+
: "The package's sources are still loading."}
|
|
206
301
|
</Typography>
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
302
|
+
}
|
|
303
|
+
footer={
|
|
304
|
+
withoutViews.length > 0 && (
|
|
305
|
+
<Typography
|
|
306
|
+
variant="caption"
|
|
307
|
+
component="p"
|
|
308
|
+
sx={{ color: "text.secondary", px: 2, pt: 1.5 }}
|
|
309
|
+
>
|
|
310
|
+
Also in this package, with no views to show:{" "}
|
|
311
|
+
{withoutViews.map((s) => s.name).join(", ")}.
|
|
312
|
+
</Typography>
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
/>
|
|
316
|
+
</Box>
|
|
317
|
+
|
|
318
|
+
<Box
|
|
319
|
+
sx={(mui) => ({
|
|
320
|
+
p: 2.5,
|
|
321
|
+
display: "flex",
|
|
322
|
+
flexDirection: "column",
|
|
323
|
+
gap: 2,
|
|
324
|
+
minHeight: 0,
|
|
325
|
+
overflowY: "auto",
|
|
326
|
+
// A shade off the paper, in the host's own colours.
|
|
327
|
+
bgcolor: `color-mix(in srgb, ${mui.palette.text.primary} 3%, ${mui.palette.background.paper})`,
|
|
328
|
+
})}
|
|
329
|
+
>
|
|
330
|
+
{picked ? (
|
|
331
|
+
<>
|
|
332
|
+
<Box
|
|
333
|
+
aria-label="Preview"
|
|
334
|
+
role="region"
|
|
335
|
+
sx={(mui) => ({
|
|
336
|
+
height: 240,
|
|
337
|
+
flex: "none",
|
|
338
|
+
display: "flex",
|
|
339
|
+
position: "relative",
|
|
340
|
+
// A preview, not the tile: what does not fit is cut
|
|
341
|
+
// off, under a fade that says there is more. The
|
|
342
|
+
// card is drawn here, round the cut, and the tile
|
|
343
|
+
// inside it has none of its own.
|
|
344
|
+
overflow: "hidden",
|
|
345
|
+
borderRadius: ui.radius.tile,
|
|
346
|
+
border: `1px solid ${edge}`,
|
|
347
|
+
bgcolor: mui.palette.background.paper,
|
|
348
|
+
"&::after": {
|
|
349
|
+
content: '""',
|
|
350
|
+
position: "absolute",
|
|
351
|
+
left: 0,
|
|
352
|
+
right: 0,
|
|
353
|
+
bottom: 0,
|
|
354
|
+
height: 40,
|
|
355
|
+
pointerEvents: "none",
|
|
356
|
+
background: `linear-gradient(to bottom, transparent, ${mui.palette.background.paper})`,
|
|
357
|
+
},
|
|
358
|
+
})}
|
|
359
|
+
>
|
|
360
|
+
{renderPreview ? (
|
|
361
|
+
<Box sx={{ flex: 1, minWidth: 0, px: 2, pt: 1.5 }}>
|
|
362
|
+
{renderPreview({
|
|
363
|
+
base: picked.source.name,
|
|
364
|
+
modelPath: picked.source.modelPath,
|
|
365
|
+
view: picked.view.name,
|
|
366
|
+
label: label.trim() || title,
|
|
367
|
+
...(chart !== "default" ? chartPart : {}),
|
|
368
|
+
givens: picked.source.givens,
|
|
369
|
+
})}
|
|
370
|
+
</Box>
|
|
371
|
+
) : (
|
|
372
|
+
<Box
|
|
373
|
+
sx={(mui) => ({
|
|
374
|
+
flex: 1,
|
|
375
|
+
border: `1px solid ${edge}`,
|
|
376
|
+
borderRadius: ui.radius.tile,
|
|
377
|
+
bgcolor: mui.palette.background.paper,
|
|
378
|
+
display: "flex",
|
|
379
|
+
flexDirection: "column",
|
|
380
|
+
alignItems: "center",
|
|
381
|
+
justifyContent: "center",
|
|
382
|
+
gap: 1,
|
|
383
|
+
color: "text.secondary",
|
|
384
|
+
})}
|
|
385
|
+
>
|
|
386
|
+
<ChartGlyph chart={picked.view.chart} />
|
|
387
|
+
<Typography variant="body2">
|
|
388
|
+
{picked.source.name} → {picked.view.name}
|
|
389
|
+
</Typography>
|
|
390
|
+
</Box>
|
|
391
|
+
)}
|
|
392
|
+
</Box>
|
|
223
393
|
<TextField
|
|
224
394
|
size="small"
|
|
225
395
|
label="Title"
|
|
226
|
-
placeholder=
|
|
396
|
+
placeholder={title}
|
|
227
397
|
value={label}
|
|
228
398
|
onChange={(event) => setLabel(event.target.value)}
|
|
399
|
+
InputLabelProps={{ shrink: true }}
|
|
229
400
|
inputProps={{ "aria-label": "Tile title" }}
|
|
230
|
-
sx={{ flex: 1 }}
|
|
231
401
|
/>
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
402
|
+
<Box>
|
|
403
|
+
<Typography
|
|
404
|
+
component="div"
|
|
405
|
+
sx={{
|
|
406
|
+
...ui.type.label,
|
|
407
|
+
color: "text.secondary",
|
|
408
|
+
mb: 0.75,
|
|
409
|
+
}}
|
|
410
|
+
>
|
|
411
|
+
Chart
|
|
412
|
+
</Typography>
|
|
413
|
+
<ToggleButtonGroup
|
|
414
|
+
size="small"
|
|
415
|
+
exclusive
|
|
416
|
+
value={chart}
|
|
417
|
+
aria-label="Chart"
|
|
418
|
+
onChange={(_event, next) => {
|
|
419
|
+
if (next !== null)
|
|
420
|
+
setChart(
|
|
421
|
+
next as ChartPick | "none" | "default",
|
|
422
|
+
);
|
|
423
|
+
}}
|
|
424
|
+
// The builder's own segmented control, as the bar's
|
|
425
|
+
// layout switch is, so it takes the host's tokens.
|
|
426
|
+
sx={{
|
|
427
|
+
...segmentedSx(edge, ui),
|
|
428
|
+
"& .MuiToggleButton-root": {
|
|
429
|
+
...segmentedSx(edge, ui)[
|
|
430
|
+
"& .MuiToggleButton-root"
|
|
431
|
+
],
|
|
432
|
+
textTransform: "none",
|
|
433
|
+
},
|
|
434
|
+
}}
|
|
435
|
+
>
|
|
436
|
+
{charts.map((choice) => (
|
|
437
|
+
<ToggleButton
|
|
438
|
+
key={choice.value}
|
|
439
|
+
value={choice.value}
|
|
440
|
+
>
|
|
441
|
+
{choice.label}
|
|
442
|
+
</ToggleButton>
|
|
443
|
+
))}
|
|
444
|
+
</ToggleButtonGroup>
|
|
445
|
+
<Typography
|
|
446
|
+
variant="caption"
|
|
447
|
+
component="p"
|
|
448
|
+
sx={{ color: "text.secondary", mt: 0.75 }}
|
|
449
|
+
>
|
|
450
|
+
{picked.view.chart
|
|
451
|
+
? `The view declares ${DECLARED[picked.view.chart] ?? "a chart"}.`
|
|
452
|
+
: "The view declares no chart, so it shows as a table."}
|
|
453
|
+
</Typography>
|
|
454
|
+
</Box>
|
|
455
|
+
{unwritable && (
|
|
456
|
+
<Typography variant="body2" color="error">
|
|
457
|
+
{unwritable}
|
|
458
|
+
</Typography>
|
|
459
|
+
)}
|
|
460
|
+
</>
|
|
461
|
+
) : (
|
|
462
|
+
<Typography
|
|
463
|
+
variant="body2"
|
|
464
|
+
sx={{ color: "text.secondary", m: "auto" }}
|
|
465
|
+
>
|
|
466
|
+
Pick a view to see it here.
|
|
467
|
+
</Typography>
|
|
468
|
+
)}
|
|
469
|
+
</Box>
|
|
470
|
+
</Box>
|
|
236
471
|
</AppDialog>
|
|
237
472
|
);
|
|
238
473
|
}
|