@malloy-publisher/sdk 0.2.7 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -204
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
- package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
- package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
- package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
- package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
- package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9561 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/api.d.ts +13 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/ApiErrorDisplay.d.ts +1 -2
- package/dist/components/Dashboard/Dashboard.d.ts +23 -16
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
- package/dist/components/Dashboard/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
- package/dist/components/DocumentStorage/index.d.ts +3 -0
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/Model/index.d.ts +0 -1
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +2 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
- package/dist/components/drill/index.d.ts +2 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/drill/useDrillSelf.d.ts +46 -0
- package/dist/components/given/filterValue.d.ts +63 -0
- package/dist/components/given/index.d.ts +1 -0
- package/dist/components/given/useGivenUrlParams.d.ts +39 -0
- package/dist/components/index.d.ts +3 -3
- package/dist/components/styles.d.ts +3 -7
- package/dist/core-8NVBCLZh.cjs.js +148 -0
- package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/hooks/useSuggestOptions.d.ts +28 -12
- package/dist/index.cjs.js +34 -1
- package/dist/index.es.js +21487 -79
- package/dist/sdk.css +1 -1
- package/dist/styles.css +0 -1
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/package.json +25 -14
- package/src/builder-entry.ts +55 -0
- package/src/components/ApiErrorDisplay.tsx +1 -1
- package/src/components/Connections/EditConnectionDialog.tsx +96 -86
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +184 -229
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +67 -101
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
- package/src/components/Dashboard/telemetry.ts +44 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
- package/src/components/DocumentStorage/index.ts +16 -0
- package/src/components/Environment/About.tsx +4 -36
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +34 -72
- package/src/components/Model/index.ts +0 -1
- package/src/components/Notebook/Notebook.tsx +27 -156
- package/src/components/Notebook/NotebookCell.tsx +37 -191
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/RenderedResult.tsx +86 -76
- package/src/components/RenderedResult/ResultContainer.tsx +25 -36
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +16 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
- package/src/components/RenderedResult/resultSizing.ts +308 -0
- package/src/components/ResultsDialog.tsx +2 -1
- package/src/components/drill/index.ts +6 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/drill/useDrillSelf.spec.tsx +64 -0
- package/src/components/drill/useDrillSelf.ts +110 -0
- package/src/components/given/GivenInput.spec.tsx +196 -2
- package/src/components/given/GivenInput.tsx +300 -25
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/given/filterValue.spec.ts +112 -0
- package/src/components/given/filterValue.ts +188 -0
- package/src/components/given/index.ts +4 -0
- package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
- package/src/components/given/useGivenUrlParams.ts +87 -0
- package/src/components/index.ts +11 -3
- package/src/components/styles.ts +0 -37
- package/src/hooks/index.ts +13 -1
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useGivensState.spec.ts +158 -0
- package/src/hooks/useGivensState.ts +114 -23
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
- package/src/hooks/useSuggestOptions.ts +94 -51
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/vite.config.ts +5 -1
- package/dist/components/AnalyzePackageButton.d.ts +0 -6
- package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
- package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
- package/dist/components/Workbook/ModelPicker.d.ts +0 -11
- package/dist/components/Workbook/MutableCell.d.ts +0 -17
- package/dist/components/Workbook/Workbook.d.ts +0 -7
- package/dist/components/Workbook/WorkbookList.d.ts +0 -7
- package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
- package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
- package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
- package/dist/components/Workbook/index.d.ts +0 -7
- package/dist/core-CWKmWEg2.cjs.js +0 -148
- package/dist/index-B0WyZAUA.es.js +0 -66412
- package/dist/index-kxVD1RjY.cjs.js +0 -356
- package/dist/markdown-editor.css +0 -341
- package/src/components/AnalyzePackageButton.tsx +0 -319
- package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
- package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
- package/src/components/Workbook/ModelPicker.tsx +0 -134
- package/src/components/Workbook/MutableCell.tsx +0 -458
- package/src/components/Workbook/Workbook.tsx +0 -501
- package/src/components/Workbook/WorkbookList.tsx +0 -110
- package/src/components/Workbook/WorkbookManager.ts +0 -214
- package/src/components/Workbook/WorkbookStorage.ts +0 -35
- package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
- package/src/components/Workbook/index.ts +0 -10
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box } from "@mui/material";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import type { QueryResultState } from "../../hooks/useQueryResult";
|
|
7
|
+
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
8
|
+
import type { DrillBinding } from "../drill/useDrill";
|
|
9
|
+
import { Loading } from "../Loading";
|
|
10
|
+
import ResultContainer from "./ResultContainer";
|
|
11
|
+
|
|
12
|
+
export interface ResultPanelProps {
|
|
13
|
+
/** From `useQueryResult`. */
|
|
14
|
+
state: QueryResultState;
|
|
15
|
+
/** Names the request in an error: the tile expression, the query name, the model path. */
|
|
16
|
+
context: string;
|
|
17
|
+
loadingText?: string;
|
|
18
|
+
maxHeight?: number;
|
|
19
|
+
maxResultSize?: number;
|
|
20
|
+
drill?: DrillBinding;
|
|
21
|
+
/**
|
|
22
|
+
* Rewrites the result before it is rendered — a dashboard tile promotes a
|
|
23
|
+
* one-row measure result to KPI cards this way. Memoized on the result
|
|
24
|
+
* string, so a large result is not re-parsed on every render around it.
|
|
25
|
+
*/
|
|
26
|
+
transform?: (result: string) => string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The three states of a running query, once: waiting, failed, and the result
|
|
31
|
+
* itself through `ResultContainer`.
|
|
32
|
+
*
|
|
33
|
+
* Every surface that runs a query goes through the same three, and each used
|
|
34
|
+
* to draw them itself with its own words ("Running…", "Loading results...",
|
|
35
|
+
* "Fetching Query Results...") and, in one case, without the failed state at
|
|
36
|
+
* all. A tile owning its own panel is still what lets a composite dashboard
|
|
37
|
+
* survive a bad tile: the broken one shows its error in place and the rest of
|
|
38
|
+
* the grid still renders.
|
|
39
|
+
*/
|
|
40
|
+
export function ResultPanel({
|
|
41
|
+
state,
|
|
42
|
+
context,
|
|
43
|
+
loadingText = "Running…",
|
|
44
|
+
maxHeight,
|
|
45
|
+
maxResultSize,
|
|
46
|
+
drill,
|
|
47
|
+
transform,
|
|
48
|
+
}: ResultPanelProps) {
|
|
49
|
+
const { data, isSuccess, isError, error } = state;
|
|
50
|
+
const raw = data?.data.result;
|
|
51
|
+
const result = useMemo(
|
|
52
|
+
() => (raw !== undefined && transform ? transform(raw) : raw),
|
|
53
|
+
[raw, transform],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (isError) {
|
|
57
|
+
return (
|
|
58
|
+
<Box sx={{ p: 2 }}>
|
|
59
|
+
<ApiErrorDisplay context={context} error={error} />
|
|
60
|
+
</Box>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (!isSuccess) return <Loading text={loadingText} />;
|
|
64
|
+
return (
|
|
65
|
+
<ResultContainer
|
|
66
|
+
result={result}
|
|
67
|
+
maxHeight={maxHeight}
|
|
68
|
+
maxResultSize={maxResultSize}
|
|
69
|
+
renderLogs={data.data.renderLogs}
|
|
70
|
+
drill={drill}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -3,3 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
export { default as RenderedResult } from "./RenderedResult";
|
|
5
5
|
export { default as ResultContainer } from "./ResultContainer";
|
|
6
|
+
export { ResultPanel, type ResultPanelProps } from "./ResultPanel";
|
|
7
|
+
export {
|
|
8
|
+
contentNodeDepth,
|
|
9
|
+
INITIAL_RENDER_HEIGHT,
|
|
10
|
+
initialResultHeight,
|
|
11
|
+
measureContentHeight,
|
|
12
|
+
MODEL_CELL_MAX_HEIGHT,
|
|
13
|
+
NOTEBOOK_CELL_MAX_HEIGHT,
|
|
14
|
+
remeasuresAfterReady,
|
|
15
|
+
resolveResultHeight,
|
|
16
|
+
RESULTS_DIALOG_MAX_HEIGHT,
|
|
17
|
+
resultSizing,
|
|
18
|
+
TILE_MAX_HEIGHT,
|
|
19
|
+
UNCAPPED_CONTAINER_HEIGHT,
|
|
20
|
+
type ResultSizing,
|
|
21
|
+
} from "./resultSizing";
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
contentNode,
|
|
7
|
+
contentNodeDepth,
|
|
8
|
+
INITIAL_RENDER_HEIGHT,
|
|
9
|
+
initialResultHeight,
|
|
10
|
+
measureContentHeight,
|
|
11
|
+
remeasuresAfterReady,
|
|
12
|
+
resolveResultHeight,
|
|
13
|
+
resultSizing,
|
|
14
|
+
UNCAPPED_CONTAINER_HEIGHT,
|
|
15
|
+
} from "./resultSizing";
|
|
16
|
+
|
|
17
|
+
describe("resultSizing", () => {
|
|
18
|
+
// `renderAs()` reports the PLUGIN's name, and the renderer's default
|
|
19
|
+
// registry names the bar and line plugins "bar" and "line" — the tag
|
|
20
|
+
// spellings "bar_chart" and "line_chart" never come back from it. Getting
|
|
21
|
+
// this wrong is invisible: the chart is simply measured, and a `# line_chart`
|
|
22
|
+
// tile quietly shrinks to the inset height it drew itself at.
|
|
23
|
+
it.each(["bar", "line", "chart", "scatter_chart"])(
|
|
24
|
+
"calls %s container-sized",
|
|
25
|
+
(renderAs) => {
|
|
26
|
+
expect(resultSizing(renderAs)).toBe("container");
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
it.each([
|
|
31
|
+
"table",
|
|
32
|
+
"dashboard",
|
|
33
|
+
"list",
|
|
34
|
+
"big_value",
|
|
35
|
+
"cell",
|
|
36
|
+
"link",
|
|
37
|
+
"image",
|
|
38
|
+
// Measured: a `# shape_map` reports 365 in a 400px tile and 365 in a
|
|
39
|
+
// 700px cell. Its height is its aspect ratio, not its box, so it shrinks
|
|
40
|
+
// to content like a table rather than filling like a bar chart, which
|
|
41
|
+
// reports its box minus an 8px inset at both of those sizes.
|
|
42
|
+
"shape_map",
|
|
43
|
+
"segment_map",
|
|
44
|
+
])("calls %s content-sized", (renderAs) => {
|
|
45
|
+
expect(resultSizing(renderAs)).toBe("content");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// A render plugin returns its own name here, and a renderer newer than this
|
|
49
|
+
// SDK can return one we have never heard of. Content-sized is what every
|
|
50
|
+
// root got before this classification existed, so an unknown name keeps the
|
|
51
|
+
// old behavior rather than silently losing its height.
|
|
52
|
+
it("treats an unknown root as content-sized", () => {
|
|
53
|
+
expect(resultSizing("vega_lite_plugin")).toBe("content");
|
|
54
|
+
expect(resultSizing(undefined)).toBe("content");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// The renderer's own answer, and the one that decides where both are present.
|
|
59
|
+
// Measured against the bundled examples: `bar:fill`, `line:fill`,
|
|
60
|
+
// `shape_map:fixed`, and no plugin at all for a table or a `# dashboard` grid.
|
|
61
|
+
describe("resultSizing from the plugin's declared strategy", () => {
|
|
62
|
+
it("takes fill as container-sized and fixed as content-sized", () => {
|
|
63
|
+
expect(resultSizing("anything", "fill")).toBe("container");
|
|
64
|
+
expect(resultSizing("anything", "fixed")).toBe("content");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// The point of reading it: a host's own plugin says which it is instead of
|
|
68
|
+
// falling into the unknown-name default, and gets re-measured accordingly.
|
|
69
|
+
it("places a plugin this SDK has never heard of", () => {
|
|
70
|
+
expect(resultSizing("acme_gauge", "fixed")).toBe("content");
|
|
71
|
+
expect(remeasuresAfterReady("acme_gauge", "fixed")).toBe(true);
|
|
72
|
+
expect(resultSizing("acme_gauge", "fill")).toBe("container");
|
|
73
|
+
expect(remeasuresAfterReady("acme_gauge", "fill")).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// A `# dashboard` grid and a table have no plugin, so the names still carry
|
|
77
|
+
// them, and every name that DOES have one agrees with it today.
|
|
78
|
+
it("falls back to the name when no plugin claims the root", () => {
|
|
79
|
+
expect(resultSizing("table", undefined)).toBe("content");
|
|
80
|
+
expect(resultSizing("dashboard", undefined)).toBe("content");
|
|
81
|
+
expect(resultSizing("bar", undefined)).toBe("container");
|
|
82
|
+
expect(resultSizing("shape_map", undefined)).toBe("content");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("still measures an unplaceable root exactly once", () => {
|
|
86
|
+
expect(resultSizing("acme_gauge", undefined)).toBe("content");
|
|
87
|
+
expect(remeasuresAfterReady("acme_gauge", undefined)).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("remeasuresAfterReady", () => {
|
|
92
|
+
// The first measurement races the renderer's layout: a table signals ready
|
|
93
|
+
// before its virtualized grid has laid out, and a `# big_value` row reports
|
|
94
|
+
// the box it was handed rather than its own 136px.
|
|
95
|
+
it.each(["table", "big_value", "dashboard", "list", "shape_map"])(
|
|
96
|
+
"keeps watching %s",
|
|
97
|
+
(renderAs) => {
|
|
98
|
+
expect(remeasuresAfterReady(renderAs)).toBe(true);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// A host's own plugin could be a fill-the-box viz wearing a name we do not
|
|
103
|
+
// know, and one measurement is what it got before any of this existed.
|
|
104
|
+
it.each(["vega_lite_plugin", undefined])(
|
|
105
|
+
"measures the unrecognised %s once",
|
|
106
|
+
(renderAs) => {
|
|
107
|
+
expect(resultSizing(renderAs)).toBe("content");
|
|
108
|
+
expect(remeasuresAfterReady(renderAs)).toBe(false);
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// The one root re-measuring is not safe for, and the reason it used to be
|
|
113
|
+
// tables only: a chart insets itself inside its box, so feeding its height
|
|
114
|
+
// back would ratchet the container down every pass. It is never measured now.
|
|
115
|
+
it.each(["bar", "line", "chart", "scatter_chart"])(
|
|
116
|
+
"never measures %s at all",
|
|
117
|
+
(renderAs) => {
|
|
118
|
+
expect(remeasuresAfterReady(renderAs)).toBe(false);
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("contentNodeDepth", () => {
|
|
124
|
+
it("reads a dashboard grid one level deeper than every other root", () => {
|
|
125
|
+
expect(contentNodeDepth("dashboard")).toBe(3);
|
|
126
|
+
expect(contentNodeDepth("table")).toBe(2);
|
|
127
|
+
expect(contentNodeDepth(undefined)).toBe(2);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/** A chain of nested divs, each with the scrollHeight it is given. */
|
|
132
|
+
function stageWithHeights(...heights: number[]): HTMLElement {
|
|
133
|
+
const stage = document.createElement("div");
|
|
134
|
+
let parent: HTMLElement = stage;
|
|
135
|
+
for (const height of heights) {
|
|
136
|
+
const node = document.createElement("div");
|
|
137
|
+
Object.defineProperty(node, "scrollHeight", {
|
|
138
|
+
value: height,
|
|
139
|
+
configurable: true,
|
|
140
|
+
});
|
|
141
|
+
parent.appendChild(node);
|
|
142
|
+
parent = node;
|
|
143
|
+
}
|
|
144
|
+
return stage;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
describe("contentNode", () => {
|
|
148
|
+
// The node measured and the node watched for changes have to be the same one,
|
|
149
|
+
// or a result that settles later settles at a height nothing reported.
|
|
150
|
+
it("is the node measureContentHeight reads", () => {
|
|
151
|
+
const stage = stageWithHeights(400, 137, 120);
|
|
152
|
+
expect(contentNode(stage, 2)?.scrollHeight).toBe(
|
|
153
|
+
measureContentHeight(stage, 2),
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("is null before the renderer has built anything", () => {
|
|
158
|
+
expect(contentNode(document.createElement("div"), 2)).toBeNull();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("is null while the renderer has not built that deep", () => {
|
|
162
|
+
expect(contentNode(stageWithHeights(400, 400), 3)).toBeNull();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe("measureContentHeight", () => {
|
|
167
|
+
// Depth 1 is the renderer's outer wrapper, which is box-sized: measuring it
|
|
168
|
+
// would floor every result at the height the container already has.
|
|
169
|
+
it("reads the root render node at depth 2", () => {
|
|
170
|
+
expect(measureContentHeight(stageWithHeights(400, 137, 120), 2)).toBe(
|
|
171
|
+
137,
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("reads a dashboard grid at depth 3", () => {
|
|
176
|
+
expect(measureContentHeight(stageWithHeights(400, 400, 227), 3)).toBe(
|
|
177
|
+
227,
|
|
178
|
+
);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// The shallow nodes are the renderer's box-sized wrappers, so answering with
|
|
182
|
+
// one reports back the height the panel already has. That reads as a
|
|
183
|
+
// successful measurement and stops the retry, which is how a `# big_value`
|
|
184
|
+
// tile got stuck at its 400px cap with its own content measuring 136.
|
|
185
|
+
it("reports nothing while the DOM is shallower than the content node", () => {
|
|
186
|
+
expect(measureContentHeight(stageWithHeights(400, 400), 3)).toBe(0);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("reports nothing when the renderer has not built anything yet", () => {
|
|
190
|
+
expect(measureContentHeight(document.createElement("div"), 2)).toBe(0);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("initialResultHeight", () => {
|
|
195
|
+
it("paints an uncapped result at the seed height", () => {
|
|
196
|
+
expect(initialResultHeight(undefined)).toBe(INITIAL_RENDER_HEIGHT);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("never paints taller than the cap", () => {
|
|
200
|
+
expect(initialResultHeight(400)).toBe(400);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("resolveResultHeight", () => {
|
|
205
|
+
const at = (
|
|
206
|
+
sizing: "content" | "container" | undefined,
|
|
207
|
+
contentHeight: number | undefined,
|
|
208
|
+
maxHeight: number | undefined,
|
|
209
|
+
) => resolveResultHeight({ sizing, contentHeight, maxHeight });
|
|
210
|
+
|
|
211
|
+
it("paints at the seed before anything is known", () => {
|
|
212
|
+
expect(at(undefined, undefined, 400)).toBe(400);
|
|
213
|
+
expect(at(undefined, undefined, undefined)).toBe(INITIAL_RENDER_HEIGHT);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// The whole point of the classification: a chart fills its box, so the cap
|
|
217
|
+
// IS its height and it is never measured. This is what the 20000px "no cap"
|
|
218
|
+
// sentinel used to turn into a 1992px bar chart.
|
|
219
|
+
it("gives a container-sized root its cap, and a default with no cap", () => {
|
|
220
|
+
expect(at("container", undefined, 400)).toBe(400);
|
|
221
|
+
expect(at("container", undefined, undefined)).toBe(
|
|
222
|
+
UNCAPPED_CONTAINER_HEIGHT,
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Even if one arrived: a chart's measurement only ever reports back the
|
|
227
|
+
// height it was handed.
|
|
228
|
+
it("ignores a measurement from a container-sized root", () => {
|
|
229
|
+
expect(at("container", 1992, undefined)).toBe(UNCAPPED_CONTAINER_HEIGHT);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("shrinks a content-sized root to its content", () => {
|
|
233
|
+
expect(at("content", 137, 400)).toBe(137);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("caps a content-sized root taller than the cap", () => {
|
|
237
|
+
expect(at("content", 4000, 700)).toBe(700);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// No cap means no cap: the single-query dashboard form lets its one result
|
|
241
|
+
// set the page height and scrolls.
|
|
242
|
+
it("lets an uncapped content-sized root use its full height", () => {
|
|
243
|
+
expect(at("content", 4000, undefined)).toBe(4000);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("stays at the seed while a content-sized root measures zero", () => {
|
|
247
|
+
expect(at("content", 0, 400)).toBe(400);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every height decision a rendered result takes, in one module.
|
|
6
|
+
*
|
|
7
|
+
* Three things used to be tangled together and spread across four files: how
|
|
8
|
+
* tall a result should paint, whether it is the kind of result that has a
|
|
9
|
+
* height of its own at all, and which DOM node that height can be read off.
|
|
10
|
+
* They are separated here so the first two are pure and testable, and the third
|
|
11
|
+
* is the single place this package touches the renderer's DOM.
|
|
12
|
+
*
|
|
13
|
+
* The renderer exposes no size API — `MalloyViz` offers `onReady` and
|
|
14
|
+
* `getMetadata()` and nothing that reports a height — so a result that sizes
|
|
15
|
+
* itself has to be measured. What CAN come from the public metadata is whether
|
|
16
|
+
* it is worth measuring, from two sources, in this order:
|
|
17
|
+
*
|
|
18
|
+
* 1. The root's render plugin declares `sizingStrategy: "fill" | "fixed"`,
|
|
19
|
+
* which is the renderer's own answer to exactly this question. Read it
|
|
20
|
+
* through `getPluginsForField(getRootField().key)`.
|
|
21
|
+
* 2. Where no plugin claims the root — a table, a `# dashboard` grid — fall
|
|
22
|
+
* back to `renderAs()` and the lists below.
|
|
23
|
+
*
|
|
24
|
+
* Keying off either instead of the rendered class names is what keeps the DOM
|
|
25
|
+
* contact down to one bounded walk.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* How a rendered root arrives at its height.
|
|
30
|
+
*
|
|
31
|
+
* - `content`: it has a height of its own and the container should shrink to
|
|
32
|
+
* it — a table, a `# dashboard` grid, a `# big_value`, a list, and the maps,
|
|
33
|
+
* whose height comes from their aspect ratio.
|
|
34
|
+
* - `container`: it fills whatever box it is handed and has no height to
|
|
35
|
+
* report. The plotted charts, and only those. Measuring one tells you what
|
|
36
|
+
* you already gave it, minus the inset it drew itself at.
|
|
37
|
+
*/
|
|
38
|
+
export type ResultSizing = "content" | "container";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Roots that fill their box, named in the renderer's `renderAs()` vocabulary.
|
|
42
|
+
*
|
|
43
|
+
* That vocabulary has two sources and they do not agree, which is the trap
|
|
44
|
+
* here. A field rendered by a plugin reports the PLUGIN's name, and the
|
|
45
|
+
* renderer's default registry names the bar and line plugins `"bar"` and
|
|
46
|
+
* `"line"` — not `"bar_chart"` and `"line_chart"`, which are the tag spellings
|
|
47
|
+
* and appear nowhere in what `renderAs()` returns. Measured: a `# line_chart`
|
|
48
|
+
* tile reports `"line"`. The tag-derived fallback in the renderer, used when no
|
|
49
|
+
* plugin claims the field, collapses both to `"chart"` instead, so that name
|
|
50
|
+
* has to be here too.
|
|
51
|
+
*
|
|
52
|
+
* "It is a chart" is not the test — filling the box is. A bar chart reports its
|
|
53
|
+
* box minus an 8px inset at every size: 392 in a 400px tile, 692 in a 700px
|
|
54
|
+
* notebook cell. That inset is the ratchet, and it is why these are never
|
|
55
|
+
* measured.
|
|
56
|
+
*
|
|
57
|
+
* The maps are deliberately NOT here, which is the trap in the other direction:
|
|
58
|
+
* the renderer declares `# shape_map` and `# segment_map` `"fixed"`, and they
|
|
59
|
+
* report 365 in a 400px tile and 365 in a 700px cell — the same number, because
|
|
60
|
+
* their size is their own and not their box's. Grouping them with the charts
|
|
61
|
+
* put a map that needs 365px into 700px of cell.
|
|
62
|
+
*
|
|
63
|
+
* Every name here is checked against the plugin's declared strategy at runtime
|
|
64
|
+
* and agrees with it today (`bar:fill`, `line:fill`, `shape_map:fixed`); the
|
|
65
|
+
* strategy wins where both are available, so this list carries the roots no
|
|
66
|
+
* plugin claims and anything a renderer stops declaring.
|
|
67
|
+
*/
|
|
68
|
+
const CONTAINER_SIZED_ROOTS: ReadonlySet<string> = new Set([
|
|
69
|
+
"bar",
|
|
70
|
+
"line",
|
|
71
|
+
"chart",
|
|
72
|
+
"scatter_chart",
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Roots known to have a height of their own, in the same vocabulary.
|
|
77
|
+
*
|
|
78
|
+
* Kept as an explicit list rather than "everything that is not a chart" so a
|
|
79
|
+
* root this SDK has never heard of — a host's own render plugin — can be told
|
|
80
|
+
* apart from both and given the conservative treatment in
|
|
81
|
+
* {@link remeasuresAfterReady}.
|
|
82
|
+
*/
|
|
83
|
+
const CONTENT_SIZED_ROOTS: ReadonlySet<string> = new Set([
|
|
84
|
+
"table",
|
|
85
|
+
"dashboard",
|
|
86
|
+
"shape_map",
|
|
87
|
+
"segment_map",
|
|
88
|
+
"list",
|
|
89
|
+
"list_detail",
|
|
90
|
+
"big_value",
|
|
91
|
+
"cell",
|
|
92
|
+
"link",
|
|
93
|
+
"image",
|
|
94
|
+
]);
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Which sizing rule a root follows.
|
|
98
|
+
*
|
|
99
|
+
* `strategy` is the root plugin's declared `sizingStrategy` and wins when it is
|
|
100
|
+
* there, because it is the renderer answering the question directly rather than
|
|
101
|
+
* this SDK inferring it from a name. Note it is the PLUGIN's strategy, not the
|
|
102
|
+
* field entry's: `renderProperties.sizingStrategy` on the root reads `"fit"` for
|
|
103
|
+
* every result and says nothing.
|
|
104
|
+
*
|
|
105
|
+
* Unknown, with no plugin — a renderer newer than this SDK — is treated as
|
|
106
|
+
* content-sized, which is the behavior every root had before this
|
|
107
|
+
* classification existed: measure once and use what comes back.
|
|
108
|
+
*/
|
|
109
|
+
export function resultSizing(
|
|
110
|
+
renderAs: string | undefined,
|
|
111
|
+
strategy?: string | undefined,
|
|
112
|
+
): ResultSizing {
|
|
113
|
+
if (strategy === "fill") return "container";
|
|
114
|
+
if (strategy === "fixed") return "content";
|
|
115
|
+
if (!renderAs) return "content";
|
|
116
|
+
return CONTAINER_SIZED_ROOTS.has(renderAs) ? "container" : "content";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Whether the result keeps being measured after the first height lands.
|
|
121
|
+
*
|
|
122
|
+
* It has to be, and the acute case is a table. The renderer signals `onReady`
|
|
123
|
+
* as soon as it knows it can paint, and for a table that is immediately — a
|
|
124
|
+
* chart waits for a non-zero parent size, a table does not — so a single
|
|
125
|
+
* measurement taken there lands before the table's virtualized grid has laid
|
|
126
|
+
* out, and reads a height the table never keeps. A `# big_value` row loses the
|
|
127
|
+
* same race more quietly: it reports the box it was handed, so the panel simply
|
|
128
|
+
* keeps the cap and the tile carries a band of empty space under its numbers.
|
|
129
|
+
*
|
|
130
|
+
* Re-measuring a content-sized root TERMINATES, because its height does not
|
|
131
|
+
* depend on the box it is in. `.malloy-table.root` is
|
|
132
|
+
* `height: fit-content; max-height: 100%` in the renderer's own CSS and the
|
|
133
|
+
* wrappers between it and the container add no padding, so shrinking the
|
|
134
|
+
* container to the table's content height is the exact point at which the cap
|
|
135
|
+
* stops binding and the next measurement reports the same number.
|
|
136
|
+
*
|
|
137
|
+
* This used to be tables only, and the reason was the one root this is NOT safe
|
|
138
|
+
* for: a chart draws itself inset from the box it is given, so feeding its
|
|
139
|
+
* height back as the new container height would ratchet the container down by
|
|
140
|
+
* that inset every pass and never converge. Charts are classified
|
|
141
|
+
* container-sized now and are never measured at all, so the hazard is out of
|
|
142
|
+
* the measured set and the narrow exemption it forced can go with it.
|
|
143
|
+
*
|
|
144
|
+
* A root this SDK cannot place stays on the one-shot path. A plugin that
|
|
145
|
+
* declares itself `"fixed"` IS placed — the renderer has said its size is its
|
|
146
|
+
* own — so it re-measures like any other content-sized root. Only a name we do
|
|
147
|
+
* not know, with no plugin behind it, falls back to one measurement, which is
|
|
148
|
+
* what it got before any of this existed.
|
|
149
|
+
*/
|
|
150
|
+
export function remeasuresAfterReady(
|
|
151
|
+
renderAs: string | undefined,
|
|
152
|
+
strategy?: string | undefined,
|
|
153
|
+
): boolean {
|
|
154
|
+
if (strategy === "fixed") return true;
|
|
155
|
+
if (strategy === "fill") return false;
|
|
156
|
+
return renderAs !== undefined && CONTENT_SIZED_ROOTS.has(renderAs);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* How far below the stage the node carrying a root's content height sits.
|
|
161
|
+
*
|
|
162
|
+
* This is the one renderer-DOM assumption left in the SDK, so it is stated
|
|
163
|
+
* rather than inlined. The stage is our own node and is box-sized, so it is
|
|
164
|
+
* never the answer: measuring it would floor every result at the height the
|
|
165
|
+
* container already has and nothing could ever shrink. Its first child is the
|
|
166
|
+
* renderer's outer wrapper, also box-sized, for the same reason.
|
|
167
|
+
*
|
|
168
|
+
* Depth 2 — the wrapper's child — is the root render node, and for every root
|
|
169
|
+
* but one its `scrollHeight` is the content height.
|
|
170
|
+
*
|
|
171
|
+
* A `# dashboard` grid is the exception: its own wrapper is constrained, and
|
|
172
|
+
* the grid one level further down is what reports the height. That used to be
|
|
173
|
+
* spelled as a class-name check on the rendered DOM
|
|
174
|
+
* (`classList.contains("malloy-dashboard")`); it is keyed off `renderAs()` now,
|
|
175
|
+
* which is metadata the renderer publishes rather than markup it happens to
|
|
176
|
+
* emit.
|
|
177
|
+
*/
|
|
178
|
+
export function contentNodeDepth(renderAs: string | undefined): number {
|
|
179
|
+
return renderAs === "dashboard" ? 3 : 2;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The node under `stage` that carries the result's content height: `depth`
|
|
184
|
+
* first children down, or null if the renderer has not built that deep yet.
|
|
185
|
+
*
|
|
186
|
+
* This is the node measured AND the node watched for changes, so the two can
|
|
187
|
+
* never drift apart.
|
|
188
|
+
*
|
|
189
|
+
* Null rather than the deepest node available, which is the tempting fallback
|
|
190
|
+
* and is actively wrong. A DOM shallower than `depth` almost always means the
|
|
191
|
+
* renderer is still building, and the shallow nodes are its box-sized wrappers:
|
|
192
|
+
* answering with one reports the height the panel already has, which reads as a
|
|
193
|
+
* successful measurement, stops the retry, and leaves the observer watching a
|
|
194
|
+
* node whose size can never change. That is a `# big_value` tile stuck at its
|
|
195
|
+
* 400px cap with 264px of white under its numbers. Reporting nothing instead
|
|
196
|
+
* leaves the panel at its first-paint height and lets the caller measure again
|
|
197
|
+
* when the renderer mutates the DOM into its final shape.
|
|
198
|
+
*/
|
|
199
|
+
export function contentNode(
|
|
200
|
+
stage: HTMLElement,
|
|
201
|
+
depth: number,
|
|
202
|
+
): HTMLElement | null {
|
|
203
|
+
let node: HTMLElement | null = stage.firstElementChild as HTMLElement | null;
|
|
204
|
+
// Depth 1 is `node` itself; walk the remainder.
|
|
205
|
+
for (let level = 1; level < depth && node; level++) {
|
|
206
|
+
node = node.firstElementChild as HTMLElement | null;
|
|
207
|
+
}
|
|
208
|
+
return node;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Content height of the rendered result under `stage`, or 0 if the renderer
|
|
213
|
+
* has not built its final shape yet. See {@link contentNode}.
|
|
214
|
+
*
|
|
215
|
+
* `scrollHeight` is the CONTENT height, so this assumes the box adds no chrome
|
|
216
|
+
* of its own. True today: `.malloy-table.root` has no border, and a horizontal
|
|
217
|
+
* scrollbar costs no layout where scrollbars overlay. A wide table clipped by a
|
|
218
|
+
* few pixels on a platform that draws classic scrollbars would be this
|
|
219
|
+
* assumption breaking, and the fix is `+ (offsetHeight - clientHeight)`.
|
|
220
|
+
*/
|
|
221
|
+
export function measureContentHeight(
|
|
222
|
+
stage: HTMLElement,
|
|
223
|
+
depth: number,
|
|
224
|
+
): number {
|
|
225
|
+
const node = contentNode(stage, depth);
|
|
226
|
+
if (!node) return 0;
|
|
227
|
+
return node.scrollHeight || node.offsetHeight || 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Per-tile cap for a dashboard's composite form. A tile is one panel among
|
|
232
|
+
* several, so capping them keeps the grid even instead of letting one long
|
|
233
|
+
* table set the height of its whole row.
|
|
234
|
+
*/
|
|
235
|
+
export const TILE_MAX_HEIGHT = 400;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Cap for a notebook cell result that lays itself out: a table, mostly. Tall
|
|
239
|
+
* enough for a screenful of rows, after which the cell scrolls rather than the
|
|
240
|
+
* page turning into one long table.
|
|
241
|
+
*/
|
|
242
|
+
export const NOTEBOOK_CELL_MAX_HEIGHT = 700;
|
|
243
|
+
|
|
244
|
+
/** Cap for a query result shown inside a model page's cell. */
|
|
245
|
+
export const MODEL_CELL_MAX_HEIGHT = 600;
|
|
246
|
+
|
|
247
|
+
/** Cap for the results dialog, which gets most of a tall viewport. */
|
|
248
|
+
export const RESULTS_DIALOG_MAX_HEIGHT = 800;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Height for a container-sized root whose caller set no cap.
|
|
252
|
+
*
|
|
253
|
+
* A chart has no height of its own, so with nothing to measure and no cap to
|
|
254
|
+
* obey, something has to choose. This is that choice, and it is the same number
|
|
255
|
+
* a dashboard tile gets, so an uncapped chart reads like a tall tile rather
|
|
256
|
+
* than a page-height band.
|
|
257
|
+
*
|
|
258
|
+
* This is what closed the stretch: the single-query dashboard form used to ask
|
|
259
|
+
* for a 20000px "no cap" height, which a bare `# bar_chart` painted at, measured
|
|
260
|
+
* back off itself, and kept — 1992px for a two-row chart against 227px for the
|
|
261
|
+
* same query under a `# dashboard` grid. The cap is `undefined` now and a chart
|
|
262
|
+
* is never measured, so neither half of that can happen.
|
|
263
|
+
*/
|
|
264
|
+
export const UNCAPPED_CONTAINER_HEIGHT = 400;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Height to paint at before a content-sized result has been measured.
|
|
268
|
+
*
|
|
269
|
+
* A cap is also the first paint's height, because the measured height starts
|
|
270
|
+
* out equal to it. Harmless while every caller passes something viewport-sized
|
|
271
|
+
* (400 to 800); a caller that passes no cap needs a number that is not "as tall
|
|
272
|
+
* as you like".
|
|
273
|
+
*/
|
|
274
|
+
export const INITIAL_RENDER_HEIGHT = 2000;
|
|
275
|
+
|
|
276
|
+
/** First-paint height, before anything is known about the result. */
|
|
277
|
+
export function initialResultHeight(maxHeight: number | undefined): number {
|
|
278
|
+
return maxHeight === undefined
|
|
279
|
+
? INITIAL_RENDER_HEIGHT
|
|
280
|
+
: Math.min(maxHeight, INITIAL_RENDER_HEIGHT);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The height a result panel should paint at, given what is known so far.
|
|
285
|
+
*
|
|
286
|
+
* `maxHeight` is a CAP and `undefined` means uncapped — it is not a height
|
|
287
|
+
* request, which is why "no cap" is expressed by leaving it out rather than by
|
|
288
|
+
* passing a number big enough to mean the same thing.
|
|
289
|
+
*/
|
|
290
|
+
export function resolveResultHeight({
|
|
291
|
+
sizing,
|
|
292
|
+
contentHeight,
|
|
293
|
+
maxHeight,
|
|
294
|
+
}: {
|
|
295
|
+
sizing: ResultSizing | undefined;
|
|
296
|
+
contentHeight: number | undefined;
|
|
297
|
+
maxHeight: number | undefined;
|
|
298
|
+
}): number {
|
|
299
|
+
if (sizing === "container") {
|
|
300
|
+
return maxHeight ?? UNCAPPED_CONTAINER_HEIGHT;
|
|
301
|
+
}
|
|
302
|
+
if (contentHeight === undefined || contentHeight <= 0) {
|
|
303
|
+
return initialResultHeight(maxHeight);
|
|
304
|
+
}
|
|
305
|
+
return maxHeight === undefined
|
|
306
|
+
? contentHeight
|
|
307
|
+
: Math.min(maxHeight, contentHeight);
|
|
308
|
+
}
|
|
@@ -6,6 +6,7 @@ import { Dialog, DialogContent, DialogTitle, IconButton } from "@mui/material";
|
|
|
6
6
|
import { LogMessage } from "../client";
|
|
7
7
|
import type { DrillBinding } from "./drill";
|
|
8
8
|
import ResultContainer from "./RenderedResult/ResultContainer";
|
|
9
|
+
import { RESULTS_DIALOG_MAX_HEIGHT } from "./RenderedResult/resultSizing";
|
|
9
10
|
|
|
10
11
|
interface ResultsDialogProps {
|
|
11
12
|
open: boolean;
|
|
@@ -60,7 +61,7 @@ export default function ResultsDialog({
|
|
|
60
61
|
>
|
|
61
62
|
<ResultContainer
|
|
62
63
|
result={result}
|
|
63
|
-
maxHeight={
|
|
64
|
+
maxHeight={RESULTS_DIALOG_MAX_HEIGHT}
|
|
64
65
|
maxResultSize={1000000}
|
|
65
66
|
renderLogs={renderLogs}
|
|
66
67
|
drill={drill}
|
|
@@ -18,6 +18,7 @@ export {
|
|
|
18
18
|
type DrillField,
|
|
19
19
|
type DrillIntent,
|
|
20
20
|
type DrillNavigation,
|
|
21
|
+
type DrillRowsRequest,
|
|
21
22
|
type DrillTagReader,
|
|
22
23
|
} from "./resolveDrill";
|
|
23
24
|
export {
|
|
@@ -26,3 +27,8 @@ export {
|
|
|
26
27
|
type UseDrillOptions,
|
|
27
28
|
type UseDrillResult,
|
|
28
29
|
} from "./useDrill";
|
|
30
|
+
export {
|
|
31
|
+
useDrillSelf,
|
|
32
|
+
type UseDrillSelfOptions,
|
|
33
|
+
type UseDrillSelfResult,
|
|
34
|
+
} from "./useDrillSelf";
|