@malloy-publisher/sdk 0.12.0 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -6
- package/dist/{RenderedResult-SgDlxzs9.cjs.js → RenderedResult-Cgw4iqev.cjs.js} +1 -1
- package/dist/{RenderedResult-D8bCgThO.es.js → RenderedResult-DEjFM1DL.es.js} +2 -2
- package/dist/ServerProvider-BRQl_cBo.cjs.js +1 -0
- package/dist/{ServerProvider-DBw-thY0.es.js → ServerProvider-RnliA2Ao.es.js} +1084 -723
- package/dist/builder/index.cjs.js +1 -1
- package/dist/builder/index.es.js +3 -3
- package/dist/client/api.d.ts +754 -41
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +120 -110
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +16 -1
- package/dist/components/Model/ExplorerPage.d.ts +9 -0
- package/dist/components/Model/Model.d.ts +27 -11
- package/dist/components/ModelViewer/AccessChips.d.ts +34 -0
- package/dist/components/ModelViewer/EmptyRow.d.ts +23 -0
- package/dist/components/ModelViewer/Facts.d.ts +15 -0
- package/dist/components/ModelViewer/FieldGroup.d.ts +31 -0
- package/dist/components/ModelViewer/FieldRow.d.ts +69 -0
- package/dist/components/ModelViewer/GivenFacts.d.ts +21 -0
- package/dist/components/ModelViewer/HeaderBar.d.ts +75 -0
- package/dist/components/ModelViewer/InlineDoc.d.ts +13 -0
- package/dist/components/ModelViewer/ModelGivensSection.d.ts +32 -0
- package/dist/components/ModelViewer/ModelSection.d.ts +21 -0
- package/dist/components/ModelViewer/ModelViewer.d.ts +91 -0
- package/dist/components/ModelViewer/QueriesGroup.d.ts +15 -0
- package/dist/components/ModelViewer/RowGlyph.d.ts +27 -0
- package/dist/components/ModelViewer/RunResult.d.ts +46 -0
- package/dist/components/ModelViewer/SampleValues.d.ts +20 -0
- package/dist/components/ModelViewer/SchemaJoin.d.ts +51 -0
- package/dist/components/ModelViewer/SchemaView.d.ts +52 -0
- package/dist/components/ModelViewer/SegmentIcons.d.ts +70 -0
- package/dist/components/ModelViewer/SourcesDropdown.d.ts +53 -0
- package/dist/components/ModelViewer/SourcesNav.d.ts +25 -0
- package/dist/components/ModelViewer/StatusPill.d.ts +56 -0
- package/dist/components/ModelViewer/ValueChip.d.ts +17 -0
- package/dist/components/ModelViewer/ViewRow.d.ts +36 -0
- package/dist/components/ModelViewer/clickableBox.d.ts +29 -0
- package/dist/components/ModelViewer/codeDisplay.d.ts +44 -0
- package/dist/components/ModelViewer/docAnnotations.d.ts +90 -0
- package/dist/components/ModelViewer/explorerModel.d.ts +12 -0
- package/dist/components/ModelViewer/extensions.d.ts +94 -0
- package/dist/components/ModelViewer/fieldCode.d.ts +74 -0
- package/dist/components/ModelViewer/fieldEntities.d.ts +45 -0
- package/dist/components/ModelViewer/fieldExpansion.d.ts +41 -0
- package/dist/components/ModelViewer/givenUsage.d.ts +71 -0
- package/dist/components/ModelViewer/headerCard.d.ts +31 -0
- package/dist/components/ModelViewer/httpStatus.d.ts +4 -0
- package/dist/components/ModelViewer/icons.d.ts +31 -0
- package/dist/components/ModelViewer/index.d.ts +9 -0
- package/dist/components/ModelViewer/joinAccess.d.ts +52 -0
- package/dist/components/ModelViewer/malloyRunText.d.ts +22 -0
- package/dist/components/ModelViewer/malloyText.d.ts +21 -0
- package/dist/components/ModelViewer/modelGivens.d.ts +61 -0
- package/dist/components/ModelViewer/modelGivensContext.d.ts +9 -0
- package/dist/components/ModelViewer/modelHeaderPresentation.d.ts +28 -0
- package/dist/components/ModelViewer/modelTextDeclarations.d.ts +32 -0
- package/dist/components/ModelViewer/modelTextParse.d.ts +27 -0
- package/dist/components/ModelViewer/namedQueryCode.d.ts +12 -0
- package/dist/components/ModelViewer/offSurface.d.ts +54 -0
- package/dist/components/ModelViewer/rowLayers.d.ts +30 -0
- package/dist/components/ModelViewer/runGate.d.ts +49 -0
- package/dist/components/ModelViewer/schemaModel.d.ts +109 -0
- package/dist/components/ModelViewer/sectionOpenCommand.d.ts +45 -0
- package/dist/components/ModelViewer/sourceAccess.d.ts +67 -0
- package/dist/components/ModelViewer/sourceLineage.d.ts +14 -0
- package/dist/components/ModelViewer/sourcePicker.d.ts +66 -0
- package/dist/components/ModelViewer/surface.d.ts +47 -0
- package/dist/components/ModelViewer/text.d.ts +6 -0
- package/dist/components/ModelViewer/theme.d.ts +63 -0
- package/dist/components/ModelViewer/tokens.d.ts +52 -0
- package/dist/components/ModelViewer/ui.d.ts +48 -0
- package/dist/components/ModelViewer/useDimensionSamples.d.ts +76 -0
- package/dist/components/ModelViewer/useModelSources.d.ts +92 -0
- package/dist/components/ModelViewer/useRunQuery.d.ts +115 -0
- package/dist/components/ReportBuilder/loadMalloy.d.ts +4 -0
- package/dist/components/ServerProvider.d.ts +17 -2
- package/dist/components/filter/utils.d.ts +1 -1
- package/dist/components/given/GivenInput.d.ts +7 -1
- package/dist/components/given/GivensPanel.d.ts +3 -1
- package/dist/components/given/filterSummary.d.ts +6 -0
- package/dist/components/given/useGivenUrlParams.d.ts +11 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/modelPage.d.ts +36 -0
- package/dist/hooks/useDimensionalFilterRangeData.d.ts +9 -0
- package/dist/hooks/useSuggestOptions.d.ts +26 -2
- package/dist/index.cjs.js +47 -19
- package/dist/index.es.js +14137 -9697
- package/dist/useCompiledDocument-D88_2cGS.cjs.js +143 -0
- package/dist/{useCompiledDocument-CXMPtJkJ.es.js → useCompiledDocument-Dmm6xkom.es.js} +6975 -6893
- package/dist/utils/filterCondition.d.ts +14 -0
- package/dist/utils/malloyLiteral.d.ts +20 -1
- package/package.json +2 -2
- package/src/components/Materializations/MaterializationDetailDialog.tsx +33 -7
- package/src/components/Materializations/Materializations.tsx +47 -4
- package/src/components/Materializations/Materializations.versions.spec.tsx +140 -1
- package/src/components/Model/ExplorerPage.tsx +269 -0
- package/src/components/Model/Model.tsx +66 -250
- package/src/components/Model/ModelExplorer.spec.tsx +64 -1
- package/src/components/ModelViewer/AccessChips.tsx +149 -0
- package/src/components/ModelViewer/EmptyRow.tsx +71 -0
- package/src/components/ModelViewer/Facts.tsx +46 -0
- package/src/components/ModelViewer/FieldGroup.tsx +137 -0
- package/src/components/ModelViewer/FieldRow.tsx +566 -0
- package/src/components/ModelViewer/GivenFacts.tsx +89 -0
- package/src/components/ModelViewer/HeaderBar.tsx +362 -0
- package/src/components/ModelViewer/InlineDoc.tsx +50 -0
- package/src/components/ModelViewer/ModelGivensSection.tsx +142 -0
- package/src/components/ModelViewer/ModelSection.tsx +98 -0
- package/src/components/ModelViewer/ModelViewer.spec.tsx +937 -0
- package/src/components/ModelViewer/ModelViewer.tsx +777 -0
- package/src/components/ModelViewer/QueriesGroup.tsx +107 -0
- package/src/components/ModelViewer/RowGlyph.tsx +138 -0
- package/src/components/ModelViewer/RunResult.tsx +298 -0
- package/src/components/ModelViewer/SampleValues.tsx +97 -0
- package/src/components/ModelViewer/SchemaJoin.tsx +258 -0
- package/src/components/ModelViewer/SchemaView.tsx +222 -0
- package/src/components/ModelViewer/SegmentIcons.tsx +129 -0
- package/src/components/ModelViewer/SourcesDropdown.tsx +265 -0
- package/src/components/ModelViewer/SourcesNav.tsx +75 -0
- package/src/components/ModelViewer/StatusPill.tsx +145 -0
- package/src/components/ModelViewer/ValueChip.tsx +39 -0
- package/src/components/ModelViewer/ViewRow.tsx +274 -0
- package/src/components/ModelViewer/clickableBox.ts +59 -0
- package/src/components/ModelViewer/codeDisplay.spec.ts +176 -0
- package/src/components/ModelViewer/codeDisplay.ts +118 -0
- package/src/components/ModelViewer/docAnnotations.spec.ts +181 -0
- package/src/components/ModelViewer/docAnnotations.ts +244 -0
- package/src/components/ModelViewer/docAnnotations.typeDetail.spec.ts +114 -0
- package/src/components/ModelViewer/explorerModel.spec.ts +43 -0
- package/src/components/ModelViewer/explorerModel.ts +31 -0
- package/src/components/ModelViewer/extensions.tsx +112 -0
- package/src/components/ModelViewer/fieldCode.spec.ts +168 -0
- package/src/components/ModelViewer/fieldCode.ts +118 -0
- package/src/components/ModelViewer/fieldEntities.ts +63 -0
- package/src/components/ModelViewer/fieldExpansion.spec.ts +116 -0
- package/src/components/ModelViewer/fieldExpansion.ts +95 -0
- package/src/components/ModelViewer/givenUsage.spec.ts +304 -0
- package/src/components/ModelViewer/givenUsage.ts +325 -0
- package/src/components/ModelViewer/headerCard.tsx +102 -0
- package/src/components/ModelViewer/httpStatus.ts +15 -0
- package/src/components/ModelViewer/icons.tsx +67 -0
- package/src/components/ModelViewer/index.ts +26 -0
- package/src/components/ModelViewer/joinAccess.spec.ts +95 -0
- package/src/components/ModelViewer/joinAccess.ts +54 -0
- package/src/components/ModelViewer/malloyRunText.spec.ts +48 -0
- package/src/components/ModelViewer/malloyRunText.ts +51 -0
- package/src/components/ModelViewer/malloyText.spec.ts +47 -0
- package/src/components/ModelViewer/malloyText.ts +77 -0
- package/src/components/ModelViewer/modelGivens.ts +228 -0
- package/src/components/ModelViewer/modelGivensContext.ts +13 -0
- package/src/components/ModelViewer/modelHeaderPresentation.spec.ts +31 -0
- package/src/components/ModelViewer/modelHeaderPresentation.ts +41 -0
- package/src/components/ModelViewer/modelTextDeclarations.spec.ts +336 -0
- package/src/components/ModelViewer/modelTextDeclarations.ts +228 -0
- package/src/components/ModelViewer/modelTextParse.ts +112 -0
- package/src/components/ModelViewer/namedQueryCode.spec.ts +58 -0
- package/src/components/ModelViewer/namedQueryCode.ts +26 -0
- package/src/components/ModelViewer/offSurface.tsx +124 -0
- package/src/components/ModelViewer/rowLayers.tsx +104 -0
- package/src/components/ModelViewer/runGate.spec.ts +219 -0
- package/src/components/ModelViewer/runGate.ts +145 -0
- package/src/components/ModelViewer/schemaModel.defaultSource.spec.ts +126 -0
- package/src/components/ModelViewer/schemaModel.queries.spec.ts +37 -0
- package/src/components/ModelViewer/schemaModel.ts +300 -0
- package/src/components/ModelViewer/sectionOpenCommand.tsx +125 -0
- package/src/components/ModelViewer/sourceAccess.spec.ts +130 -0
- package/src/components/ModelViewer/sourceAccess.ts +194 -0
- package/src/components/ModelViewer/sourceLineage.spec.ts +73 -0
- package/src/components/ModelViewer/sourceLineage.ts +38 -0
- package/src/components/ModelViewer/sourcePicker.spec.ts +294 -0
- package/src/components/ModelViewer/sourcePicker.ts +162 -0
- package/src/components/ModelViewer/surface.ts +51 -0
- package/src/components/ModelViewer/text.tsx +33 -0
- package/src/components/ModelViewer/theme.spec.ts +38 -0
- package/src/components/ModelViewer/theme.ts +58 -0
- package/src/components/ModelViewer/tokens.ts +87 -0
- package/src/components/ModelViewer/ui.tsx +201 -0
- package/src/components/ModelViewer/useDimensionSamples.spec.tsx +139 -0
- package/src/components/ModelViewer/useDimensionSamples.ts +220 -0
- package/src/components/ModelViewer/useModelSources.spec.ts +110 -0
- package/src/components/ModelViewer/useModelSources.ts +238 -0
- package/src/components/ModelViewer/useRunQuery.spec.ts +50 -0
- package/src/components/ModelViewer/useRunQuery.ts +223 -0
- package/src/components/Package/Package.agents.spec.tsx +5 -4
- package/src/components/Package/Package.tsx +8 -1
- package/src/components/ReportBuilder/emptyStart.spec.ts +8 -0
- package/src/components/ReportBuilder/loadMalloy.ts +8 -1
- package/src/components/ServerProvider.tsx +29 -3
- package/src/components/filter/utils.ts +4 -60
- package/src/components/given/FilterButton.tsx +4 -1
- package/src/components/given/GivenInput.tsx +8 -0
- package/src/components/given/GivensPanel.tsx +6 -1
- package/src/components/given/filterSummary.spec.ts +31 -1
- package/src/components/given/filterSummary.ts +41 -19
- package/src/components/given/useGivenUrlParams.spec.tsx +32 -0
- package/src/components/given/useGivenUrlParams.ts +49 -14
- package/src/components/index.ts +6 -1
- package/src/components/legacy/malloynb/Notebook.spec.tsx +38 -4
- package/src/components/legacy/malloynb/NotebookCell.tsx +8 -2
- package/src/components/modelPage.spec.ts +79 -0
- package/src/components/modelPage.ts +48 -0
- package/src/hooks/useDimensionFilters.ts +3 -58
- package/src/hooks/useDimensionFiltersQuery.ts +3 -58
- package/src/hooks/useDimensionalFilterRangeData.spec.ts +57 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +8 -63
- package/src/hooks/useSuggestOptions.dom.spec.ts +54 -1
- package/src/hooks/useSuggestOptions.spec.ts +71 -0
- package/src/hooks/useSuggestOptions.ts +102 -12
- package/src/utils/filterCondition.spec.ts +87 -0
- package/src/utils/filterCondition.ts +66 -0
- package/src/utils/malloyLiteral.spec.ts +53 -1
- package/src/utils/malloyLiteral.ts +47 -12
- package/dist/ServerProvider-BHfg1Ed6.cjs.js +0 -1
- package/dist/useCompiledDocument-D7X_K6YU.cjs.js +0 -142
|
@@ -1,273 +1,50 @@
|
|
|
1
1
|
// Copyright (c) Credible Data Inc.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
|
-
import "@malloydata/malloy-explorer/styles.css";
|
|
5
4
|
import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
Box,
|
|
9
|
-
IconButton,
|
|
10
|
-
Snackbar,
|
|
11
|
-
Stack,
|
|
12
|
-
Tooltip,
|
|
13
|
-
Typography,
|
|
14
|
-
} from "@mui/material";
|
|
5
|
+
import { IconButton, Snackbar, Tooltip } from "@mui/material";
|
|
15
6
|
import React, { useState } from "react";
|
|
16
|
-
import { parseResourceUri } from "../../utils/formatting";
|
|
17
|
-
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
18
|
-
import { FloatingIconButton } from "../FloatingIconButton";
|
|
19
7
|
import { Loading } from "../Loading";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { QueryExplorerResult } from "./SourcesExplorer";
|
|
24
|
-
import { useModelData } from "./useModelData";
|
|
8
|
+
import { ModelViewer, type ModelViewerProps } from "../ModelViewer";
|
|
9
|
+
import { useServer } from "../ServerProvider";
|
|
10
|
+
import { ExplorerPage } from "./ExplorerPage";
|
|
11
|
+
import type { QueryExplorerResult } from "./SourcesExplorer";
|
|
25
12
|
|
|
26
|
-
export interface ModelProps {
|
|
13
|
+
export interface ModelProps extends ModelViewerProps {
|
|
14
|
+
/**
|
|
15
|
+
* The Explorer page only: called with the query the Explorer builds. The
|
|
16
|
+
* model viewer builds none.
|
|
17
|
+
*/
|
|
27
18
|
onChange?: (query: QueryExplorerResult) => void;
|
|
28
|
-
resourceUri: string;
|
|
29
|
-
runOnDemand?: boolean;
|
|
30
|
-
maxResultSize?: number;
|
|
31
19
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
20
|
+
* The Explorer page only: a named query waits for its Run rather than
|
|
21
|
+
* running on render. The model viewer runs a view or a query only when it
|
|
22
|
+
* is opened, so there it turns nothing on.
|
|
35
23
|
*/
|
|
36
|
-
|
|
37
|
-
/** Applied control values, for a host that wants them in its URL. */
|
|
38
|
-
onGivensChange?: (
|
|
39
|
-
givens: Record<string, string>,
|
|
40
|
-
managed: readonly string[],
|
|
41
|
-
) => void;
|
|
24
|
+
runOnDemand?: boolean;
|
|
42
25
|
}
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// import "@malloy-publisher/sdk/malloy-explorer.css";
|
|
47
|
-
|
|
48
|
-
export default function Model({
|
|
49
|
-
onChange,
|
|
50
|
-
resourceUri,
|
|
51
|
-
runOnDemand = false,
|
|
52
|
-
maxResultSize = 0,
|
|
53
|
-
givens,
|
|
54
|
-
onGivensChange,
|
|
55
|
-
}: ModelProps) {
|
|
56
|
-
const { modelPath } = parseResourceUri(resourceUri);
|
|
57
|
-
const { data, isError, isLoading, error } = useModelData(resourceUri);
|
|
58
|
-
const [dialogOpen, setDialogOpen] = React.useState(false);
|
|
59
|
-
const [sharedQuery, setSharedQuery] = React.useState<
|
|
60
|
-
QueryExplorerResult | undefined
|
|
61
|
-
>();
|
|
62
|
-
const [sharedSourceIndex, setSharedSourceIndex] = React.useState(0);
|
|
27
|
+
/** Copies the page's address: a model, at its source and given values, is shareable. */
|
|
28
|
+
function CopyLinkButton() {
|
|
63
29
|
const [copyMessage, setCopyMessage] = useState("");
|
|
64
|
-
// Held here only when the host passes neither prop, so the embedded
|
|
65
|
-
// explorer and the maximized dialog still agree on one set of values
|
|
66
|
-
// rather than each defaulting independently.
|
|
67
|
-
const [localGivens, setLocalGivens] = React.useState<Record<string, string>>(
|
|
68
|
-
{},
|
|
69
|
-
);
|
|
70
|
-
const effectiveGivens = givens ?? localGivens;
|
|
71
|
-
const effectiveOnGivensChange =
|
|
72
|
-
onGivensChange ??
|
|
73
|
-
((applied: Record<string, string>) => setLocalGivens(applied));
|
|
74
|
-
|
|
75
|
-
// Whether the model imports other files — drives the empty-state hint for
|
|
76
|
-
// import-only models, whose discovery surface is legitimately empty (no
|
|
77
|
-
// local sources, no export{}) but whose page would otherwise render blank.
|
|
78
|
-
// `modelDef` is returned by the server but intentionally absent from the
|
|
79
|
-
// typed CompiledModel schema (internal compiler blob), hence the cast.
|
|
80
|
-
const modelDefJson = (data as { modelDef?: string } | undefined)?.modelDef;
|
|
81
|
-
const hasImports = React.useMemo(() => {
|
|
82
|
-
if (!modelDefJson) return false;
|
|
83
|
-
try {
|
|
84
|
-
const def = JSON.parse(modelDefJson) as { imports?: unknown[] };
|
|
85
|
-
return Array.isArray(def.imports) && def.imports.length > 0;
|
|
86
|
-
} catch {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}, [modelDefJson]);
|
|
90
|
-
|
|
91
|
-
if (isLoading) {
|
|
92
|
-
return <Loading text="Fetching Model..." />;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (isError) {
|
|
96
|
-
console.log("error", error);
|
|
97
|
-
return <ApiErrorDisplay error={error} context={`Model > ${modelPath}`} />;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Shared handlers for both embedded and dialog explorers
|
|
101
|
-
const handleQueryChange = (query: QueryExplorerResult) => {
|
|
102
|
-
setSharedQuery(query);
|
|
103
|
-
if (onChange) {
|
|
104
|
-
onChange(query);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const handleSourceChange = (index: number) => {
|
|
109
|
-
setSharedSourceIndex(index);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
30
|
const copyToClipboard = () => {
|
|
113
|
-
const url = window.location.href;
|
|
114
31
|
navigator.clipboard
|
|
115
|
-
.writeText(
|
|
32
|
+
.writeText(window.location.href)
|
|
116
33
|
.then(() => setCopyMessage("URL copied to clipboard!"))
|
|
117
34
|
.catch(() => setCopyMessage("Failed to copy URL"));
|
|
118
35
|
};
|
|
119
|
-
|
|
120
36
|
return (
|
|
121
37
|
<>
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
data.sourceInfos.length > 0 && (
|
|
133
|
-
<Stack spacing={2} component="section">
|
|
134
|
-
{/* Sources Header */}
|
|
135
|
-
<Box
|
|
136
|
-
sx={{
|
|
137
|
-
padding: "0 0 16px 0",
|
|
138
|
-
display: "flex",
|
|
139
|
-
alignItems: "center",
|
|
140
|
-
justifyContent: "space-between",
|
|
141
|
-
}}
|
|
142
|
-
>
|
|
143
|
-
<Typography
|
|
144
|
-
variant="h1"
|
|
145
|
-
sx={{
|
|
146
|
-
fontSize: "28px",
|
|
147
|
-
fontWeight: "600",
|
|
148
|
-
color: "#1a1a1a",
|
|
149
|
-
marginBottom: "8px",
|
|
150
|
-
marginTop: "0",
|
|
151
|
-
paddingLeft: "0",
|
|
152
|
-
}}
|
|
153
|
-
>
|
|
154
|
-
Sources
|
|
155
|
-
</Typography>
|
|
156
|
-
<Tooltip title="Copy link">
|
|
157
|
-
<IconButton
|
|
158
|
-
size="small"
|
|
159
|
-
aria-label="Copy link"
|
|
160
|
-
onClick={copyToClipboard}
|
|
161
|
-
sx={{ color: "text.secondary" }}
|
|
162
|
-
>
|
|
163
|
-
<LinkOutlinedIcon fontSize="small" />
|
|
164
|
-
</IconButton>
|
|
165
|
-
</Tooltip>
|
|
166
|
-
</Box>
|
|
167
|
-
|
|
168
|
-
<ModelExplorer
|
|
169
|
-
data={data}
|
|
170
|
-
onChange={handleQueryChange}
|
|
171
|
-
onSourceChange={handleSourceChange}
|
|
172
|
-
existingQuery={sharedQuery}
|
|
173
|
-
initialSelectedSourceIndex={sharedSourceIndex}
|
|
174
|
-
resourceUri={resourceUri}
|
|
175
|
-
givens={effectiveGivens}
|
|
176
|
-
onGivensChange={effectiveOnGivensChange}
|
|
177
|
-
/>
|
|
178
|
-
|
|
179
|
-
{/* Magnifying glass icon */}
|
|
180
|
-
<FloatingIconButton
|
|
181
|
-
aria-label="Expand results"
|
|
182
|
-
sx={{
|
|
183
|
-
position: "absolute",
|
|
184
|
-
top: "90px",
|
|
185
|
-
right: "4px",
|
|
186
|
-
zIndex: 2,
|
|
187
|
-
}}
|
|
188
|
-
onClick={() => setDialogOpen(true)}
|
|
189
|
-
>
|
|
190
|
-
<SearchIcon />
|
|
191
|
-
</FloatingIconButton>
|
|
192
|
-
</Stack>
|
|
193
|
-
)}
|
|
194
|
-
|
|
195
|
-
{/* Named Queries Section */}
|
|
196
|
-
{data?.queries?.length > 0 && (
|
|
197
|
-
<Stack
|
|
198
|
-
spacing={2}
|
|
199
|
-
component="section"
|
|
200
|
-
sx={{ marginTop: "24px" }}
|
|
201
|
-
>
|
|
202
|
-
{/* Named Queries Header */}
|
|
203
|
-
<Box sx={{ padding: "0 0 16px 0" }}>
|
|
204
|
-
<Typography
|
|
205
|
-
variant="h2"
|
|
206
|
-
sx={{
|
|
207
|
-
fontSize: "24px",
|
|
208
|
-
fontWeight: "600",
|
|
209
|
-
color: "#1a1a1a",
|
|
210
|
-
marginBottom: "0",
|
|
211
|
-
marginTop: "8px",
|
|
212
|
-
paddingLeft: "0",
|
|
213
|
-
}}
|
|
214
|
-
>
|
|
215
|
-
Named Queries
|
|
216
|
-
</Typography>
|
|
217
|
-
</Box>
|
|
218
|
-
|
|
219
|
-
{/* Render the named queries */}
|
|
220
|
-
{data.queries.map((query) => (
|
|
221
|
-
<ModelCell
|
|
222
|
-
key={query.name}
|
|
223
|
-
queryName={query.name}
|
|
224
|
-
annotations={query.annotations}
|
|
225
|
-
resourceUri={resourceUri}
|
|
226
|
-
runOnDemand={runOnDemand}
|
|
227
|
-
maxResultSize={maxResultSize}
|
|
228
|
-
/>
|
|
229
|
-
))}
|
|
230
|
-
</Stack>
|
|
231
|
-
)}
|
|
232
|
-
|
|
233
|
-
{/* Empty discovery surface: nothing exported, nothing to render.
|
|
234
|
-
For import-only models, say why and how to fix it — otherwise
|
|
235
|
-
the page reads as broken. */}
|
|
236
|
-
{(!Array.isArray(data?.sourceInfos) ||
|
|
237
|
-
data.sourceInfos.length === 0) &&
|
|
238
|
-
!(data?.queries && data.queries.length > 0) && (
|
|
239
|
-
<Box sx={{ textAlign: "center", py: 6 }}>
|
|
240
|
-
<Typography
|
|
241
|
-
variant="body1"
|
|
242
|
-
sx={{ color: "text.secondary", marginBottom: "8px" }}
|
|
243
|
-
>
|
|
244
|
-
This model exposes no sources or queries.
|
|
245
|
-
</Typography>
|
|
246
|
-
{hasImports && (
|
|
247
|
-
<Typography variant="body2" color="text.secondary">
|
|
248
|
-
It imports other files but re-exports nothing. Add{" "}
|
|
249
|
-
<code>export {"{ source_name }"}</code> to surface
|
|
250
|
-
imported sources here.
|
|
251
|
-
</Typography>
|
|
252
|
-
)}
|
|
253
|
-
</Box>
|
|
254
|
-
)}
|
|
255
|
-
|
|
256
|
-
{/* Model Explorer Dialog */}
|
|
257
|
-
<ModelExplorerDialog
|
|
258
|
-
open={dialogOpen}
|
|
259
|
-
onClose={() => setDialogOpen(false)}
|
|
260
|
-
resourceUri={resourceUri}
|
|
261
|
-
data={data}
|
|
262
|
-
title={`Model: ${modelPath.split("/").pop()}`}
|
|
263
|
-
existingQuery={sharedQuery}
|
|
264
|
-
initialSelectedSourceIndex={sharedSourceIndex}
|
|
265
|
-
onChange={handleQueryChange}
|
|
266
|
-
onSourceChange={handleSourceChange}
|
|
267
|
-
givens={effectiveGivens}
|
|
268
|
-
onGivensChange={effectiveOnGivensChange}
|
|
269
|
-
/>
|
|
270
|
-
</Box>
|
|
38
|
+
<Tooltip title="Copy link">
|
|
39
|
+
<IconButton
|
|
40
|
+
size="small"
|
|
41
|
+
aria-label="Copy link"
|
|
42
|
+
onClick={copyToClipboard}
|
|
43
|
+
sx={{ color: "text.secondary" }}
|
|
44
|
+
>
|
|
45
|
+
<LinkOutlinedIcon fontSize="small" />
|
|
46
|
+
</IconButton>
|
|
47
|
+
</Tooltip>
|
|
271
48
|
<Snackbar
|
|
272
49
|
open={copyMessage !== ""}
|
|
273
50
|
autoHideDuration={6000}
|
|
@@ -277,3 +54,42 @@ export default function Model({
|
|
|
277
54
|
</>
|
|
278
55
|
);
|
|
279
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A model's page, the one the server's `PUBLISHER_MODEL_PAGE` names (see
|
|
60
|
+
* `useServer().modelPage`). Nothing shows until `/status` answers, so a
|
|
61
|
+
* `viewer` server never flashes the Explorer.
|
|
62
|
+
*
|
|
63
|
+
* - `explorer`, the default: the Malloy Explorer over the model's sources
|
|
64
|
+
* ({@link ExplorerPage}), and its named queries. The Explorer writes the
|
|
65
|
+
* queries it builds back to Malloy text through
|
|
66
|
+
* `@malloydata/malloy-interfaces`, whose string escaping is a TODO, so a
|
|
67
|
+
* drilled value holding a double quote rewrites its query.
|
|
68
|
+
* - `viewer`: the model viewer ({@link ModelViewer}) with a Copy link action
|
|
69
|
+
* on its heading. Each source's views, measures, calculations, dimensions
|
|
70
|
+
* and joins, the model's named queries, and the givens they read. It writes
|
|
71
|
+
* no value into Malloy text.
|
|
72
|
+
*/
|
|
73
|
+
export default function Model(props: ModelProps) {
|
|
74
|
+
const { modelPage, isLoadingStatus } = useServer();
|
|
75
|
+
if (isLoadingStatus) {
|
|
76
|
+
return <Loading text="Fetching Model..." />;
|
|
77
|
+
}
|
|
78
|
+
if (modelPage !== "viewer") {
|
|
79
|
+
return <ExplorerPage {...props} />;
|
|
80
|
+
}
|
|
81
|
+
const {
|
|
82
|
+
onChange: _onChange,
|
|
83
|
+
runOnDemand: _runOnDemand,
|
|
84
|
+
headerActions,
|
|
85
|
+
...viewerProps
|
|
86
|
+
} = props;
|
|
87
|
+
return (
|
|
88
|
+
<ModelViewer
|
|
89
|
+
{...viewerProps}
|
|
90
|
+
headerActions={headerActions ?? <CopyLinkButton />}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type { ModelViewerProps };
|
|
@@ -74,10 +74,35 @@ const executeQueryModel = mock(
|
|
|
74
74
|
) => pending<{ data: { result: string } }>(),
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
const getModel = mock(() =>
|
|
78
|
+
Promise.resolve({
|
|
79
|
+
data: {
|
|
80
|
+
sourceInfos: [
|
|
81
|
+
JSON.stringify({
|
|
82
|
+
name: "orders",
|
|
83
|
+
schema: {
|
|
84
|
+
fields: [
|
|
85
|
+
{
|
|
86
|
+
kind: "dimension",
|
|
87
|
+
name: "status",
|
|
88
|
+
type: { kind: "string_type" },
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
}),
|
|
93
|
+
],
|
|
94
|
+
} as CompiledModel,
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// What `/status` said: the model page `Model` shows, and whether it is still
|
|
99
|
+
// loading. A test sets either and clears it again.
|
|
100
|
+
const serverContext: { modelPage?: string; isLoadingStatus?: boolean } = {};
|
|
101
|
+
mockServerProvider({ models: { executeQueryModel, getModel } }, serverContext);
|
|
78
102
|
|
|
79
103
|
// Imported after the stubs above: a static import would hoist above them.
|
|
80
104
|
const { ModelExplorer } = await import("./ModelExplorer");
|
|
105
|
+
const { default: Model } = await import("./Model");
|
|
81
106
|
|
|
82
107
|
const URI = "publisher://environments/env/packages/pkg/models/orders.malloy";
|
|
83
108
|
|
|
@@ -97,6 +122,9 @@ const run = () => fireEvent.click(screen.getByRole("button", { name: "Run" }));
|
|
|
97
122
|
|
|
98
123
|
beforeEach(() => {
|
|
99
124
|
clearCache();
|
|
125
|
+
delete serverContext.modelPage;
|
|
126
|
+
delete serverContext.isLoadingStatus;
|
|
127
|
+
getModel.mockClear();
|
|
100
128
|
executeQueryModel.mockReset();
|
|
101
129
|
executeQueryModel.mockImplementation(() => pending());
|
|
102
130
|
});
|
|
@@ -402,3 +430,38 @@ describe("startingGivens", () => {
|
|
|
402
430
|
});
|
|
403
431
|
});
|
|
404
432
|
});
|
|
433
|
+
|
|
434
|
+
// The server's PUBLISHER_MODEL_PAGE picks the page: the Explorer unless it says
|
|
435
|
+
// viewer, and nothing until /status has answered.
|
|
436
|
+
describe("Model's page", () => {
|
|
437
|
+
it("is the Explorer on a server that names no model page", async () => {
|
|
438
|
+
render(<Model resourceUri={URI} />, { wrapper: serverWrapper });
|
|
439
|
+
|
|
440
|
+
expect(await screen.findByRole("button", { name: "Run" })).toBeTruthy();
|
|
441
|
+
expect(screen.getByLabelText("Expand results")).toBeTruthy();
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it("is the model viewer on a server whose model page is the viewer", async () => {
|
|
445
|
+
serverContext.modelPage = "viewer";
|
|
446
|
+
render(<Model resourceUri={URI} />, { wrapper: serverWrapper });
|
|
447
|
+
|
|
448
|
+
expect(
|
|
449
|
+
await screen.findByRole("heading", { name: "orders", level: 1 }),
|
|
450
|
+
).toBeTruthy();
|
|
451
|
+
expect(screen.getByText("status")).toBeTruthy();
|
|
452
|
+
expect(screen.getByLabelText("Copy link")).toBeTruthy();
|
|
453
|
+
expect(screen.queryByRole("button", { name: "Run" })).toBeNull();
|
|
454
|
+
expect(screen.queryByLabelText("Expand results")).toBeNull();
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it("shows neither page while /status loads", async () => {
|
|
458
|
+
serverContext.modelPage = "viewer";
|
|
459
|
+
serverContext.isLoadingStatus = true;
|
|
460
|
+
render(<Model resourceUri={URI} />, { wrapper: serverWrapper });
|
|
461
|
+
|
|
462
|
+
expect(await screen.findByText(/Fetching Model/)).toBeTruthy();
|
|
463
|
+
expect(getModel).not.toHaveBeenCalled();
|
|
464
|
+
expect(screen.queryByRole("heading", { name: "orders" })).toBeNull();
|
|
465
|
+
expect(screen.queryByRole("button", { name: "Run" })).toBeNull();
|
|
466
|
+
});
|
|
467
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, Tooltip } from "@mui/material";
|
|
5
|
+
import { StatusPill } from "./StatusPill";
|
|
6
|
+
import { Fact } from "./Facts";
|
|
7
|
+
import { HeaderChip } from "./headerCard";
|
|
8
|
+
import {
|
|
9
|
+
isRestricted,
|
|
10
|
+
isRowFiltered,
|
|
11
|
+
restrictedToWords,
|
|
12
|
+
RESTRICTED_MEANING,
|
|
13
|
+
ROW_FILTERED_MEANING,
|
|
14
|
+
type SourceAccess,
|
|
15
|
+
} from "./sourceAccess";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A source's access declarations as page-header chips, on the status row under
|
|
19
|
+
* its name: "Restricted" for an `#(authorize)` rule, "Row filtered" for an
|
|
20
|
+
* `#(access_filter)`. Declarations-layer state (ux-design-guide §4 "Reference
|
|
21
|
+
* surfaces"), so neutral: the chip says what the source declares, never whether
|
|
22
|
+
* this reader passes — only the publisher knows that. Each is a tab stop whose
|
|
23
|
+
* accessible name is its tooltip (§7); in the source header each opens the
|
|
24
|
+
* card on who can query.
|
|
25
|
+
*/
|
|
26
|
+
export function AccessChips({ access }: { access: SourceAccess | undefined }) {
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{isRestricted(access) && (
|
|
30
|
+
<AccessChip label="Restricted" meaning={RESTRICTED_MEANING} />
|
|
31
|
+
)}
|
|
32
|
+
{isRowFiltered(access) && (
|
|
33
|
+
<AccessChip label="Row filtered" meaning={ROW_FILTERED_MEANING} />
|
|
34
|
+
)}
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function AccessChip({ label, meaning }: { label: string; meaning: string }) {
|
|
40
|
+
// In the source header it opens the card on who can query (HeaderChip).
|
|
41
|
+
return (
|
|
42
|
+
<HeaderChip
|
|
43
|
+
layer="access"
|
|
44
|
+
title={`${label}: ${meaning}`}
|
|
45
|
+
testId={`source-access-chip-${label === "Restricted" ? "restricted" : "row-filtered"}`}
|
|
46
|
+
>
|
|
47
|
+
<StatusPill tone="neutral" size="header">
|
|
48
|
+
{label}
|
|
49
|
+
</StatusPill>
|
|
50
|
+
</HeaderChip>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The same declarations as row pills — a source in the picker, a join to a
|
|
56
|
+
* gated source — in the Declarations layer's token voice. Not focusable: a row
|
|
57
|
+
* is one button, and its accessible name carries the same words
|
|
58
|
+
* ({@link accessRowLabel}).
|
|
59
|
+
*/
|
|
60
|
+
export function AccessPills({ access }: { access: SourceAccess | undefined }) {
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{isRestricted(access) && (
|
|
64
|
+
<Tooltip title={`Restricted: ${RESTRICTED_MEANING}`}>
|
|
65
|
+
<StatusPill
|
|
66
|
+
voice="token"
|
|
67
|
+
tone="neutral"
|
|
68
|
+
sx={{ alignSelf: "center" }}
|
|
69
|
+
>
|
|
70
|
+
Restricted
|
|
71
|
+
</StatusPill>
|
|
72
|
+
</Tooltip>
|
|
73
|
+
)}
|
|
74
|
+
{isRowFiltered(access) && (
|
|
75
|
+
<Tooltip title={`Row filtered: ${ROW_FILTERED_MEANING}`}>
|
|
76
|
+
<StatusPill
|
|
77
|
+
voice="token"
|
|
78
|
+
tone="neutral"
|
|
79
|
+
sx={{ alignSelf: "center" }}
|
|
80
|
+
>
|
|
81
|
+
Row filtered
|
|
82
|
+
</StatusPill>
|
|
83
|
+
</Tooltip>
|
|
84
|
+
)}
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The words a row's accessible name adds for its access pills ("", ", restricted"). */
|
|
90
|
+
export function accessRowLabel(access: SourceAccess | undefined): string {
|
|
91
|
+
return [
|
|
92
|
+
isRestricted(access) && "restricted",
|
|
93
|
+
isRowFiltered(access) && "row filtered",
|
|
94
|
+
]
|
|
95
|
+
.filter(Boolean)
|
|
96
|
+
.map((w) => `, ${w}`)
|
|
97
|
+
.join("");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The access facts in the source's card, as rows of the facts grid the
|
|
102
|
+
* binding's facts use. Readers get sentences; an editor (who can change the
|
|
103
|
+
* model) also gets the Malloy rule and filter verbatim (§4a.2: expressions are
|
|
104
|
+
* writer vocabulary).
|
|
105
|
+
*/
|
|
106
|
+
export function AccessFacts({
|
|
107
|
+
access,
|
|
108
|
+
showRules,
|
|
109
|
+
}: {
|
|
110
|
+
access: SourceAccess;
|
|
111
|
+
showRules: boolean;
|
|
112
|
+
}) {
|
|
113
|
+
const restricted = isRestricted(access);
|
|
114
|
+
const filtered = isRowFiltered(access);
|
|
115
|
+
if (!restricted && !filtered) return null;
|
|
116
|
+
return (
|
|
117
|
+
<Box
|
|
118
|
+
data-testid="source-access-facts"
|
|
119
|
+
sx={{
|
|
120
|
+
display: "grid",
|
|
121
|
+
gridTemplateColumns: "max-content 1fr",
|
|
122
|
+
columnGap: "16px",
|
|
123
|
+
rowGap: "6px",
|
|
124
|
+
alignItems: "baseline",
|
|
125
|
+
}}
|
|
126
|
+
>
|
|
127
|
+
{restricted && (
|
|
128
|
+
<Fact label="Restricted to" value={restrictedToWords(access)} />
|
|
129
|
+
)}
|
|
130
|
+
{/* One row per rule: several all apply, and joining them into one line
|
|
131
|
+
would read as a single expression. */}
|
|
132
|
+
{restricted &&
|
|
133
|
+
showRules &&
|
|
134
|
+
access.authorize
|
|
135
|
+
.filter((e) => e.trim() !== "true")
|
|
136
|
+
.map((e, i) => (
|
|
137
|
+
<Fact key={`a${i}`} label="Access rule" value={e} mono />
|
|
138
|
+
))}
|
|
139
|
+
{filtered && (
|
|
140
|
+
<Fact label="Rows" value="Rows are filtered for each reader" />
|
|
141
|
+
)}
|
|
142
|
+
{filtered &&
|
|
143
|
+
showRules &&
|
|
144
|
+
access.accessFilter.map((e, i) => (
|
|
145
|
+
<Fact key={`f${i}`} label="Row filter" value={e} mono />
|
|
146
|
+
))}
|
|
147
|
+
</Box>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box } from "@mui/material";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import { BodyText } from "./text";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Quiet empty-state row for a section list: a single dashed row carrying a
|
|
10
|
+
* message and a right-aligned action slot. Matches the width and rhythm of a
|
|
11
|
+
* populated list so an empty section reads as the same surface, not a hero
|
|
12
|
+
* card.
|
|
13
|
+
*
|
|
14
|
+
* An empty state carries a one-line explanation of what the section will hold,
|
|
15
|
+
* plus the action that puts the first thing in it where there is one.
|
|
16
|
+
*
|
|
17
|
+
* `secondary` is a quieter follow-on line under the message — the "or, do it
|
|
18
|
+
* this other way" alternative that shouldn't compete with the primary action.
|
|
19
|
+
*
|
|
20
|
+
* Where a section has no action that would fill it (a read-only artifact, a
|
|
21
|
+
* container whose contents arrive from elsewhere), pass `message` alone: the
|
|
22
|
+
* explanation is still worth more than the bare line, and an invented CTA is
|
|
23
|
+
* worse than none.
|
|
24
|
+
*/
|
|
25
|
+
export function EmptyRow({
|
|
26
|
+
message,
|
|
27
|
+
secondary,
|
|
28
|
+
actions,
|
|
29
|
+
}: {
|
|
30
|
+
message: string;
|
|
31
|
+
secondary?: ReactNode;
|
|
32
|
+
actions?: ReactNode;
|
|
33
|
+
}) {
|
|
34
|
+
return (
|
|
35
|
+
<Box
|
|
36
|
+
// So a caller's test can assert the SHAPE, not just the words.
|
|
37
|
+
data-testid="empty-row"
|
|
38
|
+
sx={{
|
|
39
|
+
display: "flex",
|
|
40
|
+
alignItems: "center",
|
|
41
|
+
gap: 2,
|
|
42
|
+
flexWrap: "wrap",
|
|
43
|
+
p: 2,
|
|
44
|
+
border: "1px dashed",
|
|
45
|
+
borderColor: "divider",
|
|
46
|
+
borderRadius: 2,
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<Box sx={{ flex: 1, minWidth: 200 }}>
|
|
50
|
+
<BodyText>{message}</BodyText>
|
|
51
|
+
{secondary && (
|
|
52
|
+
<BodyText sx={{ color: "text.secondary", mt: 0.5 }}>
|
|
53
|
+
{secondary}
|
|
54
|
+
</BodyText>
|
|
55
|
+
)}
|
|
56
|
+
</Box>
|
|
57
|
+
{actions && (
|
|
58
|
+
<Box
|
|
59
|
+
sx={{
|
|
60
|
+
display: "flex",
|
|
61
|
+
gap: 1,
|
|
62
|
+
flexShrink: 0,
|
|
63
|
+
alignItems: "center",
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
{actions}
|
|
67
|
+
</Box>
|
|
68
|
+
)}
|
|
69
|
+
</Box>
|
|
70
|
+
);
|
|
71
|
+
}
|