@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,352 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Alert, Box, Stack, Typography } from "@mui/material";
|
|
5
|
+
import { useCallback, useMemo, useState } from "react";
|
|
6
|
+
import type { DashboardManifest } from "../../client";
|
|
7
|
+
import type { GivenValue } from "../../hooks/givenValue";
|
|
8
|
+
import { useDocumentControls } from "../../hooks/useDocumentControls";
|
|
9
|
+
import {
|
|
10
|
+
useDrill,
|
|
11
|
+
type DrillBinding,
|
|
12
|
+
type DrillClickPayload,
|
|
13
|
+
type DrillNavigation,
|
|
14
|
+
type DrillRowsRequest,
|
|
15
|
+
} from "../drill";
|
|
16
|
+
import { GivensPanel } from "../given";
|
|
17
|
+
import { givensToParams, givensToRequest } from "../given/paramCodec";
|
|
18
|
+
import { Prose } from "../Prose";
|
|
19
|
+
import { TILE_MAX_HEIGHT } from "../RenderedResult/resultSizing";
|
|
20
|
+
import { DashboardGrid, DEFAULT_COLUMNS } from "./DashboardGrid";
|
|
21
|
+
import { DashboardTile } from "./DashboardTile";
|
|
22
|
+
import { ExploreDialog } from "./ExploreDialog";
|
|
23
|
+
import { RowsDialog, stepsOf, type RowsRequest } from "./RowsDialog";
|
|
24
|
+
import type { DashboardEventHandler } from "./telemetry";
|
|
25
|
+
import { TileCard, type TileChrome } from "./TileCard";
|
|
26
|
+
import { tileIgnoredFilterLabels } from "./TileFilterTag";
|
|
27
|
+
|
|
28
|
+
/** Narrowest a tile that sets no `colspan` is allowed to render. */
|
|
29
|
+
const MIN_TILE_PX = 240;
|
|
30
|
+
|
|
31
|
+
export interface DashboardViewProps {
|
|
32
|
+
/** The dashboard, or the tile layout a layout notebook carries. */
|
|
33
|
+
manifest: DashboardManifest;
|
|
34
|
+
environmentName: string;
|
|
35
|
+
packageName: string;
|
|
36
|
+
versionId?: string;
|
|
37
|
+
/** The slug or path the manifest was fetched under, which keys its control edits. */
|
|
38
|
+
documentName: string;
|
|
39
|
+
givens?: Record<string, string>;
|
|
40
|
+
onGivensChange?: (
|
|
41
|
+
givens: Record<string, string>,
|
|
42
|
+
managed: readonly string[],
|
|
43
|
+
) => void;
|
|
44
|
+
onNavigate?: (target: DrillNavigation, event?: MouseEvent) => void;
|
|
45
|
+
height?: number;
|
|
46
|
+
maxResultSize?: number;
|
|
47
|
+
onEvent?: DashboardEventHandler;
|
|
48
|
+
/** `none` renders tiles as a document, with no cards or title block. */
|
|
49
|
+
chrome?: TileChrome;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A loaded dashboard manifest, drawn: the control row and the tile grid.
|
|
54
|
+
*
|
|
55
|
+
* Split from the manifest fetch so a notebook written as a tile layout, whose
|
|
56
|
+
* manifest arrives inside the notebook response, renders through the same code.
|
|
57
|
+
*/
|
|
58
|
+
export function DashboardView({
|
|
59
|
+
manifest,
|
|
60
|
+
environmentName,
|
|
61
|
+
packageName,
|
|
62
|
+
versionId,
|
|
63
|
+
documentName,
|
|
64
|
+
givens,
|
|
65
|
+
onGivensChange,
|
|
66
|
+
onNavigate,
|
|
67
|
+
height,
|
|
68
|
+
maxResultSize,
|
|
69
|
+
onEvent,
|
|
70
|
+
chrome = "card",
|
|
71
|
+
}: DashboardViewProps) {
|
|
72
|
+
const specs = useMemo(() => manifest.givens ?? [], [manifest]);
|
|
73
|
+
|
|
74
|
+
// The control row's state, options and `to=self` drill: the same hook the
|
|
75
|
+
// notebook uses, so a control behaves identically on both surfaces.
|
|
76
|
+
const controls = useDocumentControls({
|
|
77
|
+
specs,
|
|
78
|
+
loaded: true,
|
|
79
|
+
startingValues: manifest.startingGivens,
|
|
80
|
+
params: givens,
|
|
81
|
+
onGivensChange,
|
|
82
|
+
// Version included: two dashboards whose starting values coincide would
|
|
83
|
+
// otherwise look like one document, and the one you came from would keep
|
|
84
|
+
// filtering the one you drilled into.
|
|
85
|
+
documentKey: `${environmentName}/${packageName}/${versionId ?? ""}/${documentName}`,
|
|
86
|
+
// Absent means autorun; only an explicit `autorun=false` batches.
|
|
87
|
+
autorun: manifest.autorun !== false,
|
|
88
|
+
environmentName,
|
|
89
|
+
packageName,
|
|
90
|
+
modelPath: manifest.path,
|
|
91
|
+
versionId,
|
|
92
|
+
documentName,
|
|
93
|
+
});
|
|
94
|
+
const { applied, declaredTypes, canSelf, onSelf } = controls;
|
|
95
|
+
|
|
96
|
+
// A given only a gate reads is in a tile's `givenNames` but not the row, so
|
|
97
|
+
// the host's value for it is sent as given: the row would drop it as undeclared.
|
|
98
|
+
const tileGivens = useMemo(() => {
|
|
99
|
+
const named = new Set(
|
|
100
|
+
(manifest.tiles ?? []).flatMap((tile) => tile.givenNames ?? []),
|
|
101
|
+
);
|
|
102
|
+
const hostOnly = Object.entries(givens ?? {}).filter(
|
|
103
|
+
([name]) => named.has(name) && !declaredTypes.has(name),
|
|
104
|
+
);
|
|
105
|
+
if (hostOnly.length === 0) return applied;
|
|
106
|
+
return new Map<string, GivenValue>([...hostOnly, ...applied]);
|
|
107
|
+
}, [manifest, givens, declaredTypes, applied]);
|
|
108
|
+
|
|
109
|
+
// The rows behind a clicked value, and a tile's query in the explorer —
|
|
110
|
+
// the two ways past a number. Composite tiles only: each names its
|
|
111
|
+
// source, which is what the rows are of and what the explorer opens on.
|
|
112
|
+
const [rows, setRows] = useState<RowsRequest | undefined>(undefined);
|
|
113
|
+
const [exploring, setExploring] = useState<string | undefined>(undefined);
|
|
114
|
+
const onRows = useCallback((request: DrillRowsRequest) => {
|
|
115
|
+
const steps = stepsOf(request.context);
|
|
116
|
+
if (steps === undefined) return;
|
|
117
|
+
setRows({
|
|
118
|
+
...steps,
|
|
119
|
+
field: request.field,
|
|
120
|
+
rawValue: request.rawValue,
|
|
121
|
+
label: request.label,
|
|
122
|
+
});
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
// The whole applied row and any gate givens: a source's own `where:` may read any of it, and a
|
|
126
|
+
// given the rows query does not reference is ignored by the server.
|
|
127
|
+
const rowsGivens = useMemo(
|
|
128
|
+
() => givensToRequest(tileGivens, declaredTypes),
|
|
129
|
+
[tileGivens, declaredTypes],
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// The explorer's controls take the URL-string form, not the request form.
|
|
133
|
+
const exploreGivens = useMemo(
|
|
134
|
+
() => givensToParams(applied, declaredTypes),
|
|
135
|
+
[applied, declaredTypes],
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const { drill, drillMenu } = useDrill({
|
|
139
|
+
onNavigate,
|
|
140
|
+
onSelf,
|
|
141
|
+
canSelf,
|
|
142
|
+
selfLabel: "Filter this dashboard",
|
|
143
|
+
onRows,
|
|
144
|
+
});
|
|
145
|
+
// Each tile's clicks carry the tile they came from, so the rows behind a
|
|
146
|
+
// value know which source to run against.
|
|
147
|
+
const drillFor = useCallback(
|
|
148
|
+
(tile: string): DrillBinding => ({
|
|
149
|
+
canDrill: drill.canDrill,
|
|
150
|
+
onClick: (payload: DrillClickPayload) =>
|
|
151
|
+
drill.onClick({ ...payload, context: tile }),
|
|
152
|
+
}),
|
|
153
|
+
[drill],
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
// Reachable on the in-process load path only: production aborts the package
|
|
157
|
+
// on the first compile error, so an uncompilable file answers 424 instead.
|
|
158
|
+
if (manifest.error) {
|
|
159
|
+
return (
|
|
160
|
+
<Stack spacing={2}>
|
|
161
|
+
<DashboardHeader manifest={manifest} />
|
|
162
|
+
<Alert severity="error">{manifest.error}</Alert>
|
|
163
|
+
</Stack>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const modelPath = manifest.path;
|
|
168
|
+
const tiles = manifest.tiles ?? [];
|
|
169
|
+
const columns = manifest.dashboardColumns ?? DEFAULT_COLUMNS;
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<Stack spacing={2}>
|
|
173
|
+
{chrome === "card" && <DashboardHeader manifest={manifest} />}
|
|
174
|
+
|
|
175
|
+
{/* Sticky so the controls stay in reach while the tiles scroll under. */}
|
|
176
|
+
<Box
|
|
177
|
+
sx={{
|
|
178
|
+
position: "sticky",
|
|
179
|
+
top: 0,
|
|
180
|
+
zIndex: 2,
|
|
181
|
+
bgcolor: "background.default",
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
<GivensPanel {...controls.panel} layout="bar" />
|
|
185
|
+
</Box>
|
|
186
|
+
|
|
187
|
+
{modelPath === undefined ? (
|
|
188
|
+
<Alert severity="error">
|
|
189
|
+
This dashboard has no model path, so there is nothing to run.
|
|
190
|
+
</Alert>
|
|
191
|
+
) : manifest.query !== undefined ? (
|
|
192
|
+
// Single-query form: one query whose result IS the dashboard. Its
|
|
193
|
+
// `# dashboard {columns=N}` tag is the renderer's business, so no
|
|
194
|
+
// grid is imposed here: doing so would nest a grid in a grid.
|
|
195
|
+
<DashboardTile
|
|
196
|
+
environmentName={environmentName}
|
|
197
|
+
packageName={packageName}
|
|
198
|
+
versionId={versionId}
|
|
199
|
+
modelPath={modelPath}
|
|
200
|
+
queryName={manifest.query}
|
|
201
|
+
givens={applied}
|
|
202
|
+
declaredTypes={declaredTypes}
|
|
203
|
+
height={height}
|
|
204
|
+
maxResultSize={maxResultSize}
|
|
205
|
+
drill={drill}
|
|
206
|
+
chrome={chrome}
|
|
207
|
+
/>
|
|
208
|
+
) : tiles.length > 0 ? (
|
|
209
|
+
// Composite form: each tile runs on its own and the results are
|
|
210
|
+
// combined into one grid here, since no single Malloy result spans
|
|
211
|
+
// them.
|
|
212
|
+
<DashboardGrid
|
|
213
|
+
tiles={tiles}
|
|
214
|
+
columns={columns}
|
|
215
|
+
minTilePx={MIN_TILE_PX}
|
|
216
|
+
// Position too, not the expression alone: `tiles=[…]` can repeat
|
|
217
|
+
// one, which is a typo rather than a request for two identical
|
|
218
|
+
// panels, and keying on the expression made the duplicate warn
|
|
219
|
+
// and reconcile onto its twin.
|
|
220
|
+
keyOf={(tile, index) =>
|
|
221
|
+
`${index}:${tile.kind === "text" ? `text:${tile.name}` : tile.query}`
|
|
222
|
+
}
|
|
223
|
+
renderTile={(tile) =>
|
|
224
|
+
// An absent `kind` is a query tile, as it was before text tiles.
|
|
225
|
+
tile.kind === "text" || tile.query === undefined ? (
|
|
226
|
+
<TextTile markdown={tile.markdown ?? ""} chrome={chrome} />
|
|
227
|
+
) : (
|
|
228
|
+
<DashboardTile
|
|
229
|
+
environmentName={environmentName}
|
|
230
|
+
packageName={packageName}
|
|
231
|
+
versionId={versionId}
|
|
232
|
+
modelPath={modelPath}
|
|
233
|
+
tile={tile.query}
|
|
234
|
+
label={tile.label}
|
|
235
|
+
subtitle={tile.subtitle}
|
|
236
|
+
borderless={tile.borderless}
|
|
237
|
+
givens={tileGivens}
|
|
238
|
+
declaredTypes={declaredTypes}
|
|
239
|
+
givenNames={tile.givenNames}
|
|
240
|
+
height={height ?? TILE_MAX_HEIGHT}
|
|
241
|
+
maxResultSize={maxResultSize}
|
|
242
|
+
drill={drillFor(tile.query)}
|
|
243
|
+
chrome={chrome}
|
|
244
|
+
ignoredFilters={tileIgnoredFilterLabels(
|
|
245
|
+
tile.givenNames,
|
|
246
|
+
specs,
|
|
247
|
+
)}
|
|
248
|
+
onExplore={() => {
|
|
249
|
+
setExploring(tile.query);
|
|
250
|
+
onEvent?.({
|
|
251
|
+
type: "dashboard.explored",
|
|
252
|
+
tile: tile.query ?? "",
|
|
253
|
+
});
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
/>
|
|
259
|
+
) : (
|
|
260
|
+
<Alert severity="warning">
|
|
261
|
+
This dashboard names neither a query nor any tiles.
|
|
262
|
+
</Alert>
|
|
263
|
+
)}
|
|
264
|
+
|
|
265
|
+
{drillMenu}
|
|
266
|
+
{modelPath !== undefined && (
|
|
267
|
+
<>
|
|
268
|
+
<RowsDialog
|
|
269
|
+
request={rows}
|
|
270
|
+
environmentName={environmentName}
|
|
271
|
+
packageName={packageName}
|
|
272
|
+
{...(versionId === undefined ? {} : { versionId })}
|
|
273
|
+
modelPath={modelPath}
|
|
274
|
+
givens={rowsGivens}
|
|
275
|
+
onClose={() => setRows(undefined)}
|
|
276
|
+
onDone={(ok, durationMs) => {
|
|
277
|
+
if (rows)
|
|
278
|
+
onEvent?.({
|
|
279
|
+
type: "dashboard.rows_shown",
|
|
280
|
+
source: rows.source,
|
|
281
|
+
view: rows.view,
|
|
282
|
+
field: rows.field,
|
|
283
|
+
ok,
|
|
284
|
+
durationMs,
|
|
285
|
+
});
|
|
286
|
+
}}
|
|
287
|
+
/>
|
|
288
|
+
<ExploreDialog
|
|
289
|
+
tile={exploring}
|
|
290
|
+
environmentName={environmentName}
|
|
291
|
+
packageName={packageName}
|
|
292
|
+
{...(versionId === undefined ? {} : { versionId })}
|
|
293
|
+
modelPath={modelPath}
|
|
294
|
+
givens={exploreGivens}
|
|
295
|
+
onClose={() => setExploring(undefined)}
|
|
296
|
+
/>
|
|
297
|
+
</>
|
|
298
|
+
)}
|
|
299
|
+
</Stack>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** A text tile: its markdown and nothing else, no heading. */
|
|
304
|
+
function TextTile({
|
|
305
|
+
markdown,
|
|
306
|
+
chrome,
|
|
307
|
+
}: {
|
|
308
|
+
markdown: string;
|
|
309
|
+
chrome: TileChrome;
|
|
310
|
+
}) {
|
|
311
|
+
return (
|
|
312
|
+
<TileCard chrome={chrome}>
|
|
313
|
+
<Prose variant="document">{markdown}</Prose>
|
|
314
|
+
</TileCard>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The dashboard's prose header: its title, and the description as MARKDOWN
|
|
320
|
+
* (Malloy carries a `##"` block through with its newlines intact).
|
|
321
|
+
*/
|
|
322
|
+
function DashboardHeader({ manifest }: { manifest: DashboardManifest }) {
|
|
323
|
+
return (
|
|
324
|
+
<DashboardProse
|
|
325
|
+
title={manifest.title ?? manifest.name}
|
|
326
|
+
{...(manifest.description
|
|
327
|
+
? { description: manifest.description }
|
|
328
|
+
: {})}
|
|
329
|
+
/>
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The prose header over just the two fields it needs, so the BUILDER can draw
|
|
335
|
+
* the same header over a `DashboardDocument`, which is not a manifest.
|
|
336
|
+
*/
|
|
337
|
+
export function DashboardProse({
|
|
338
|
+
title,
|
|
339
|
+
description,
|
|
340
|
+
}: {
|
|
341
|
+
title: string;
|
|
342
|
+
description?: string;
|
|
343
|
+
}) {
|
|
344
|
+
return (
|
|
345
|
+
<Box>
|
|
346
|
+
<Typography variant="h5" sx={{ fontWeight: 600 }}>
|
|
347
|
+
{title}
|
|
348
|
+
</Typography>
|
|
349
|
+
{description && <Prose variant="caption">{description}</Prose>}
|
|
350
|
+
</Box>
|
|
351
|
+
);
|
|
352
|
+
}
|
|
@@ -18,7 +18,7 @@ import { malloyLiteral } from "../../utils/malloyLiteral";
|
|
|
18
18
|
import { isIdentifier, tileSteps } from "../DashboardBuilder/malloyText";
|
|
19
19
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
20
20
|
import { ResultPanel } from "../RenderedResult/ResultPanel";
|
|
21
|
-
import { now } from "
|
|
21
|
+
import { now } from "../../utils/clock";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* The rows behind a value: "show the rows" on a cell, as one query.
|
|
@@ -12,6 +12,9 @@ import type { ReactNode } from "react";
|
|
|
12
12
|
import { DASHBOARD_CARD_PADDING_PX } from "../../theme/buildTableCssVars";
|
|
13
13
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
14
14
|
|
|
15
|
+
/** `card` is a dashboard tile's panel; `none` is a notebook's bare flow. */
|
|
16
|
+
export type TileChrome = "card" | "none";
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* The card a dashboard tile sits in, and nothing else — so the builder, which
|
|
17
20
|
* draws a stand-in tile when it has no server to run one, draws the same card
|
|
@@ -42,26 +45,39 @@ import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
|
42
45
|
*/
|
|
43
46
|
export function TileCard({
|
|
44
47
|
borderless = false,
|
|
48
|
+
chrome = "card",
|
|
45
49
|
sx,
|
|
46
50
|
children,
|
|
47
51
|
}: {
|
|
48
52
|
borderless?: boolean;
|
|
53
|
+
/** `none` drops the card entirely, for a document that reads top to bottom. */
|
|
54
|
+
chrome?: TileChrome;
|
|
49
55
|
sx?: SxProps<Theme>;
|
|
50
56
|
children: ReactNode;
|
|
51
57
|
}) {
|
|
52
58
|
const { theme } = usePublisherTheme();
|
|
59
|
+
const bare = borderless || chrome === "none";
|
|
53
60
|
return (
|
|
54
61
|
<Paper
|
|
55
62
|
elevation={0}
|
|
63
|
+
data-chrome={chrome}
|
|
56
64
|
sx={[
|
|
57
65
|
{
|
|
58
|
-
border:
|
|
59
|
-
borderRadius:
|
|
60
|
-
background:
|
|
66
|
+
border: bare ? "none" : theme.cardBorder,
|
|
67
|
+
borderRadius: bare ? 0 : 1,
|
|
68
|
+
background: bare ? "none" : theme.tile,
|
|
61
69
|
overflow: "hidden",
|
|
70
|
+
// A column so a tile's result can take the room under its heading.
|
|
71
|
+
display: "flex",
|
|
72
|
+
flexDirection: "column",
|
|
62
73
|
minWidth: 0,
|
|
63
|
-
minHeight: 120,
|
|
64
|
-
p:
|
|
74
|
+
minHeight: chrome === "none" ? 0 : 120,
|
|
75
|
+
p:
|
|
76
|
+
chrome === "none"
|
|
77
|
+
? 0
|
|
78
|
+
: borderless
|
|
79
|
+
? "12px 0"
|
|
80
|
+
: `${DASHBOARD_CARD_PADDING_PX}px`,
|
|
65
81
|
},
|
|
66
82
|
...(Array.isArray(sx) ? sx : [sx]),
|
|
67
83
|
]}
|
|
@@ -71,6 +87,12 @@ export function TileCard({
|
|
|
71
87
|
);
|
|
72
88
|
}
|
|
73
89
|
|
|
90
|
+
/** The heading's text as nodes, for a surface that makes it editable in place. */
|
|
91
|
+
export interface TileHeadingSlots {
|
|
92
|
+
title: ReactNode;
|
|
93
|
+
subtitle: ReactNode;
|
|
94
|
+
}
|
|
95
|
+
|
|
74
96
|
/**
|
|
75
97
|
* A tile's heading: its `# label`, and its `# subtitle` under it. In the
|
|
76
98
|
* instance theme's title colour and face, so a tile is titled the same
|
|
@@ -81,9 +103,12 @@ export function TileHeading({
|
|
|
81
103
|
subtitle,
|
|
82
104
|
tooltip,
|
|
83
105
|
action,
|
|
106
|
+
quiet = false,
|
|
84
107
|
}: {
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
/** A small caption instead of a heading, for a tile with no card around it. */
|
|
109
|
+
quiet?: boolean;
|
|
110
|
+
title: ReactNode;
|
|
111
|
+
subtitle?: ReactNode;
|
|
87
112
|
/** What actually ran, kept reachable without being the heading. */
|
|
88
113
|
tooltip?: string;
|
|
89
114
|
/** A control on the heading's row, hard right — the tile's Explore button. */
|
|
@@ -91,12 +116,21 @@ export function TileHeading({
|
|
|
91
116
|
}) {
|
|
92
117
|
const { theme } = usePublisherTheme();
|
|
93
118
|
return (
|
|
94
|
-
<Box
|
|
119
|
+
<Box
|
|
120
|
+
sx={{
|
|
121
|
+
pb: quiet ? 0.5 : 1.5,
|
|
122
|
+
display: "flex",
|
|
123
|
+
alignItems: "flex-start",
|
|
124
|
+
gap: 1,
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
95
127
|
<Box sx={{ minWidth: 0, flex: 1 }}>
|
|
96
128
|
<Typography
|
|
97
|
-
variant="subtitle2"
|
|
129
|
+
variant={quiet ? "caption" : "subtitle2"}
|
|
98
130
|
sx={{
|
|
99
|
-
fontWeight: 500,
|
|
131
|
+
fontWeight: quiet ? 400 : 500,
|
|
132
|
+
display: quiet ? "block" : undefined,
|
|
133
|
+
opacity: quiet ? 0.8 : undefined,
|
|
100
134
|
color: theme.tileTitle,
|
|
101
135
|
fontFamily: theme.font.family,
|
|
102
136
|
}}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { render, screen } from "@testing-library/react";
|
|
6
|
+
import { TileFilterTag, tileIgnoredFilterLabels } from "./TileFilterTag";
|
|
7
|
+
|
|
8
|
+
const declared = [
|
|
9
|
+
{ name: "CATEGORY", label: "Category" },
|
|
10
|
+
{ name: "REGION" },
|
|
11
|
+
{ name: "SINCE", label: "Ordered since" },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
describe("tileIgnoredFilterLabels", () => {
|
|
15
|
+
it("is empty when the tile reads every control", () => {
|
|
16
|
+
expect(
|
|
17
|
+
tileIgnoredFilterLabels(["SINCE", "CATEGORY", "REGION"], declared),
|
|
18
|
+
).toEqual([]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("names the controls the tile does not read, by label, in row order", () => {
|
|
22
|
+
expect(tileIgnoredFilterLabels(["REGION"], declared)).toEqual([
|
|
23
|
+
"Category",
|
|
24
|
+
"Ordered since",
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("is empty when discovery could not resolve the tile, since the whole row applies", () => {
|
|
29
|
+
expect(tileIgnoredFilterLabels(undefined, declared)).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("names every control for a tile that reads none", () => {
|
|
33
|
+
expect(tileIgnoredFilterLabels([], declared)).toEqual([
|
|
34
|
+
"Category",
|
|
35
|
+
"REGION",
|
|
36
|
+
"Ordered since",
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("TileFilterTag", () => {
|
|
42
|
+
it("names one ignored filter, and says why in its tooltip", () => {
|
|
43
|
+
render(<TileFilterTag ignored={["Brand"]} />);
|
|
44
|
+
const chip = screen.getByTestId("tile-filter-tag");
|
|
45
|
+
expect(chip.textContent).toBe("Doesn't respond to Brand");
|
|
46
|
+
expect(chip.getAttribute("title")).toBe(
|
|
47
|
+
"This tile's query never reads Brand, so changing it won't change this tile",
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("names up to three", () => {
|
|
52
|
+
render(<TileFilterTag ignored={["Brand", "Region", "Year"]} />);
|
|
53
|
+
const chip = screen.getByTestId("tile-filter-tag");
|
|
54
|
+
expect(chip.textContent).toBe("Doesn't respond to Brand, Region, Year");
|
|
55
|
+
expect(chip.getAttribute("title")).toBe(
|
|
56
|
+
"This tile's query never reads Brand, Region or Year, so changing them won't change this tile",
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("counts past three, and keeps the names in the tooltip", () => {
|
|
61
|
+
render(<TileFilterTag ignored={["Brand", "Region", "Year", "Store"]} />);
|
|
62
|
+
const chip = screen.getByTestId("tile-filter-tag");
|
|
63
|
+
expect(chip.textContent).toBe("Doesn't respond to 4 filters");
|
|
64
|
+
expect(chip.getAttribute("title")).toContain(
|
|
65
|
+
"Brand, Region, Year or Store",
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("renders nothing when the tile reads every filter", () => {
|
|
70
|
+
render(<TileFilterTag ignored={[]} />);
|
|
71
|
+
expect(screen.queryByTestId("tile-filter-tag")).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import FilterAltOffOutlinedIcon from "@mui/icons-material/FilterAltOffOutlined";
|
|
5
|
+
import { Box } from "@mui/material";
|
|
6
|
+
import type { Given } from "../../client";
|
|
7
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
8
|
+
|
|
9
|
+
/** Past this many, the chip counts the filters instead of naming them. */
|
|
10
|
+
const NAMED_LIMIT = 3;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Display labels of the controls on the page that a tile does NOT read.
|
|
14
|
+
*
|
|
15
|
+
* `givenNames` undefined means discovery could not resolve the tile, so the
|
|
16
|
+
* whole control row applies, as it does when the tile runs: nothing to warn of.
|
|
17
|
+
*/
|
|
18
|
+
export function tileIgnoredFilterLabels(
|
|
19
|
+
givenNames: readonly string[] | undefined,
|
|
20
|
+
declared: readonly Given[],
|
|
21
|
+
): string[] {
|
|
22
|
+
if (givenNames === undefined) return [];
|
|
23
|
+
const reads = new Set(givenNames);
|
|
24
|
+
return declared.flatMap((given) =>
|
|
25
|
+
given.name && !reads.has(given.name) ? [given.label ?? given.name] : [],
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function joinOr(labels: readonly string[]): string {
|
|
30
|
+
return labels.length < 2
|
|
31
|
+
? labels.join("")
|
|
32
|
+
: `${labels.slice(0, -1).join(", ")} or ${labels[labels.length - 1]}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A small amber chip naming the page's filters a tile ignores; nothing when it reads them all. */
|
|
36
|
+
export function TileFilterTag({ ignored }: { ignored: readonly string[] }) {
|
|
37
|
+
const { theme } = usePublisherTheme();
|
|
38
|
+
if (ignored.length === 0) return null;
|
|
39
|
+
const text =
|
|
40
|
+
ignored.length > NAMED_LIMIT
|
|
41
|
+
? `Doesn't respond to ${ignored.length} filters`
|
|
42
|
+
: `Doesn't respond to ${ignored.join(", ")}`;
|
|
43
|
+
return (
|
|
44
|
+
<Box
|
|
45
|
+
data-testid="tile-filter-tag"
|
|
46
|
+
title={`This tile's query never reads ${joinOr(ignored)}, so changing ${ignored.length === 1 ? "it" : "them"} won't change this tile`}
|
|
47
|
+
sx={{
|
|
48
|
+
display: "inline-flex",
|
|
49
|
+
alignItems: "center",
|
|
50
|
+
gap: 0.5,
|
|
51
|
+
maxWidth: "100%",
|
|
52
|
+
mb: 1,
|
|
53
|
+
alignSelf: "flex-start",
|
|
54
|
+
px: 0.75,
|
|
55
|
+
py: 0.125,
|
|
56
|
+
border: 1,
|
|
57
|
+
borderColor: "warning.main",
|
|
58
|
+
borderRadius: 1,
|
|
59
|
+
fontSize: 11,
|
|
60
|
+
lineHeight: 1.6,
|
|
61
|
+
color: "warning.main",
|
|
62
|
+
fontFamily: theme.font.family,
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<FilterAltOffOutlinedIcon sx={{ fontSize: 12 }} />
|
|
66
|
+
<Box
|
|
67
|
+
component="span"
|
|
68
|
+
sx={{
|
|
69
|
+
overflow: "hidden",
|
|
70
|
+
textOverflow: "ellipsis",
|
|
71
|
+
whiteSpace: "nowrap",
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{text}
|
|
75
|
+
</Box>
|
|
76
|
+
</Box>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { defaultTileSpan } from "./DashboardGrid";
|
|
6
|
+
|
|
7
|
+
// A 16-wide grid of 16 untagged tiles rendered as one row of ~45px slivers.
|
|
8
|
+
describe("defaultTileSpan", () => {
|
|
9
|
+
it("widens a one-column tile in a 16-column grid until it is readable", () => {
|
|
10
|
+
expect(defaultTileSpan(16, 1000, 240)).toBe(5);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("widens a one-column tile in a 12-column grid", () => {
|
|
14
|
+
expect(defaultTileSpan(12, 1000, 240)).toBe(4);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("leaves a roomy grid alone", () => {
|
|
18
|
+
expect(defaultTileSpan(2, 1000, 240)).toBe(1);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("changes nothing before the width is measured", () => {
|
|
22
|
+
expect(defaultTileSpan(16, 0, 240)).toBe(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("never exceeds the grid width", () => {
|
|
26
|
+
expect(defaultTileSpan(4, 100, 240)).toBe(4);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("leaves a one-column grid alone", () => {
|
|
30
|
+
expect(defaultTileSpan(1, 100, 240)).toBe(1);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
export { Dashboard, type DashboardProps } from "./Dashboard";
|
|
5
|
+
export { DashboardView, type DashboardViewProps } from "./DashboardView";
|
|
6
|
+
export { TileFilterTag, tileIgnoredFilterLabels } from "./TileFilterTag";
|
|
5
7
|
export { DashboardTile, type DashboardTileProps } from "./DashboardTile";
|
|
6
8
|
export type { DashboardEvent, DashboardEventHandler } from "./telemetry";
|
|
7
9
|
export { TileCard, TileHeading } from "./TileCard";
|
|
10
|
+
export type { TileHeadingSlots } from "./TileCard";
|