@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,362 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, Collapse } from "@mui/material";
|
|
5
|
+
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
|
|
6
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
7
|
+
import { AccessChips, AccessFacts } from "./AccessChips";
|
|
8
|
+
import { HeaderCardContext } from "./headerCard";
|
|
9
|
+
import { OffSurfaceChip, PublicSurfaceChip } from "./offSurface";
|
|
10
|
+
import type { RowLayer } from "./rowLayers";
|
|
11
|
+
import { isRestricted, isRowFiltered, type SourceAccess } from "./sourceAccess";
|
|
12
|
+
import { FILE_VIEW_TOP_GAP, PANE_CARD_SX, PANE_INSET } from "./surface";
|
|
13
|
+
import { fontSizes, MONO_FONT_FAMILY } from "./theme";
|
|
14
|
+
|
|
15
|
+
/** The last defined value, kept while a collapsing card closes with its contents in it. */
|
|
16
|
+
function useHeld<T>(value: T | undefined): T | undefined {
|
|
17
|
+
const held = useRef(value);
|
|
18
|
+
if (value !== undefined) held.current = value;
|
|
19
|
+
return held.current;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The model page's header: the source's name as the page's heading, and beside
|
|
24
|
+
* it the source picker ("2 sources ▾", {@link import("./SourcesNav").SourcesNav}),
|
|
25
|
+
* with a host's actions on the right. Then the source's status row (who can
|
|
26
|
+
* query it, whether the package exposes the file, and what a host adds), the
|
|
27
|
+
* model's and the source's docs, and the quiet meta line ("Source · 33 fields ·
|
|
28
|
+
* from …").
|
|
29
|
+
*/
|
|
30
|
+
export function HeaderBar({
|
|
31
|
+
/** The heading: the source's name, or on a model with only queries the model's name. */
|
|
32
|
+
title,
|
|
33
|
+
/** Beside the heading: the source picker. */
|
|
34
|
+
titleAdornments,
|
|
35
|
+
/** What the title is, leading the meta line: "Source · 43 fields". */
|
|
36
|
+
kindLabel,
|
|
37
|
+
/** The meta line's count, after the kind: "33 fields", or "2 queries" on a model with only queries. */
|
|
38
|
+
meta,
|
|
39
|
+
/** The source's own `#(doc)`, printed under its name. */
|
|
40
|
+
doc,
|
|
41
|
+
/** Where the source comes from, at the end of the meta line. */
|
|
42
|
+
provenance,
|
|
43
|
+
/** Controls on the heading line's right. */
|
|
44
|
+
actions,
|
|
45
|
+
/** A host's chips on the status row, after the viewer's own. */
|
|
46
|
+
status,
|
|
47
|
+
/** The title's heading level: the page's h1 where the viewer is the page,
|
|
48
|
+
* a level down where it is a panel on another page. */
|
|
49
|
+
headingLevel = "h1",
|
|
50
|
+
/** The model file's own description, ahead of the source's. */
|
|
51
|
+
modelDoc,
|
|
52
|
+
/** The source's `#(authorize)` / `#(access_filter)` declarations: chips on
|
|
53
|
+
* the status row, and their facts in the card the chips open. */
|
|
54
|
+
access,
|
|
55
|
+
/** Whether the reader can change the model, so the card also shows the
|
|
56
|
+
* rules' Malloy (an editor's vocabulary) beside their words. */
|
|
57
|
+
showRules = false,
|
|
58
|
+
/** False for a model's own header (no sources, only queries): it has no status row. */
|
|
59
|
+
isSource = true,
|
|
60
|
+
/** The file is one the package's `index.malloy` leaves out: its Private chip leads the status row. */
|
|
61
|
+
offSurface,
|
|
62
|
+
/** The file is the package's root `index.malloy`, whose sources are the package's public
|
|
63
|
+
* ones: its Public chip sits in the status row where a hidden file's Private does. */
|
|
64
|
+
publicSurface = false,
|
|
65
|
+
}: {
|
|
66
|
+
title: ReactNode;
|
|
67
|
+
titleAdornments?: ReactNode;
|
|
68
|
+
kindLabel?: string;
|
|
69
|
+
meta?: ReactNode;
|
|
70
|
+
doc?: string;
|
|
71
|
+
provenance?: ReactNode;
|
|
72
|
+
actions?: ReactNode;
|
|
73
|
+
status?: ReactNode;
|
|
74
|
+
headingLevel?: "h1" | "h2";
|
|
75
|
+
modelDoc?: string;
|
|
76
|
+
access?: SourceAccess;
|
|
77
|
+
showRules?: boolean;
|
|
78
|
+
isSource?: boolean;
|
|
79
|
+
offSurface?: boolean;
|
|
80
|
+
publicSurface?: boolean;
|
|
81
|
+
}) {
|
|
82
|
+
const hasAccess = isRestricted(access) || isRowFiltered(access);
|
|
83
|
+
// The card under the header holds who can query the source, opened from the
|
|
84
|
+
// Restricted / Row filtered chip that names it, never from the name.
|
|
85
|
+
const layers: RowLayer[] = hasAccess ? ["access"] : [];
|
|
86
|
+
const [openLayer, setOpenLayer] = useState<RowLayer | undefined>(undefined);
|
|
87
|
+
const shownLayer: RowLayer | undefined =
|
|
88
|
+
openLayer !== undefined && layers.includes(openLayer)
|
|
89
|
+
? openLayer
|
|
90
|
+
: undefined;
|
|
91
|
+
const cardLayer = useHeld(shownLayer);
|
|
92
|
+
const cardId = useId();
|
|
93
|
+
const headerCard = {
|
|
94
|
+
openLayer: shownLayer,
|
|
95
|
+
layers,
|
|
96
|
+
toggle: (layer: RowLayer) =>
|
|
97
|
+
setOpenLayer((current) => (current === layer ? undefined : layer)),
|
|
98
|
+
cardId,
|
|
99
|
+
};
|
|
100
|
+
const hasStatus = hasAccess || offSurface || publicSurface || !!status;
|
|
101
|
+
// The host's page title, a step smaller where the viewer is a section of a page.
|
|
102
|
+
const pageTitle = usePublisherTheme().theme.ui.type.pageTitle;
|
|
103
|
+
const titleSize =
|
|
104
|
+
typeof pageTitle.fontSize === "number"
|
|
105
|
+
? `${pageTitle.fontSize}px`
|
|
106
|
+
: pageTitle.fontSize;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<Box>
|
|
110
|
+
<Box
|
|
111
|
+
data-testid="model-viewer-source-heading"
|
|
112
|
+
sx={{
|
|
113
|
+
display: "flex",
|
|
114
|
+
alignItems: "center",
|
|
115
|
+
flexWrap: "wrap",
|
|
116
|
+
gap: 1.5,
|
|
117
|
+
pt: FILE_VIEW_TOP_GAP,
|
|
118
|
+
pb: 0.5,
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<Box
|
|
122
|
+
component={headingLevel}
|
|
123
|
+
sx={{
|
|
124
|
+
m: 0,
|
|
125
|
+
fontSize:
|
|
126
|
+
headingLevel === "h1"
|
|
127
|
+
? titleSize
|
|
128
|
+
: `calc(${titleSize} * 0.8)`,
|
|
129
|
+
fontWeight: pageTitle.fontWeight ?? 600,
|
|
130
|
+
lineHeight: 1.25,
|
|
131
|
+
color: "text.primary",
|
|
132
|
+
fontFamily: MONO_FONT_FAMILY,
|
|
133
|
+
minWidth: 0,
|
|
134
|
+
overflowWrap: "anywhere",
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{title}
|
|
138
|
+
</Box>
|
|
139
|
+
{titleAdornments}
|
|
140
|
+
{actions && (
|
|
141
|
+
<Box
|
|
142
|
+
sx={{
|
|
143
|
+
ml: "auto",
|
|
144
|
+
display: "flex",
|
|
145
|
+
alignItems: "center",
|
|
146
|
+
gap: 1,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{actions}
|
|
150
|
+
</Box>
|
|
151
|
+
)}
|
|
152
|
+
</Box>
|
|
153
|
+
{!isSource && offSurface && (
|
|
154
|
+
<Box sx={{ display: "flex", alignItems: "center", pt: 0.5, pb: 1 }}>
|
|
155
|
+
<OffSurfaceChip />
|
|
156
|
+
</Box>
|
|
157
|
+
)}
|
|
158
|
+
{isSource && hasStatus && (
|
|
159
|
+
// The source's state, all on one row under its name.
|
|
160
|
+
<HeaderCardContext.Provider value={headerCard}>
|
|
161
|
+
<Box
|
|
162
|
+
data-testid="model-viewer-status-row"
|
|
163
|
+
sx={{
|
|
164
|
+
display: "flex",
|
|
165
|
+
alignItems: "center",
|
|
166
|
+
flexWrap: "wrap",
|
|
167
|
+
gap: 1.5,
|
|
168
|
+
pt: 0.5,
|
|
169
|
+
pb: 1,
|
|
170
|
+
}}
|
|
171
|
+
>
|
|
172
|
+
<AccessChips access={access} />
|
|
173
|
+
{offSurface && <OffSurfaceChip />}
|
|
174
|
+
{publicSurface && <PublicSurfaceChip />}
|
|
175
|
+
{status}
|
|
176
|
+
</Box>
|
|
177
|
+
</HeaderCardContext.Provider>
|
|
178
|
+
)}
|
|
179
|
+
{/* The model's own description, ahead of the source's: it describes the
|
|
180
|
+
file every source here belongs to. */}
|
|
181
|
+
{modelDoc && (
|
|
182
|
+
<SourceDoc
|
|
183
|
+
key={`model:${modelDoc}`}
|
|
184
|
+
doc={modelDoc}
|
|
185
|
+
label="model description"
|
|
186
|
+
testId="model-viewer-model-doc"
|
|
187
|
+
/>
|
|
188
|
+
)}
|
|
189
|
+
{/* Keyed by the doc: another source's or query's starts clamped, measured afresh. */}
|
|
190
|
+
{doc && <SourceDoc key={doc} doc={doc} />}
|
|
191
|
+
{/* One quiet line under the name: what it is, how many fields, and where it comes from. */}
|
|
192
|
+
{(kindLabel !== undefined || meta !== undefined || provenance) && (
|
|
193
|
+
<Box
|
|
194
|
+
// Addressable because every join row in the pane below carries
|
|
195
|
+
// its own "N fields" too, so a text match for the count is
|
|
196
|
+
// ambiguous on any source with joins.
|
|
197
|
+
data-testid="model-viewer-source-meta"
|
|
198
|
+
sx={{
|
|
199
|
+
display: "flex",
|
|
200
|
+
alignItems: "center",
|
|
201
|
+
gap: 0.75,
|
|
202
|
+
minWidth: 0,
|
|
203
|
+
pb: 2,
|
|
204
|
+
fontSize: fontSizes.body,
|
|
205
|
+
color: "text.secondary",
|
|
206
|
+
whiteSpace: "nowrap",
|
|
207
|
+
overflow: "hidden",
|
|
208
|
+
textOverflow: "ellipsis",
|
|
209
|
+
}}
|
|
210
|
+
>
|
|
211
|
+
{kindLabel !== undefined && (
|
|
212
|
+
<Box component="span" data-testid="model-viewer-source-kind">
|
|
213
|
+
{kindLabel}
|
|
214
|
+
</Box>
|
|
215
|
+
)}
|
|
216
|
+
{kindLabel !== undefined &&
|
|
217
|
+
(meta !== undefined || provenance) && (
|
|
218
|
+
<Box component="span" aria-hidden>
|
|
219
|
+
·
|
|
220
|
+
</Box>
|
|
221
|
+
)}
|
|
222
|
+
{meta !== undefined && <Box component="span">{meta}</Box>}
|
|
223
|
+
{meta !== undefined && provenance && (
|
|
224
|
+
<Box component="span" aria-hidden>
|
|
225
|
+
·
|
|
226
|
+
</Box>
|
|
227
|
+
)}
|
|
228
|
+
{provenance && (
|
|
229
|
+
<Box
|
|
230
|
+
component="span"
|
|
231
|
+
sx={{
|
|
232
|
+
minWidth: 0,
|
|
233
|
+
overflow: "hidden",
|
|
234
|
+
textOverflow: "ellipsis",
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
{provenance}
|
|
238
|
+
</Box>
|
|
239
|
+
)}
|
|
240
|
+
</Box>
|
|
241
|
+
)}
|
|
242
|
+
<Collapse in={shownLayer !== undefined} timeout="auto" unmountOnExit>
|
|
243
|
+
<Box
|
|
244
|
+
id={cardId}
|
|
245
|
+
data-testid="model-viewer-source-detail"
|
|
246
|
+
data-layer={cardLayer ?? undefined}
|
|
247
|
+
sx={{ ...PANE_CARD_SX, p: PANE_INSET, mb: 2 }}
|
|
248
|
+
>
|
|
249
|
+
{cardLayer === "access" && access && (
|
|
250
|
+
<AccessFacts access={access} showRules={showRules} />
|
|
251
|
+
)}
|
|
252
|
+
</Box>
|
|
253
|
+
</Collapse>
|
|
254
|
+
</Box>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Lines a source's doc shows before "More". */
|
|
259
|
+
const DOC_LINES = 2;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* A source's doc under its name: at most two lines until the reader asks for the
|
|
263
|
+
* rest, with `backticked` names set as code rather than showing the backticks. A
|
|
264
|
+
* doc is written for the agent as much as the reader and runs long; the header's
|
|
265
|
+
* job is to say what the source is at a glance.
|
|
266
|
+
*/
|
|
267
|
+
export function SourceDoc({
|
|
268
|
+
doc,
|
|
269
|
+
label = "description",
|
|
270
|
+
testId = "model-viewer-source-doc",
|
|
271
|
+
}: {
|
|
272
|
+
doc: string;
|
|
273
|
+
/** What the More / Less button's accessible name calls the text. */
|
|
274
|
+
label?: string;
|
|
275
|
+
testId?: string;
|
|
276
|
+
}) {
|
|
277
|
+
const [open, setOpen] = useState(false);
|
|
278
|
+
const [overflows, setOverflows] = useState(false);
|
|
279
|
+
const textRef = useRef<HTMLElement | null>(null);
|
|
280
|
+
// Measured on every resize, not once: a panel narrowed after load clips more
|
|
281
|
+
// lines, and without re-measuring the rest would be clipped with no More.
|
|
282
|
+
useEffect(() => {
|
|
283
|
+
const el = textRef.current;
|
|
284
|
+
if (!el || open) return;
|
|
285
|
+
const measure = () => setOverflows(el.scrollHeight > el.clientHeight + 1);
|
|
286
|
+
measure();
|
|
287
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
288
|
+
const observer = new ResizeObserver(measure);
|
|
289
|
+
observer.observe(el);
|
|
290
|
+
return () => observer.disconnect();
|
|
291
|
+
}, [open, doc]);
|
|
292
|
+
return (
|
|
293
|
+
<Box data-testid={testId} sx={{ pb: 0.5 }}>
|
|
294
|
+
<Box
|
|
295
|
+
ref={textRef}
|
|
296
|
+
sx={{
|
|
297
|
+
fontSize: fontSizes.body,
|
|
298
|
+
lineHeight: 1.5,
|
|
299
|
+
color: "text.secondary",
|
|
300
|
+
whiteSpace: "pre-line",
|
|
301
|
+
...(open
|
|
302
|
+
? {}
|
|
303
|
+
: {
|
|
304
|
+
display: "-webkit-box",
|
|
305
|
+
WebkitBoxOrient: "vertical",
|
|
306
|
+
WebkitLineClamp: DOC_LINES,
|
|
307
|
+
overflow: "hidden",
|
|
308
|
+
}),
|
|
309
|
+
}}
|
|
310
|
+
>
|
|
311
|
+
{withInlineCode(doc)}
|
|
312
|
+
</Box>
|
|
313
|
+
{(overflows || open) && (
|
|
314
|
+
<Box
|
|
315
|
+
component="button"
|
|
316
|
+
type="button"
|
|
317
|
+
onClick={() => setOpen(!open)}
|
|
318
|
+
aria-expanded={open}
|
|
319
|
+
aria-label={
|
|
320
|
+
open ? `Show less of the ${label}` : `Show the full ${label}`
|
|
321
|
+
}
|
|
322
|
+
sx={{
|
|
323
|
+
all: "unset",
|
|
324
|
+
cursor: "pointer",
|
|
325
|
+
fontSize: fontSizes.small,
|
|
326
|
+
color: "text.secondary",
|
|
327
|
+
textDecoration: "underline",
|
|
328
|
+
"&:hover": { color: "text.primary" },
|
|
329
|
+
"&:focus-visible": {
|
|
330
|
+
outline: "2px solid",
|
|
331
|
+
outlineColor: "primary.main",
|
|
332
|
+
outlineOffset: 2,
|
|
333
|
+
},
|
|
334
|
+
}}
|
|
335
|
+
>
|
|
336
|
+
{open ? "Less" : "More"}
|
|
337
|
+
</Box>
|
|
338
|
+
)}
|
|
339
|
+
</Box>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** `name` spans as code; everything else as written. */
|
|
344
|
+
export function withInlineCode(text: string): ReactNode[] {
|
|
345
|
+
return text.split(/(`[^`\n]+`)/g).map((part, i) =>
|
|
346
|
+
/^`[^`]+`$/.test(part) ? (
|
|
347
|
+
<Box
|
|
348
|
+
key={i}
|
|
349
|
+
component="code"
|
|
350
|
+
sx={{
|
|
351
|
+
fontFamily: MONO_FONT_FAMILY,
|
|
352
|
+
fontSize: "0.92em",
|
|
353
|
+
color: "text.primary",
|
|
354
|
+
}}
|
|
355
|
+
>
|
|
356
|
+
{part.slice(1, -1)}
|
|
357
|
+
</Box>
|
|
358
|
+
) : (
|
|
359
|
+
part
|
|
360
|
+
),
|
|
361
|
+
);
|
|
362
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, type SxProps, type Theme } from "@mui/material";
|
|
5
|
+
import type { MouseEvent } from "react";
|
|
6
|
+
import { fontSizes, TEXT_TERTIARY } from "./theme";
|
|
7
|
+
|
|
8
|
+
/** Whether a one-line description hides part of `doc`: clipped by its ellipsis,
|
|
9
|
+
* or showing only the first of several lines. */
|
|
10
|
+
export function isDocCut(el: HTMLElement, doc: string): boolean {
|
|
11
|
+
return doc.includes("\n") || el.scrollWidth > el.clientWidth;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A row's description, printed on the row: its first line, cut to the space it
|
|
16
|
+
* has, with the whole text as a plain title only when some of it is cut off.
|
|
17
|
+
*/
|
|
18
|
+
export function InlineDoc({
|
|
19
|
+
doc,
|
|
20
|
+
sx,
|
|
21
|
+
testId,
|
|
22
|
+
}: {
|
|
23
|
+
doc: string;
|
|
24
|
+
sx?: SxProps<Theme>;
|
|
25
|
+
testId?: string;
|
|
26
|
+
}) {
|
|
27
|
+
return (
|
|
28
|
+
<Box
|
|
29
|
+
component="span"
|
|
30
|
+
data-testid={testId}
|
|
31
|
+
onMouseEnter={(e: MouseEvent<HTMLElement>) => {
|
|
32
|
+
const el = e.currentTarget;
|
|
33
|
+
el.title = isDocCut(el, doc) ? doc : "";
|
|
34
|
+
}}
|
|
35
|
+
sx={[
|
|
36
|
+
{
|
|
37
|
+
minWidth: 0,
|
|
38
|
+
fontSize: fontSizes.small,
|
|
39
|
+
color: TEXT_TERTIARY,
|
|
40
|
+
whiteSpace: "nowrap",
|
|
41
|
+
overflow: "hidden",
|
|
42
|
+
textOverflow: "ellipsis",
|
|
43
|
+
},
|
|
44
|
+
...(Array.isArray(sx) ? sx : [sx]),
|
|
45
|
+
]}
|
|
46
|
+
>
|
|
47
|
+
{doc.split("\n")[0]}
|
|
48
|
+
</Box>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box } from "@mui/material";
|
|
5
|
+
import { useCallback, useMemo, useState } from "react";
|
|
6
|
+
import type { GivenValue } from "../../hooks/givenValue";
|
|
7
|
+
import { useSettled } from "../../hooks/useSettled";
|
|
8
|
+
import { useSuggestOptions } from "../../hooks/useSuggestOptions";
|
|
9
|
+
import { GivensPanel } from "../given/GivensPanel";
|
|
10
|
+
import type { GivenInfo } from "./modelGivens";
|
|
11
|
+
import { ModelSection } from "./ModelSection";
|
|
12
|
+
import { wordList } from "./runGate";
|
|
13
|
+
import { BodyText } from "./text";
|
|
14
|
+
|
|
15
|
+
/** How long given values hold still before the suggest queries behind a select re-run. */
|
|
16
|
+
const GIVEN_SETTLE_MS = 400;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The page's Givens section: the givens this source reads, as a page section
|
|
20
|
+
* like its Views and fields (title, "2 givens"), first on the page because they
|
|
21
|
+
* set every run below it. Inside it, the SDK's `GivensPanel` in its `bar`
|
|
22
|
+
* layout, the dashboard's filter bar, so a given is set with the same control,
|
|
23
|
+
* the same "Default: …" line and the same Reset on a model page as on a
|
|
24
|
+
* dashboard. None when the source reads no given. When the page can't tell
|
|
25
|
+
* whether the source reads a given it shows, it says that a value set for it
|
|
26
|
+
* may not apply, rather than offering a control that looks as if it narrows
|
|
27
|
+
* every run.
|
|
28
|
+
*/
|
|
29
|
+
export function ModelGivensSection({
|
|
30
|
+
givens,
|
|
31
|
+
unknown,
|
|
32
|
+
inheritedFrom,
|
|
33
|
+
values,
|
|
34
|
+
onChange,
|
|
35
|
+
onReset,
|
|
36
|
+
environmentName,
|
|
37
|
+
packageName,
|
|
38
|
+
modelPath,
|
|
39
|
+
versionId,
|
|
40
|
+
declaredTypes,
|
|
41
|
+
}: {
|
|
42
|
+
/** The givens this source reads (host-filled ones already left out). */
|
|
43
|
+
givens: ReadonlyArray<GivenInfo>;
|
|
44
|
+
/** Names of the givens shown that the page can't tie to the source either
|
|
45
|
+
* way: its model file builds it on an import, a query or a `compose(…)`
|
|
46
|
+
* (scanGivensForSource). */
|
|
47
|
+
unknown?: ReadonlySet<string>;
|
|
48
|
+
/** Given name → the sources it is read by that the page can't open (the
|
|
49
|
+
* model doesn't export them), for the line naming where it comes from. */
|
|
50
|
+
inheritedFrom?: ReadonlyMap<string, string[]>;
|
|
51
|
+
values: Map<string, GivenValue>;
|
|
52
|
+
onChange: (name: string, value: GivenValue) => void;
|
|
53
|
+
onReset: () => void;
|
|
54
|
+
environmentName: string;
|
|
55
|
+
packageName: string;
|
|
56
|
+
modelPath: string;
|
|
57
|
+
versionId?: string;
|
|
58
|
+
declaredTypes: ReadonlyMap<string, string | undefined>;
|
|
59
|
+
}) {
|
|
60
|
+
const specs = useMemo(() => [...givens], [givens]);
|
|
61
|
+
const unknownNote = useMemo(() => {
|
|
62
|
+
const shown = givens.filter((g) => unknown?.has(g.name));
|
|
63
|
+
if (shown.length === 0) return undefined;
|
|
64
|
+
if (shown.length === givens.length)
|
|
65
|
+
return "This page can't tell which of these givens this source reads, so a value set here may not apply to it.";
|
|
66
|
+
return `This page can't tell whether this source reads ${wordList(
|
|
67
|
+
shown.map((g) => g.label ?? g.name),
|
|
68
|
+
"or",
|
|
69
|
+
)}, so a value set for ${shown.length === 1 ? "it" : "them"} may not apply.`;
|
|
70
|
+
}, [givens, unknown]);
|
|
71
|
+
// A picker's options are read when it is first opened, never on render:
|
|
72
|
+
// nothing on the page runs until the reader asks, and a suggest is a query
|
|
73
|
+
// like any other. Once opened, its list stays live for the page.
|
|
74
|
+
const [opened, setOpened] = useState<ReadonlySet<string>>(() => new Set());
|
|
75
|
+
const onControlOpen = useCallback(
|
|
76
|
+
(name: string) =>
|
|
77
|
+
setOpened((current) =>
|
|
78
|
+
current.has(name) ? current : new Set([...current, name]),
|
|
79
|
+
),
|
|
80
|
+
[],
|
|
81
|
+
);
|
|
82
|
+
// A suggest query carries the values of the givens that gate its source, so
|
|
83
|
+
// it re-runs as they change: settled first, so typing a gating given queries
|
|
84
|
+
// once rather than once per keystroke.
|
|
85
|
+
const settledValues = useSettled(values, GIVEN_SETTLE_MS);
|
|
86
|
+
const applied = useMemo(
|
|
87
|
+
() => ({ values: settledValues, declaredTypes }),
|
|
88
|
+
[settledValues, declaredTypes],
|
|
89
|
+
);
|
|
90
|
+
const { options, isLoading, failed, truncated, search } = useSuggestOptions(
|
|
91
|
+
environmentName,
|
|
92
|
+
packageName,
|
|
93
|
+
modelPath,
|
|
94
|
+
specs,
|
|
95
|
+
versionId,
|
|
96
|
+
applied,
|
|
97
|
+
undefined,
|
|
98
|
+
opened,
|
|
99
|
+
// The viewer writes every name quoted, whatever the server's model page.
|
|
100
|
+
true,
|
|
101
|
+
);
|
|
102
|
+
return (
|
|
103
|
+
<ModelSection
|
|
104
|
+
label="Givens"
|
|
105
|
+
count={givens.length}
|
|
106
|
+
testId="model-givens-section"
|
|
107
|
+
>
|
|
108
|
+
{/* The bar draws no heading of its own; the section's is the page's. */}
|
|
109
|
+
<Box sx={{ "& .MuiPaper-root": { borderColor: "divider" } }}>
|
|
110
|
+
<GivensPanel
|
|
111
|
+
layout="bar"
|
|
112
|
+
givens={specs}
|
|
113
|
+
values={values}
|
|
114
|
+
onChange={onChange}
|
|
115
|
+
onReset={onReset}
|
|
116
|
+
options={options}
|
|
117
|
+
optionsLoading={isLoading}
|
|
118
|
+
optionsFailed={failed}
|
|
119
|
+
optionsTruncated={truncated}
|
|
120
|
+
optionSearch={search}
|
|
121
|
+
onControlOpen={onControlOpen}
|
|
122
|
+
/>
|
|
123
|
+
</Box>
|
|
124
|
+
{unknownNote && (
|
|
125
|
+
<BodyText data-testid="model-givens-unknown" sx={{ mt: 1 }}>
|
|
126
|
+
{unknownNote}
|
|
127
|
+
</BodyText>
|
|
128
|
+
)}
|
|
129
|
+
{inheritedFrom && inheritedFrom.size > 0 && (
|
|
130
|
+
<BodyText data-testid="model-givens-inherited" sx={{ mt: 1 }}>
|
|
131
|
+
{[...inheritedFrom]
|
|
132
|
+
.map(([name, from]) =>
|
|
133
|
+
from.length === 1
|
|
134
|
+
? `${name} is inherited from ${from[0]}, which this model doesn't export.`
|
|
135
|
+
: `${name} is inherited from ${from.slice(0, -1).join(", ")} and ${from.at(-1)}, none of which this model exports.`,
|
|
136
|
+
)
|
|
137
|
+
.join(" ")}
|
|
138
|
+
</BodyText>
|
|
139
|
+
)}
|
|
140
|
+
</ModelSection>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { fontSizes, fontWeights } from "./theme";
|
|
7
|
+
import { ink, ROW_META_SX } from "./tokens";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One kind of thing a source holds (Views, Queries, Measures, Calculations,
|
|
11
|
+
* Dimensions, Joins)
|
|
12
|
+
* as a page section that is always open: the page's own section header (an h2),
|
|
13
|
+
* its Expand all under the title where it has one, then everything in it. No count: every
|
|
14
|
+
* row is on the page, and the line is the section's control's. A source page is read like a
|
|
15
|
+
* notebook, top to bottom, so nothing on it is folded away.
|
|
16
|
+
*
|
|
17
|
+
* <p>`level="h3"` is the same section one step down, inside a join: a joined
|
|
18
|
+
* source's Measures and Dimensions, titled as the page's own, a size smaller.
|
|
19
|
+
*/
|
|
20
|
+
export function ModelSection({
|
|
21
|
+
label,
|
|
22
|
+
count,
|
|
23
|
+
level = "h2",
|
|
24
|
+
testId,
|
|
25
|
+
action,
|
|
26
|
+
children,
|
|
27
|
+
}: {
|
|
28
|
+
label: string;
|
|
29
|
+
count: number;
|
|
30
|
+
level?: "h2" | "h3";
|
|
31
|
+
testId?: string;
|
|
32
|
+
/** A control on the line under the title (Expand all), on an h2 section. */
|
|
33
|
+
action?: ReactNode;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}) {
|
|
36
|
+
if (count === 0) return null;
|
|
37
|
+
if (level === "h3") {
|
|
38
|
+
// The h2's shape one step down: the title, then the rows.
|
|
39
|
+
return (
|
|
40
|
+
<Box
|
|
41
|
+
component="section"
|
|
42
|
+
aria-label={label}
|
|
43
|
+
data-testid={testId}
|
|
44
|
+
sx={{ mb: 2 }}
|
|
45
|
+
>
|
|
46
|
+
<Box
|
|
47
|
+
component="h3"
|
|
48
|
+
sx={{
|
|
49
|
+
m: 0,
|
|
50
|
+
mb: 1,
|
|
51
|
+
fontSize: fontSizes.bodyLarge,
|
|
52
|
+
fontWeight: fontWeights.strong,
|
|
53
|
+
color: ink,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{label}
|
|
57
|
+
</Box>
|
|
58
|
+
{children}
|
|
59
|
+
</Box>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return (
|
|
63
|
+
<Box
|
|
64
|
+
component="section"
|
|
65
|
+
aria-label={label}
|
|
66
|
+
data-testid={testId}
|
|
67
|
+
sx={{ mb: 3 }}
|
|
68
|
+
>
|
|
69
|
+
<Box sx={{ mb: 2 }}>
|
|
70
|
+
<Box
|
|
71
|
+
component="h2"
|
|
72
|
+
sx={{
|
|
73
|
+
m: 0,
|
|
74
|
+
fontSize: "1.25rem",
|
|
75
|
+
fontWeight: fontWeights.strong,
|
|
76
|
+
color: ink,
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
{label}
|
|
80
|
+
</Box>
|
|
81
|
+
{/* The section's Expand all, under the title rather than beside it. */}
|
|
82
|
+
{action && (
|
|
83
|
+
<Box
|
|
84
|
+
sx={{
|
|
85
|
+
...ROW_META_SX,
|
|
86
|
+
mt: 0.25,
|
|
87
|
+
display: "flex",
|
|
88
|
+
alignItems: "center",
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
{action}
|
|
92
|
+
</Box>
|
|
93
|
+
)}
|
|
94
|
+
</Box>
|
|
95
|
+
{children}
|
|
96
|
+
</Box>
|
|
97
|
+
);
|
|
98
|
+
}
|