@finos/legend-query-builder 4.17.89 → 4.17.91
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/lib/components/sql-playground/SQLPlaygroundEditor.d.ts +29 -0
- package/lib/components/sql-playground/SQLPlaygroundEditor.d.ts.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundEditor.js +122 -0
- package/lib/components/sql-playground/SQLPlaygroundEditor.js.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundExplorer.d.ts +35 -0
- package/lib/components/sql-playground/SQLPlaygroundExplorer.d.ts.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundExplorer.js +157 -0
- package/lib/components/sql-playground/SQLPlaygroundExplorer.js.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundGrid.d.ts +24 -0
- package/lib/components/sql-playground/SQLPlaygroundGrid.d.ts.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundGrid.js +143 -0
- package/lib/components/sql-playground/SQLPlaygroundGrid.js.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundPanel.d.ts +20 -0
- package/lib/components/sql-playground/SQLPlaygroundPanel.d.ts.map +1 -0
- package/lib/components/sql-playground/SQLPlaygroundPanel.js +43 -0
- package/lib/components/sql-playground/SQLPlaygroundPanel.js.map +1 -0
- package/lib/data-access-overview.css +1 -1
- package/lib/index.css +17 -1
- package/lib/index.css.map +1 -1
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/stores/sql-playground/AbstractSQLPlaygroundState.d.ts +48 -0
- package/lib/stores/sql-playground/AbstractSQLPlaygroundState.d.ts.map +1 -0
- package/lib/stores/sql-playground/AbstractSQLPlaygroundState.js +125 -0
- package/lib/stores/sql-playground/AbstractSQLPlaygroundState.js.map +1 -0
- package/lib/stores/sql-playground/LegendSQLPlaygroundState.d.ts +35 -0
- package/lib/stores/sql-playground/LegendSQLPlaygroundState.d.ts.map +1 -0
- package/lib/stores/sql-playground/LegendSQLPlaygroundState.js +78 -0
- package/lib/stores/sql-playground/LegendSQLPlaygroundState.js.map +1 -0
- package/lib/stores/sql-playground/SqlPlaygroundAccessorExplorerState.d.ts +98 -0
- package/lib/stores/sql-playground/SqlPlaygroundAccessorExplorerState.d.ts.map +1 -0
- package/lib/stores/sql-playground/SqlPlaygroundAccessorExplorerState.js +370 -0
- package/lib/stores/sql-playground/SqlPlaygroundAccessorExplorerState.js.map +1 -0
- package/package.json +10 -10
- package/src/components/sql-playground/SQLPlaygroundEditor.tsx +201 -0
- package/src/components/sql-playground/SQLPlaygroundExplorer.tsx +329 -0
- package/src/components/sql-playground/SQLPlaygroundGrid.tsx +245 -0
- package/src/components/sql-playground/SQLPlaygroundPanel.tsx +170 -0
- package/src/index.ts +10 -0
- package/src/stores/sql-playground/AbstractSQLPlaygroundState.ts +156 -0
- package/src/stores/sql-playground/LegendSQLPlaygroundState.ts +120 -0
- package/src/stores/sql-playground/SqlPlaygroundAccessorExplorerState.ts +596 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { observer } from 'mobx-react-lite';
|
|
18
|
+
import { PanelDropZone } from '@finos/legend-art';
|
|
19
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { useCommands } from '@finos/legend-application';
|
|
21
|
+
import {
|
|
22
|
+
CODE_EDITOR_LANGUAGE,
|
|
23
|
+
CODE_EDITOR_THEME,
|
|
24
|
+
getBaseCodeEditorOptions,
|
|
25
|
+
} from '@finos/legend-code-editor';
|
|
26
|
+
import {
|
|
27
|
+
editor as monacoEditorAPI,
|
|
28
|
+
languages as monacoLanguagesAPI,
|
|
29
|
+
type IDisposable,
|
|
30
|
+
} from 'monaco-editor';
|
|
31
|
+
import { useDrop } from 'react-dnd';
|
|
32
|
+
import { isString } from '@finos/legend-shared';
|
|
33
|
+
import type { AbstractSQLPlaygroundState } from '../../stores/sql-playground/AbstractSQLPlaygroundState.js';
|
|
34
|
+
import type { SQLPlaygroundAccessorExplorerState } from '../../stores/sql-playground/SqlPlaygroundAccessorExplorerState.js';
|
|
35
|
+
|
|
36
|
+
type SqlEditorNodeDragType = { text: string };
|
|
37
|
+
const SQL_DROP_NODE_DND_TYPE = 'SQL_DROP_NODE_DND_TYPE';
|
|
38
|
+
|
|
39
|
+
export interface SQLPlaygroundPanelProps {
|
|
40
|
+
playgroundState: AbstractSQLPlaygroundState;
|
|
41
|
+
advancedMode: boolean;
|
|
42
|
+
disableDragDrop?: boolean;
|
|
43
|
+
enableDarkMode?: boolean;
|
|
44
|
+
accessorExplorerState?: SQLPlaygroundAccessorExplorerState;
|
|
45
|
+
showAccessorExplorer?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const toCompletionItems = (
|
|
49
|
+
labels: string[],
|
|
50
|
+
): monacoLanguagesAPI.CompletionItem[] =>
|
|
51
|
+
labels.map(
|
|
52
|
+
(label) =>
|
|
53
|
+
({
|
|
54
|
+
label,
|
|
55
|
+
kind: monacoLanguagesAPI.CompletionItemKind.Keyword,
|
|
56
|
+
insertTextRules:
|
|
57
|
+
monacoLanguagesAPI.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
58
|
+
insertText: `${label} `,
|
|
59
|
+
}) as monacoLanguagesAPI.CompletionItem,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
export const PlaygroundSQLCodeEditor = observer(
|
|
63
|
+
(props: SQLPlaygroundPanelProps) => {
|
|
64
|
+
const {
|
|
65
|
+
playgroundState,
|
|
66
|
+
disableDragDrop = false,
|
|
67
|
+
enableDarkMode = false,
|
|
68
|
+
} = props;
|
|
69
|
+
const codeEditorRef = useRef<HTMLDivElement>(null);
|
|
70
|
+
const sqlIdentifierSuggestionProviderDisposer = useRef<
|
|
71
|
+
IDisposable | undefined
|
|
72
|
+
>(undefined);
|
|
73
|
+
const [editor, setEditor] = useState<
|
|
74
|
+
monacoEditorAPI.IStandaloneCodeEditor | undefined
|
|
75
|
+
>();
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!editor && codeEditorRef.current) {
|
|
78
|
+
const element = codeEditorRef.current;
|
|
79
|
+
playgroundState.setTheme(enableDarkMode ? 'dark' : 'light');
|
|
80
|
+
const newEditor = monacoEditorAPI.create(element, {
|
|
81
|
+
...getBaseCodeEditorOptions(),
|
|
82
|
+
theme:
|
|
83
|
+
playgroundState.theme === 'light'
|
|
84
|
+
? CODE_EDITOR_THEME.GITHUB_LIGHT
|
|
85
|
+
: CODE_EDITOR_THEME.DEFAULT_DARK,
|
|
86
|
+
language: CODE_EDITOR_LANGUAGE.SQL,
|
|
87
|
+
padding: {
|
|
88
|
+
top: 10,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
newEditor.onDidChangeModelContent(() => {
|
|
93
|
+
const currentVal = newEditor.getValue();
|
|
94
|
+
playgroundState.setSQLText(currentVal);
|
|
95
|
+
});
|
|
96
|
+
newEditor.setModel(playgroundState.sqlEditorTextModel);
|
|
97
|
+
if (playgroundState.sqlEditorViewState) {
|
|
98
|
+
newEditor.restoreViewState(playgroundState.sqlEditorViewState);
|
|
99
|
+
}
|
|
100
|
+
newEditor.focus();
|
|
101
|
+
playgroundState.setSQLEditor(newEditor);
|
|
102
|
+
setEditor(newEditor);
|
|
103
|
+
}
|
|
104
|
+
}, [playgroundState, editor, enableDarkMode]);
|
|
105
|
+
useCommands(playgroundState);
|
|
106
|
+
if (editor) {
|
|
107
|
+
sqlIdentifierSuggestionProviderDisposer.current?.dispose();
|
|
108
|
+
sqlIdentifierSuggestionProviderDisposer.current =
|
|
109
|
+
monacoLanguagesAPI.registerCompletionItemProvider(
|
|
110
|
+
CODE_EDITOR_LANGUAGE.SQL,
|
|
111
|
+
{
|
|
112
|
+
triggerCharacters: [],
|
|
113
|
+
provideCompletionItems: async (model, position, context) => {
|
|
114
|
+
let suggestions: monacoLanguagesAPI.CompletionItem[] = [];
|
|
115
|
+
if (
|
|
116
|
+
context.triggerKind ===
|
|
117
|
+
monacoLanguagesAPI.CompletionTriggerKind.Invoke
|
|
118
|
+
) {
|
|
119
|
+
const labels = playgroundState.getCodeCompletionSuggestions();
|
|
120
|
+
suggestions = suggestions.concat(toCompletionItems(labels));
|
|
121
|
+
}
|
|
122
|
+
return { suggestions };
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
useEffect(
|
|
128
|
+
() => (): void => {
|
|
129
|
+
if (editor) {
|
|
130
|
+
playgroundState.setSQLEditorViewState(
|
|
131
|
+
editor.saveViewState() ?? undefined,
|
|
132
|
+
);
|
|
133
|
+
editor.dispose();
|
|
134
|
+
|
|
135
|
+
sqlIdentifierSuggestionProviderDisposer.current?.dispose();
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
[playgroundState, editor],
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const handleSqlEditorNodeDrop = useCallback(
|
|
142
|
+
(item: SqlEditorNodeDragType): void => {
|
|
143
|
+
if (isString(item.text)) {
|
|
144
|
+
if (playgroundState.sqlEditor) {
|
|
145
|
+
const currentValue = playgroundState.sqlEditorTextModel.getValue();
|
|
146
|
+
const lines = currentValue.split('\n');
|
|
147
|
+
const position = playgroundState.sqlEditor.getPosition() ?? {
|
|
148
|
+
lineNumber: lines.length,
|
|
149
|
+
column: lines.at(-1)?.length ?? 0,
|
|
150
|
+
};
|
|
151
|
+
playgroundState.sqlEditor.executeEdits('', [
|
|
152
|
+
{
|
|
153
|
+
range: {
|
|
154
|
+
startLineNumber: position.lineNumber,
|
|
155
|
+
startColumn: position.column,
|
|
156
|
+
endLineNumber: position.lineNumber,
|
|
157
|
+
endColumn: position.column,
|
|
158
|
+
},
|
|
159
|
+
text: item.text,
|
|
160
|
+
forceMoveMarkers: true,
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
playgroundState.setSQLText(
|
|
164
|
+
playgroundState.sqlEditorTextModel.getValue(),
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
[playgroundState],
|
|
170
|
+
);
|
|
171
|
+
const [{ isDatabaseNodeDragOver }, dropConnector] = useDrop<
|
|
172
|
+
SqlEditorNodeDragType,
|
|
173
|
+
void,
|
|
174
|
+
{ isDatabaseNodeDragOver: boolean }
|
|
175
|
+
>(
|
|
176
|
+
() => ({
|
|
177
|
+
accept: [SQL_DROP_NODE_DND_TYPE],
|
|
178
|
+
drop: (item): void => handleSqlEditorNodeDrop(item),
|
|
179
|
+
collect: (monitor) => ({
|
|
180
|
+
isDatabaseNodeDragOver: monitor.isOver({ shallow: true }),
|
|
181
|
+
}),
|
|
182
|
+
}),
|
|
183
|
+
[handleSqlEditorNodeDrop],
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div className="sql-playground__code-editor">
|
|
188
|
+
<PanelDropZone
|
|
189
|
+
className="sql-playground__code-editor__content"
|
|
190
|
+
isDragOver={isDatabaseNodeDragOver}
|
|
191
|
+
dropTargetConnector={dropConnector}
|
|
192
|
+
disabled={disableDragDrop}
|
|
193
|
+
>
|
|
194
|
+
<div className="code-editor__container">
|
|
195
|
+
<div className="code-editor__body" ref={codeEditorRef} />
|
|
196
|
+
</div>
|
|
197
|
+
</PanelDropZone>
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
);
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { forwardRef, useRef } from 'react';
|
|
18
|
+
import {
|
|
19
|
+
TreeView,
|
|
20
|
+
StringTypeIcon,
|
|
21
|
+
HashtagIcon,
|
|
22
|
+
ClockIcon,
|
|
23
|
+
QuestionCircleIcon,
|
|
24
|
+
ChevronDownIcon,
|
|
25
|
+
ChevronRightIcon,
|
|
26
|
+
compareLabelFn,
|
|
27
|
+
AccessPointIcon,
|
|
28
|
+
PURE_FlatDataStoreIcon,
|
|
29
|
+
PURE_DatabaseTableIcon,
|
|
30
|
+
PURE_IngestIcon,
|
|
31
|
+
PanelLoadingIndicator,
|
|
32
|
+
type TreeData,
|
|
33
|
+
} from '@finos/legend-art';
|
|
34
|
+
import { flowResult } from 'mobx';
|
|
35
|
+
import {
|
|
36
|
+
type AccessorExplorerTreeNodeData,
|
|
37
|
+
AccessorExplorerTreeColumnNodeData,
|
|
38
|
+
AccessorExplorerTreeDataProductNodeData,
|
|
39
|
+
AccessorExplorerTreeIngestNodeData,
|
|
40
|
+
AccessorExplorerTreeAccessPointNodeData,
|
|
41
|
+
AccessorExplorerTreeAccessPointGroupNodeData,
|
|
42
|
+
AccessorExplorerTreeDatasetNodeData,
|
|
43
|
+
AccessorExplorerTreeHeaderNodeData,
|
|
44
|
+
type SQLPlaygroundAccessorExplorerState,
|
|
45
|
+
type AccessorExplorerTreeNodeContainerProps,
|
|
46
|
+
} from '../../stores/sql-playground/SqlPlaygroundAccessorExplorerState.js';
|
|
47
|
+
import {
|
|
48
|
+
PRECISE_PRIMITIVE_TYPE,
|
|
49
|
+
type V1_RelationTypeColumn,
|
|
50
|
+
V1_PackageableType,
|
|
51
|
+
PRIMITIVE_TYPE,
|
|
52
|
+
V1_AccessPoint,
|
|
53
|
+
extractElementNameFromPath,
|
|
54
|
+
} from '@finos/legend-graph';
|
|
55
|
+
import { observer } from 'mobx-react-lite';
|
|
56
|
+
import { useApplicationStore } from '@finos/legend-application';
|
|
57
|
+
import { useDrag } from 'react-dnd';
|
|
58
|
+
|
|
59
|
+
const SQL_DROP_NODE_DND_TYPE = 'SQL_DROP_NODE_DND_TYPE';
|
|
60
|
+
|
|
61
|
+
type SqlEditorNodeDragType = { text: string };
|
|
62
|
+
|
|
63
|
+
const STRING_TYPE_NAMES = new Set([
|
|
64
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.VARCHAR),
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
const NUMERIC_TYPE_NAMES = new Set([
|
|
68
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.BIG_INT),
|
|
69
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.DECIMAL),
|
|
70
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.DOUBLE),
|
|
71
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.FLOAT),
|
|
72
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.INT),
|
|
73
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.NUMERIC),
|
|
74
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.SMALL_INT),
|
|
75
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.TINY_INT),
|
|
76
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.U_BIG_INT),
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
const DATE_TYPE_NAMES = new Set([
|
|
80
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.STRICTDATE),
|
|
81
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.STRICTTIME),
|
|
82
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.DATETIME),
|
|
83
|
+
extractElementNameFromPath(PRECISE_PRIMITIVE_TYPE.TIMESTAMP),
|
|
84
|
+
extractElementNameFromPath(PRIMITIVE_TYPE.STRICTDATE),
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
export const renderColumnTypeIcon = (
|
|
88
|
+
type: V1_RelationTypeColumn,
|
|
89
|
+
): React.ReactNode => {
|
|
90
|
+
const rawType = type.genericType.rawType;
|
|
91
|
+
if (rawType instanceof V1_PackageableType) {
|
|
92
|
+
const typeName = extractElementNameFromPath(rawType.fullPath);
|
|
93
|
+
|
|
94
|
+
if (STRING_TYPE_NAMES.has(typeName)) {
|
|
95
|
+
return (
|
|
96
|
+
<StringTypeIcon className="relation-source-tree__icon relation-source-tree__icon__string" />
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (NUMERIC_TYPE_NAMES.has(typeName)) {
|
|
100
|
+
return (
|
|
101
|
+
<HashtagIcon className="relation-source-tree__icon relation-source-tree__icon__number" />
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (DATE_TYPE_NAMES.has(typeName)) {
|
|
105
|
+
return (
|
|
106
|
+
<ClockIcon className="relation-source-tree__icon relation-source-tree__icon__time" />
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return (
|
|
111
|
+
<QuestionCircleIcon className="relation-source-tree__icon relation-source-tree__icon__unknown" />
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const getAccessorNodeIcon = (
|
|
116
|
+
node: AccessorExplorerTreeNodeData,
|
|
117
|
+
): React.ReactNode => {
|
|
118
|
+
if (node instanceof AccessorExplorerTreeColumnNodeData) {
|
|
119
|
+
return renderColumnTypeIcon(node.column);
|
|
120
|
+
}
|
|
121
|
+
if (node instanceof AccessorExplorerTreeDataProductNodeData) {
|
|
122
|
+
return (
|
|
123
|
+
<div className="Accessor-schema-explorer__icon--schema">
|
|
124
|
+
<AccessPointIcon />
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (node instanceof AccessorExplorerTreeIngestNodeData) {
|
|
129
|
+
return (
|
|
130
|
+
<div className="Accessor-schema-explorer__icon--schema">
|
|
131
|
+
<PURE_IngestIcon />
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (node instanceof AccessorExplorerTreeAccessPointGroupNodeData) {
|
|
136
|
+
return (
|
|
137
|
+
<div className="Accessor-schema-explorer__icon--table">
|
|
138
|
+
<PURE_FlatDataStoreIcon />
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
if (
|
|
143
|
+
node instanceof AccessorExplorerTreeAccessPointNodeData ||
|
|
144
|
+
node instanceof AccessorExplorerTreeDatasetNodeData
|
|
145
|
+
) {
|
|
146
|
+
return (
|
|
147
|
+
<div className="Accessor-schema-explorer__icon--table">
|
|
148
|
+
<PURE_DatabaseTableIcon />
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const AccessorExplorerTreeNodeContainer = observer(
|
|
156
|
+
forwardRef<HTMLDivElement, AccessorExplorerTreeNodeContainerProps>(
|
|
157
|
+
function AccessorExplorerTreeNodeContainer(props, ref) {
|
|
158
|
+
const { node, level, onNodeSelect, innerProps } = props;
|
|
159
|
+
const { toggleCheckedNode } = innerProps;
|
|
160
|
+
const isExpandable =
|
|
161
|
+
Boolean(!node.childrenIds || node.childrenIds.length) &&
|
|
162
|
+
!(node instanceof AccessorExplorerTreeColumnNodeData);
|
|
163
|
+
const nodeExpandIcon = isExpandable ? (
|
|
164
|
+
node.isOpen ? (
|
|
165
|
+
<ChevronDownIcon />
|
|
166
|
+
) : (
|
|
167
|
+
<ChevronRightIcon />
|
|
168
|
+
)
|
|
169
|
+
) : (
|
|
170
|
+
<div />
|
|
171
|
+
);
|
|
172
|
+
const nodeTypeIcon = getAccessorNodeIcon(node);
|
|
173
|
+
const toggleExpandNode = (): void => {
|
|
174
|
+
onNodeSelect?.(node);
|
|
175
|
+
if (!isExpandable) {
|
|
176
|
+
toggleCheckedNode(node);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<div
|
|
182
|
+
className={`tree-view__node__container Accessor-schema-explorer__node__container Accessor-schema-explorer__node__container--level-${Math.min(level, 6)}`}
|
|
183
|
+
ref={ref}
|
|
184
|
+
onClick={toggleExpandNode}
|
|
185
|
+
>
|
|
186
|
+
<div className="tree-view__node__icon Accessor-schema-explorer__node__icon__group">
|
|
187
|
+
<div className="Accessor-schema-explorer__expand-icon">
|
|
188
|
+
{nodeExpandIcon}
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
{nodeTypeIcon && (
|
|
192
|
+
<div className="Accessor-schema-explorer__type-icon">
|
|
193
|
+
{nodeTypeIcon}
|
|
194
|
+
</div>
|
|
195
|
+
)}
|
|
196
|
+
<div className="tree-view__node__label Accessor-schema-explorer__node__label">
|
|
197
|
+
{node.label}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
export const SQLAccessorExplorer = observer(
|
|
206
|
+
(props: {
|
|
207
|
+
accessorExplorerState: SQLPlaygroundAccessorExplorerState;
|
|
208
|
+
treeData: TreeData<AccessorExplorerTreeNodeData>;
|
|
209
|
+
isReadOnly?: boolean;
|
|
210
|
+
treeNodeContainerComponent?:
|
|
211
|
+
| React.FC<AccessorExplorerTreeNodeContainerProps>
|
|
212
|
+
| undefined;
|
|
213
|
+
}) => {
|
|
214
|
+
const { treeData, accessorExplorerState, treeNodeContainerComponent } =
|
|
215
|
+
props;
|
|
216
|
+
const applicationStore = useApplicationStore();
|
|
217
|
+
const onNodeSelect = (node: AccessorExplorerTreeNodeData): void => {
|
|
218
|
+
flowResult(accessorExplorerState.onNodeSelect(node, treeData)).catch(
|
|
219
|
+
applicationStore.alertUnhandledError,
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
const getChildNodes = (
|
|
223
|
+
node: AccessorExplorerTreeNodeData,
|
|
224
|
+
): AccessorExplorerTreeNodeData[] =>
|
|
225
|
+
accessorExplorerState
|
|
226
|
+
.getChildNodes(node, treeData)
|
|
227
|
+
?.sort(compareLabelFn) ?? [];
|
|
228
|
+
const isPartiallySelected = (
|
|
229
|
+
node: AccessorExplorerTreeNodeData,
|
|
230
|
+
): boolean => {
|
|
231
|
+
if (
|
|
232
|
+
node instanceof AccessorExplorerTreeDataProductNodeData &&
|
|
233
|
+
!node.isChecked
|
|
234
|
+
) {
|
|
235
|
+
return (
|
|
236
|
+
accessorExplorerState
|
|
237
|
+
.getChildNodes(node, treeData)
|
|
238
|
+
?.some((childNode) => childNode.isChecked) ?? false
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return false;
|
|
242
|
+
};
|
|
243
|
+
const toggleCheckedNode = (node: AccessorExplorerTreeNodeData): void =>
|
|
244
|
+
accessorExplorerState.toggleCheckedNode(node, treeData);
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<TreeView
|
|
248
|
+
className="Accessor-schema-explorer"
|
|
249
|
+
components={{
|
|
250
|
+
TreeNodeContainer:
|
|
251
|
+
treeNodeContainerComponent ?? AccessorExplorerTreeNodeContainer,
|
|
252
|
+
}}
|
|
253
|
+
innerProps={{
|
|
254
|
+
toggleCheckedNode,
|
|
255
|
+
isPartiallySelected,
|
|
256
|
+
}}
|
|
257
|
+
treeData={treeData}
|
|
258
|
+
onNodeSelect={onNodeSelect}
|
|
259
|
+
getChildNodes={getChildNodes}
|
|
260
|
+
/>
|
|
261
|
+
);
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const SQLPlaygroundAccessorExplorerTreeNodeContainer = observer(
|
|
266
|
+
(props: AccessorExplorerTreeNodeContainerProps) => {
|
|
267
|
+
const { node } = props;
|
|
268
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
269
|
+
|
|
270
|
+
const isDraggable =
|
|
271
|
+
!(node instanceof AccessorExplorerTreeHeaderNodeData) &&
|
|
272
|
+
!(node instanceof AccessorExplorerTreeAccessPointGroupNodeData);
|
|
273
|
+
|
|
274
|
+
const dragText =
|
|
275
|
+
node instanceof AccessorExplorerTreeColumnNodeData
|
|
276
|
+
? node.owner instanceof V1_AccessPoint
|
|
277
|
+
? `${node.parentId}.${node.label}`
|
|
278
|
+
: `${node.owner.name}.${node.label}`
|
|
279
|
+
: node instanceof AccessorExplorerTreeAccessPointNodeData
|
|
280
|
+
? `${node.dataProductPath}.${node.accessPoint.id}`
|
|
281
|
+
: node instanceof AccessorExplorerTreeDatasetNodeData
|
|
282
|
+
? `${node.parentId}.${node.dataset.name}`
|
|
283
|
+
: node instanceof AccessorExplorerTreeDataProductNodeData
|
|
284
|
+
? node.id
|
|
285
|
+
: node instanceof AccessorExplorerTreeIngestNodeData
|
|
286
|
+
? node.id
|
|
287
|
+
: node.id;
|
|
288
|
+
|
|
289
|
+
const [, dragConnector] = useDrag<SqlEditorNodeDragType>(
|
|
290
|
+
() => ({
|
|
291
|
+
type: SQL_DROP_NODE_DND_TYPE,
|
|
292
|
+
item: {
|
|
293
|
+
text: dragText,
|
|
294
|
+
},
|
|
295
|
+
canDrag: isDraggable,
|
|
296
|
+
}),
|
|
297
|
+
[node, isDraggable],
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
if (isDraggable) {
|
|
301
|
+
dragConnector(ref);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return <AccessorExplorerTreeNodeContainer {...props} ref={ref} />;
|
|
305
|
+
},
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
export const SQLPlaygroundExplorer = observer(
|
|
309
|
+
(props: { accessorExplorerState: SQLPlaygroundAccessorExplorerState }) => {
|
|
310
|
+
const { accessorExplorerState } = props;
|
|
311
|
+
|
|
312
|
+
return (
|
|
313
|
+
<div className="sql-playground__explorer">
|
|
314
|
+
<PanelLoadingIndicator
|
|
315
|
+
isLoading={Boolean(accessorExplorerState.isGeneratingAccessor)}
|
|
316
|
+
/>
|
|
317
|
+
{accessorExplorerState.treeData && (
|
|
318
|
+
<SQLAccessorExplorer
|
|
319
|
+
treeData={accessorExplorerState.treeData}
|
|
320
|
+
accessorExplorerState={accessorExplorerState}
|
|
321
|
+
treeNodeContainerComponent={
|
|
322
|
+
SQLPlaygroundAccessorExplorerTreeNodeContainer
|
|
323
|
+
}
|
|
324
|
+
/>
|
|
325
|
+
)}
|
|
326
|
+
</div>
|
|
327
|
+
);
|
|
328
|
+
},
|
|
329
|
+
);
|