@malloy-publisher/sdk 0.9.0 → 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 +82 -48
- 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
|
@@ -2,19 +2,28 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { Box } from "@mui/material";
|
|
5
|
-
import type
|
|
5
|
+
import { useEffect, useRef, useState, type ReactNode } from "react";
|
|
6
6
|
|
|
7
7
|
/** Grid width when the dashboard declares no `# dashboard { columns=N }`. */
|
|
8
8
|
export const DEFAULT_COLUMNS = 2;
|
|
9
9
|
|
|
10
|
+
/** The widest grid the builder offers; the server lints wider ones and the reader still renders them. */
|
|
11
|
+
export const MAX_COLUMNS = 24;
|
|
12
|
+
|
|
13
|
+
/** A tile's width after an arrow nudge, held to the grid and to what the builder offers. */
|
|
14
|
+
export const nudgedSpan = (current: number, delta: 1 | -1, columns: number) =>
|
|
15
|
+
Math.min(Math.max(current + delta, 1), Math.min(columns, MAX_COLUMNS));
|
|
16
|
+
|
|
17
|
+
/** A tile's width for a width preset: a share of the grid, held to what the builder offers. */
|
|
18
|
+
export const presetSpan = (columns: number, share: number) =>
|
|
19
|
+
Math.min(Math.max(1, Math.round(columns / share)), MAX_COLUMNS);
|
|
20
|
+
|
|
10
21
|
/**
|
|
11
22
|
* The gutter between tiles, in px.
|
|
12
23
|
*
|
|
13
|
-
* A number rather than a `gap: 2` spacing unit because
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `getBoundingClientRect`. Exported so the value the grid paints and the value
|
|
17
|
-
* the drag solves with cannot drift apart.
|
|
24
|
+
* A number rather than a `gap: 2` spacing unit because a tile's default span is
|
|
25
|
+
* solved for the track width in px. Exported so the builder's column guides sit
|
|
26
|
+
* on the same gutters the grid paints.
|
|
18
27
|
*/
|
|
19
28
|
export const GRID_GAP_PX = 16;
|
|
20
29
|
|
|
@@ -35,6 +44,26 @@ export function tileGridColumn(
|
|
|
35
44
|
return tile.break ? `1 / span ${span}` : `span ${span}`;
|
|
36
45
|
}
|
|
37
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Columns a tile with no `# colspan` spans so it is at least `minTilePx` wide.
|
|
49
|
+
*
|
|
50
|
+
* In a 12 or 16 column grid a one-column tile is a sliver a few dozen px wide.
|
|
51
|
+
* Only tiles that never asked for a width are widened, so an explicit
|
|
52
|
+
* `colspan=1` stays the author's call. An unmeasured width changes nothing.
|
|
53
|
+
*/
|
|
54
|
+
export function defaultTileSpan(
|
|
55
|
+
columns: number,
|
|
56
|
+
containerPx: number,
|
|
57
|
+
minTilePx: number,
|
|
58
|
+
): number {
|
|
59
|
+
if (!(containerPx > 0) || columns <= 1) return 1;
|
|
60
|
+
const track = (containerPx - (columns - 1) * GRID_GAP_PX) / columns;
|
|
61
|
+
return Math.min(
|
|
62
|
+
columns,
|
|
63
|
+
Math.max(1, Math.ceil((minTilePx + GRID_GAP_PX) / (track + GRID_GAP_PX))),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
38
67
|
/** The layout a tile carries, whatever else its own shape holds. */
|
|
39
68
|
export interface GridTile {
|
|
40
69
|
colspan?: number;
|
|
@@ -69,6 +98,7 @@ export function DashboardGrid<T extends GridTile>({
|
|
|
69
98
|
columns,
|
|
70
99
|
keyOf,
|
|
71
100
|
renderTile,
|
|
101
|
+
minTilePx,
|
|
72
102
|
}: {
|
|
73
103
|
tiles: readonly T[];
|
|
74
104
|
/** Track count — `# dashboard { columns=N }`, or {@link DEFAULT_COLUMNS}. */
|
|
@@ -81,9 +111,33 @@ export function DashboardGrid<T extends GridTile>({
|
|
|
81
111
|
*/
|
|
82
112
|
keyOf: (tile: T, index: number) => string;
|
|
83
113
|
renderTile: (tile: T, index: number) => ReactNode;
|
|
114
|
+
/**
|
|
115
|
+
* Floor on the width of a tile that sets no `colspan`. Off by default: the
|
|
116
|
+
* builder assumes an unset colspan is one column.
|
|
117
|
+
*/
|
|
118
|
+
minTilePx?: number;
|
|
84
119
|
}) {
|
|
120
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
121
|
+
const [width, setWidth] = useState(0);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const node = ref.current;
|
|
124
|
+
if (
|
|
125
|
+
minTilePx === undefined ||
|
|
126
|
+
!node ||
|
|
127
|
+
typeof ResizeObserver === "undefined"
|
|
128
|
+
)
|
|
129
|
+
return;
|
|
130
|
+
const observer = new ResizeObserver(([entry]) =>
|
|
131
|
+
setWidth(entry?.contentRect.width ?? 0),
|
|
132
|
+
);
|
|
133
|
+
observer.observe(node);
|
|
134
|
+
return () => observer.disconnect();
|
|
135
|
+
}, [minTilePx]);
|
|
136
|
+
const floor =
|
|
137
|
+
minTilePx === undefined ? 1 : defaultTileSpan(columns, width, minTilePx);
|
|
85
138
|
return (
|
|
86
139
|
<Box
|
|
140
|
+
ref={ref}
|
|
87
141
|
sx={{
|
|
88
142
|
display: "grid",
|
|
89
143
|
gridTemplateColumns: {
|
|
@@ -113,7 +167,14 @@ export function DashboardGrid<T extends GridTile>({
|
|
|
113
167
|
minWidth: 0,
|
|
114
168
|
// Only above `md`: the narrow breakpoint is one column, where
|
|
115
169
|
// a span would overflow the grid rather than widen anything.
|
|
116
|
-
gridColumn: {
|
|
170
|
+
gridColumn: {
|
|
171
|
+
md: tileGridColumn(
|
|
172
|
+
tile.colspan === undefined && floor > 1
|
|
173
|
+
? { ...tile, colspan: floor }
|
|
174
|
+
: tile,
|
|
175
|
+
columns,
|
|
176
|
+
),
|
|
177
|
+
},
|
|
117
178
|
}}
|
|
118
179
|
>
|
|
119
180
|
{renderTile(tile, index)}
|
|
@@ -103,3 +103,27 @@ it("has no explore button when the host offers nowhere to go", () => {
|
|
|
103
103
|
render(tileAt(), { wrapper: serverWrapper });
|
|
104
104
|
expect(screen.queryByLabelText(/^Explore /)).toBeNull();
|
|
105
105
|
});
|
|
106
|
+
|
|
107
|
+
it("puts the filter warning under the heading and above the result", () => {
|
|
108
|
+
render(
|
|
109
|
+
<DashboardTile
|
|
110
|
+
environmentName="env"
|
|
111
|
+
packageName="pkg"
|
|
112
|
+
modelPath="dashboards/ops.malloy"
|
|
113
|
+
tile="overview -> sales_by_month"
|
|
114
|
+
givens={new Map()}
|
|
115
|
+
declaredTypes={new Map()}
|
|
116
|
+
height={400}
|
|
117
|
+
ignoredFilters={["Region"]}
|
|
118
|
+
/>,
|
|
119
|
+
{ wrapper: serverWrapper },
|
|
120
|
+
);
|
|
121
|
+
const heading = screen.getByText("Sales by month");
|
|
122
|
+
const tag = screen.getByTestId("tile-filter-tag");
|
|
123
|
+
expect(tag.textContent).toBe("Doesn't respond to Region");
|
|
124
|
+
const body = screen.getByText("Running…");
|
|
125
|
+
const follows = (a: Node, b: Node) =>
|
|
126
|
+
Boolean(a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING);
|
|
127
|
+
expect(follows(heading, tag)).toBe(true);
|
|
128
|
+
expect(follows(tag, body)).toBe(true);
|
|
129
|
+
});
|
|
@@ -10,7 +10,13 @@ import { humanizeSlug, type DrillBinding } from "../drill";
|
|
|
10
10
|
import { givensToRequest } from "../given/paramCodec";
|
|
11
11
|
import { ResultPanel } from "../RenderedResult/ResultPanel";
|
|
12
12
|
import { promoteMeasureRowToKpis } from "./promoteMeasureRow";
|
|
13
|
-
import {
|
|
13
|
+
import { TileFilterTag } from "./TileFilterTag";
|
|
14
|
+
import {
|
|
15
|
+
TileCard,
|
|
16
|
+
TileHeading,
|
|
17
|
+
type TileChrome,
|
|
18
|
+
type TileHeadingSlots,
|
|
19
|
+
} from "./TileCard";
|
|
14
20
|
|
|
15
21
|
export interface DashboardTileProps {
|
|
16
22
|
environmentName: string;
|
|
@@ -22,10 +28,14 @@ export interface DashboardTileProps {
|
|
|
22
28
|
queryName?: string;
|
|
23
29
|
/** A run expression (a composite tile). */
|
|
24
30
|
tile?: string;
|
|
31
|
+
/** Annotation lines placed above the tile's `run:`, which stack on the view's own. */
|
|
32
|
+
annotation?: string;
|
|
25
33
|
/** `# label` on the view the tile names, when it has one. */
|
|
26
34
|
label?: string;
|
|
27
35
|
/** `# subtitle` on it: a second line under the heading. */
|
|
28
36
|
subtitle?: string;
|
|
37
|
+
/** The heading's text as nodes, which replace `label` and `subtitle` where a surface edits them in place. */
|
|
38
|
+
heading?: TileHeadingSlots;
|
|
29
39
|
/** `# borderless` on it: no card around the result. */
|
|
30
40
|
borderless?: boolean;
|
|
31
41
|
/**
|
|
@@ -52,6 +62,10 @@ export interface DashboardTileProps {
|
|
|
52
62
|
* the heading, on hover; absent, the heading has no button.
|
|
53
63
|
*/
|
|
54
64
|
onExplore?: () => void;
|
|
65
|
+
/** `none` draws the result bare, its label a quiet caption above it. */
|
|
66
|
+
chrome?: TileChrome;
|
|
67
|
+
/** Labels of the page's filters this tile ignores, shown as a warning chip. */
|
|
68
|
+
ignoredFilters?: readonly string[];
|
|
55
69
|
}
|
|
56
70
|
|
|
57
71
|
/**
|
|
@@ -85,8 +99,10 @@ export function DashboardTile({
|
|
|
85
99
|
modelPath,
|
|
86
100
|
queryName,
|
|
87
101
|
tile,
|
|
102
|
+
annotation,
|
|
88
103
|
label,
|
|
89
104
|
subtitle,
|
|
105
|
+
heading,
|
|
90
106
|
borderless,
|
|
91
107
|
givens,
|
|
92
108
|
declaredTypes,
|
|
@@ -95,6 +111,8 @@ export function DashboardTile({
|
|
|
95
111
|
maxResultSize,
|
|
96
112
|
drill,
|
|
97
113
|
onExplore,
|
|
114
|
+
chrome = "card",
|
|
115
|
+
ignoredFilters,
|
|
98
116
|
}: DashboardTileProps) {
|
|
99
117
|
const { theme } = usePublisherTheme();
|
|
100
118
|
const state = useQueryResult({
|
|
@@ -103,7 +121,10 @@ export function DashboardTile({
|
|
|
103
121
|
modelPath,
|
|
104
122
|
versionId,
|
|
105
123
|
queryName,
|
|
106
|
-
query:
|
|
124
|
+
query:
|
|
125
|
+
tile !== undefined
|
|
126
|
+
? `${annotation ? `${annotation}\n` : ""}run: ${tile}`
|
|
127
|
+
: undefined,
|
|
107
128
|
// Narrowed to the givens this tile references: see `givenNames`.
|
|
108
129
|
givens: givensToRequest(givens, declaredTypes, givenNames),
|
|
109
130
|
});
|
|
@@ -111,7 +132,10 @@ export function DashboardTile({
|
|
|
111
132
|
return (
|
|
112
133
|
<TileCard
|
|
113
134
|
borderless={borderless}
|
|
135
|
+
chrome={chrome}
|
|
114
136
|
sx={{
|
|
137
|
+
// A table is as wide as its tile body, whatever its columns need.
|
|
138
|
+
"& .malloy-render, & .malloy-table": { width: "100%" },
|
|
115
139
|
// The heading's button shows on hover and keyboard focus, the way
|
|
116
140
|
// a tile's chrome does everywhere else; always-on it competes with
|
|
117
141
|
// the title on every card at once.
|
|
@@ -125,8 +149,9 @@ export function DashboardTile({
|
|
|
125
149
|
>
|
|
126
150
|
{tile !== undefined && (
|
|
127
151
|
<TileHeading
|
|
128
|
-
title={label ?? tileTitle(tile)}
|
|
129
|
-
subtitle={subtitle}
|
|
152
|
+
title={heading?.title ?? label ?? tileTitle(tile)}
|
|
153
|
+
subtitle={heading ? heading.subtitle : subtitle}
|
|
154
|
+
quiet={chrome === "none"}
|
|
130
155
|
// The expression is what actually ran, so it stays reachable as
|
|
131
156
|
// a tooltip rather than as the heading.
|
|
132
157
|
tooltip={tile}
|
|
@@ -147,7 +172,9 @@ export function DashboardTile({
|
|
|
147
172
|
}
|
|
148
173
|
/>
|
|
149
174
|
)}
|
|
175
|
+
{ignoredFilters && <TileFilterTag ignored={ignoredFilters} />}
|
|
150
176
|
<ResultPanel
|
|
177
|
+
fill
|
|
151
178
|
state={state}
|
|
152
179
|
context={tile ?? queryName ?? modelPath}
|
|
153
180
|
maxHeight={height}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
5
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
6
|
+
import {
|
|
7
|
+
clearCache,
|
|
8
|
+
mockServerProvider,
|
|
9
|
+
pending,
|
|
10
|
+
serverWrapper,
|
|
11
|
+
} from "../../../test/serverProvider";
|
|
12
|
+
import type { DashboardManifest } from "../../client";
|
|
13
|
+
|
|
14
|
+
const executeQueryModel = mock(
|
|
15
|
+
(
|
|
16
|
+
_environmentName: string,
|
|
17
|
+
_packageName: string,
|
|
18
|
+
_modelPath: string,
|
|
19
|
+
_request: unknown,
|
|
20
|
+
) => pending(),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
mockServerProvider({
|
|
24
|
+
models: { executeQueryModel, getModel: () => pending() },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { DashboardView } = await import("./DashboardView");
|
|
28
|
+
|
|
29
|
+
const base: DashboardManifest = {
|
|
30
|
+
name: "ops",
|
|
31
|
+
path: "dashboards/ops.malloy",
|
|
32
|
+
dashboardColumns: 2,
|
|
33
|
+
givens: [{ name: "REGION", type: "string", label: "Region" }],
|
|
34
|
+
tiles: [
|
|
35
|
+
{ kind: "text", name: "intro", markdown: "Hello **reader**" },
|
|
36
|
+
{
|
|
37
|
+
kind: "query",
|
|
38
|
+
query: "orders -> by_month",
|
|
39
|
+
givenNames: ["REGION"],
|
|
40
|
+
label: "Monthly",
|
|
41
|
+
},
|
|
42
|
+
// No `kind`: servers before text tiles omitted it.
|
|
43
|
+
{ query: "orders -> by_year", givenNames: [] },
|
|
44
|
+
],
|
|
45
|
+
} as DashboardManifest;
|
|
46
|
+
|
|
47
|
+
const view = (chrome?: "card" | "none") => (
|
|
48
|
+
<DashboardView
|
|
49
|
+
manifest={base}
|
|
50
|
+
environmentName="env"
|
|
51
|
+
packageName="pkg"
|
|
52
|
+
documentName="ops"
|
|
53
|
+
chrome={chrome}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
clearCache();
|
|
59
|
+
executeQueryModel.mockReset();
|
|
60
|
+
executeQueryModel.mockImplementation(() => pending());
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("DashboardView tiles", () => {
|
|
64
|
+
it("renders a text tile's markdown with no heading and runs no query for it", async () => {
|
|
65
|
+
render(view(), { wrapper: serverWrapper });
|
|
66
|
+
|
|
67
|
+
const strong = await screen.findByText("reader");
|
|
68
|
+
expect(strong.tagName).toBe("STRONG");
|
|
69
|
+
// Two query tiles run; the text tile adds none.
|
|
70
|
+
await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(2));
|
|
71
|
+
const text = strong.closest("[data-chrome]");
|
|
72
|
+
expect(text?.textContent).toBe("Hello reader");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("treats a tile with no kind as a query", async () => {
|
|
76
|
+
render(view(), { wrapper: serverWrapper });
|
|
77
|
+
|
|
78
|
+
await waitFor(() => expect(executeQueryModel).toHaveBeenCalledTimes(2));
|
|
79
|
+
const queries = executeQueryModel.mock.calls.map(
|
|
80
|
+
(call) => (call[3] as { query?: string }).query,
|
|
81
|
+
);
|
|
82
|
+
expect(queries).toContain("run: orders -> by_year");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("warns only on a tile that ignores some of the page's filters", async () => {
|
|
86
|
+
const manifest = {
|
|
87
|
+
...base,
|
|
88
|
+
givens: [
|
|
89
|
+
{ name: "REGION", type: "string", label: "Region" },
|
|
90
|
+
{ name: "BRAND", type: "string", label: "Brand" },
|
|
91
|
+
],
|
|
92
|
+
tiles: [
|
|
93
|
+
{ kind: "text", name: "intro", markdown: "Hello **reader**" },
|
|
94
|
+
{
|
|
95
|
+
kind: "query",
|
|
96
|
+
query: "orders -> all_apply",
|
|
97
|
+
givenNames: ["BRAND", "REGION"],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
kind: "query",
|
|
101
|
+
query: "orders -> one_missing",
|
|
102
|
+
givenNames: ["REGION"],
|
|
103
|
+
},
|
|
104
|
+
// Unresolved: it runs with the whole row, so nothing is ignored.
|
|
105
|
+
{ kind: "query", query: "orders -> unresolved" },
|
|
106
|
+
],
|
|
107
|
+
} as DashboardManifest;
|
|
108
|
+
render(
|
|
109
|
+
<DashboardView
|
|
110
|
+
manifest={manifest}
|
|
111
|
+
environmentName="env"
|
|
112
|
+
packageName="pkg"
|
|
113
|
+
documentName="ops"
|
|
114
|
+
/>,
|
|
115
|
+
{ wrapper: serverWrapper },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const tags = await screen.findAllByTestId("tile-filter-tag");
|
|
119
|
+
expect(tags.map((tag) => tag.textContent)).toEqual([
|
|
120
|
+
"Doesn't respond to Brand",
|
|
121
|
+
]);
|
|
122
|
+
expect(tags[0].closest("[data-chrome]")?.textContent).toContain(
|
|
123
|
+
"One missing",
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("puts no warning on a single-query dashboard", async () => {
|
|
128
|
+
render(
|
|
129
|
+
<DashboardView
|
|
130
|
+
manifest={
|
|
131
|
+
{
|
|
132
|
+
name: "ops",
|
|
133
|
+
path: "dashboards/ops.malloy",
|
|
134
|
+
query: "overview",
|
|
135
|
+
givens: [{ name: "REGION", type: "string", label: "Region" }],
|
|
136
|
+
} as DashboardManifest
|
|
137
|
+
}
|
|
138
|
+
environmentName="env"
|
|
139
|
+
packageName="pkg"
|
|
140
|
+
documentName="ops"
|
|
141
|
+
/>,
|
|
142
|
+
{ wrapper: serverWrapper },
|
|
143
|
+
);
|
|
144
|
+
await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
|
|
145
|
+
expect(screen.queryByTestId("tile-filter-tag")).toBeNull();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("DashboardView chrome", () => {
|
|
150
|
+
it("draws cards by default", async () => {
|
|
151
|
+
const { container } = render(view(), { wrapper: serverWrapper });
|
|
152
|
+
await screen.findByText("reader");
|
|
153
|
+
expect(
|
|
154
|
+
container.querySelectorAll('[data-chrome="card"]').length,
|
|
155
|
+
).toBeGreaterThan(0);
|
|
156
|
+
expect(container.querySelector('[data-chrome="none"]')).toBeNull();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("draws no cards and no title block with chrome none", async () => {
|
|
160
|
+
const { container } = render(view("none"), { wrapper: serverWrapper });
|
|
161
|
+
await screen.findByText("reader");
|
|
162
|
+
expect(container.querySelector('[data-chrome="card"]')).toBeNull();
|
|
163
|
+
expect(container.querySelectorAll('[data-chrome="none"]').length).toBe(3);
|
|
164
|
+
expect(screen.queryByText("ops")).toBeNull();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("DashboardView gate givens", () => {
|
|
169
|
+
// ORG is read only by the source's `#(authorize)` gate: the tile names it,
|
|
170
|
+
// the control row does not declare it, and the host supplies it.
|
|
171
|
+
const gated = {
|
|
172
|
+
name: "ops",
|
|
173
|
+
path: "dashboards/ops.malloy",
|
|
174
|
+
givens: [{ name: "REGION", type: "string", label: "Region" }],
|
|
175
|
+
tiles: [
|
|
176
|
+
{
|
|
177
|
+
kind: "query",
|
|
178
|
+
query: "orders -> by_month",
|
|
179
|
+
givenNames: ["ORG", "REGION"],
|
|
180
|
+
},
|
|
181
|
+
{ kind: "query", query: "orders -> by_year", givenNames: ["REGION"] },
|
|
182
|
+
],
|
|
183
|
+
} as DashboardManifest;
|
|
184
|
+
|
|
185
|
+
const tileGivens = (query: string) =>
|
|
186
|
+
executeQueryModel.mock.calls
|
|
187
|
+
.map((call) => call[3] as { query?: string; givens?: unknown })
|
|
188
|
+
.filter((request) => request.query === `run: ${query}`)
|
|
189
|
+
.at(-1)?.givens;
|
|
190
|
+
|
|
191
|
+
it("sends a host-supplied gate given to the tiles that name it, with no control for it", async () => {
|
|
192
|
+
render(
|
|
193
|
+
<DashboardView
|
|
194
|
+
manifest={gated}
|
|
195
|
+
environmentName="env"
|
|
196
|
+
packageName="pkg"
|
|
197
|
+
documentName="ops"
|
|
198
|
+
givens={{ ORG: "1", REGION: "CA" }}
|
|
199
|
+
/>,
|
|
200
|
+
{ wrapper: serverWrapper },
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
await waitFor(() =>
|
|
204
|
+
expect(tileGivens("orders -> by_month")).toEqual({
|
|
205
|
+
ORG: "1",
|
|
206
|
+
REGION: "CA",
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
expect(tileGivens("orders -> by_year")).toEqual({ REGION: "CA" });
|
|
210
|
+
expect(screen.queryByText("ORG")).toBeNull();
|
|
211
|
+
});
|
|
212
|
+
});
|