@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,179 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, type SxProps, type Theme } from "@mui/material";
|
|
5
|
+
import Markdown from "markdown-to-jsx";
|
|
6
|
+
import type { ReactNode } from "react";
|
|
7
|
+
import type { NavigationClick } from "./click_helper";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Markdown authored inside a package — a dashboard's `##"` description, a
|
|
11
|
+
* notebook's markdown cell, a README — rendered one way.
|
|
12
|
+
*
|
|
13
|
+
* Three surfaces each rendered it with their own style sheet, and only one of
|
|
14
|
+
* them guarded the links. Package content comes from untrusted git and S3
|
|
15
|
+
* sources, so a crafted `javascript:` or `data:` href in a README or a
|
|
16
|
+
* description must never run; the notebook cell knew this and the other two did
|
|
17
|
+
* not. Every link here goes through {@link ProseLink}.
|
|
18
|
+
*
|
|
19
|
+
* Two variants, because the prose plays two roles:
|
|
20
|
+
*
|
|
21
|
+
* - `document`: the prose IS the content — a notebook's markdown cells, read
|
|
22
|
+
* top to bottom. Full-size headings, reading-length lines.
|
|
23
|
+
* - `caption`: the prose sits under a title it must not compete with — a
|
|
24
|
+
* dashboard's description, a package's README card. Body size; headings are
|
|
25
|
+
* section labels within the block, at body size and bold.
|
|
26
|
+
*/
|
|
27
|
+
export type ProseVariant = "document" | "caption";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* How a relative link is resolved. Links in package content are authored
|
|
31
|
+
* relative to the SOURCE FILE (`spielberg.malloynb`), and a plain anchor
|
|
32
|
+
* resolves them against the page URL instead, which drops the package segment
|
|
33
|
+
* for a README shown at the package route. With this, a relative link resolves
|
|
34
|
+
* against the file's own directory and routes through the host.
|
|
35
|
+
*/
|
|
36
|
+
export interface ProseLinkContext {
|
|
37
|
+
environmentName: string;
|
|
38
|
+
packageName: string;
|
|
39
|
+
/** The file the prose came from, within the package; its directory is the base. */
|
|
40
|
+
sourcePath?: string;
|
|
41
|
+
/**
|
|
42
|
+
* SPA navigation for a resolved link. Omitted, the absolute href navigates on
|
|
43
|
+
* its own, so rendering prose needs no router context.
|
|
44
|
+
*/
|
|
45
|
+
onNavigate?: (to: string, event?: NavigationClick) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ProseProps {
|
|
49
|
+
children: string;
|
|
50
|
+
variant?: ProseVariant;
|
|
51
|
+
links?: ProseLinkContext;
|
|
52
|
+
sx?: SxProps<Theme>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const SAFE_SCHEME = /^(https?|mailto|tel):/i;
|
|
56
|
+
const HAS_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
57
|
+
|
|
58
|
+
function ProseLink({
|
|
59
|
+
href,
|
|
60
|
+
title,
|
|
61
|
+
children,
|
|
62
|
+
context,
|
|
63
|
+
}: {
|
|
64
|
+
href?: string;
|
|
65
|
+
title?: string;
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
context: ProseLinkContext | undefined;
|
|
68
|
+
}) {
|
|
69
|
+
const hasScheme = !!href && HAS_SCHEME.test(href);
|
|
70
|
+
const isRelative =
|
|
71
|
+
!!href && !hasScheme && !href.startsWith("/") && !href.startsWith("#");
|
|
72
|
+
|
|
73
|
+
if (!href || !isRelative || !context) {
|
|
74
|
+
// External, absolute, or hash: a normal anchor — but only over a safe
|
|
75
|
+
// scheme, so a crafted href cannot run script.
|
|
76
|
+
const unsafe = hasScheme && !SAFE_SCHEME.test(href ?? "");
|
|
77
|
+
return (
|
|
78
|
+
<a
|
|
79
|
+
href={unsafe ? undefined : href}
|
|
80
|
+
title={title}
|
|
81
|
+
{...(hasScheme
|
|
82
|
+
? { target: "_blank", rel: "noopener noreferrer" }
|
|
83
|
+
: {})}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</a>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Resolve against the source file's directory (empty for a package-root
|
|
91
|
+
// README) via a dummy origin, which normalises `./` and `../` and clamps
|
|
92
|
+
// escapes at the package root, then prefix the package path.
|
|
93
|
+
const sourceDir =
|
|
94
|
+
context.sourcePath && context.sourcePath.includes("/")
|
|
95
|
+
? context.sourcePath.slice(0, context.sourcePath.lastIndexOf("/") + 1)
|
|
96
|
+
: "";
|
|
97
|
+
const resolved = new URL(href, `https://malloy.invalid/${sourceDir}`);
|
|
98
|
+
const packageRelative =
|
|
99
|
+
resolved.pathname.slice(1) + resolved.search + resolved.hash;
|
|
100
|
+
const to = `/${context.environmentName}/${context.packageName}/${packageRelative}`;
|
|
101
|
+
const { onNavigate } = context;
|
|
102
|
+
return (
|
|
103
|
+
<a
|
|
104
|
+
href={to}
|
|
105
|
+
title={title}
|
|
106
|
+
onClick={
|
|
107
|
+
onNavigate
|
|
108
|
+
? (event) => {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
onNavigate(to, event);
|
|
111
|
+
}
|
|
112
|
+
: undefined
|
|
113
|
+
}
|
|
114
|
+
>
|
|
115
|
+
{children}
|
|
116
|
+
</a>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const STYLES: Record<ProseVariant, SxProps<Theme>> = {
|
|
121
|
+
document: {
|
|
122
|
+
"& h1, & h2, & h3, & h4, & h5, & h6": {
|
|
123
|
+
fontWeight: 600,
|
|
124
|
+
color: "text.primary",
|
|
125
|
+
mb: 1,
|
|
126
|
+
mt: 2,
|
|
127
|
+
},
|
|
128
|
+
"& h1": { fontSize: "28px" },
|
|
129
|
+
"& h2": { fontSize: "24px" },
|
|
130
|
+
"& h3": { fontSize: "20px" },
|
|
131
|
+
"& p, & ul, & ol": {
|
|
132
|
+
color: "text.primary",
|
|
133
|
+
lineHeight: 1.7,
|
|
134
|
+
mb: 1,
|
|
135
|
+
fontSize: "16px",
|
|
136
|
+
},
|
|
137
|
+
"& li": { mb: 0.5 },
|
|
138
|
+
},
|
|
139
|
+
caption: {
|
|
140
|
+
color: "text.secondary",
|
|
141
|
+
typography: "body2",
|
|
142
|
+
// The block starts flush under whatever titles it and ends flush against
|
|
143
|
+
// what follows, so a one-line caption sits where a plain line would and a
|
|
144
|
+
// longer one grows downward rather than pushing its title around.
|
|
145
|
+
"& > :first-of-type": { mt: 0 },
|
|
146
|
+
"& > :last-child": { mb: 0 },
|
|
147
|
+
// Headings in a caption are section labels within the block, not
|
|
148
|
+
// competitors to the title above it, so they stay at body size.
|
|
149
|
+
"& h1, & h2, & h3, & h4, & h5, & h6": {
|
|
150
|
+
fontSize: "inherit",
|
|
151
|
+
fontWeight: 600,
|
|
152
|
+
m: "0.5em 0 0.25em",
|
|
153
|
+
},
|
|
154
|
+
"& p": { m: "0.5em 0" },
|
|
155
|
+
"& ul, & ol": { m: "0.5em 0", pl: 3 },
|
|
156
|
+
"& code": { fontFamily: "monospace", fontSize: "0.9em" },
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export function Prose({
|
|
161
|
+
children,
|
|
162
|
+
variant = "caption",
|
|
163
|
+
links,
|
|
164
|
+
sx,
|
|
165
|
+
}: ProseProps) {
|
|
166
|
+
return (
|
|
167
|
+
<Box sx={[STYLES[variant], ...(Array.isArray(sx) ? sx : [sx])]}>
|
|
168
|
+
<Markdown
|
|
169
|
+
options={{
|
|
170
|
+
overrides: {
|
|
171
|
+
a: { component: ProseLink, props: { context: links } },
|
|
172
|
+
},
|
|
173
|
+
}}
|
|
174
|
+
>
|
|
175
|
+
{children}
|
|
176
|
+
</Markdown>
|
|
177
|
+
</Box>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
|
|
4
|
+
import { useQueryResult } from "../../hooks/useQueryResult";
|
|
6
5
|
import { parseResourceUri } from "../../utils/formatting";
|
|
7
|
-
import {
|
|
8
|
-
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
9
|
-
import { Loading } from "../Loading";
|
|
10
|
-
import ResultContainer from "../RenderedResult/ResultContainer";
|
|
11
|
-
import { useServer } from "../ServerProvider";
|
|
6
|
+
import { ResultPanel } from "../RenderedResult/ResultPanel";
|
|
12
7
|
|
|
13
8
|
interface QueryResultProps {
|
|
14
9
|
query?: string;
|
|
@@ -72,7 +67,6 @@ export default function QueryResult({
|
|
|
72
67
|
}: QueryResultProps) {
|
|
73
68
|
const { modelPath, environmentName, packageName, versionId } =
|
|
74
69
|
parseResourceUri(resourceUri);
|
|
75
|
-
const { apiClients } = useServer();
|
|
76
70
|
|
|
77
71
|
if (!environmentName || !packageName) {
|
|
78
72
|
throw new Error(
|
|
@@ -80,43 +74,21 @@ export default function QueryResult({
|
|
|
80
74
|
);
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
query: query,
|
|
92
|
-
sourceName: sourceName,
|
|
93
|
-
queryName: queryName,
|
|
94
|
-
versionId: versionId,
|
|
95
|
-
},
|
|
96
|
-
),
|
|
97
|
-
...CHART_RESULT_QUERY_OPTIONS,
|
|
77
|
+
const state = useQueryResult({
|
|
78
|
+
environmentName,
|
|
79
|
+
packageName,
|
|
80
|
+
modelPath,
|
|
81
|
+
versionId,
|
|
82
|
+
query,
|
|
83
|
+
sourceName,
|
|
84
|
+
queryName,
|
|
98
85
|
});
|
|
99
86
|
|
|
100
87
|
return (
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<Suspense fallback={<div>Loading...</div>}>
|
|
107
|
-
<ResultContainer
|
|
108
|
-
result={data.data.result}
|
|
109
|
-
maxHeight={height}
|
|
110
|
-
renderLogs={data.data.renderLogs}
|
|
111
|
-
/>
|
|
112
|
-
</Suspense>
|
|
113
|
-
)}
|
|
114
|
-
{isError && (
|
|
115
|
-
<ApiErrorDisplay
|
|
116
|
-
context={`${environmentName} > ${packageName} > ${modelPath}`}
|
|
117
|
-
error={error}
|
|
118
|
-
/>
|
|
119
|
-
)}
|
|
120
|
-
</>
|
|
88
|
+
<ResultPanel
|
|
89
|
+
state={state}
|
|
90
|
+
context={`${environmentName} > ${packageName} > ${modelPath}`}
|
|
91
|
+
maxHeight={height}
|
|
92
|
+
/>
|
|
121
93
|
);
|
|
122
94
|
}
|
|
@@ -17,6 +17,14 @@ import {
|
|
|
17
17
|
type DashboardCardGeometry,
|
|
18
18
|
} from "../../theme/buildTableCssVars";
|
|
19
19
|
import { buildVegaThemeOverride } from "../../theme/buildVegaThemeOverride";
|
|
20
|
+
import {
|
|
21
|
+
contentNode,
|
|
22
|
+
contentNodeDepth,
|
|
23
|
+
measureContentHeight,
|
|
24
|
+
remeasuresAfterReady,
|
|
25
|
+
resultSizing,
|
|
26
|
+
type ResultSizing,
|
|
27
|
+
} from "./resultSizing";
|
|
20
28
|
import { readChartAnnotations } from "../../theme/readChartAnnotations";
|
|
21
29
|
import { resolveTheme } from "../../theme/resolveTheme";
|
|
22
30
|
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
@@ -41,11 +49,17 @@ type MalloyRenderElement = HTMLElement & Record<string, unknown>;
|
|
|
41
49
|
*/
|
|
42
50
|
interface MalloyVizHandle extends DrillMetadataSource {
|
|
43
51
|
// Narrowed from `DrillMetadataSource`, which only declares the part the
|
|
44
|
-
// drill affordance reads. `getRootField().renderAs()` is what
|
|
45
|
-
//
|
|
52
|
+
// drill affordance reads. `getRootField().renderAs()` is what every sizing
|
|
53
|
+
// decision keys off; see `./resultSizing`.
|
|
46
54
|
getMetadata: () =>
|
|
47
55
|
| (NonNullable<ReturnType<DrillMetadataSource["getMetadata"]>> & {
|
|
48
|
-
getRootField: () => { renderAs: () => string };
|
|
56
|
+
getRootField: () => { renderAs: () => string; key: string };
|
|
57
|
+
// The root's render plugin, whose `sizingStrategy` is the renderer's
|
|
58
|
+
// own answer to whether the result fills its box; see
|
|
59
|
+
// `./resultSizing`. A table or a `# dashboard` grid has none.
|
|
60
|
+
getPluginsForField: (
|
|
61
|
+
key: string,
|
|
62
|
+
) => Array<{ sizingStrategy?: string }> | undefined;
|
|
49
63
|
})
|
|
50
64
|
| null
|
|
51
65
|
| undefined;
|
|
@@ -74,7 +88,18 @@ interface RenderedResultProps {
|
|
|
74
88
|
result: string;
|
|
75
89
|
height?: number;
|
|
76
90
|
isFillElement?: (boolean) => void;
|
|
91
|
+
/**
|
|
92
|
+
* The measured content height. Fires only for a content-sized root; a
|
|
93
|
+
* container-sized one has no height of its own to report. See
|
|
94
|
+
* {@link resultSizing}.
|
|
95
|
+
*/
|
|
77
96
|
onSizeChange?: (height: number) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Which sizing rule the rendered root follows, as soon as the renderer's
|
|
99
|
+
* metadata says. Lets a caller stop treating its cap as a height for a
|
|
100
|
+
* result that will never report one.
|
|
101
|
+
*/
|
|
102
|
+
onSizing?: (sizing: ResultSizing) => void;
|
|
78
103
|
/**
|
|
79
104
|
* Makes `# drill` cells clickable, and makes them look it. From `useDrill`
|
|
80
105
|
* on the host surface, which decides where a click may go; omitted where
|
|
@@ -328,48 +353,12 @@ function injectRendererOverrides(): void {
|
|
|
328
353
|
document.head.appendChild(style);
|
|
329
354
|
}
|
|
330
355
|
|
|
331
|
-
/**
|
|
332
|
-
* Whether the renderer's top-level output sizes itself to its CONTENT rather
|
|
333
|
-
* than to the box it was handed, which decides whether measuring it once is
|
|
334
|
-
* enough.
|
|
335
|
-
*
|
|
336
|
-
* It is not, for a table. The renderer signals `onReady` as soon as it knows it
|
|
337
|
-
* can paint, and for a table that is immediately — a chart waits for a non-zero
|
|
338
|
-
* parent size, a table does not — so the single measurement taken there lands
|
|
339
|
-
* before the table's virtualized grid has laid out, and reads a height the
|
|
340
|
-
* table never keeps.
|
|
341
|
-
*
|
|
342
|
-
* Re-measuring a table TERMINATES: `.malloy-table.root` is
|
|
343
|
-
* `height: fit-content; max-height: 100%` in the renderer's own CSS and the
|
|
344
|
-
* wrappers between it and the container add no padding, so shrinking the
|
|
345
|
-
* container to the table's content height is the exact point at which the cap
|
|
346
|
-
* stops binding and the next measurement reports the same number.
|
|
347
|
-
*
|
|
348
|
-
* A root that FILLS its container stays on the one-shot path deliberately: a
|
|
349
|
-
* chart draws itself inset from the box it is given, so feeding its height back
|
|
350
|
-
* as the new container height would ratchet the container down by that inset
|
|
351
|
-
* every pass and never converge.
|
|
352
|
-
*
|
|
353
|
-
* A table is the only root that needs this, and the reason is the virtualized
|
|
354
|
-
* grid rather than the sizing strategy it shares with a `# size=` chart: that
|
|
355
|
-
* chart takes its dimensions from a lookup synchronously, so its first
|
|
356
|
-
* measurement is already right. Measured, for every size value and spelling.
|
|
357
|
-
*/
|
|
358
|
-
function sizesToContent(viz: MalloyVizHandle): boolean {
|
|
359
|
-
try {
|
|
360
|
-
return viz.getMetadata()?.getRootField().renderAs() === "table";
|
|
361
|
-
} catch {
|
|
362
|
-
// Metadata unavailable: measure once, which is the behavior every
|
|
363
|
-
// non-table root gets anyway.
|
|
364
|
-
return false;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
356
|
function RenderedResultInner({
|
|
369
357
|
result,
|
|
370
358
|
height: inputHeight,
|
|
371
359
|
drill,
|
|
372
360
|
onSizeChange,
|
|
361
|
+
onSizing,
|
|
373
362
|
}: RenderedResultProps) {
|
|
374
363
|
const ref = useRef<HTMLDivElement>(null);
|
|
375
364
|
// The renderer binds its click handler at construction, so a changing
|
|
@@ -469,38 +458,29 @@ function RenderedResultInner({
|
|
|
469
458
|
|
|
470
459
|
hasMeasuredRef.current = false;
|
|
471
460
|
|
|
472
|
-
//
|
|
473
|
-
//
|
|
474
|
-
//
|
|
461
|
+
// What the renderer says it is rendering, read once from its metadata
|
|
462
|
+
// after `setResult`. Every height decision below keys off this rather
|
|
463
|
+
// than off the DOM the renderer went on to build; see `./resultSizing`.
|
|
464
|
+
let renderAs: string | undefined;
|
|
465
|
+
let strategy: string | undefined;
|
|
466
|
+
|
|
467
|
+
// Measure the rendered result's content height off `root` (the stage
|
|
468
|
+
// that wraps the renderer output) and report it up.
|
|
475
469
|
const measureRenderedSize = (root: HTMLElement) => {
|
|
476
470
|
if (cancelled || !root.firstElementChild) return;
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
//
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
// fix is `+ (offsetHeight - clientHeight)`.
|
|
491
|
-
let renderedHeight =
|
|
492
|
-
grandchild.scrollHeight || grandchild.offsetHeight || 0;
|
|
493
|
-
|
|
494
|
-
// HACK - malloy dashboards height are determined by the greatgrandchild.
|
|
495
|
-
if (
|
|
496
|
-
greatgrandchild &&
|
|
497
|
-
grandchild.classList.contains("malloy-dashboard")
|
|
498
|
-
) {
|
|
499
|
-
renderedHeight =
|
|
500
|
-
greatgrandchild.scrollHeight ||
|
|
501
|
-
greatgrandchild.offsetHeight ||
|
|
502
|
-
0;
|
|
503
|
-
}
|
|
471
|
+
// A chart fills the box it is handed, so measuring one reports back
|
|
472
|
+
// the height we just gave it. Nothing to learn, and reporting it is
|
|
473
|
+
// what used to ratchet an uncapped chart to its first-paint height.
|
|
474
|
+
if (resultSizing(renderAs, strategy) === "container") return;
|
|
475
|
+
// A content-sized root keeps being measured after the first height
|
|
476
|
+
// lands, because the first one races the renderer's layout.
|
|
477
|
+
const remeasures = remeasuresAfterReady(renderAs, strategy);
|
|
478
|
+
if (hasMeasuredRef.current && !remeasures) return;
|
|
479
|
+
|
|
480
|
+
const renderedHeight = measureContentHeight(
|
|
481
|
+
root,
|
|
482
|
+
contentNodeDepth(renderAs),
|
|
483
|
+
);
|
|
504
484
|
|
|
505
485
|
if (renderedHeight > 0) {
|
|
506
486
|
hasMeasuredRef.current = true;
|
|
@@ -509,14 +489,16 @@ function RenderedResultInner({
|
|
|
509
489
|
onSizeChange(renderedHeight);
|
|
510
490
|
}
|
|
511
491
|
}
|
|
512
|
-
// Watch
|
|
513
|
-
// rather than at render time because the node does not
|
|
514
|
-
// the renderer builds it, and this is the callback that
|
|
515
|
-
|
|
516
|
-
|
|
492
|
+
// Watch that same node from here on. Attached after the first
|
|
493
|
+
// measurement rather than at render time because the node does not
|
|
494
|
+
// exist until the renderer builds it, and this is the callback that
|
|
495
|
+
// first sees it.
|
|
496
|
+
const measured = contentNode(root, contentNodeDepth(renderAs));
|
|
497
|
+
if (remeasures && measured && observedNode !== measured) {
|
|
498
|
+
observedNode = measured;
|
|
517
499
|
sizeObserver?.disconnect();
|
|
518
500
|
sizeObserver = new ResizeObserver(() => measureRenderedSize(root));
|
|
519
|
-
sizeObserver.observe(
|
|
501
|
+
sizeObserver.observe(measured);
|
|
520
502
|
}
|
|
521
503
|
};
|
|
522
504
|
|
|
@@ -626,6 +608,33 @@ function RenderedResultInner({
|
|
|
626
608
|
// The renderer accepts a Malloy Result; we don't import that type
|
|
627
609
|
// in the SDK to avoid pinning to the malloy core types here.
|
|
628
610
|
viz.setResult(parsed);
|
|
611
|
+
// Read the root's render type before painting, so the first
|
|
612
|
+
// measurement already knows whether it is worth taking. Metadata is
|
|
613
|
+
// complete as soon as the result is set; the DOM is not.
|
|
614
|
+
try {
|
|
615
|
+
const metadata = viz.getMetadata();
|
|
616
|
+
const root = metadata?.getRootField();
|
|
617
|
+
renderAs = root?.renderAs();
|
|
618
|
+
// The plugin's own `sizingStrategy`, which decides this outright
|
|
619
|
+
// where there is one. Read from the PLUGIN; the field entry's
|
|
620
|
+
// `renderProperties.sizingStrategy` reads "fit" for every root.
|
|
621
|
+
strategy = root
|
|
622
|
+
? metadata?.getPluginsForField(root.key)?.[0]?.sizingStrategy
|
|
623
|
+
: undefined;
|
|
624
|
+
} catch {
|
|
625
|
+
// Metadata unavailable: fall through to the content-sized
|
|
626
|
+
// default, which is what every root got before this existed.
|
|
627
|
+
renderAs = undefined;
|
|
628
|
+
strategy = undefined;
|
|
629
|
+
}
|
|
630
|
+
onSizing?.(resultSizing(renderAs, strategy));
|
|
631
|
+
// Published on the stage because every sizing decision keys off it
|
|
632
|
+
// and nothing else in the DOM says what it was. A panel at an
|
|
633
|
+
// unexpected height is otherwise a guessing game about which rule
|
|
634
|
+
// applied, and the rule is chosen from a vocabulary — plugin names
|
|
635
|
+
// — that the rendered markup does not spell out anywhere.
|
|
636
|
+
stage.dataset.malloyRenderAs = renderAs ?? "unknown";
|
|
637
|
+
stage.dataset.malloySizing = resultSizing(renderAs, strategy);
|
|
629
638
|
viz.render(stage);
|
|
630
639
|
|
|
631
640
|
// Mark the cells a `# drill` makes clickable, so they read as
|
|
@@ -876,6 +885,7 @@ function RenderedResultInner({
|
|
|
876
885
|
handleDrillClick,
|
|
877
886
|
drillable,
|
|
878
887
|
onSizeChange,
|
|
888
|
+
onSizing,
|
|
879
889
|
baseTheme,
|
|
880
890
|
layers,
|
|
881
891
|
mode,
|
|
@@ -3,18 +3,26 @@
|
|
|
3
3
|
|
|
4
4
|
import { Warning } from "@mui/icons-material";
|
|
5
5
|
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
6
|
-
import { Box, Button,
|
|
6
|
+
import { Box, Button, Tooltip, Typography } from "@mui/material";
|
|
7
7
|
import { lazy, Suspense, useRef, useState } from "react";
|
|
8
8
|
import { LogMessage } from "../../client";
|
|
9
9
|
import type { DrillBinding } from "../drill/useDrill";
|
|
10
|
+
import { FloatingIconButton } from "../FloatingIconButton";
|
|
10
11
|
import { Loading } from "../Loading";
|
|
11
12
|
import { summarizeRenderLogs } from "./renderLogs";
|
|
13
|
+
import { resolveResultHeight, type ResultSizing } from "./resultSizing";
|
|
12
14
|
|
|
13
15
|
const RenderedResult = lazy(() => import("../RenderedResult/RenderedResult"));
|
|
14
16
|
|
|
15
17
|
interface ResultContainerProps {
|
|
16
18
|
result: string | undefined;
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Cap on the panel's height. A CAP, not a height request: a result shorter
|
|
21
|
+
* than this paints at its own height. Leave it out for no cap, which is what
|
|
22
|
+
* the single-query dashboard form wants — a result that IS the page should
|
|
23
|
+
* not be clipped to tidy it.
|
|
24
|
+
*/
|
|
25
|
+
maxHeight?: number;
|
|
18
26
|
// if Results are larger than this size, show a warning and a button to proceed
|
|
19
27
|
// this is to prevent performance issues with large results.
|
|
20
28
|
// the default is 0, which means no warning will be shown.
|
|
@@ -28,24 +36,6 @@ interface ResultContainerProps {
|
|
|
28
36
|
drill?: DrillBinding;
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
/**
|
|
32
|
-
* Height to paint at before the result has been measured.
|
|
33
|
-
*
|
|
34
|
-
* `maxHeight` is a CAP, but it was also the first paint's height, because the
|
|
35
|
-
* measured height starts out equal to it. That was harmless while every caller
|
|
36
|
-
* passed something viewport-sized (400 to 800). A caller that means "no cap"
|
|
37
|
-
* passes a number that is not a height anyone wants to see: the dashboard
|
|
38
|
-
* viewer's whole-page form passes 20000, so the panel painted twenty thousand
|
|
39
|
-
* pixels tall until the measurement landed, and a result the renderer sizes to
|
|
40
|
-
* its CONTAINER (a top-level chart, as opposed to a `# dashboard` grid, which
|
|
41
|
-
* reports its own height) measured that back and kept it.
|
|
42
|
-
*
|
|
43
|
-
* Bounded here rather than by lowering the cap, so "no cap" stays expressible.
|
|
44
|
-
* Above the cap it does nothing, which is every caller that passes a real
|
|
45
|
-
* height, so this changes nothing for them.
|
|
46
|
-
*/
|
|
47
|
-
const INITIAL_RENDER_HEIGHT = 2000;
|
|
48
|
-
|
|
49
39
|
// ResultContainer is a component that renders a result, with a toggle button to expand/collapse the result.
|
|
50
40
|
// For fill-elements, the result is rendered at minHeight, and the toggle button is shown to scale up to maxHeight.
|
|
51
41
|
// For non-fill-elements, the result is rendered at explicitHeight, with a small window (minHeight) that can be expanded to maxHeight.
|
|
@@ -58,8 +48,12 @@ export default function ResultContainer({
|
|
|
58
48
|
drill,
|
|
59
49
|
}: ResultContainerProps) {
|
|
60
50
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
// Both start unknown and are filled in by the render: `sizing` as soon as
|
|
52
|
+
// the renderer's metadata is read, `contentHeight` only if the root has one
|
|
53
|
+
// to report. `resolveResultHeight` owns what to paint at each stage.
|
|
54
|
+
const [sizing, setSizing] = useState<ResultSizing | undefined>(undefined);
|
|
55
|
+
const [contentHeight, setContentHeight] = useState<number | undefined>(
|
|
56
|
+
undefined,
|
|
63
57
|
);
|
|
64
58
|
const [userAcknowledged, setUserAcknowledged] = useState(false);
|
|
65
59
|
const renderLogSummary = summarizeRenderLogs(renderLogs);
|
|
@@ -104,8 +98,11 @@ export default function ResultContainer({
|
|
|
104
98
|
}
|
|
105
99
|
|
|
106
100
|
const loading = <Loading text="Loading..." centered={true} size={32} />;
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
const renderedHeight = resolveResultHeight({
|
|
102
|
+
sizing,
|
|
103
|
+
contentHeight,
|
|
104
|
+
maxHeight,
|
|
105
|
+
});
|
|
109
106
|
|
|
110
107
|
return (
|
|
111
108
|
<Box
|
|
@@ -123,7 +120,8 @@ export default function ResultContainer({
|
|
|
123
120
|
<RenderedResult
|
|
124
121
|
result={result}
|
|
125
122
|
height={renderedHeight}
|
|
126
|
-
onSizeChange={
|
|
123
|
+
onSizeChange={setContentHeight}
|
|
124
|
+
onSizing={setSizing}
|
|
127
125
|
drill={drill}
|
|
128
126
|
/>
|
|
129
127
|
</Suspense>
|
|
@@ -137,16 +135,7 @@ export default function ResultContainer({
|
|
|
137
135
|
title={renderLogSummary.title}
|
|
138
136
|
slotProps={{ tooltip: { sx: { whiteSpace: "pre-line" } } }}
|
|
139
137
|
>
|
|
140
|
-
<
|
|
141
|
-
size="small"
|
|
142
|
-
aria-label="Render tag warnings"
|
|
143
|
-
sx={{
|
|
144
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
145
|
-
"&:hover": {
|
|
146
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
147
|
-
},
|
|
148
|
-
}}
|
|
149
|
-
>
|
|
138
|
+
<FloatingIconButton aria-label="Render tag warnings">
|
|
150
139
|
<InfoOutlinedIcon
|
|
151
140
|
fontSize="small"
|
|
152
141
|
color={
|
|
@@ -155,7 +144,7 @@ export default function ResultContainer({
|
|
|
155
144
|
: "warning"
|
|
156
145
|
}
|
|
157
146
|
/>
|
|
158
|
-
</
|
|
147
|
+
</FloatingIconButton>
|
|
159
148
|
</Tooltip>
|
|
160
149
|
</Box>
|
|
161
150
|
)}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { render, screen } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it } from "bun:test";
|
|
6
|
+
import type { QueryResultState } from "../../hooks/useQueryResult";
|
|
7
|
+
import { ResultPanel } from "./ResultPanel";
|
|
8
|
+
|
|
9
|
+
// The two states short of a result, which every query surface used to draw
|
|
10
|
+
// for itself — and one of them (the model cell) not at all. The result state
|
|
11
|
+
// goes through `ResultContainer`, which has its own coverage and lazy-loads
|
|
12
|
+
// the renderer, so it is not driven from here.
|
|
13
|
+
|
|
14
|
+
const stateOf = (partial: Partial<QueryResultState>) =>
|
|
15
|
+
({ isSuccess: false, isError: false, ...partial }) as QueryResultState;
|
|
16
|
+
|
|
17
|
+
describe("ResultPanel", () => {
|
|
18
|
+
it("says it is running until the query answers", () => {
|
|
19
|
+
render(<ResultPanel state={stateOf({})} context="orders -> by_month" />);
|
|
20
|
+
expect(screen.getByText("Running…")).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("takes the caller's words for the wait", () => {
|
|
24
|
+
render(
|
|
25
|
+
<ResultPanel
|
|
26
|
+
state={stateOf({})}
|
|
27
|
+
context="orders -> by_month"
|
|
28
|
+
loadingText="Fetching…"
|
|
29
|
+
/>,
|
|
30
|
+
);
|
|
31
|
+
expect(screen.getByText("Fetching…")).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("shows a refused query's reason, and what was asked", () => {
|
|
35
|
+
const error = Object.assign(new Error("refused"), {
|
|
36
|
+
status: 400,
|
|
37
|
+
data: { code: 400, message: "filter 'state' is required" },
|
|
38
|
+
});
|
|
39
|
+
render(
|
|
40
|
+
<ResultPanel
|
|
41
|
+
state={stateOf({ isError: true, error })}
|
|
42
|
+
context="orders -> by_month"
|
|
43
|
+
/>,
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByText("filter 'state' is required")).toBeDefined();
|
|
46
|
+
expect(screen.getByText("orders -> by_month")).toBeDefined();
|
|
47
|
+
expect(screen.queryByText("Running…")).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
});
|