@malloy-publisher/sdk 0.12.1 → 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-DrNhQ2_9.cjs.js → RenderedResult-Cgw4iqev.cjs.js} +1 -1
- package/dist/{RenderedResult-AyM-RQaA.es.js → RenderedResult-DEjFM1DL.es.js} +2 -2
- package/dist/ServerProvider-BRQl_cBo.cjs.js +1 -0
- package/dist/{ServerProvider-a9Ki0QXO.es.js → ServerProvider-RnliA2Ao.es.js} +577 -555
- package/dist/builder/index.cjs.js +1 -1
- package/dist/builder/index.es.js +3 -3
- package/dist/client/api.d.ts +10 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +28 -27
- 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 +15 -1
- 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 +14281 -9879
- package/dist/useCompiledDocument-D88_2cGS.cjs.js +143 -0
- package/dist/{useCompiledDocument-Utj2u8CG.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/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/ReportBuilder/emptyStart.spec.ts +8 -0
- package/src/components/ReportBuilder/loadMalloy.ts +8 -1
- package/src/components/ServerProvider.tsx +27 -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-BvD7PYZ7.cjs.js +0 -1
- package/dist/useCompiledDocument-CRhFBKv_.cjs.js +0 -142
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FilterSelection } from '../hooks/useDimensionFilters';
|
|
2
|
+
/**
|
|
3
|
+
* One dimension filter's selection as a Malloy condition on `fieldName` (an
|
|
4
|
+
* already-quoted path such as `` `name` ``), or "" when the selection says
|
|
5
|
+
* nothing a condition can.
|
|
6
|
+
*
|
|
7
|
+
* The one place a dimension filter's value becomes Malloy text. A "Contains"
|
|
8
|
+
* value is written in the string filter grammar, where `,` separates
|
|
9
|
+
* alternatives and `%` and `_` are wildcards, so it goes out through
|
|
10
|
+
* `@malloydata/malloy-filter`'s own printer rather than being spliced into
|
|
11
|
+
* `%…%`: spliced, "a,b" matched `a` and `b` but not "a,b", and "50%" also
|
|
12
|
+
* matched "500".
|
|
13
|
+
*/
|
|
14
|
+
export declare function filterCondition(fieldName: string, selection: FilterSelection): string;
|
|
@@ -9,5 +9,24 @@
|
|
|
9
9
|
* value, or one the type cannot spell.
|
|
10
10
|
*/
|
|
11
11
|
export declare function malloyLiteral(value: unknown, type?: string): string | undefined;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Filter text as a Malloy filter literal: `f'…'`.
|
|
14
|
+
*
|
|
15
|
+
* Malloy hands the text between the quotes to the filter parser as written, so
|
|
16
|
+
* the filter grammar's own escapes (`\,` for a comma that is part of a value,
|
|
17
|
+
* `\%` for a percent sign) have to reach it untouched. Only a quote the text
|
|
18
|
+
* leaves bare is escaped, and a lone trailing backslash is doubled so it cannot
|
|
19
|
+
* swallow the closing quote. Escaping filter text the way a string literal is
|
|
20
|
+
* escaped doubles every backslash, and `a\,b`, the one value "a,b", runs as
|
|
21
|
+
* "a\" or "b".
|
|
22
|
+
*/
|
|
23
|
+
export declare function malloyFilterLiteral(filter: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* A filter value as a Malloy literal; unlike `malloyLiteral`, a Date is spelled
|
|
26
|
+
* as a local-time day. A string is a quoted string, whatever it holds, except
|
|
27
|
+
* where `isDate` says the dimension is a date and the string is an ISO date or
|
|
28
|
+
* timestamp, which is written as a date literal (`@2024-01-31`). Any other
|
|
29
|
+
* string stays quoted with `isDate` too: written after `@` unquoted, a value
|
|
30
|
+
* like `2024-01-31 or true` became Malloy.
|
|
31
|
+
*/
|
|
13
32
|
export declare function formatMalloyValue(value: string | number | boolean | Date | null | undefined, isDate?: boolean): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloy-publisher/sdk",
|
|
3
3
|
"description": "Malloy Publisher SDK",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
7
7
|
"module": "dist/index.es.js",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"build": "bun generate-api-types && bunx vite build",
|
|
76
76
|
"postbuild": "cp ../../node_modules/@malloydata/malloy-explorer/dist/malloy-explorer.css ./dist/malloy-explorer.css && echo '/* SDK Styles */\n@import \"./malloy-explorer.css\";' > ./dist/styles.css",
|
|
77
77
|
"test": "bun test",
|
|
78
|
-
"test:tz": "bun test ./src/components/given/GivenInput.spec.tsx ./src/components/given/filterSummary.spec.ts ./src/components/given/paramCodec.spec.ts ./src/utils/malloyLiteral.spec.ts ./src/components/drill/resolveDrill.spec.ts ./src/components/ReportBuilder/preview.spec.ts ./src/components/Materializations/cron.spec.ts ./src/components/Materializations/utils.spec.ts",
|
|
78
|
+
"test:tz": "bun test ./src/components/given/GivenInput.spec.tsx ./src/components/given/filterSummary.spec.ts ./src/components/given/paramCodec.spec.ts ./src/utils/malloyLiteral.spec.ts ./src/utils/filterCondition.spec.ts ./src/hooks/useDimensionalFilterRangeData.spec.ts ./src/components/drill/resolveDrill.spec.ts ./src/components/ReportBuilder/preview.spec.ts ./src/components/Materializations/cron.spec.ts ./src/components/Materializations/utils.spec.ts",
|
|
79
79
|
"lint": "bunx eslint ./src ./test --fix",
|
|
80
80
|
"format": "bunx prettier --write --parser typescript '**/*.{ts,tsx}'",
|
|
81
81
|
"analyze": "bunx vite-bundle-visualizer",
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import "@malloydata/malloy-explorer/styles.css";
|
|
5
|
+
import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
|
|
6
|
+
import SearchIcon from "@mui/icons-material/Search";
|
|
7
|
+
import {
|
|
8
|
+
Box,
|
|
9
|
+
IconButton,
|
|
10
|
+
Snackbar,
|
|
11
|
+
Stack,
|
|
12
|
+
Tooltip,
|
|
13
|
+
Typography,
|
|
14
|
+
} from "@mui/material";
|
|
15
|
+
import React, { useState } from "react";
|
|
16
|
+
import { parseResourceUri } from "../../utils/formatting";
|
|
17
|
+
import { ApiErrorDisplay } from "../ApiErrorDisplay";
|
|
18
|
+
import { FloatingIconButton } from "../FloatingIconButton";
|
|
19
|
+
import { Loading } from "../Loading";
|
|
20
|
+
import { ModelCell } from "./ModelCell";
|
|
21
|
+
import { ModelExplorer } from "./ModelExplorer";
|
|
22
|
+
import type { ModelProps } from "./Model";
|
|
23
|
+
import { ModelExplorerDialog } from "./ModelExplorerDialog";
|
|
24
|
+
import { QueryExplorerResult } from "./SourcesExplorer";
|
|
25
|
+
import { useModelData } from "./useModelData";
|
|
26
|
+
|
|
27
|
+
// Note: For this to properly render outside of publisher,
|
|
28
|
+
// you must explicitly import the styles from the package:
|
|
29
|
+
// import "@malloy-publisher/sdk/malloy-explorer.css";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The model page on a server whose `PUBLISHER_MODEL_PAGE` is `explorer`, the
|
|
33
|
+
* default: the Malloy Explorer over the model's sources, and its named
|
|
34
|
+
* queries. The Explorer writes the queries it builds back to Malloy text
|
|
35
|
+
* through `@malloydata/malloy-interfaces`, which puts a string value in
|
|
36
|
+
* unescaped, so a drilled value holding a double quote rewrites its query.
|
|
37
|
+
*/
|
|
38
|
+
export function ExplorerPage({
|
|
39
|
+
onChange,
|
|
40
|
+
resourceUri,
|
|
41
|
+
runOnDemand = false,
|
|
42
|
+
maxResultSize = 0,
|
|
43
|
+
givens,
|
|
44
|
+
onGivensChange,
|
|
45
|
+
}: ModelProps) {
|
|
46
|
+
const { modelPath } = parseResourceUri(resourceUri);
|
|
47
|
+
const { data, isError, isLoading, error } = useModelData(resourceUri);
|
|
48
|
+
const [dialogOpen, setDialogOpen] = React.useState(false);
|
|
49
|
+
const [sharedQuery, setSharedQuery] = React.useState<
|
|
50
|
+
QueryExplorerResult | undefined
|
|
51
|
+
>();
|
|
52
|
+
const [sharedSourceIndex, setSharedSourceIndex] = React.useState(0);
|
|
53
|
+
const [copyMessage, setCopyMessage] = useState("");
|
|
54
|
+
// Held here only when the host passes neither prop, so the embedded
|
|
55
|
+
// explorer and the maximized dialog still agree on one set of values
|
|
56
|
+
// rather than each defaulting independently.
|
|
57
|
+
const [localGivens, setLocalGivens] = React.useState<Record<string, string>>(
|
|
58
|
+
{},
|
|
59
|
+
);
|
|
60
|
+
const effectiveGivens = givens ?? localGivens;
|
|
61
|
+
const effectiveOnGivensChange =
|
|
62
|
+
onGivensChange ??
|
|
63
|
+
((applied: Record<string, string>) => setLocalGivens(applied));
|
|
64
|
+
|
|
65
|
+
// Whether the model imports other files — drives the empty-state hint for
|
|
66
|
+
// import-only models, whose discovery surface is legitimately empty (no
|
|
67
|
+
// local sources, no export{}) but whose page would otherwise render blank.
|
|
68
|
+
// `modelDef` is returned by the server but intentionally absent from the
|
|
69
|
+
// typed CompiledModel schema (internal compiler blob), hence the cast.
|
|
70
|
+
const modelDefJson = (data as { modelDef?: string } | undefined)?.modelDef;
|
|
71
|
+
const hasImports = React.useMemo(() => {
|
|
72
|
+
if (!modelDefJson) return false;
|
|
73
|
+
try {
|
|
74
|
+
const def = JSON.parse(modelDefJson) as { imports?: unknown[] };
|
|
75
|
+
return Array.isArray(def.imports) && def.imports.length > 0;
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}, [modelDefJson]);
|
|
80
|
+
|
|
81
|
+
if (isLoading) {
|
|
82
|
+
return <Loading text="Fetching Model..." />;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (isError) {
|
|
86
|
+
console.log("error", error);
|
|
87
|
+
return <ApiErrorDisplay error={error} context={`Model > ${modelPath}`} />;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Shared handlers for both embedded and dialog explorers
|
|
91
|
+
const handleQueryChange = (query: QueryExplorerResult) => {
|
|
92
|
+
setSharedQuery(query);
|
|
93
|
+
if (onChange) {
|
|
94
|
+
onChange(query);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const handleSourceChange = (index: number) => {
|
|
99
|
+
setSharedSourceIndex(index);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const copyToClipboard = () => {
|
|
103
|
+
const url = window.location.href;
|
|
104
|
+
navigator.clipboard
|
|
105
|
+
.writeText(url)
|
|
106
|
+
.then(() => setCopyMessage("URL copied to clipboard!"))
|
|
107
|
+
.catch(() => setCopyMessage("Failed to copy URL"));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<>
|
|
112
|
+
<Box
|
|
113
|
+
sx={{
|
|
114
|
+
position: "relative",
|
|
115
|
+
maxWidth: "1200px",
|
|
116
|
+
margin: "0 auto",
|
|
117
|
+
paddingTop: "24px",
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
{/* Sources Section */}
|
|
121
|
+
{Array.isArray(data?.sourceInfos) &&
|
|
122
|
+
data.sourceInfos.length > 0 && (
|
|
123
|
+
<Stack spacing={2} component="section">
|
|
124
|
+
{/* Sources Header */}
|
|
125
|
+
<Box
|
|
126
|
+
sx={{
|
|
127
|
+
padding: "0 0 16px 0",
|
|
128
|
+
display: "flex",
|
|
129
|
+
alignItems: "center",
|
|
130
|
+
justifyContent: "space-between",
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<Typography
|
|
134
|
+
variant="h1"
|
|
135
|
+
sx={{
|
|
136
|
+
fontSize: "28px",
|
|
137
|
+
fontWeight: "600",
|
|
138
|
+
color: "#1a1a1a",
|
|
139
|
+
marginBottom: "8px",
|
|
140
|
+
marginTop: "0",
|
|
141
|
+
paddingLeft: "0",
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
Sources
|
|
145
|
+
</Typography>
|
|
146
|
+
<Tooltip title="Copy link">
|
|
147
|
+
<IconButton
|
|
148
|
+
size="small"
|
|
149
|
+
aria-label="Copy link"
|
|
150
|
+
onClick={copyToClipboard}
|
|
151
|
+
sx={{ color: "text.secondary" }}
|
|
152
|
+
>
|
|
153
|
+
<LinkOutlinedIcon fontSize="small" />
|
|
154
|
+
</IconButton>
|
|
155
|
+
</Tooltip>
|
|
156
|
+
</Box>
|
|
157
|
+
|
|
158
|
+
<ModelExplorer
|
|
159
|
+
data={data}
|
|
160
|
+
onChange={handleQueryChange}
|
|
161
|
+
onSourceChange={handleSourceChange}
|
|
162
|
+
existingQuery={sharedQuery}
|
|
163
|
+
initialSelectedSourceIndex={sharedSourceIndex}
|
|
164
|
+
resourceUri={resourceUri}
|
|
165
|
+
givens={effectiveGivens}
|
|
166
|
+
onGivensChange={effectiveOnGivensChange}
|
|
167
|
+
/>
|
|
168
|
+
|
|
169
|
+
{/* Magnifying glass icon */}
|
|
170
|
+
<FloatingIconButton
|
|
171
|
+
aria-label="Expand results"
|
|
172
|
+
sx={{
|
|
173
|
+
position: "absolute",
|
|
174
|
+
top: "90px",
|
|
175
|
+
right: "4px",
|
|
176
|
+
zIndex: 2,
|
|
177
|
+
}}
|
|
178
|
+
onClick={() => setDialogOpen(true)}
|
|
179
|
+
>
|
|
180
|
+
<SearchIcon />
|
|
181
|
+
</FloatingIconButton>
|
|
182
|
+
</Stack>
|
|
183
|
+
)}
|
|
184
|
+
|
|
185
|
+
{/* Named Queries Section */}
|
|
186
|
+
{data?.queries?.length > 0 && (
|
|
187
|
+
<Stack
|
|
188
|
+
spacing={2}
|
|
189
|
+
component="section"
|
|
190
|
+
sx={{ marginTop: "24px" }}
|
|
191
|
+
>
|
|
192
|
+
{/* Named Queries Header */}
|
|
193
|
+
<Box sx={{ padding: "0 0 16px 0" }}>
|
|
194
|
+
<Typography
|
|
195
|
+
variant="h2"
|
|
196
|
+
sx={{
|
|
197
|
+
fontSize: "24px",
|
|
198
|
+
fontWeight: "600",
|
|
199
|
+
color: "#1a1a1a",
|
|
200
|
+
marginBottom: "0",
|
|
201
|
+
marginTop: "8px",
|
|
202
|
+
paddingLeft: "0",
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
Named Queries
|
|
206
|
+
</Typography>
|
|
207
|
+
</Box>
|
|
208
|
+
|
|
209
|
+
{/* Render the named queries */}
|
|
210
|
+
{data.queries.map((query) => (
|
|
211
|
+
<ModelCell
|
|
212
|
+
key={query.name}
|
|
213
|
+
queryName={query.name}
|
|
214
|
+
annotations={query.annotations}
|
|
215
|
+
resourceUri={resourceUri}
|
|
216
|
+
runOnDemand={runOnDemand}
|
|
217
|
+
maxResultSize={maxResultSize}
|
|
218
|
+
/>
|
|
219
|
+
))}
|
|
220
|
+
</Stack>
|
|
221
|
+
)}
|
|
222
|
+
|
|
223
|
+
{/* Empty discovery surface: nothing exported, nothing to render.
|
|
224
|
+
For import-only models, say why and how to fix it — otherwise
|
|
225
|
+
the page reads as broken. */}
|
|
226
|
+
{(!Array.isArray(data?.sourceInfos) ||
|
|
227
|
+
data.sourceInfos.length === 0) &&
|
|
228
|
+
!(data?.queries && data.queries.length > 0) && (
|
|
229
|
+
<Box sx={{ textAlign: "center", py: 6 }}>
|
|
230
|
+
<Typography
|
|
231
|
+
variant="body1"
|
|
232
|
+
sx={{ color: "text.secondary", marginBottom: "8px" }}
|
|
233
|
+
>
|
|
234
|
+
This model exposes no sources or queries.
|
|
235
|
+
</Typography>
|
|
236
|
+
{hasImports && (
|
|
237
|
+
<Typography variant="body2" color="text.secondary">
|
|
238
|
+
It imports other files but re-exports nothing. Add{" "}
|
|
239
|
+
<code>export {"{ source_name }"}</code> to surface
|
|
240
|
+
imported sources here.
|
|
241
|
+
</Typography>
|
|
242
|
+
)}
|
|
243
|
+
</Box>
|
|
244
|
+
)}
|
|
245
|
+
|
|
246
|
+
{/* Model Explorer Dialog */}
|
|
247
|
+
<ModelExplorerDialog
|
|
248
|
+
open={dialogOpen}
|
|
249
|
+
onClose={() => setDialogOpen(false)}
|
|
250
|
+
resourceUri={resourceUri}
|
|
251
|
+
data={data}
|
|
252
|
+
title={`Model: ${modelPath.split("/").pop()}`}
|
|
253
|
+
existingQuery={sharedQuery}
|
|
254
|
+
initialSelectedSourceIndex={sharedSourceIndex}
|
|
255
|
+
onChange={handleQueryChange}
|
|
256
|
+
onSourceChange={handleSourceChange}
|
|
257
|
+
givens={effectiveGivens}
|
|
258
|
+
onGivensChange={effectiveOnGivensChange}
|
|
259
|
+
/>
|
|
260
|
+
</Box>
|
|
261
|
+
<Snackbar
|
|
262
|
+
open={copyMessage !== ""}
|
|
263
|
+
autoHideDuration={6000}
|
|
264
|
+
onClose={() => setCopyMessage("")}
|
|
265
|
+
message={copyMessage}
|
|
266
|
+
/>
|
|
267
|
+
</>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
@@ -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 };
|