@surfaces-ui/components 0.0.0-stage → 0.2.0
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +48 -2
- package/dist/appComponents.d.ts +86 -0
- package/dist/appComponents.js +555 -0
- package/dist/appComponents.js.map +1 -0
- package/dist/chart/BulletGraph.d.ts +44 -0
- package/dist/chart/BulletGraph.js +40 -0
- package/dist/chart/BulletGraph.js.map +1 -0
- package/dist/chart/Chart.d.ts +177 -0
- package/dist/chart/Chart.js +279 -0
- package/dist/chart/Chart.js.map +1 -0
- package/dist/chart/Sparkline.d.ts +35 -0
- package/dist/chart/Sparkline.js +37 -0
- package/dist/chart/Sparkline.js.map +1 -0
- package/dist/chart/advice.d.ts +28 -0
- package/dist/chart/advice.js +39 -0
- package/dist/chart/advice.js.map +1 -0
- package/dist/chart/option.d.ts +90 -0
- package/dist/chart/option.js +252 -0
- package/dist/chart/option.js.map +1 -0
- package/dist/controls/Combobox.d.ts +39 -0
- package/dist/controls/Combobox.js +75 -0
- package/dist/controls/Combobox.js.map +1 -0
- package/dist/controls/ConfirmDialog.d.ts +35 -0
- package/dist/controls/ConfirmDialog.js +84 -0
- package/dist/controls/ConfirmDialog.js.map +1 -0
- package/dist/controls/ItemControls.d.ts +115 -0
- package/dist/controls/ItemControls.js +109 -0
- package/dist/controls/ItemControls.js.map +1 -0
- package/dist/controls/Popover.d.ts +31 -0
- package/dist/controls/Popover.js +114 -0
- package/dist/controls/Popover.js.map +1 -0
- package/dist/controls/ResizeHandle.d.ts +48 -0
- package/dist/controls/ResizeHandle.js +91 -0
- package/dist/controls/ResizeHandle.js.map +1 -0
- package/dist/controls/SegmentedControl.d.ts +27 -0
- package/dist/controls/SegmentedControl.js +17 -0
- package/dist/controls/SegmentedControl.js.map +1 -0
- package/dist/controls/StatusBadge.d.ts +17 -0
- package/dist/controls/StatusBadge.js +10 -0
- package/dist/controls/StatusBadge.js.map +1 -0
- package/dist/controls/context.d.ts +17 -0
- package/dist/controls/context.js +2 -0
- package/dist/controls/context.js.map +1 -0
- package/dist/controls/placement.d.ts +43 -0
- package/dist/controls/placement.js +19 -0
- package/dist/controls/placement.js.map +1 -0
- package/dist/controls/resize.d.ts +23 -0
- package/dist/controls/resize.js +49 -0
- package/dist/controls/resize.js.map +1 -0
- package/dist/data/DataSourceProvider.d.ts +11 -0
- package/dist/data/DataSourceProvider.js +21 -0
- package/dist/data/DataSourceProvider.js.map +1 -0
- package/dist/data/export.d.ts +33 -0
- package/dist/data/export.js +77 -0
- package/dist/data/export.js.map +1 -0
- package/dist/data/format.d.ts +44 -0
- package/dist/data/format.js +127 -0
- package/dist/data/format.js.map +1 -0
- package/dist/data/messages.d.ts +13 -0
- package/dist/data/messages.js +2 -0
- package/dist/data/messages.js.map +1 -0
- package/dist/data/useRowWindow.d.ts +70 -0
- package/dist/data/useRowWindow.js +175 -0
- package/dist/data/useRowWindow.js.map +1 -0
- package/dist/discovery/AskData.d.ts +22 -0
- package/dist/discovery/AskData.js +48 -0
- package/dist/discovery/AskData.js.map +1 -0
- package/dist/discovery/ContextBuilder.d.ts +49 -0
- package/dist/discovery/ContextBuilder.js +167 -0
- package/dist/discovery/ContextBuilder.js.map +1 -0
- package/dist/discovery/DataSearch.d.ts +27 -0
- package/dist/discovery/DataSearch.js +73 -0
- package/dist/discovery/DataSearch.js.map +1 -0
- package/dist/discovery/ObjectDetail.d.ts +38 -0
- package/dist/discovery/ObjectDetail.js +129 -0
- package/dist/discovery/ObjectDetail.js.map +1 -0
- package/dist/discovery/RelationshipGraph.d.ts +19 -0
- package/dist/discovery/RelationshipGraph.js +64 -0
- package/dist/discovery/RelationshipGraph.js.map +1 -0
- package/dist/discovery/shared.d.ts +38 -0
- package/dist/discovery/shared.js +64 -0
- package/dist/discovery/shared.js.map +1 -0
- package/dist/editor/SqlEditor.d.ts +41 -0
- package/dist/editor/SqlEditor.js +181 -0
- package/dist/editor/SqlEditor.js.map +1 -0
- package/dist/explore/Explorer.d.ts +110 -0
- package/dist/explore/Explorer.js +471 -0
- package/dist/explore/Explorer.js.map +1 -0
- package/dist/explore/ModelLineage.d.ts +22 -0
- package/dist/explore/ModelLineage.js +70 -0
- package/dist/explore/ModelLineage.js.map +1 -0
- package/dist/explore/ReportBuilder.d.ts +39 -0
- package/dist/explore/ReportBuilder.js +98 -0
- package/dist/explore/ReportBuilder.js.map +1 -0
- package/dist/explore/SemanticModelEditor.d.ts +60 -0
- package/dist/explore/SemanticModelEditor.js +220 -0
- package/dist/explore/SemanticModelEditor.js.map +1 -0
- package/dist/explore/SemanticRows.d.ts +42 -0
- package/dist/explore/SemanticRows.js +117 -0
- package/dist/explore/SemanticRows.js.map +1 -0
- package/dist/explore/SemanticsProvider.d.ts +31 -0
- package/dist/explore/SemanticsProvider.js +72 -0
- package/dist/explore/SemanticsProvider.js.map +1 -0
- package/dist/explore/model.d.ts +151 -0
- package/dist/explore/model.js +344 -0
- package/dist/explore/model.js.map +1 -0
- package/dist/explore/report.d.ts +60 -0
- package/dist/explore/report.js +92 -0
- package/dist/explore/report.js.map +1 -0
- package/dist/explore/semantic-proposal.d.ts +44 -0
- package/dist/explore/semantic-proposal.js +67 -0
- package/dist/explore/semantic-proposal.js.map +1 -0
- package/dist/explore/semantic.d.ts +44 -0
- package/dist/explore/semantic.js +154 -0
- package/dist/explore/semantic.js.map +1 -0
- package/dist/files/FileBrowser.d.ts +42 -0
- package/dist/files/FileBrowser.js +314 -0
- package/dist/files/FileBrowser.js.map +1 -0
- package/dist/files/files.d.ts +65 -0
- package/dist/files/files.js +165 -0
- package/dist/files/files.js.map +1 -0
- package/dist/filter/FilterBar.d.ts +49 -0
- package/dist/filter/FilterBar.js +153 -0
- package/dist/filter/FilterBar.js.map +1 -0
- package/dist/filter/QueryFilters.d.ts +25 -0
- package/dist/filter/QueryFilters.js +58 -0
- package/dist/filter/QueryFilters.js.map +1 -0
- package/dist/form/Form.d.ts +76 -0
- package/dist/form/Form.js +131 -0
- package/dist/form/Form.js.map +1 -0
- package/dist/graph/NodeGraph.d.ts +30 -0
- package/dist/graph/NodeGraph.js +86 -0
- package/dist/graph/NodeGraph.js.map +1 -0
- package/dist/graph/model.d.ts +68 -0
- package/dist/graph/model.js +122 -0
- package/dist/graph/model.js.map +1 -0
- package/dist/grid/DataGrid.d.ts +98 -0
- package/dist/grid/DataGrid.js +399 -0
- package/dist/grid/DataGrid.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -0
- package/dist/locale/SurfacesText.d.ts +17 -0
- package/dist/locale/SurfacesText.js +17 -0
- package/dist/locale/SurfacesText.js.map +1 -0
- package/dist/locale/locale.d.ts +305 -0
- package/dist/locale/locale.js +359 -0
- package/dist/locale/locale.js.map +1 -0
- package/dist/menu/ContextMenu.d.ts +31 -0
- package/dist/menu/ContextMenu.js +95 -0
- package/dist/menu/ContextMenu.js.map +1 -0
- package/dist/metric/Metric.d.ts +33 -0
- package/dist/metric/Metric.js +63 -0
- package/dist/metric/Metric.js.map +1 -0
- package/dist/metric/useMeasure.d.ts +23 -0
- package/dist/metric/useMeasure.js +43 -0
- package/dist/metric/useMeasure.js.map +1 -0
- package/dist/model/ModelDiagram.d.ts +142 -0
- package/dist/model/ModelDiagram.js +699 -0
- package/dist/model/ModelDiagram.js.map +1 -0
- package/dist/panzoom/usePanZoom.d.ts +117 -0
- package/dist/panzoom/usePanZoom.js +313 -0
- package/dist/panzoom/usePanZoom.js.map +1 -0
- package/dist/pipeline/DatasetReview.d.ts +48 -0
- package/dist/pipeline/DatasetReview.js +157 -0
- package/dist/pipeline/DatasetReview.js.map +1 -0
- package/dist/pipeline/IngestWizard.d.ts +51 -0
- package/dist/pipeline/IngestWizard.js +79 -0
- package/dist/pipeline/IngestWizard.js.map +1 -0
- package/dist/pipeline/Pipeline.d.ts +171 -0
- package/dist/pipeline/Pipeline.js +203 -0
- package/dist/pipeline/Pipeline.js.map +1 -0
- package/dist/pipeline/PipelineView.d.ts +63 -0
- package/dist/pipeline/PipelineView.js +239 -0
- package/dist/pipeline/PipelineView.js.map +1 -0
- package/dist/pivot/PivotTable.d.ts +94 -0
- package/dist/pivot/PivotTable.js +171 -0
- package/dist/pivot/PivotTable.js.map +1 -0
- package/dist/plan/QueryPlan.d.ts +29 -0
- package/dist/plan/QueryPlan.js +79 -0
- package/dist/plan/QueryPlan.js.map +1 -0
- package/dist/result/QueryResult.d.ts +51 -0
- package/dist/result/QueryResult.js +255 -0
- package/dist/result/QueryResult.js.map +1 -0
- package/dist/review/ActionReceipt.d.ts +52 -0
- package/dist/review/ActionReceipt.js +32 -0
- package/dist/review/ActionReceipt.js.map +1 -0
- package/dist/review/PiiReview.d.ts +37 -0
- package/dist/review/PiiReview.js +29 -0
- package/dist/review/PiiReview.js.map +1 -0
- package/dist/review/PlanReview.d.ts +42 -0
- package/dist/review/PlanReview.js +37 -0
- package/dist/review/PlanReview.js.map +1 -0
- package/dist/review/StepFlow.d.ts +25 -0
- package/dist/review/StepFlow.js +21 -0
- package/dist/review/StepFlow.js.map +1 -0
- package/dist/review/pii.d.ts +21 -0
- package/dist/review/pii.js +67 -0
- package/dist/review/pii.js.map +1 -0
- package/dist/rows/RowList.d.ts +41 -0
- package/dist/rows/RowList.js +71 -0
- package/dist/rows/RowList.js.map +1 -0
- package/dist/schema/ObjectBrowser.d.ts +78 -0
- package/dist/schema/ObjectBrowser.js +467 -0
- package/dist/schema/ObjectBrowser.js.map +1 -0
- package/dist/schema/ObjectInfo.d.ts +25 -0
- package/dist/schema/ObjectInfo.js +69 -0
- package/dist/schema/ObjectInfo.js.map +1 -0
- package/dist/schema/SchemaExplorer.d.ts +32 -0
- package/dist/schema/SchemaExplorer.js +175 -0
- package/dist/schema/SchemaExplorer.js.map +1 -0
- package/dist/schema/refs.d.ts +32 -0
- package/dist/schema/refs.js +65 -0
- package/dist/schema/refs.js.map +1 -0
- package/dist/site/Site.d.ts +191 -0
- package/dist/site/Site.js +138 -0
- package/dist/site/Site.js.map +1 -0
- package/dist/source/ConnectionBuilder.d.ts +54 -0
- package/dist/source/ConnectionBuilder.js +115 -0
- package/dist/source/ConnectionBuilder.js.map +1 -0
- package/dist/source/SourceList.d.ts +17 -0
- package/dist/source/SourceList.js +71 -0
- package/dist/source/SourceList.js.map +1 -0
- package/dist/styles.css +9882 -0
- package/dist/styles.layer.css +9886 -0
- package/dist/table/DataTable.d.ts +72 -0
- package/dist/table/DataTable.js +68 -0
- package/dist/table/DataTable.js.map +1 -0
- package/dist/table/Pagination.d.ts +20 -0
- package/dist/table/Pagination.js +16 -0
- package/dist/table/Pagination.js.map +1 -0
- package/dist/table/SelectionBar.d.ts +43 -0
- package/dist/table/SelectionBar.js +18 -0
- package/dist/table/SelectionBar.js.map +1 -0
- package/dist/text/Markdown.d.ts +71 -0
- package/dist/text/Markdown.js +187 -0
- package/dist/text/Markdown.js.map +1 -0
- package/dist/text/highlight.d.ts +23 -0
- package/dist/text/highlight.js +196 -0
- package/dist/text/highlight.js.map +1 -0
- package/dist/theme/ThemePicker.d.ts +16 -0
- package/dist/theme/ThemePicker.js +49 -0
- package/dist/theme/ThemePicker.js.map +1 -0
- package/dist/theme/ThemeProvider.d.ts +43 -0
- package/dist/theme/ThemeProvider.js +107 -0
- package/dist/theme/ThemeProvider.js.map +1 -0
- package/dist/workspace/NavBar.d.ts +23 -0
- package/dist/workspace/NavBar.js +171 -0
- package/dist/workspace/NavBar.js.map +1 -0
- package/dist/workspace/SideNav.d.ts +61 -0
- package/dist/workspace/SideNav.js +149 -0
- package/dist/workspace/SideNav.js.map +1 -0
- package/dist/workspace/Workspace.d.ts +50 -0
- package/dist/workspace/Workspace.js +243 -0
- package/dist/workspace/Workspace.js.map +1 -0
- package/dist/workspace/icons.d.ts +34 -0
- package/dist/workspace/icons.js +37 -0
- package/dist/workspace/icons.js.map +1 -0
- package/dist/workspace/layout.d.ts +74 -0
- package/dist/workspace/layout.js +276 -0
- package/dist/workspace/layout.js.map +1 -0
- package/package.json +85 -3
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CertificationStatus, DescriptionOrigin, RelationKind } from "@surfaces-ui/proto";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { messageOf } from "../data/useRowWindow.js";
|
|
5
|
+
import { DataGrid } from "../grid/DataGrid.js";
|
|
6
|
+
import { CertificationBadge, FORMAT_LABEL, ORIGIN_LABEL, certificationText, fullCount, useDiscovery } from "./shared.js";
|
|
7
|
+
const RELATION_LABEL = {
|
|
8
|
+
[RelationKind.JOIN]: "Joins with",
|
|
9
|
+
[RelationKind.SIMILAR]: "Similar to",
|
|
10
|
+
[RelationKind.UPSTREAM]: "Built from",
|
|
11
|
+
[RelationKind.DOWNSTREAM]: "Feeds",
|
|
12
|
+
[RelationKind.USED_BY_QUERY]: "Used by",
|
|
13
|
+
};
|
|
14
|
+
/** One column's statistics: how full it is, how varied, and its range or most common values when those may be shown. */
|
|
15
|
+
export function ColumnProfile({ column, rowCount }) {
|
|
16
|
+
const filled = rowCount && column.nullCount !== undefined ? 1 - Number(column.nullCount) / rowCount : undefined;
|
|
17
|
+
const top = column.topValues.slice(0, 3);
|
|
18
|
+
const most = Math.max(1, ...top.map((t) => Number(t.count)));
|
|
19
|
+
return (_jsxs(_Fragment, { children: [_jsx("td", { className: "sf-object-fill", children: filled === undefined ? (_jsx("span", { className: "sf-object-muted", children: "\u2013" })) : (_jsxs("span", { className: "sf-meter", role: "img", "aria-label": `${Math.round(filled * 100)}% filled`, children: [_jsx("span", { style: { inlineSize: `${Math.round(filled * 100)}%` } }), _jsxs("em", { children: [Math.round(filled * 100), "%"] })] })) }), _jsx("td", { className: "sf-object-number", children: column.distinctCount === undefined ? ("–") : (_jsxs("span", { title: column.distinctCountEstimated ? "An estimate" : undefined, children: [column.distinctCountEstimated ? "~" : "", fullCount.format(Number(column.distinctCount))] })) }), _jsx("td", { className: "sf-object-values", children: column.sampleValuesWithheld ? (_jsx("span", { className: "sf-object-muted", children: "Withheld" })) : top.length > 0 ? (_jsx("span", { className: "sf-top-values", children: top.map((value) => (_jsxs("span", { className: "sf-top-value", title: `${value.value}: ${fullCount.format(Number(value.count))}`, children: [_jsx("span", { style: { inlineSize: `${Math.round((Number(value.count) / most) * 100)}%` } }), _jsx("em", { children: value.value })] }, value.value))) })) : column.min !== undefined && column.min !== "" ? (_jsxs("span", { children: [column.min, " \u2192 ", column.max] })) : (_jsx("span", { className: "sf-object-muted", children: "\u2013" })) })] }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Everything known about one table: its description and who wrote it, its
|
|
23
|
+
* columns with statistics, and the tables it relates to. A generated
|
|
24
|
+
* description is only a proposal until a person accepts or edits it.
|
|
25
|
+
*/
|
|
26
|
+
export function ObjectDetail(props) {
|
|
27
|
+
const discovery = useDiscovery(props.discovery);
|
|
28
|
+
const key = JSON.stringify(props.objectRef);
|
|
29
|
+
const [profile, setProfile] = useState();
|
|
30
|
+
const [relations, setRelations] = useState([]);
|
|
31
|
+
const [error, setError] = useState();
|
|
32
|
+
const [draft, setDraft] = useState();
|
|
33
|
+
const [busy, setBusy] = useState(false);
|
|
34
|
+
const [certifying, setCertifying] = useState();
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
let current = true;
|
|
37
|
+
setProfile(undefined);
|
|
38
|
+
setRelations([]);
|
|
39
|
+
setError(undefined);
|
|
40
|
+
setDraft(undefined);
|
|
41
|
+
setCertifying(undefined);
|
|
42
|
+
// Names and types first, then statistics, so the page is useful immediately.
|
|
43
|
+
discovery
|
|
44
|
+
.getObject({ ref: props.objectRef })
|
|
45
|
+
.then((response) => {
|
|
46
|
+
if (current)
|
|
47
|
+
setProfile((existing) => existing ?? response.profile);
|
|
48
|
+
})
|
|
49
|
+
.catch((e) => current && setError(messageOf(e)));
|
|
50
|
+
discovery
|
|
51
|
+
.getObject({ ref: props.objectRef, includeProfile: true })
|
|
52
|
+
.then((response) => current && setProfile(response.profile))
|
|
53
|
+
.catch(() => { });
|
|
54
|
+
discovery
|
|
55
|
+
.getRelated({ ref: props.objectRef })
|
|
56
|
+
.then((response) => current && setRelations(response.relations))
|
|
57
|
+
.catch(() => { });
|
|
58
|
+
return () => {
|
|
59
|
+
current = false;
|
|
60
|
+
};
|
|
61
|
+
}, [discovery, key]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
62
|
+
if (error) {
|
|
63
|
+
return (_jsx("p", { className: "sf-search-error", role: "alert", children: error }));
|
|
64
|
+
}
|
|
65
|
+
if (!profile?.object)
|
|
66
|
+
return _jsx("p", { className: "sf-object-muted", children: "Loading\u2026" });
|
|
67
|
+
const object = profile.object;
|
|
68
|
+
const rows = profile.rowCount === undefined ? undefined : Number(profile.rowCount);
|
|
69
|
+
const suggest = async () => {
|
|
70
|
+
setBusy(true);
|
|
71
|
+
try {
|
|
72
|
+
const response = await discovery.describe({ ref: props.objectRef });
|
|
73
|
+
setDraft({ text: response.description, proposed: response.description, by: response.generatedBy });
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
setError(messageOf(e));
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
setBusy(false);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const save = async () => {
|
|
83
|
+
if (!draft)
|
|
84
|
+
return;
|
|
85
|
+
setBusy(true);
|
|
86
|
+
try {
|
|
87
|
+
const edited = draft.text.trim() !== draft.proposed.trim() || draft.by === "";
|
|
88
|
+
const response = await discovery.saveDescription({
|
|
89
|
+
ref: props.objectRef,
|
|
90
|
+
description: draft.text,
|
|
91
|
+
origin: edited ? DescriptionOrigin.HUMAN : DescriptionOrigin.GENERATED,
|
|
92
|
+
});
|
|
93
|
+
if (response.object)
|
|
94
|
+
setProfile({ ...profile, object: response.object });
|
|
95
|
+
setDraft(undefined);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
setError(messageOf(e));
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
setBusy(false);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const certify = async (status, note) => {
|
|
105
|
+
setBusy(true);
|
|
106
|
+
try {
|
|
107
|
+
const response = await discovery.setCertification({ ref: props.objectRef, status, setBy: props.certifier ?? "", note });
|
|
108
|
+
if (response.object)
|
|
109
|
+
setProfile({ ...profile, object: response.object });
|
|
110
|
+
setCertifying(undefined);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
setError(messageOf(e));
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
setBusy(false);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const mark = object.certification?.status ? object.certification : undefined;
|
|
120
|
+
return (_jsxs("article", { className: ["sf-object", props.className].filter(Boolean).join(" "), children: [_jsxs("header", { className: "sf-object-head", children: [_jsxs("div", { children: [_jsxs("h3", { className: "sf-object-title", children: [object.name, " ", _jsx(CertificationBadge, { certification: object.certification })] }), _jsx("p", { className: "sf-object-facts", children: [object.ref?.sourceId, FORMAT_LABEL[object.format], rows === undefined ? undefined : `${fullCount.format(rows)} rows`, `${profile.columns.length} columns`]
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.join(" · ") })] }), props.renderActions && _jsx("div", { className: "sf-object-actions", children: props.renderActions(object) })] }), (mark || props.certifier) && (_jsxs("section", { className: "sf-object-certification", "aria-label": "Certification", children: [mark && _jsx("p", { children: certificationText(mark) }), props.certifier &&
|
|
123
|
+
(certifying ? (_jsxs(_Fragment, { children: [_jsx("label", { className: "sf-object-label", htmlFor: "sf-object-cert-note", children: certifying.status === CertificationStatus.DEPRECATED ? "What should people use instead?" : "Why is it certified? (optional)" }), _jsx("input", { id: "sf-object-cert-note", className: "sf-input", value: certifying.note, onChange: (e) => setCertifying({ ...certifying, note: e.target.value }) }), _jsxs("div", { className: "sf-object-buttons", children: [_jsxs("button", { type: "button", className: "sf-button", "data-variant": "primary", disabled: busy, onClick: () => void certify(certifying.status, certifying.note), children: [certifying.status === CertificationStatus.DEPRECATED ? "Mark as deprecated" : "Certify", " as ", props.certifier] }), _jsx("button", { type: "button", className: "sf-button", onClick: () => setCertifying(undefined), children: "Cancel" })] })] })) : (_jsxs("div", { className: "sf-object-buttons", children: [mark?.status !== CertificationStatus.CERTIFIED && (_jsx("button", { type: "button", className: "sf-button", onClick: () => setCertifying({ status: CertificationStatus.CERTIFIED, note: "" }), children: "Certify\u2026" })), mark?.status !== CertificationStatus.DEPRECATED && (_jsx("button", { type: "button", className: "sf-button", onClick: () => setCertifying({ status: CertificationStatus.DEPRECATED, note: "" }), children: "Deprecate\u2026" })), mark && (_jsx("button", { type: "button", className: "sf-button", disabled: busy, onClick: () => void certify(CertificationStatus.UNSPECIFIED, ""), children: "Remove mark" }))] })))] })), _jsx("section", { className: "sf-object-description", "aria-label": "Description", children: draft ? (_jsxs(_Fragment, { children: [_jsx("label", { className: "sf-object-label", htmlFor: "sf-object-draft", children: draft.by === "placeholder"
|
|
124
|
+
? "Proposed description (a summary of the facts; no language model is connected)"
|
|
125
|
+
: draft.by
|
|
126
|
+
? `Proposed description, generated by ${draft.by}`
|
|
127
|
+
: "Description" }), _jsx("textarea", { id: "sf-object-draft", className: "sf-input sf-object-draft", rows: 3, value: draft.text, onChange: (e) => setDraft({ ...draft, text: e.target.value }) }), _jsxs("div", { className: "sf-object-buttons", children: [_jsx("button", { type: "button", className: "sf-button", "data-variant": "primary", disabled: busy || draft.text.trim() === "", onClick: () => void save(), children: "Save description" }), _jsx("button", { type: "button", className: "sf-button", onClick: () => setDraft(undefined), children: "Discard" })] })] })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: object.description ? undefined : "sf-object-muted", children: object.description || "No description yet." }), _jsxs("div", { className: "sf-object-buttons", children: [object.description && ORIGIN_LABEL[object.descriptionOrigin] && _jsx("span", { className: "sf-schema-tag", children: ORIGIN_LABEL[object.descriptionOrigin] }), _jsx("button", { type: "button", className: "sf-button", disabled: busy, onClick: () => void suggest(), children: "Suggest a description" }), _jsx("button", { type: "button", className: "sf-button", onClick: () => setDraft({ text: object.description, proposed: object.description, by: "" }), children: object.description ? "Edit" : "Write one" })] })] })) }), _jsxs("section", { "aria-label": "Columns", children: [!profile.sampleValuesAllowed && (_jsx("p", { className: "sf-object-policy", children: "Data values are withheld for this source, so ranges and common values are not shown." })), _jsx("div", { className: "sf-object-table", tabIndex: 0, role: "region", "aria-label": "Column statistics", children: _jsxs("table", { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "Column" }), _jsx("th", { scope: "col", children: "Type" }), _jsx("th", { scope: "col", children: "Filled" }), _jsx("th", { scope: "col", className: "sf-object-number", children: "Distinct" }), _jsx("th", { scope: "col", children: "Values" })] }) }), _jsx("tbody", { children: profile.columns.map((column) => (_jsxs("tr", { children: [_jsxs("th", { scope: "row", children: [column.name, column.description && _jsx("span", { className: "sf-object-column-note", children: column.description })] }), _jsx("td", { className: "sf-object-type", children: column.nativeType.toLowerCase() }), _jsx(ColumnProfile, { column: column, rowCount: rows })] }, column.name))) })] }) })] }), relations.length > 0 && (_jsxs("section", { "aria-label": "Related tables", children: [_jsx("h4", { className: "sf-object-label", children: "Related" }), _jsx("ul", { className: "sf-object-related", children: relations.map((relation, i) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "sf-object-relation", onClick: () => relation.object && props.onOpen?.(relation.object), children: [_jsx("span", { className: "sf-object-muted", children: RELATION_LABEL[relation.kind] ?? "Related to" }), " ", _jsx("strong", { children: relation.object?.name }), " ", _jsx(CertificationBadge, { certification: relation.object?.certification }), _jsxs("span", { className: "sf-object-muted", children: [" \u00B7 ", relation.reason] }), relation.inferred ? _jsx("span", { className: "sf-schema-tag", children: "Inferred" }) : relation.kind === RelationKind.JOIN && _jsx("span", { className: "sf-schema-tag", children: "Declared" })] }) }, `${relation.kind}-${relation.object?.name}-${i}`))) })] })), props.showSampleRows && profile.sampleValuesAllowed && object.ref && (_jsxs("section", { "aria-label": "Sample rows", children: [_jsx("h4", { className: "sf-object-label", children: "Rows" }), _jsx(DataGrid, { sourceId: object.ref.sourceId, sql: `SELECT * FROM ${object.ref.table}`, height: 260, label: `Rows of ${object.name}` })] }))] }));
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=ObjectDetail.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectDetail.js","sourceRoot":"","sources":["../../src/discovery/ObjectDetail.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,mBAAmB,EAA+D,iBAAiB,EAAqC,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC1L,OAAO,EAAkB,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,YAAY,EAAsB,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAwB7I,MAAM,cAAc,GAA0C;IAC5D,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,YAAY;IACjC,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,YAAY;IACpC,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,YAAY;IACrC,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,OAAO;IAClC,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,SAAS;CACxC,CAAC;AAQF,wHAAwH;AACxH,MAAM,UAAU,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAsB;IACpE,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,CA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K,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,aACpH,eAAM,SAAS,EAAC,iBAAiB,YAAE,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,YAAY,GAAQ,OAAC,2BAAS,QAAQ,CAAC,MAAM,EAAE,IAAI,GAAU,OAAC,KAAC,kBAAkB,IAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAI,EACvM,gBAAM,SAAS,EAAC,iBAAiB,yBAAK,QAAQ,CAAC,MAAM,IAAQ,EAC5D,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,eAAe,yBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,IAAI,eAAM,SAAS,EAAC,eAAe,yBAAgB,IACtJ,IALF,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,CAMpD,CACN,CAAC,GACC,IACG,CACX,EAEA,KAAK,CAAC,cAAc,IAAI,OAAO,CAAC,mBAAmB,IAAI,MAAM,CAAC,GAAG,IAAI,CACpE,iCAAoB,aAAa,aAC/B,aAAI,SAAS,EAAC,iBAAiB,qBAAU,EACzC,KAAC,QAAQ,IAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,iBAAiB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,MAAM,CAAC,IAAI,EAAE,GAAI,IAC3H,CACX,IACO,CACX,CAAC;AACJ,CAAC","sourcesContent":["import type { Discovery } from \"@surfaces-ui/data\";\nimport { CertificationStatus, type ColumnProfile as ColumnProfileMessage, type DataObject, DescriptionOrigin, type ObjectProfile, type Relation, RelationKind } from \"@surfaces-ui/proto\";\nimport { type ReactNode, useEffect, useState } from \"react\";\nimport { messageOf } from \"../data/useRowWindow.js\";\nimport { DataGrid } from \"../grid/DataGrid.js\";\nimport { CertificationBadge, FORMAT_LABEL, ORIGIN_LABEL, type ObjectRefInit, certificationText, fullCount, useDiscovery } from \"./shared.js\";\n\nexport interface ObjectDetailProps {\n /** The table to show. */\n objectRef: ObjectRefInit;\n /** Called when a related object is chosen. */\n onOpen?(object: DataObject): void;\n /** Controls beside the title, e.g. \"Add to context\". */\n renderActions?(object: DataObject): ReactNode;\n /**\n * Show a preview of the table's rows. Only shown when the source allows\n * data values, and needs a DataSourceProvider above.\n */\n showSampleRows?: boolean;\n /**\n * The name of the person using the page, if they may certify data. Setting\n * it shows the controls to certify, deprecate or clear the mark, and the\n * name is recorded with the decision. Who is allowed is the host's call.\n */\n certifier?: string;\n discovery?: Discovery;\n className?: string;\n}\n\nconst RELATION_LABEL: Partial<Record<RelationKind, string>> = {\n [RelationKind.JOIN]: \"Joins with\",\n [RelationKind.SIMILAR]: \"Similar to\",\n [RelationKind.UPSTREAM]: \"Built from\",\n [RelationKind.DOWNSTREAM]: \"Feeds\",\n [RelationKind.USED_BY_QUERY]: \"Used by\",\n};\n\nexport interface ColumnProfileProps {\n column: ColumnProfileMessage;\n /** Rows in the table, to turn counts into shares. */\n rowCount: number | undefined;\n}\n\n/** One column's statistics: how full it is, how varied, and its range or most common values when those may be shown. */\nexport function ColumnProfile({ column, rowCount }: ColumnProfileProps) {\n const filled = rowCount && column.nullCount !== undefined ? 1 - Number(column.nullCount) / rowCount : undefined;\n const top = column.topValues.slice(0, 3);\n const most = Math.max(1, ...top.map((t) => Number(t.count)));\n return (\n <>\n <td className=\"sf-object-fill\">\n {filled === undefined ? (\n <span className=\"sf-object-muted\">–</span>\n ) : (\n <span className=\"sf-meter\" role=\"img\" aria-label={`${Math.round(filled * 100)}% filled`}>\n <span style={{ inlineSize: `${Math.round(filled * 100)}%` }} />\n <em>{Math.round(filled * 100)}%</em>\n </span>\n )}\n </td>\n <td className=\"sf-object-number\">{column.distinctCount === undefined ? (\n \"–\"\n ) : (\n <span title={column.distinctCountEstimated ? \"An estimate\" : undefined}>\n {column.distinctCountEstimated ? \"~\" : \"\"}\n {fullCount.format(Number(column.distinctCount))}\n </span>\n )}</td>\n <td className=\"sf-object-values\">\n {column.sampleValuesWithheld ? (\n <span className=\"sf-object-muted\">Withheld</span>\n ) : top.length > 0 ? (\n <span className=\"sf-top-values\">\n {top.map((value) => (\n <span key={value.value} className=\"sf-top-value\" title={`${value.value}: ${fullCount.format(Number(value.count))}`}>\n <span style={{ inlineSize: `${Math.round((Number(value.count) / most) * 100)}%` }} />\n <em>{value.value}</em>\n </span>\n ))}\n </span>\n ) : column.min !== undefined && column.min !== \"\" ? (\n <span>\n {column.min} → {column.max}\n </span>\n ) : (\n <span className=\"sf-object-muted\">–</span>\n )}\n </td>\n </>\n );\n}\n\n/**\n * Everything known about one table: its description and who wrote it, its\n * columns with statistics, and the tables it relates to. A generated\n * description is only a proposal until a person accepts or edits it.\n */\nexport function ObjectDetail(props: ObjectDetailProps) {\n const discovery = useDiscovery(props.discovery);\n const key = JSON.stringify(props.objectRef);\n const [profile, setProfile] = useState<ObjectProfile | undefined>();\n const [relations, setRelations] = useState<Relation[]>([]);\n const [error, setError] = useState<string | undefined>();\n const [draft, setDraft] = useState<{ text: string; proposed: string; by: string } | undefined>();\n const [busy, setBusy] = useState(false);\n const [certifying, setCertifying] = useState<{ status: CertificationStatus; note: string } | undefined>();\n\n useEffect(() => {\n let current = true;\n setProfile(undefined);\n setRelations([]);\n setError(undefined);\n setDraft(undefined);\n setCertifying(undefined);\n // Names and types first, then statistics, so the page is useful immediately.\n discovery\n .getObject({ ref: props.objectRef })\n .then((response) => {\n if (current) setProfile((existing) => existing ?? response.profile);\n })\n .catch((e: unknown) => current && setError(messageOf(e)));\n discovery\n .getObject({ ref: props.objectRef, includeProfile: true })\n .then((response) => current && setProfile(response.profile))\n .catch(() => {});\n discovery\n .getRelated({ ref: props.objectRef })\n .then((response) => current && setRelations(response.relations))\n .catch(() => {});\n return () => {\n current = false;\n };\n }, [discovery, key]); // eslint-disable-line react-hooks/exhaustive-deps\n\n if (error) {\n return (\n <p className=\"sf-search-error\" role=\"alert\">\n {error}\n </p>\n );\n }\n if (!profile?.object) return <p className=\"sf-object-muted\">Loading…</p>;\n\n const object = profile.object;\n const rows = profile.rowCount === undefined ? undefined : Number(profile.rowCount);\n\n const suggest = async () => {\n setBusy(true);\n try {\n const response = await discovery.describe({ ref: props.objectRef });\n setDraft({ text: response.description, proposed: response.description, by: response.generatedBy });\n } catch (e) {\n setError(messageOf(e));\n } finally {\n setBusy(false);\n }\n };\n const save = async () => {\n if (!draft) return;\n setBusy(true);\n try {\n const edited = draft.text.trim() !== draft.proposed.trim() || draft.by === \"\";\n const response = await discovery.saveDescription({\n ref: props.objectRef,\n description: draft.text,\n origin: edited ? DescriptionOrigin.HUMAN : DescriptionOrigin.GENERATED,\n });\n if (response.object) setProfile({ ...profile, object: response.object });\n setDraft(undefined);\n } catch (e) {\n setError(messageOf(e));\n } finally {\n setBusy(false);\n }\n };\n\n const certify = async (status: CertificationStatus, note: string) => {\n setBusy(true);\n try {\n const response = await discovery.setCertification({ ref: props.objectRef, status, setBy: props.certifier ?? \"\", note });\n if (response.object) setProfile({ ...profile, object: response.object });\n setCertifying(undefined);\n } catch (e) {\n setError(messageOf(e));\n } finally {\n setBusy(false);\n }\n };\n const mark = object.certification?.status ? object.certification : undefined;\n\n return (\n <article className={[\"sf-object\", props.className].filter(Boolean).join(\" \")}>\n <header className=\"sf-object-head\">\n <div>\n <h3 className=\"sf-object-title\">\n {object.name} <CertificationBadge certification={object.certification} />\n </h3>\n <p className=\"sf-object-facts\">\n {[object.ref?.sourceId, FORMAT_LABEL[object.format], rows === undefined ? undefined : `${fullCount.format(rows)} rows`, `${profile.columns.length} columns`]\n .filter(Boolean)\n .join(\" · \")}\n </p>\n </div>\n {props.renderActions && <div className=\"sf-object-actions\">{props.renderActions(object)}</div>}\n </header>\n\n {(mark || props.certifier) && (\n <section className=\"sf-object-certification\" aria-label=\"Certification\">\n {mark && <p>{certificationText(mark)}</p>}\n {props.certifier &&\n (certifying ? (\n <>\n <label className=\"sf-object-label\" htmlFor=\"sf-object-cert-note\">\n {certifying.status === CertificationStatus.DEPRECATED ? \"What should people use instead?\" : \"Why is it certified? (optional)\"}\n </label>\n <input\n id=\"sf-object-cert-note\"\n className=\"sf-input\"\n value={certifying.note}\n onChange={(e) => setCertifying({ ...certifying, note: e.target.value })}\n />\n <div className=\"sf-object-buttons\">\n <button type=\"button\" className=\"sf-button\" data-variant=\"primary\" disabled={busy} onClick={() => void certify(certifying.status, certifying.note)}>\n {certifying.status === CertificationStatus.DEPRECATED ? \"Mark as deprecated\" : \"Certify\"} as {props.certifier}\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setCertifying(undefined)}>\n Cancel\n </button>\n </div>\n </>\n ) : (\n <div className=\"sf-object-buttons\">\n {mark?.status !== CertificationStatus.CERTIFIED && (\n <button type=\"button\" className=\"sf-button\" onClick={() => setCertifying({ status: CertificationStatus.CERTIFIED, note: \"\" })}>\n Certify…\n </button>\n )}\n {mark?.status !== CertificationStatus.DEPRECATED && (\n <button type=\"button\" className=\"sf-button\" onClick={() => setCertifying({ status: CertificationStatus.DEPRECATED, note: \"\" })}>\n Deprecate…\n </button>\n )}\n {mark && (\n <button type=\"button\" className=\"sf-button\" disabled={busy} onClick={() => void certify(CertificationStatus.UNSPECIFIED, \"\")}>\n Remove mark\n </button>\n )}\n </div>\n ))}\n </section>\n )}\n\n <section className=\"sf-object-description\" aria-label=\"Description\">\n {draft ? (\n <>\n <label className=\"sf-object-label\" htmlFor=\"sf-object-draft\">\n {draft.by === \"placeholder\"\n ? \"Proposed description (a summary of the facts; no language model is connected)\"\n : draft.by\n ? `Proposed description, generated by ${draft.by}`\n : \"Description\"}\n </label>\n <textarea id=\"sf-object-draft\" className=\"sf-input sf-object-draft\" rows={3} value={draft.text} onChange={(e) => setDraft({ ...draft, text: e.target.value })} />\n <div className=\"sf-object-buttons\">\n <button type=\"button\" className=\"sf-button\" data-variant=\"primary\" disabled={busy || draft.text.trim() === \"\"} onClick={() => void save()}>\n Save description\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setDraft(undefined)}>\n Discard\n </button>\n </div>\n </>\n ) : (\n <>\n <p className={object.description ? undefined : \"sf-object-muted\"}>{object.description || \"No description yet.\"}</p>\n <div className=\"sf-object-buttons\">\n {object.description && ORIGIN_LABEL[object.descriptionOrigin] && <span className=\"sf-schema-tag\">{ORIGIN_LABEL[object.descriptionOrigin]}</span>}\n <button type=\"button\" className=\"sf-button\" disabled={busy} onClick={() => void suggest()}>\n Suggest a description\n </button>\n <button type=\"button\" className=\"sf-button\" onClick={() => setDraft({ text: object.description, proposed: object.description, by: \"\" })}>\n {object.description ? \"Edit\" : \"Write one\"}\n </button>\n </div>\n </>\n )}\n </section>\n\n <section aria-label=\"Columns\">\n {!profile.sampleValuesAllowed && (\n <p className=\"sf-object-policy\">Data values are withheld for this source, so ranges and common values are not shown.</p>\n )}\n <div className=\"sf-object-table\" tabIndex={0} role=\"region\" aria-label=\"Column statistics\">\n <table>\n <thead>\n <tr>\n <th scope=\"col\">Column</th>\n <th scope=\"col\">Type</th>\n <th scope=\"col\">Filled</th>\n <th scope=\"col\" className=\"sf-object-number\">\n Distinct\n </th>\n <th scope=\"col\">Values</th>\n </tr>\n </thead>\n <tbody>\n {profile.columns.map((column) => (\n <tr key={column.name}>\n <th scope=\"row\">\n {column.name}\n {column.description && <span className=\"sf-object-column-note\">{column.description}</span>}\n </th>\n <td className=\"sf-object-type\">{column.nativeType.toLowerCase()}</td>\n <ColumnProfile column={column} rowCount={rows} />\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n </section>\n\n {relations.length > 0 && (\n <section aria-label=\"Related tables\">\n <h4 className=\"sf-object-label\">Related</h4>\n <ul className=\"sf-object-related\">\n {relations.map((relation, i) => (\n <li key={`${relation.kind}-${relation.object?.name}-${i}`}>\n <button type=\"button\" className=\"sf-object-relation\" onClick={() => relation.object && props.onOpen?.(relation.object)}>\n <span className=\"sf-object-muted\">{RELATION_LABEL[relation.kind] ?? \"Related to\"}</span> <strong>{relation.object?.name}</strong> <CertificationBadge certification={relation.object?.certification} />\n <span className=\"sf-object-muted\"> · {relation.reason}</span>\n {relation.inferred ? <span className=\"sf-schema-tag\">Inferred</span> : relation.kind === RelationKind.JOIN && <span className=\"sf-schema-tag\">Declared</span>}\n </button>\n </li>\n ))}\n </ul>\n </section>\n )}\n\n {props.showSampleRows && profile.sampleValuesAllowed && object.ref && (\n <section aria-label=\"Sample rows\">\n <h4 className=\"sf-object-label\">Rows</h4>\n <DataGrid sourceId={object.ref.sourceId} sql={`SELECT * FROM ${object.ref.table}`} height={260} label={`Rows of ${object.name}`} />\n </section>\n )}\n </article>\n );\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Discovery } from "@surfaces-ui/data";
|
|
2
|
+
import { type DataObject } from "@surfaces-ui/proto";
|
|
3
|
+
import { type ObjectRefInit } from "./shared.js";
|
|
4
|
+
export interface RelationshipGraphProps {
|
|
5
|
+
/** The table at the centre. */
|
|
6
|
+
objectRef: ObjectRefInit;
|
|
7
|
+
/** Called when a related table is chosen, typically to re-centre on it. */
|
|
8
|
+
onOpen?(object: DataObject): void;
|
|
9
|
+
/** Most related tables drawn. Defaults to 8. */
|
|
10
|
+
limit?: number;
|
|
11
|
+
discovery?: Discovery;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A map of one table and the tables it connects to. Solid lines are joins,
|
|
16
|
+
* labelled with their key; dashed lines are look-alike tables. Choosing a
|
|
17
|
+
* table moves to it, so you can walk across the data.
|
|
18
|
+
*/
|
|
19
|
+
export declare function RelationshipGraph(props: RelationshipGraphProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RelationKind } from "@surfaces-ui/proto";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { useDiscovery } from "./shared.js";
|
|
5
|
+
const WIDTH = 640;
|
|
6
|
+
const HEIGHT = 300;
|
|
7
|
+
const short = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
|
|
8
|
+
/**
|
|
9
|
+
* A map of one table and the tables it connects to. Solid lines are joins,
|
|
10
|
+
* labelled with their key; dashed lines are look-alike tables. Choosing a
|
|
11
|
+
* table moves to it, so you can walk across the data.
|
|
12
|
+
*/
|
|
13
|
+
export function RelationshipGraph(props) {
|
|
14
|
+
const { limit = 8 } = props;
|
|
15
|
+
const discovery = useDiscovery(props.discovery);
|
|
16
|
+
const key = JSON.stringify(props.objectRef);
|
|
17
|
+
const [relations, setRelations] = useState();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let current = true;
|
|
20
|
+
setRelations(undefined);
|
|
21
|
+
discovery
|
|
22
|
+
.getRelated({ ref: props.objectRef })
|
|
23
|
+
.then((response) => {
|
|
24
|
+
if (!current)
|
|
25
|
+
return;
|
|
26
|
+
// One node per table: prefer the join when a table is both joinable and similar.
|
|
27
|
+
const byTable = new Map();
|
|
28
|
+
for (const relation of response.relations) {
|
|
29
|
+
const name = relation.object?.name ?? "";
|
|
30
|
+
if (!byTable.has(name) || relation.kind === RelationKind.JOIN)
|
|
31
|
+
byTable.set(name, relation);
|
|
32
|
+
}
|
|
33
|
+
setRelations([...byTable.values()].slice(0, limit));
|
|
34
|
+
})
|
|
35
|
+
.catch(() => current && setRelations([]));
|
|
36
|
+
return () => {
|
|
37
|
+
current = false;
|
|
38
|
+
};
|
|
39
|
+
}, [discovery, key, limit]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
40
|
+
const centre = { x: WIDTH / 2, y: HEIGHT / 2 };
|
|
41
|
+
const name = props.objectRef.table ?? "";
|
|
42
|
+
if (relations === undefined)
|
|
43
|
+
return _jsx("p", { className: "sf-object-muted", children: "Loading\u2026" });
|
|
44
|
+
if (relations.length === 0)
|
|
45
|
+
return _jsxs("p", { className: "sf-object-muted", children: ["No related tables were found for ", name, "."] });
|
|
46
|
+
const nodes = relations.map((relation, i) => {
|
|
47
|
+
const angle = (2 * Math.PI * i) / relations.length - Math.PI / 2;
|
|
48
|
+
return { relation, x: centre.x + Math.cos(angle) * 235, y: centre.y + Math.sin(angle) * 105 };
|
|
49
|
+
});
|
|
50
|
+
return (_jsxs("figure", { className: ["sf-graph", props.className].filter(Boolean).join(" "), children: [_jsxs("svg", { viewBox: `0 0 ${WIDTH} ${HEIGHT}`, role: "group", "aria-label": `Tables related to ${name}`, children: [nodes.map(({ relation, x, y }) => {
|
|
51
|
+
const join = relation.kind === RelationKind.JOIN;
|
|
52
|
+
return (_jsxs("g", { children: [_jsx("line", { x1: centre.x, y1: centre.y, x2: x, y2: y, className: "sf-graph-edge", "data-kind": join ? "join" : "similar" }), _jsx("text", { x: (centre.x + x) / 2, y: (centre.y + y) / 2 - 5, className: "sf-graph-edge-label", textAnchor: "middle", children: join ? short(relation.keys.map((k) => k.leftColumn).join(", "), 18) : "similar" })] }, `edge-${relation.object?.name}`));
|
|
53
|
+
}), _jsxs("g", { className: "sf-graph-node", "data-centre": true, children: [_jsx("rect", { x: centre.x - 70, y: centre.y - 17, width: 140, height: 34, rx: 8 }), _jsx("text", { x: centre.x, y: centre.y + 5, textAnchor: "middle", children: short(name, 18) })] }), nodes.map(({ relation, x, y }) => (_jsxs("g", { className: "sf-graph-node", role: "button", tabIndex: 0, "aria-label": `${relation.object?.name}: ${relation.reason}`, onClick: () => relation.object && props.onOpen?.(relation.object), onKeyDown: (event) => {
|
|
54
|
+
if ((event.key === "Enter" || event.key === " ") && relation.object) {
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
props.onOpen?.(relation.object);
|
|
57
|
+
}
|
|
58
|
+
}, children: [_jsx("rect", { x: x - 66, y: y - 16, width: 132, height: 32, rx: 8 }), _jsx("text", { x: x, y: y + 5, textAnchor: "middle", children: short(relation.object?.name ?? "", 17) })] }, relation.object?.name)))] }), _jsxs("figcaption", { className: "sf-graph-legend", children: [_jsx("span", { "data-kind": "join", children: "Join on shared key" }), _jsx("span", { "data-kind": "similar", children: "Similar columns" }), _jsx("span", { children: relations.every((r) => r.inferred)
|
|
59
|
+
? "Relationships are inferred from names and types."
|
|
60
|
+
: relations.every((r) => !r.inferred)
|
|
61
|
+
? "Joins are the source's declared keys."
|
|
62
|
+
: "Joins on declared keys are facts; the rest are inferred from names and types." })] })] }));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=RelationshipGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationshipGraph.js","sourceRoot":"","sources":["../../src/discovery/RelationshipGraph.tsx"],"names":[],"mappings":";AACA,OAAO,EAAkC,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;AAa/D,MAAM,KAAK,GAAG,GAAG,CAAC;AAClB,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEvG;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC;IAC5B,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC5C,M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J,CAAC","sourcesContent":["import type { Discovery } from \"@surfaces-ui/data\";\nimport { type DataObject, type Relation, RelationKind } from \"@surfaces-ui/proto\";\nimport { useEffect, useState } from \"react\";\nimport { type ObjectRefInit, useDiscovery } from \"./shared.js\";\n\nexport interface RelationshipGraphProps {\n /** The table at the centre. */\n objectRef: ObjectRefInit;\n /** Called when a related table is chosen, typically to re-centre on it. */\n onOpen?(object: DataObject): void;\n /** Most related tables drawn. Defaults to 8. */\n limit?: number;\n discovery?: Discovery;\n className?: string;\n}\n\nconst WIDTH = 640;\nconst HEIGHT = 300;\nconst short = (text: string, max: number) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);\n\n/**\n * A map of one table and the tables it connects to. Solid lines are joins,\n * labelled with their key; dashed lines are look-alike tables. Choosing a\n * table moves to it, so you can walk across the data.\n */\nexport function RelationshipGraph(props: RelationshipGraphProps) {\n const { limit = 8 } = props;\n const discovery = useDiscovery(props.discovery);\n const key = JSON.stringify(props.objectRef);\n const [relations, setRelations] = useState<Relation[] | undefined>();\n\n useEffect(() => {\n let current = true;\n setRelations(undefined);\n discovery\n .getRelated({ ref: props.objectRef })\n .then((response) => {\n if (!current) return;\n // One node per table: prefer the join when a table is both joinable and similar.\n const byTable = new Map<string, Relation>();\n for (const relation of response.relations) {\n const name = relation.object?.name ?? \"\";\n if (!byTable.has(name) || relation.kind === RelationKind.JOIN) byTable.set(name, relation);\n }\n setRelations([...byTable.values()].slice(0, limit));\n })\n .catch(() => current && setRelations([]));\n return () => {\n current = false;\n };\n }, [discovery, key, limit]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const centre = { x: WIDTH / 2, y: HEIGHT / 2 };\n const name = props.objectRef.table ?? \"\";\n if (relations === undefined) return <p className=\"sf-object-muted\">Loading…</p>;\n if (relations.length === 0) return <p className=\"sf-object-muted\">No related tables were found for {name}.</p>;\n\n const nodes = relations.map((relation, i) => {\n const angle = (2 * Math.PI * i) / relations.length - Math.PI / 2;\n return { relation, x: centre.x + Math.cos(angle) * 235, y: centre.y + Math.sin(angle) * 105 };\n });\n\n return (\n <figure className={[\"sf-graph\", props.className].filter(Boolean).join(\" \")}>\n <svg viewBox={`0 0 ${WIDTH} ${HEIGHT}`} role=\"group\" aria-label={`Tables related to ${name}`}>\n {nodes.map(({ relation, x, y }) => {\n const join = relation.kind === RelationKind.JOIN;\n return (\n <g key={`edge-${relation.object?.name}`}>\n <line x1={centre.x} y1={centre.y} x2={x} y2={y} className=\"sf-graph-edge\" data-kind={join ? \"join\" : \"similar\"} />\n <text x={(centre.x + x) / 2} y={(centre.y + y) / 2 - 5} className=\"sf-graph-edge-label\" textAnchor=\"middle\">\n {join ? short(relation.keys.map((k) => k.leftColumn).join(\", \"), 18) : \"similar\"}\n </text>\n </g>\n );\n })}\n <g className=\"sf-graph-node\" data-centre>\n <rect x={centre.x - 70} y={centre.y - 17} width={140} height={34} rx={8} />\n <text x={centre.x} y={centre.y + 5} textAnchor=\"middle\">\n {short(name, 18)}\n </text>\n </g>\n {nodes.map(({ relation, x, y }) => (\n <g\n key={relation.object?.name}\n className=\"sf-graph-node\"\n role=\"button\"\n tabIndex={0}\n aria-label={`${relation.object?.name}: ${relation.reason}`}\n onClick={() => relation.object && props.onOpen?.(relation.object)}\n onKeyDown={(event) => {\n if ((event.key === \"Enter\" || event.key === \" \") && relation.object) {\n event.preventDefault();\n props.onOpen?.(relation.object);\n }\n }}\n >\n <rect x={x - 66} y={y - 16} width={132} height={32} rx={8} />\n <text x={x} y={y + 5} textAnchor=\"middle\">\n {short(relation.object?.name ?? \"\", 17)}\n </text>\n </g>\n ))}\n </svg>\n <figcaption className=\"sf-graph-legend\">\n <span data-kind=\"join\">Join on shared key</span>\n <span data-kind=\"similar\">Similar columns</span>\n <span>\n {relations.every((r) => r.inferred)\n ? \"Relationships are inferred from names and types.\"\n : relations.every((r) => !r.inferred)\n ? \"Joins are the source's declared keys.\"\n : \"Joins on declared keys are facts; the rest are inferred from names and types.\"}\n </span>\n </figcaption>\n </figure>\n );\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { MessageInitShape } from "@bufbuild/protobuf";
|
|
2
|
+
import type { Discovery } from "@surfaces-ui/data";
|
|
3
|
+
import { type Certification, type DataObject, DescriptionOrigin, type ObjectRefSchema, TableFormat } from "@surfaces-ui/proto";
|
|
4
|
+
import { type ReactNode } from "react";
|
|
5
|
+
export interface DiscoveryProviderProps {
|
|
6
|
+
/** Any implementation: a Connect client, the reference `createDiscovery`, or your own. */
|
|
7
|
+
discovery: Discovery;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/** Makes a Discovery backend available to the discovery and context components below it. */
|
|
11
|
+
export declare function DiscoveryProvider({ discovery, children }: DiscoveryProviderProps): import("react").JSX.Element;
|
|
12
|
+
export declare function useDiscovery(override?: Discovery): Discovery;
|
|
13
|
+
/** The Discovery backend if one is available, for components that work without it. */
|
|
14
|
+
export declare function useOptionalDiscovery(override?: Discovery): Discovery | undefined;
|
|
15
|
+
/** What a certification says in words, e.g. for a tooltip. */
|
|
16
|
+
export declare function certificationText(certification: Certification): string;
|
|
17
|
+
/**
|
|
18
|
+
* Marks an object a steward has certified or deprecated. Renders nothing when
|
|
19
|
+
* there is no verdict. The mark and the text both carry the meaning, so it
|
|
20
|
+
* does not rely on colour.
|
|
21
|
+
*/
|
|
22
|
+
export declare function CertificationBadge({ certification }: {
|
|
23
|
+
certification: Certification | undefined;
|
|
24
|
+
}): import("react").JSX.Element | null;
|
|
25
|
+
export type ObjectRefInit = MessageInitShape<typeof ObjectRefSchema>;
|
|
26
|
+
/** A table reference in the shape the Discovery interface expects. */
|
|
27
|
+
export declare function tableRef(sourceId: string, table: string): ObjectRefInit;
|
|
28
|
+
export declare const FORMAT_LABEL: Partial<Record<TableFormat, string>>;
|
|
29
|
+
export declare const ORIGIN_LABEL: Partial<Record<DescriptionOrigin, string>>;
|
|
30
|
+
export declare function kindLabel(object: DataObject | undefined): string;
|
|
31
|
+
/** Writes 1.2K, in the page's locale. */
|
|
32
|
+
export declare const compactCount: {
|
|
33
|
+
format: (n: number | bigint) => string;
|
|
34
|
+
};
|
|
35
|
+
/** Writes 1,234, in the page's locale. */
|
|
36
|
+
export declare const fullCount: {
|
|
37
|
+
format: (n: number | bigint) => string;
|
|
38
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CertificationStatus, DescriptionOrigin, ObjectKind, TableFormat } from "@surfaces-ui/proto";
|
|
3
|
+
import { useProvided, useTraced } from "@surfaces-ui/trace/react";
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { numberFormat } from "../locale/locale.js";
|
|
6
|
+
const DiscoveryContext = createContext(undefined);
|
|
7
|
+
/** Makes a Discovery backend available to the discovery and context components below it. */
|
|
8
|
+
export function DiscoveryProvider({ discovery, children }) {
|
|
9
|
+
useProvided("discovery", discovery);
|
|
10
|
+
return _jsx(DiscoveryContext.Provider, { value: discovery, children: children });
|
|
11
|
+
}
|
|
12
|
+
export function useDiscovery(override) {
|
|
13
|
+
const fromContext = useContext(DiscoveryContext);
|
|
14
|
+
const discovery = useTraced("Discovery", override ?? fromContext);
|
|
15
|
+
if (!discovery)
|
|
16
|
+
throw new Error("No Discovery backend: wrap the component in <DiscoveryProvider> or pass discovery.");
|
|
17
|
+
return discovery;
|
|
18
|
+
}
|
|
19
|
+
/** The Discovery backend if one is available, for components that work without it. */
|
|
20
|
+
export function useOptionalDiscovery(override) {
|
|
21
|
+
const fromContext = useContext(DiscoveryContext);
|
|
22
|
+
return useTraced("Discovery", override ?? fromContext);
|
|
23
|
+
}
|
|
24
|
+
/** What a certification says in words, e.g. for a tooltip. */
|
|
25
|
+
export function certificationText(certification) {
|
|
26
|
+
const verb = certification.status === CertificationStatus.DEPRECATED ? "Deprecated" : "Certified";
|
|
27
|
+
const when = certification.setAt ? ` on ${certification.setAt.slice(0, 10)}` : "";
|
|
28
|
+
return `${verb} by ${certification.setBy || "an unnamed person"}${when}${certification.note ? `. ${certification.note}` : ""}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Marks an object a steward has certified or deprecated. Renders nothing when
|
|
32
|
+
* there is no verdict. The mark and the text both carry the meaning, so it
|
|
33
|
+
* does not rely on colour.
|
|
34
|
+
*/
|
|
35
|
+
export function CertificationBadge({ certification }) {
|
|
36
|
+
if (!certification || certification.status === CertificationStatus.UNSPECIFIED)
|
|
37
|
+
return null;
|
|
38
|
+
const deprecated = certification.status === CertificationStatus.DEPRECATED;
|
|
39
|
+
return (_jsxs("span", { className: "sf-cert", "data-status": deprecated ? "deprecated" : "certified", title: certificationText(certification), children: [_jsx("span", { "aria-hidden": "true", children: deprecated ? "!" : "✓" }), deprecated ? "Deprecated" : "Certified"] }));
|
|
40
|
+
}
|
|
41
|
+
/** A table reference in the shape the Discovery interface expects. */
|
|
42
|
+
export function tableRef(sourceId, table) {
|
|
43
|
+
return { sourceId, kind: ObjectKind.TABLE, table };
|
|
44
|
+
}
|
|
45
|
+
export const FORMAT_LABEL = {
|
|
46
|
+
[TableFormat.PARQUET]: "Parquet",
|
|
47
|
+
[TableFormat.CSV]: "CSV",
|
|
48
|
+
[TableFormat.JSON]: "JSON",
|
|
49
|
+
[TableFormat.ICEBERG]: "Iceberg",
|
|
50
|
+
[TableFormat.DELTA]: "Delta",
|
|
51
|
+
};
|
|
52
|
+
export const ORIGIN_LABEL = {
|
|
53
|
+
[DescriptionOrigin.SOURCE]: "From the source",
|
|
54
|
+
[DescriptionOrigin.HUMAN]: "Written by a person",
|
|
55
|
+
[DescriptionOrigin.GENERATED]: "Generated",
|
|
56
|
+
};
|
|
57
|
+
export function kindLabel(object) {
|
|
58
|
+
return object?.ref?.kind === ObjectKind.COLUMN ? "Column" : "Table";
|
|
59
|
+
}
|
|
60
|
+
/** Writes 1.2K, in the page's locale. */
|
|
61
|
+
export const compactCount = { format: (n) => numberFormat({ notation: "compact", maximumFractionDigits: 1 }).format(n) };
|
|
62
|
+
/** Writes 1,234, in the page's locale. */
|
|
63
|
+
export const fullCount = { format: (n) => numberFormat().format(n) };
|
|
64
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/discovery/shared.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAsB,mBAAmB,EAAmB,iBAAiB,EAAE,UAAU,EAAwB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChK,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAkB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,gBAAgB,GAAG,aAAa,CAAwB,SAAS,CAAC,CAAC;AAQzE,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAA0B;IAC/E,WAAW,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACpC,OAAO,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,YAAG,QAAQ,GAA6B,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAoB;IAC/C,MAAM,WAAW,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,QAAQ,IAAI,WAAW,CAAC,CAAC;IAClE,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;IACtH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,oBAAoB,CAAC,QAAoB;IACvD,MAAM,WAAW,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IACjD,OAAO,SAAS,CAAC,WAAW,EAA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Q,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAyC;IAChE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS;IAChC,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,KAAK;IACxB,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM;IAC1B,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,SAAS;IAChC,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,OAAO;CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAA+C;IACtE,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,iBAAiB;IAC7C,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,qBAAqB;IAChD,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,WAAW;CAC3C,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,MAA8B;IACtD,OAAO,MAAM,EAAE,GAAG,EAAE,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;AACtE,CAAC;AAED,yCAAyC;AACzC,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,MAAM,EAAE,CAAC,CAAkB,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1I,0CAA0C;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,MAAM,EAAE,CAAC,CAAkB,EAAE,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import type { MessageInitShape } from \"@bufbuild/protobuf\";\nimport type { Discovery } from \"@surfaces-ui/data\";\nimport { type Certification, CertificationStatus, type DataObject, DescriptionOrigin, ObjectKind, type ObjectRefSchema, TableFormat } from \"@surfaces-ui/proto\";\nimport { useProvided, useTraced } from \"@surfaces-ui/trace/react\";\nimport { type ReactNode, createContext, useContext } from \"react\";\nimport { numberFormat } from \"../locale/locale.js\";\n\nconst DiscoveryContext = createContext<Discovery | undefined>(undefined);\n\nexport interface DiscoveryProviderProps {\n /** Any implementation: a Connect client, the reference `createDiscovery`, or your own. */\n discovery: Discovery;\n children: ReactNode;\n}\n\n/** Makes a Discovery backend available to the discovery and context components below it. */\nexport function DiscoveryProvider({ discovery, children }: DiscoveryProviderProps) {\n useProvided(\"discovery\", discovery);\n return <DiscoveryContext.Provider value={discovery}>{children}</DiscoveryContext.Provider>;\n}\n\nexport function useDiscovery(override?: Discovery): Discovery {\n const fromContext = useContext(DiscoveryContext);\n const discovery = useTraced(\"Discovery\", override ?? fromContext);\n if (!discovery) throw new Error(\"No Discovery backend: wrap the component in <DiscoveryProvider> or pass discovery.\");\n return discovery;\n}\n\n/** The Discovery backend if one is available, for components that work without it. */\nexport function useOptionalDiscovery(override?: Discovery): Discovery | undefined {\n const fromContext = useContext(DiscoveryContext);\n return useTraced(\"Discovery\", override ?? fromContext);\n}\n\n/** What a certification says in words, e.g. for a tooltip. */\nexport function certificationText(certification: Certification): string {\n const verb = certification.status === CertificationStatus.DEPRECATED ? \"Deprecated\" : \"Certified\";\n const when = certification.setAt ? ` on ${certification.setAt.slice(0, 10)}` : \"\";\n return `${verb} by ${certification.setBy || \"an unnamed person\"}${when}${certification.note ? `. ${certification.note}` : \"\"}`;\n}\n\n/**\n * Marks an object a steward has certified or deprecated. Renders nothing when\n * there is no verdict. The mark and the text both carry the meaning, so it\n * does not rely on colour.\n */\nexport function CertificationBadge({ certification }: { certification: Certification | undefined }) {\n if (!certification || certification.status === CertificationStatus.UNSPECIFIED) return null;\n const deprecated = certification.status === CertificationStatus.DEPRECATED;\n return (\n <span className=\"sf-cert\" data-status={deprecated ? \"deprecated\" : \"certified\"} title={certificationText(certification)}>\n <span aria-hidden=\"true\">{deprecated ? \"!\" : \"✓\"}</span>\n {deprecated ? \"Deprecated\" : \"Certified\"}\n </span>\n );\n}\n\nexport type ObjectRefInit = MessageInitShape<typeof ObjectRefSchema>;\n\n/** A table reference in the shape the Discovery interface expects. */\nexport function tableRef(sourceId: string, table: string): ObjectRefInit {\n return { sourceId, kind: ObjectKind.TABLE, table };\n}\n\nexport const FORMAT_LABEL: Partial<Record<TableFormat, string>> = {\n [TableFormat.PARQUET]: \"Parquet\",\n [TableFormat.CSV]: \"CSV\",\n [TableFormat.JSON]: \"JSON\",\n [TableFormat.ICEBERG]: \"Iceberg\",\n [TableFormat.DELTA]: \"Delta\",\n};\n\nexport const ORIGIN_LABEL: Partial<Record<DescriptionOrigin, string>> = {\n [DescriptionOrigin.SOURCE]: \"From the source\",\n [DescriptionOrigin.HUMAN]: \"Written by a person\",\n [DescriptionOrigin.GENERATED]: \"Generated\",\n};\n\nexport function kindLabel(object: DataObject | undefined): string {\n return object?.ref?.kind === ObjectKind.COLUMN ? \"Column\" : \"Table\";\n}\n\n/** Writes 1.2K, in the page's locale. */\nexport const compactCount = { format: (n: number | bigint) => numberFormat({ notation: \"compact\", maximumFractionDigits: 1 }).format(n) };\n/** Writes 1,234, in the page's locale. */\nexport const fullCount = { format: (n: number | bigint) => numberFormat().format(n) };\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DataSource } from "@surfaces-ui/data";
|
|
2
|
+
export type SqlEditorDialect = "standard" | "duckdb" | "postgres" | "teradata";
|
|
3
|
+
export interface SqlEditorError {
|
|
4
|
+
message: string;
|
|
5
|
+
/** 1-based position in the text; 0 or missing marks the whole first line. */
|
|
6
|
+
line?: number;
|
|
7
|
+
column?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface SqlEditorProps {
|
|
10
|
+
value: string;
|
|
11
|
+
onChange(value: string): void;
|
|
12
|
+
/** Called on Cmd/Ctrl+Enter with the selected text, or all of it when nothing is selected. */
|
|
13
|
+
onRun?(sql: string): void;
|
|
14
|
+
dialect?: SqlEditorDialect;
|
|
15
|
+
/** Tables and their columns, for autocomplete. See `useSqlSchema`. */
|
|
16
|
+
schema?: Record<string, string[]>;
|
|
17
|
+
readOnly?: boolean;
|
|
18
|
+
/** Marks a problem in the text, e.g. from a failed query. */
|
|
19
|
+
error?: SqlEditorError;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/** Minimum height in px. Defaults to 120. The editor grows with its content up to `maxHeight`. */
|
|
22
|
+
minHeight?: number;
|
|
23
|
+
maxHeight?: number;
|
|
24
|
+
/** Accessible name. Defaults to "SQL editor". */
|
|
25
|
+
label?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A SQL editor (CodeMirror 6) with syntax highlighting, schema-aware
|
|
30
|
+
* autocomplete, run on Cmd/Ctrl+Enter and inline error marking. Dropping a
|
|
31
|
+
* table or column dragged from SchemaExplorer inserts its name.
|
|
32
|
+
*/
|
|
33
|
+
export declare function SqlEditor(props: SqlEditorProps): import("react").JSX.Element;
|
|
34
|
+
/**
|
|
35
|
+
* Loads table and column names from a source for the editor's autocomplete.
|
|
36
|
+
* Describes at most `maxTables` tables so very large catalogs stay cheap.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useSqlSchema(sourceId: string, options?: {
|
|
39
|
+
dataSource?: DataSource;
|
|
40
|
+
maxTables?: number;
|
|
41
|
+
}): Record<string, string[]>;
|