@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
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, Collapse, Link } from "@mui/material";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { AccessPills } from "./AccessChips";
|
|
7
|
+
import { makeGetFieldCode } from "./fieldCode";
|
|
8
|
+
import type { EntitiesByField } from "./fieldEntities";
|
|
9
|
+
import { FieldGroup } from "./FieldGroup";
|
|
10
|
+
import { RowLine } from "./FieldRow";
|
|
11
|
+
import { IconOpen } from "./icons";
|
|
12
|
+
import type { JoinLink } from "./joinAccess";
|
|
13
|
+
import { RowGlyph } from "./RowGlyph";
|
|
14
|
+
import { RowLayerSwitch, useRowLayer, type RowLayer } from "./rowLayers";
|
|
15
|
+
import type { ExplorerJoin } from "./schemaModel";
|
|
16
|
+
import { useSectionOpen } from "./sectionOpenCommand";
|
|
17
|
+
import { joinGateWarning, type SourceAccess } from "./sourceAccess";
|
|
18
|
+
import { StatusPill } from "./StatusPill";
|
|
19
|
+
import { PANE_CARD_SX } from "./surface";
|
|
20
|
+
import { CaptionText } from "./text";
|
|
21
|
+
import { fontSizes } from "./theme";
|
|
22
|
+
import { ink } from "./tokens";
|
|
23
|
+
import { QueryCode } from "./ui";
|
|
24
|
+
import type { RunContext } from "./useRunQuery";
|
|
25
|
+
|
|
26
|
+
/** An open join's two layers: the joined source's fields, or the join's Malloy. */
|
|
27
|
+
const JOIN_LAYERS: RowLayer[] = ["fields", "code"];
|
|
28
|
+
|
|
29
|
+
/** The trailing "open the joined source" arrow, link or button alike. */
|
|
30
|
+
const OPEN_ARROW_SX = {
|
|
31
|
+
display: "inline-flex",
|
|
32
|
+
alignItems: "center",
|
|
33
|
+
color: "text.secondary",
|
|
34
|
+
borderRadius: 1,
|
|
35
|
+
padding: "2px",
|
|
36
|
+
flexShrink: 0,
|
|
37
|
+
"&:hover": { color: ink },
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
interface SchemaJoinProps {
|
|
41
|
+
join: ExplorerJoin;
|
|
42
|
+
run?: RunContext;
|
|
43
|
+
modelPath: string;
|
|
44
|
+
sourceName: string;
|
|
45
|
+
/** Whether the joined SOURCE has a page of its own, and where. A package
|
|
46
|
+
* can serve a source only as a join partner (see joinAccess.ts), and the
|
|
47
|
+
* row must not offer a door that isn't there — those say so in words
|
|
48
|
+
* instead. Absent, or `unknown`, → neither arrow nor note: not yet
|
|
49
|
+
* established is not the same as established absent. */
|
|
50
|
+
link?: JoinLink;
|
|
51
|
+
/** The JOINED source's own fields. A joined source is the same source seen
|
|
52
|
+
* from another page, so its fields expand to definitions exactly as they
|
|
53
|
+
* do there. Absent (e.g. the target's model hasn't loaded) → the rows
|
|
54
|
+
* render with nothing to open rather than claiming "no
|
|
55
|
+
* definition". */
|
|
56
|
+
entitiesByName?: EntitiesByField;
|
|
57
|
+
entitiesLoading?: boolean;
|
|
58
|
+
entitiesError?: boolean;
|
|
59
|
+
/** The join's declaration, verbatim from a host's entities
|
|
60
|
+
* ("customer is customers with customer_id"), drawn in the page's code card. */
|
|
61
|
+
code?: string;
|
|
62
|
+
/** The joined source, where it declares an access rule: its Restricted or
|
|
63
|
+
* Row filtered pill rides on this row. */
|
|
64
|
+
target?: { sourceName: string; access: SourceAccess };
|
|
65
|
+
/** Whether the reader can change the model, so an open join to a gated
|
|
66
|
+
* source warns that its gate does not apply here. */
|
|
67
|
+
showRules?: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A join as a row of the page, opened and closed as every other row is (RowLine):
|
|
72
|
+
* its name, its field count, its doc, and at the right its relationship and the
|
|
73
|
+
* arrow to the joined source's own page. Open, it shows the joined source's
|
|
74
|
+
* fields — the same sections and rows the source's own use, one level in, framed
|
|
75
|
+
* as one block — with Fields | Code on its line, as an open view's Result | Code,
|
|
76
|
+
* and its declaration in the page's one code card (QueryCode) one click over.
|
|
77
|
+
*
|
|
78
|
+
* Opening is the default gesture (the join is part of this source). Navigating
|
|
79
|
+
* away to the joined source's own page is the deliberate one, so it gets a
|
|
80
|
+
* trailing arrow rather than being armed on the name.
|
|
81
|
+
*/
|
|
82
|
+
export function SchemaJoin({
|
|
83
|
+
join,
|
|
84
|
+
run,
|
|
85
|
+
modelPath,
|
|
86
|
+
sourceName,
|
|
87
|
+
link,
|
|
88
|
+
entitiesByName,
|
|
89
|
+
entitiesLoading,
|
|
90
|
+
entitiesError,
|
|
91
|
+
code,
|
|
92
|
+
target,
|
|
93
|
+
showRules = false,
|
|
94
|
+
}: SchemaJoinProps) {
|
|
95
|
+
// Open or shut by the reader, and by its section's Expand / Collapse.
|
|
96
|
+
const [open, setOpen] = useSectionOpen();
|
|
97
|
+
const { layers, layer: view, setLayer: setView } = useRowLayer(JOIN_LAYERS);
|
|
98
|
+
|
|
99
|
+
const getFieldCode = useMemo(
|
|
100
|
+
() =>
|
|
101
|
+
entitiesByName
|
|
102
|
+
? makeGetFieldCode({
|
|
103
|
+
entities: entitiesByName,
|
|
104
|
+
loading: !!entitiesLoading,
|
|
105
|
+
error: !!entitiesError,
|
|
106
|
+
})
|
|
107
|
+
: undefined,
|
|
108
|
+
[entitiesByName, entitiesLoading, entitiesError],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const fieldCount = join.dimensions.length + join.measures.length;
|
|
112
|
+
|
|
113
|
+
const trailing = (
|
|
114
|
+
<Box sx={{ display: "inline-flex", alignItems: "center", gap: 1 }}>
|
|
115
|
+
{open && (
|
|
116
|
+
// Fields | Code, as an open view's Result | Code: what it opens to first,
|
|
117
|
+
// and its Malloy one click over.
|
|
118
|
+
<RowLayerSwitch
|
|
119
|
+
aria-label={`Show for ${join.name}`}
|
|
120
|
+
layers={layers}
|
|
121
|
+
value={view}
|
|
122
|
+
onChange={setView}
|
|
123
|
+
disabledReasons={{
|
|
124
|
+
code: code
|
|
125
|
+
? undefined
|
|
126
|
+
: "No Malloy code to show for this join",
|
|
127
|
+
}}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
{link?.kind === "link" && link.href && (
|
|
131
|
+
<Link
|
|
132
|
+
href={link.href}
|
|
133
|
+
aria-label={`Open ${join.name}`}
|
|
134
|
+
title={`Open ${join.name}`}
|
|
135
|
+
sx={OPEN_ARROW_SX}
|
|
136
|
+
>
|
|
137
|
+
<IconOpen size={14} />
|
|
138
|
+
</Link>
|
|
139
|
+
)}
|
|
140
|
+
{link?.kind === "link" && !link.href && link.onOpen && (
|
|
141
|
+
// The same arrow, as an in-page selection rather than a
|
|
142
|
+
// navigation (see JoinLink.onOpen).
|
|
143
|
+
<Link
|
|
144
|
+
component="button"
|
|
145
|
+
type="button"
|
|
146
|
+
onClick={link.onOpen}
|
|
147
|
+
aria-label={`Open ${join.name}`}
|
|
148
|
+
title={`Open ${join.name}`}
|
|
149
|
+
sx={OPEN_ARROW_SX}
|
|
150
|
+
>
|
|
151
|
+
<IconOpen size={14} />
|
|
152
|
+
</Link>
|
|
153
|
+
)}
|
|
154
|
+
{link?.kind === "join-only" && (
|
|
155
|
+
<Box
|
|
156
|
+
component="span"
|
|
157
|
+
sx={{
|
|
158
|
+
fontSize: fontSizes.micro,
|
|
159
|
+
fontStyle: "italic",
|
|
160
|
+
color: "text.secondary",
|
|
161
|
+
flexShrink: 0,
|
|
162
|
+
}}
|
|
163
|
+
>
|
|
164
|
+
only accessible via join
|
|
165
|
+
</Box>
|
|
166
|
+
)}
|
|
167
|
+
</Box>
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<Box
|
|
172
|
+
data-testid="model-viewer-join-row"
|
|
173
|
+
data-name={join.name}
|
|
174
|
+
sx={open ? { pb: 1.25 } : undefined}
|
|
175
|
+
>
|
|
176
|
+
<RowLine
|
|
177
|
+
glyph={<RowGlyph kind="join" />}
|
|
178
|
+
name={join.name}
|
|
179
|
+
typeLabel={`${fieldCount} ${fieldCount === 1 ? "field" : "fields"}`}
|
|
180
|
+
// A field row's layout: what the join is beside its name — its
|
|
181
|
+
// relationship, a quiet token like a field's type — and the joined
|
|
182
|
+
// source's access state on the line under it.
|
|
183
|
+
stackPills
|
|
184
|
+
descriptors={
|
|
185
|
+
<StatusPill
|
|
186
|
+
tone="quiet"
|
|
187
|
+
voice="token"
|
|
188
|
+
sx={{ alignSelf: "center", flexShrink: 0 }}
|
|
189
|
+
>
|
|
190
|
+
join_{join.relationship}
|
|
191
|
+
</StatusPill>
|
|
192
|
+
}
|
|
193
|
+
doc={join.doc}
|
|
194
|
+
open={open}
|
|
195
|
+
expandable
|
|
196
|
+
onToggle={() => setOpen((o) => !o)}
|
|
197
|
+
trailing={trailing}
|
|
198
|
+
pills={target && <AccessPills access={target.access} />}
|
|
199
|
+
/>
|
|
200
|
+
<Collapse in={open} timeout="auto" unmountOnExit>
|
|
201
|
+
{/* Hangs under the join's name, as every row's opening does. */}
|
|
202
|
+
<Box sx={{ mx: "10px", mt: "2px" }}>
|
|
203
|
+
{view === "code" && code ? (
|
|
204
|
+
<QueryCode testId="model-viewer-join-code" code={code} />
|
|
205
|
+
) : (
|
|
206
|
+
// The joined source's fields as a contained block — framed as a
|
|
207
|
+
// result or a code card is, on the page with no fill — so they read
|
|
208
|
+
// as this join's contents, not more rows of the page. Measures before
|
|
209
|
+
// dimensions, as on the source itself (SchemaView).
|
|
210
|
+
<Box
|
|
211
|
+
data-testid="model-viewer-join-fields"
|
|
212
|
+
sx={{
|
|
213
|
+
...PANE_CARD_SX,
|
|
214
|
+
bgcolor: "transparent",
|
|
215
|
+
p: 1.5,
|
|
216
|
+
pb: 0,
|
|
217
|
+
}}
|
|
218
|
+
>
|
|
219
|
+
{target && showRules && (
|
|
220
|
+
// A gate fires only on the source a query enters through, so a
|
|
221
|
+
// join publishes the joined source's rows under this source's
|
|
222
|
+
// rules: the footgun an editor needs told. Inside the card, over
|
|
223
|
+
// the fields it is about.
|
|
224
|
+
<CaptionText
|
|
225
|
+
component="div"
|
|
226
|
+
data-testid="model-viewer-join-gate-warning"
|
|
227
|
+
sx={{ mb: 1 }}
|
|
228
|
+
>
|
|
229
|
+
{joinGateWarning(target.sourceName, target.access)}
|
|
230
|
+
</CaptionText>
|
|
231
|
+
)}
|
|
232
|
+
<FieldGroup
|
|
233
|
+
label="Measures"
|
|
234
|
+
noun={["measure", "measures"]}
|
|
235
|
+
level="h3"
|
|
236
|
+
items={join.measures}
|
|
237
|
+
run={run}
|
|
238
|
+
modelPath={modelPath}
|
|
239
|
+
sourceName={sourceName}
|
|
240
|
+
getFieldCode={getFieldCode}
|
|
241
|
+
/>
|
|
242
|
+
<FieldGroup
|
|
243
|
+
label="Dimensions"
|
|
244
|
+
noun={["dimension", "dimensions"]}
|
|
245
|
+
level="h3"
|
|
246
|
+
items={join.dimensions}
|
|
247
|
+
run={run}
|
|
248
|
+
modelPath={modelPath}
|
|
249
|
+
sourceName={sourceName}
|
|
250
|
+
getFieldCode={getFieldCode}
|
|
251
|
+
/>
|
|
252
|
+
</Box>
|
|
253
|
+
)}
|
|
254
|
+
</Box>
|
|
255
|
+
</Collapse>
|
|
256
|
+
</Box>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box } from "@mui/material";
|
|
5
|
+
import { useMemo, type ReactNode } from "react";
|
|
6
|
+
import { makeGetFieldCode } from "./fieldCode";
|
|
7
|
+
import type { EntitiesByField } from "./fieldEntities";
|
|
8
|
+
import { FieldGroup } from "./FieldGroup";
|
|
9
|
+
import type { JoinLink } from "./joinAccess";
|
|
10
|
+
import { ModelSection } from "./ModelSection";
|
|
11
|
+
import { fieldDeclarations } from "./modelTextDeclarations";
|
|
12
|
+
import { useParsedModelText } from "./modelTextParse";
|
|
13
|
+
import { SchemaJoin } from "./SchemaJoin";
|
|
14
|
+
import type { ExplorerSource } from "./schemaModel";
|
|
15
|
+
import {
|
|
16
|
+
SectionOpenCommandContext,
|
|
17
|
+
useSectionExpand,
|
|
18
|
+
} from "./sectionOpenCommand";
|
|
19
|
+
import type { SourceAccess } from "./sourceAccess";
|
|
20
|
+
import { useModelViewerExtensions } from "./extensions";
|
|
21
|
+
import type { RunContext } from "./useRunQuery";
|
|
22
|
+
import { ViewRow } from "./ViewRow";
|
|
23
|
+
|
|
24
|
+
interface SchemaViewProps {
|
|
25
|
+
source: ExplorerSource;
|
|
26
|
+
modelPath: string;
|
|
27
|
+
/** A host's entities for the source (per-field code and provenance), when
|
|
28
|
+
* it passes any. Undefined until loaded, and when there are none. */
|
|
29
|
+
entitiesByName?: EntitiesByField;
|
|
30
|
+
entitiesLoading?: boolean;
|
|
31
|
+
entitiesError?: boolean;
|
|
32
|
+
/** The model file's text, for the code of a field the entities don't carry
|
|
33
|
+
* (all of them, without a host's entities): see `fieldDeclarations`. */
|
|
34
|
+
modelText?: string;
|
|
35
|
+
/** Join name → whether the joined source has a page, and where. */
|
|
36
|
+
joinLinks?: Map<string, JoinLink>;
|
|
37
|
+
/** Join name → the JOINED source's own fields, so a joined source offers
|
|
38
|
+
* the same per-field definitions as it would on its own page. Keyed by
|
|
39
|
+
* join alias because that is what the rendered join is named. */
|
|
40
|
+
joinEntities?: Map<string, EntitiesByField>;
|
|
41
|
+
/** Join name → its declaration, verbatim from the host's entities. */
|
|
42
|
+
joinCodes?: Map<string, string>;
|
|
43
|
+
/** Join name → the joined source's access rules, where it declares any. */
|
|
44
|
+
joinAccess?: ReadonlyMap<
|
|
45
|
+
string,
|
|
46
|
+
{ sourceName: string; access: SourceAccess }
|
|
47
|
+
>;
|
|
48
|
+
/** Whether the reader can change the model (an editor sees the join's
|
|
49
|
+
* gate warning). */
|
|
50
|
+
showRules?: boolean;
|
|
51
|
+
/** A host's descriptions of the base table's columns (column → text), for
|
|
52
|
+
* the dimensions this source inherits rather than defines. */
|
|
53
|
+
columnDescriptions?: ReadonlyMap<string, string>;
|
|
54
|
+
/** Where to run this source's views against the served model. */
|
|
55
|
+
run?: RunContext;
|
|
56
|
+
/** The model's named queries, as their own section after the views: the two
|
|
57
|
+
* are the page's results, so they read together before the fields. */
|
|
58
|
+
queries?: ReactNode;
|
|
59
|
+
/** The givens this source reads, as the page's first section: they set every
|
|
60
|
+
* run below them (ModelGivensSection). */
|
|
61
|
+
givens?: ReactNode;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Single-source browse view, as always-open sections: the givens it reads, the
|
|
66
|
+
* views, the model's queries, the measures, calculations and dimensions, each a
|
|
67
|
+
* row that opens in place, then each join as an expandable row.
|
|
68
|
+
*/
|
|
69
|
+
export function SchemaView({
|
|
70
|
+
source,
|
|
71
|
+
modelPath,
|
|
72
|
+
entitiesByName,
|
|
73
|
+
entitiesLoading,
|
|
74
|
+
entitiesError,
|
|
75
|
+
modelText,
|
|
76
|
+
joinLinks,
|
|
77
|
+
joinEntities,
|
|
78
|
+
joinCodes,
|
|
79
|
+
joinAccess,
|
|
80
|
+
showRules = false,
|
|
81
|
+
columnDescriptions,
|
|
82
|
+
run,
|
|
83
|
+
queries,
|
|
84
|
+
givens,
|
|
85
|
+
}: SchemaViewProps) {
|
|
86
|
+
const rowProps = { run, modelPath, sourceName: source.name };
|
|
87
|
+
// The views a host lists, where it narrows them (`showField`); the field
|
|
88
|
+
// sections narrow their own.
|
|
89
|
+
const { showField } = useModelViewerExtensions();
|
|
90
|
+
const views = useMemo(
|
|
91
|
+
() =>
|
|
92
|
+
showField
|
|
93
|
+
? source.views.filter((field) =>
|
|
94
|
+
showField({
|
|
95
|
+
modelPath,
|
|
96
|
+
sourceName: source.name,
|
|
97
|
+
field,
|
|
98
|
+
joined: false,
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
101
|
+
: source.views,
|
|
102
|
+
[showField, source, modelPath],
|
|
103
|
+
);
|
|
104
|
+
// Every section takes the same Expand. A view opens on its result, so Expand
|
|
105
|
+
// runs every view in the section; a join opens on its fields.
|
|
106
|
+
const viewsExpand = useSectionExpand({ noun: ["view", "views"] });
|
|
107
|
+
const joinsExpand = useSectionExpand({ noun: ["join", "joins"] });
|
|
108
|
+
|
|
109
|
+
// The file is parsed only for a row the entities left without code (every
|
|
110
|
+
// row, without a host's entities), so a page whose entities cover it all
|
|
111
|
+
// doesn't load the parser.
|
|
112
|
+
const needsText = useMemo(
|
|
113
|
+
() =>
|
|
114
|
+
!entitiesLoading &&
|
|
115
|
+
[
|
|
116
|
+
...source.views,
|
|
117
|
+
...source.measures,
|
|
118
|
+
...source.calculations,
|
|
119
|
+
...source.dimensions,
|
|
120
|
+
].some((f) => !entitiesByName?.get(f.name)),
|
|
121
|
+
[entitiesLoading, entitiesByName, source],
|
|
122
|
+
);
|
|
123
|
+
const { parsed, pending } = useParsedModelText(modelText, needsText);
|
|
124
|
+
// Read once per source and text, not per row.
|
|
125
|
+
const declarations = useMemo(
|
|
126
|
+
() => fieldDeclarations(parsed, source.name),
|
|
127
|
+
[parsed, source.name],
|
|
128
|
+
);
|
|
129
|
+
const getFieldCode = useMemo(
|
|
130
|
+
() =>
|
|
131
|
+
makeGetFieldCode({
|
|
132
|
+
entities: entitiesByName,
|
|
133
|
+
loading: !!entitiesLoading,
|
|
134
|
+
error: !!entitiesError,
|
|
135
|
+
columnDescriptions,
|
|
136
|
+
declarations,
|
|
137
|
+
declarationsLoading: pending,
|
|
138
|
+
}),
|
|
139
|
+
[
|
|
140
|
+
entitiesByName,
|
|
141
|
+
entitiesLoading,
|
|
142
|
+
entitiesError,
|
|
143
|
+
columnDescriptions,
|
|
144
|
+
declarations,
|
|
145
|
+
pending,
|
|
146
|
+
],
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<Box sx={{ paddingBottom: "24px" }}>
|
|
151
|
+
{givens}
|
|
152
|
+
{/* Most-answered-first: a view is a question the source already
|
|
153
|
+
answers, a measure is one it can compute, a dimension is the raw
|
|
154
|
+
material, and a join is a neighbouring source — so the reader meets
|
|
155
|
+
the source's own vocabulary before its columns. */}
|
|
156
|
+
<ModelSection
|
|
157
|
+
label="Views"
|
|
158
|
+
count={views.length}
|
|
159
|
+
action={viewsExpand.action}
|
|
160
|
+
>
|
|
161
|
+
<SectionOpenCommandContext.Provider value={viewsExpand.command}>
|
|
162
|
+
{views.map((view) => (
|
|
163
|
+
<ViewRow
|
|
164
|
+
key={view.name}
|
|
165
|
+
field={view}
|
|
166
|
+
modelPath={modelPath}
|
|
167
|
+
sourceName={source.name}
|
|
168
|
+
fieldCode={getFieldCode(view)}
|
|
169
|
+
run={run}
|
|
170
|
+
/>
|
|
171
|
+
))}
|
|
172
|
+
</SectionOpenCommandContext.Provider>
|
|
173
|
+
</ModelSection>
|
|
174
|
+
{queries}
|
|
175
|
+
<FieldGroup
|
|
176
|
+
label="Measures"
|
|
177
|
+
noun={["measure", "measures"]}
|
|
178
|
+
items={source.measures}
|
|
179
|
+
getFieldCode={getFieldCode}
|
|
180
|
+
{...rowProps}
|
|
181
|
+
/>
|
|
182
|
+
<FieldGroup
|
|
183
|
+
label="Calculations"
|
|
184
|
+
noun={["calculation", "calculations"]}
|
|
185
|
+
items={source.calculations}
|
|
186
|
+
getFieldCode={getFieldCode}
|
|
187
|
+
{...rowProps}
|
|
188
|
+
/>
|
|
189
|
+
<FieldGroup
|
|
190
|
+
label="Dimensions"
|
|
191
|
+
noun={["dimension", "dimensions"]}
|
|
192
|
+
items={source.dimensions}
|
|
193
|
+
getFieldCode={getFieldCode}
|
|
194
|
+
{...rowProps}
|
|
195
|
+
/>
|
|
196
|
+
<ModelSection
|
|
197
|
+
label="Joins"
|
|
198
|
+
count={source.joins.length}
|
|
199
|
+
action={joinsExpand.action}
|
|
200
|
+
>
|
|
201
|
+
<SectionOpenCommandContext.Provider value={joinsExpand.command}>
|
|
202
|
+
{source.joins.map((join) => (
|
|
203
|
+
<SchemaJoin
|
|
204
|
+
key={join.name}
|
|
205
|
+
join={join}
|
|
206
|
+
run={run}
|
|
207
|
+
modelPath={modelPath}
|
|
208
|
+
sourceName={source.name}
|
|
209
|
+
link={joinLinks?.get(join.name)}
|
|
210
|
+
entitiesByName={joinEntities?.get(join.name)}
|
|
211
|
+
code={joinCodes?.get(join.name)}
|
|
212
|
+
target={joinAccess?.get(join.name)}
|
|
213
|
+
showRules={showRules}
|
|
214
|
+
entitiesLoading={entitiesLoading}
|
|
215
|
+
entitiesError={entitiesError}
|
|
216
|
+
/>
|
|
217
|
+
))}
|
|
218
|
+
</SectionOpenCommandContext.Provider>
|
|
219
|
+
</ModelSection>
|
|
220
|
+
</Box>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { Box, IconButton, Tooltip } from "@mui/material";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import { roles } from "./theme";
|
|
7
|
+
|
|
8
|
+
export interface SegmentIconOption<T extends string> {
|
|
9
|
+
value: T;
|
|
10
|
+
icon: ReactNode;
|
|
11
|
+
/** The accessible name AND the tooltip — kept equal (ux-design-guide §4). */
|
|
12
|
+
label: string;
|
|
13
|
+
/**
|
|
14
|
+
* Present but not selectable. For a representation this thing HAS but cannot show yet
|
|
15
|
+
* (or at all) — the option keeps its place so the switch does not change width as the
|
|
16
|
+
* data behind it arrives, which is the layout shift that omitting it causes.
|
|
17
|
+
*/
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Why it is disabled, as the tooltip, replacing `label`. A disabled control with no
|
|
21
|
+
* explanation is the failure mode this exists to avoid: the reader can see the option
|
|
22
|
+
* and cannot tell whether it is broken or merely not applicable here.
|
|
23
|
+
*/
|
|
24
|
+
disabledReason?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* An action icon's button: a switch option's (active when pressed) and an action
|
|
29
|
+
* beside a switch (ActionIconButton) are one look, so a row of them reads as one set.
|
|
30
|
+
* The pressed one sits in a faint fill so the active layer reads at a glance; the
|
|
31
|
+
* rest are quiet.
|
|
32
|
+
*/
|
|
33
|
+
export function actionIconSx(active: boolean) {
|
|
34
|
+
return {
|
|
35
|
+
p: "3px",
|
|
36
|
+
borderRadius: 1,
|
|
37
|
+
color: active ? "text.primary" : "text.secondary",
|
|
38
|
+
bgcolor: active ? roles.background.strong : "transparent",
|
|
39
|
+
"&:hover": {
|
|
40
|
+
bgcolor: active ? roles.background.strong : roles.background.muted,
|
|
41
|
+
color: "text.primary",
|
|
42
|
+
},
|
|
43
|
+
"&.Mui-disabled": { color: "text.disabled" },
|
|
44
|
+
} as const;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A "which layer of this thing am I looking at" switch, drawn as **action
|
|
49
|
+
* icons** rather than labelled chips — the app's one switch of record for
|
|
50
|
+
* choosing a representation of something already named beside it: on an
|
|
51
|
+
* open model row (its layers — Result, Code, Givens, Materialization — through
|
|
52
|
+
* RowLayerSwitch, at the row's line) and over a result. (A whole file's views are not a switch but the first items of
|
|
53
|
+
* its ⋯ — `viewActions`.) Any number of options, one pressed. The caller sizes
|
|
54
|
+
* its own glyphs — 14 on a row.
|
|
55
|
+
*
|
|
56
|
+
* <p>Why icons, not labelled chips: these switches choose a REPRESENTATION of
|
|
57
|
+
* something already named next to them, so words would restate the noun rather
|
|
58
|
+
* than add to it — "Model | Code" under a heading that says `auto_recalls`.
|
|
59
|
+
* The glyphs are
|
|
60
|
+
* the app's own (ContentTypeIcon's mark for each kind of file, the code
|
|
61
|
+
* brackets), so the switch reads as a lens over the named thing instead of
|
|
62
|
+
* chrome beside it.
|
|
63
|
+
*
|
|
64
|
+
* <p>The label is not lost, only moved: every option's `label` is BOTH its
|
|
65
|
+
* tooltip and its accessible name (ux-design-guide §4), so pointer users get
|
|
66
|
+
* the word on hover and screen readers get it unconditionally — and the option
|
|
67
|
+
* stays addressable by name, which is what keeps an icon switch testable. A
|
|
68
|
+
* disabled option keeps its place and swaps both for its `disabledReason`.
|
|
69
|
+
*
|
|
70
|
+
* <p>Group semantics: `role="group"` named by the caller, each option a
|
|
71
|
+
* `role="button"` with `aria-pressed`, so it is one control to a screen reader.
|
|
72
|
+
*/
|
|
73
|
+
export function SegmentIcons<T extends string>({
|
|
74
|
+
value,
|
|
75
|
+
options,
|
|
76
|
+
onChange,
|
|
77
|
+
"aria-label": ariaLabel,
|
|
78
|
+
}: {
|
|
79
|
+
value: T;
|
|
80
|
+
options: ReadonlyArray<SegmentIconOption<T>>;
|
|
81
|
+
onChange: (value: T) => void;
|
|
82
|
+
"aria-label": string;
|
|
83
|
+
}) {
|
|
84
|
+
return (
|
|
85
|
+
<Box
|
|
86
|
+
role="group"
|
|
87
|
+
aria-label={ariaLabel}
|
|
88
|
+
sx={{ display: "inline-flex", gap: "2px" }}
|
|
89
|
+
>
|
|
90
|
+
{options.map((option) => {
|
|
91
|
+
const active = option.value === value;
|
|
92
|
+
const disabled = option.disabled === true;
|
|
93
|
+
return (
|
|
94
|
+
// `span` wrapper: MUI's Tooltip needs a mountable child that fires pointer
|
|
95
|
+
// events, and a disabled IconButton fires none — without it the explanation
|
|
96
|
+
// is unreachable on exactly the options that need one.
|
|
97
|
+
<Tooltip
|
|
98
|
+
key={option.value}
|
|
99
|
+
title={
|
|
100
|
+
disabled
|
|
101
|
+
? (option.disabledReason ?? option.label)
|
|
102
|
+
: option.label
|
|
103
|
+
}
|
|
104
|
+
>
|
|
105
|
+
<span style={{ display: "inline-flex" }}>
|
|
106
|
+
<IconButton
|
|
107
|
+
size="small"
|
|
108
|
+
role="button"
|
|
109
|
+
aria-pressed={active}
|
|
110
|
+
// Matches the tooltip: a screen-reader user on a disabled option
|
|
111
|
+
// otherwise hears only its name and no reason.
|
|
112
|
+
aria-label={
|
|
113
|
+
disabled
|
|
114
|
+
? (option.disabledReason ?? option.label)
|
|
115
|
+
: option.label
|
|
116
|
+
}
|
|
117
|
+
disabled={disabled}
|
|
118
|
+
onClick={() => onChange(option.value)}
|
|
119
|
+
sx={actionIconSx(active)}
|
|
120
|
+
>
|
|
121
|
+
{option.icon}
|
|
122
|
+
</IconButton>
|
|
123
|
+
</span>
|
|
124
|
+
</Tooltip>
|
|
125
|
+
);
|
|
126
|
+
})}
|
|
127
|
+
</Box>
|
|
128
|
+
);
|
|
129
|
+
}
|