@malloy-publisher/sdk 0.3.0 → 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 +8 -0
- 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-CH71GsoL.cjs.js +1 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-X2Ma0HRs.es.js} +486 -521
- 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/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/Dashboard.d.ts +19 -14
- 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 +7 -3
- 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/DocumentStorageProvider.d.ts +7 -0
- package/dist/components/DocumentStorage/index.d.ts +1 -1
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +1 -0
- package/dist/components/drill/index.d.ts +1 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/index.d.ts +1 -0
- package/dist/components/styles.d.ts +0 -4
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +23 -270
- package/dist/index.es.js +16977 -41293
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +66 -123
- 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 +70 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
- 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/DocumentStorageProvider.tsx +12 -0
- package/src/components/DocumentStorage/index.ts +1 -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 +33 -72
- package/src/components/Notebook/Notebook.tsx +25 -88
- package/src/components/Notebook/NotebookCell.tsx +35 -183
- 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/ResultContainer.tsx +4 -12
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +1 -0
- package/src/components/drill/index.ts +1 -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/given/GivensPanel.tsx +1 -1
- package/src/components/index.ts +6 -0
- package/src/components/styles.ts +0 -37
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import { Prose } from "./Prose";
|
|
7
|
+
|
|
8
|
+
// Package content comes from untrusted git and S3 sources, so the one thing
|
|
9
|
+
// every surface that renders it has to agree on is what a link may do. These
|
|
10
|
+
// are that agreement, tested once against the one component that now renders
|
|
11
|
+
// prose everywhere; the notebook cell used to be the only surface that held
|
|
12
|
+
// to it.
|
|
13
|
+
|
|
14
|
+
describe("Prose: links", () => {
|
|
15
|
+
it("refuses a script-bearing href, keeping the text", () => {
|
|
16
|
+
render(
|
|
17
|
+
<Prose>
|
|
18
|
+
{"[run](javascript:alert(1)) and [d](data:text/html,x)"}
|
|
19
|
+
</Prose>,
|
|
20
|
+
);
|
|
21
|
+
expect(screen.getByText("run").getAttribute("href")).toBeNull();
|
|
22
|
+
expect(screen.getByText("d").getAttribute("href")).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("opens an external link in a new tab, disowning the opener", () => {
|
|
26
|
+
render(<Prose>{"[docs](https://example.com/docs)"}</Prose>);
|
|
27
|
+
const a = screen.getByText("docs");
|
|
28
|
+
expect(a.getAttribute("href")).toBe("https://example.com/docs");
|
|
29
|
+
expect(a.getAttribute("target")).toBe("_blank");
|
|
30
|
+
expect(a.getAttribute("rel")).toBe("noopener noreferrer");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("resolves a relative link against the source file, within the package", () => {
|
|
34
|
+
render(
|
|
35
|
+
<Prose
|
|
36
|
+
links={{
|
|
37
|
+
environmentName: "env",
|
|
38
|
+
packageName: "pkg",
|
|
39
|
+
sourcePath: "guides/intro.malloynb",
|
|
40
|
+
}}
|
|
41
|
+
>
|
|
42
|
+
{"[next](../sales.malloynb) [up](../../../etc/passwd)"}
|
|
43
|
+
</Prose>,
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByText("next").getAttribute("href")).toBe(
|
|
46
|
+
"/env/pkg/sales.malloynb",
|
|
47
|
+
);
|
|
48
|
+
// An escape past the package root is clamped at it, never above.
|
|
49
|
+
expect(screen.getByText("up").getAttribute("href")).toBe(
|
|
50
|
+
"/env/pkg/etc/passwd",
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("routes a resolved link through the host when it can", () => {
|
|
55
|
+
const onNavigate = mock((_to: string) => undefined);
|
|
56
|
+
render(
|
|
57
|
+
<Prose
|
|
58
|
+
links={{ environmentName: "env", packageName: "pkg", onNavigate }}
|
|
59
|
+
>
|
|
60
|
+
{"[readme](README.md)"}
|
|
61
|
+
</Prose>,
|
|
62
|
+
);
|
|
63
|
+
fireEvent.click(screen.getByText("readme"));
|
|
64
|
+
expect(onNavigate).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(onNavigate.mock.calls[0][0]).toBe("/env/pkg/README.md");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("leaves a relative link alone when it has no package to resolve against", () => {
|
|
69
|
+
render(<Prose>{"[here](./notes.md)"}</Prose>);
|
|
70
|
+
expect(screen.getByText("here").getAttribute("href")).toBe("./notes.md");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("Prose: variants", () => {
|
|
75
|
+
it("renders headings as headings in both, so structure survives", () => {
|
|
76
|
+
render(<Prose variant="document">{"# Title\n\nBody"}</Prose>);
|
|
77
|
+
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe(
|
|
78
|
+
"Title",
|
|
79
|
+
);
|
|
80
|
+
render(<Prose variant="caption">{"## Section\n\nBody"}</Prose>);
|
|
81
|
+
expect(screen.getByRole("heading", { level: 2 }).textContent).toBe(
|
|
82
|
+
"Section",
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -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
|
}
|
|
@@ -3,10 +3,11 @@
|
|
|
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";
|
|
12
13
|
import { resolveResultHeight, type ResultSizing } from "./resultSizing";
|
|
@@ -134,16 +135,7 @@ export default function ResultContainer({
|
|
|
134
135
|
title={renderLogSummary.title}
|
|
135
136
|
slotProps={{ tooltip: { sx: { whiteSpace: "pre-line" } } }}
|
|
136
137
|
>
|
|
137
|
-
<
|
|
138
|
-
size="small"
|
|
139
|
-
aria-label="Render tag warnings"
|
|
140
|
-
sx={{
|
|
141
|
-
backgroundColor: "rgba(255, 255, 255, 0.9)",
|
|
142
|
-
"&:hover": {
|
|
143
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
144
|
-
},
|
|
145
|
-
}}
|
|
146
|
-
>
|
|
138
|
+
<FloatingIconButton aria-label="Render tag warnings">
|
|
147
139
|
<InfoOutlinedIcon
|
|
148
140
|
fontSize="small"
|
|
149
141
|
color={
|
|
@@ -152,7 +144,7 @@ export default function ResultContainer({
|
|
|
152
144
|
: "warning"
|
|
153
145
|
}
|
|
154
146
|
/>
|
|
155
|
-
</
|
|
147
|
+
</FloatingIconButton>
|
|
156
148
|
</Tooltip>
|
|
157
149
|
</Box>
|
|
158
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
|
+
});
|
|
@@ -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
|
+
}
|
|
@@ -72,6 +72,27 @@ export interface DrillClickPayload {
|
|
|
72
72
|
* a modifier was held (cmd/ctrl to open in a new tab).
|
|
73
73
|
*/
|
|
74
74
|
event?: MouseEvent;
|
|
75
|
+
/**
|
|
76
|
+
* Where the click came from, as the host names it — for a dashboard, the
|
|
77
|
+
* tile expression whose result was clicked. Set by the host when it wraps
|
|
78
|
+
* a binding per tile; the renderer never fills it. What "the rows behind
|
|
79
|
+
* this value" runs against is read from here.
|
|
80
|
+
*/
|
|
81
|
+
context?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A click asking for the rows behind a value, on a surface that offers them.
|
|
86
|
+
* No tag is involved: any grouped value has rows behind it.
|
|
87
|
+
*/
|
|
88
|
+
export interface DrillRowsRequest {
|
|
89
|
+
/** The clicked field's name, as the result spells it. */
|
|
90
|
+
field: string;
|
|
91
|
+
rawValue: unknown;
|
|
92
|
+
/** The value as it read on screen. */
|
|
93
|
+
label: string;
|
|
94
|
+
/** {@link DrillClickPayload.context}, when the host set one. */
|
|
95
|
+
context?: string;
|
|
75
96
|
}
|
|
76
97
|
|
|
77
98
|
/** The literal `to=self`: filter the current view instead of leaving it. */
|
|
@@ -232,7 +253,7 @@ export function drillValueToFilter(value: unknown): string | undefined {
|
|
|
232
253
|
}
|
|
233
254
|
|
|
234
255
|
/** How the clicked value read on screen, for a menu label. */
|
|
235
|
-
function drillValueLabel(value: unknown): string {
|
|
256
|
+
export function drillValueLabel(value: unknown): string {
|
|
236
257
|
if (value instanceof Date) return drillValueToFilter(value) ?? "";
|
|
237
258
|
return String(value);
|
|
238
259
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { act, renderHook } from "@testing-library/react";
|
|
5
|
+
import { describe, expect, it, mock } from "bun:test";
|
|
6
|
+
import type { DrillField, DrillTagReader } from "./resolveDrill";
|
|
7
|
+
import { useDrill } from "./useDrill";
|
|
8
|
+
|
|
9
|
+
const tag = (drill?: { to: string[]; given?: string }): DrillTagReader => ({
|
|
10
|
+
tag: (...at: string[]) =>
|
|
11
|
+
drill && at[0] === "drill" ? tag(drill) : undefined,
|
|
12
|
+
text: (...at: string[]) =>
|
|
13
|
+
at[0] === "given"
|
|
14
|
+
? drill?.given
|
|
15
|
+
: at[0] === "to"
|
|
16
|
+
? drill?.to[0]
|
|
17
|
+
: undefined,
|
|
18
|
+
textArray: (...at: string[]) => (at[0] === "to" ? drill?.to : undefined),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const dimension = (
|
|
22
|
+
name: string,
|
|
23
|
+
drill?: { to: string[]; given?: string },
|
|
24
|
+
): DrillField => ({ name, tag: tag(drill), wasDimension: () => true });
|
|
25
|
+
const measure = (name: string): DrillField => ({
|
|
26
|
+
name,
|
|
27
|
+
tag: tag(),
|
|
28
|
+
wasDimension: () => false,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("useDrill: the rows behind a value", () => {
|
|
32
|
+
it("opens the rows for a grouped value that has no drill, and marks it clickable", () => {
|
|
33
|
+
const onRows = mock(() => {});
|
|
34
|
+
const { result } = renderHook(() => useDrill({ onRows }));
|
|
35
|
+
expect(result.current.drill.canDrill(dimension("cat"))).toBe(true);
|
|
36
|
+
expect(result.current.drill.canDrill(measure("revenue"))).toBe(false);
|
|
37
|
+
act(() =>
|
|
38
|
+
result.current.drill.onClick({
|
|
39
|
+
field: dimension("cat"),
|
|
40
|
+
value: "Jeans",
|
|
41
|
+
context: "overview -> by_cat",
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
expect(onRows).toHaveBeenCalledWith({
|
|
45
|
+
field: "cat",
|
|
46
|
+
rawValue: "Jeans",
|
|
47
|
+
label: "Jeans",
|
|
48
|
+
context: "overview -> by_cat",
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("does nothing for a header, a measure, or an empty cell", () => {
|
|
53
|
+
const onRows = mock(() => {});
|
|
54
|
+
const { result } = renderHook(() => useDrill({ onRows }));
|
|
55
|
+
act(() => {
|
|
56
|
+
result.current.drill.onClick({
|
|
57
|
+
field: dimension("cat"),
|
|
58
|
+
value: "Jeans",
|
|
59
|
+
isHeader: true,
|
|
60
|
+
});
|
|
61
|
+
result.current.drill.onClick({ field: measure("revenue"), value: 3 });
|
|
62
|
+
result.current.drill.onClick({ field: dimension("cat"), value: null });
|
|
63
|
+
});
|
|
64
|
+
expect(onRows).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("leaves a drilled value to its drill: one destination still navigates at once", () => {
|
|
68
|
+
const onRows = mock(() => {});
|
|
69
|
+
const onSelf = mock(() => {});
|
|
70
|
+
const { result } = renderHook(() => useDrill({ onRows, onSelf }));
|
|
71
|
+
act(() =>
|
|
72
|
+
result.current.drill.onClick({
|
|
73
|
+
field: dimension("cat", { to: ["self"], given: "CATEGORY" }),
|
|
74
|
+
value: "Jeans",
|
|
75
|
+
context: "overview -> by_cat",
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
expect(onSelf).toHaveBeenCalledWith("CATEGORY", "Jeans");
|
|
79
|
+
expect(onRows).not.toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("still navigates straight away when rows are not on offer", () => {
|
|
83
|
+
const onSelf = mock(() => {});
|
|
84
|
+
const { result } = renderHook(() => useDrill({ onSelf }));
|
|
85
|
+
expect(result.current.drill.canDrill(dimension("cat"))).toBe(false);
|
|
86
|
+
act(() =>
|
|
87
|
+
result.current.drill.onClick({
|
|
88
|
+
field: dimension("cat", { to: ["self"], given: "CATEGORY" }),
|
|
89
|
+
value: "Jeans",
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
expect(onSelf).toHaveBeenCalledWith("CATEGORY", "Jeans");
|
|
93
|
+
});
|
|
94
|
+
});
|