@finos/legend-lego 2.0.151 → 2.0.153
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/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/sql-playground/SQLPlaygroundEditor.d.ts +26 -0
- package/lib/sql-playground/SQLPlaygroundEditor.d.ts.map +1 -0
- package/lib/sql-playground/SQLPlaygroundEditor.js +122 -0
- package/lib/sql-playground/SQLPlaygroundEditor.js.map +1 -0
- package/lib/sql-playground/SQLPlaygroundGrid.d.ts +24 -0
- package/lib/sql-playground/SQLPlaygroundGrid.d.ts.map +1 -0
- package/lib/sql-playground/SQLPlaygroundGrid.js +143 -0
- package/lib/sql-playground/SQLPlaygroundGrid.js.map +1 -0
- package/lib/sql-playground/SQLPlaygroundPanel.d.ts +20 -0
- package/lib/sql-playground/SQLPlaygroundPanel.d.ts.map +1 -0
- package/lib/sql-playground/SQLPlaygroundPanel.js +39 -0
- package/lib/sql-playground/SQLPlaygroundPanel.js.map +1 -0
- package/lib/sql-playground/index.d.ts +20 -0
- package/lib/sql-playground/index.d.ts.map +1 -0
- package/lib/sql-playground/index.js +20 -0
- package/lib/sql-playground/index.js.map +1 -0
- package/lib/sql-playground/store/AbstractSQLPlaygroundState.d.ts +47 -0
- package/lib/sql-playground/store/AbstractSQLPlaygroundState.d.ts.map +1 -0
- package/lib/sql-playground/store/AbstractSQLPlaygroundState.js +122 -0
- package/lib/sql-playground/store/AbstractSQLPlaygroundState.js.map +1 -0
- package/package.json +6 -5
- package/src/sql-playground/SQLPlaygroundEditor.tsx +197 -0
- package/src/sql-playground/SQLPlaygroundGrid.tsx +245 -0
- package/src/sql-playground/SQLPlaygroundPanel.tsx +150 -0
- package/src/sql-playground/index.ts +20 -0
- package/src/sql-playground/store/AbstractSQLPlaygroundState.ts +152 -0
- package/tsconfig.json +6 -1
|
@@ -0,0 +1,150 @@
|
|
|
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 {
|
|
19
|
+
CheckSquareIcon,
|
|
20
|
+
clsx,
|
|
21
|
+
PlayIcon,
|
|
22
|
+
ResizablePanel,
|
|
23
|
+
ResizablePanelGroup,
|
|
24
|
+
ResizablePanelSplitter,
|
|
25
|
+
ResizablePanelSplitterLine,
|
|
26
|
+
SquareIcon,
|
|
27
|
+
} from '@finos/legend-art';
|
|
28
|
+
import { prettyDuration } from '@finos/legend-shared';
|
|
29
|
+
import {
|
|
30
|
+
PlaygroundSQLCodeEditor,
|
|
31
|
+
type SQLPlaygroundPanelProps,
|
|
32
|
+
} from './SQLPlaygroundEditor.js';
|
|
33
|
+
import { PlayGroundSQLExecutionResultGrid } from './SQLPlaygroundGrid.js';
|
|
34
|
+
|
|
35
|
+
export const SQLPlaygroundEditorResultPanel = observer(
|
|
36
|
+
(props: SQLPlaygroundPanelProps) => {
|
|
37
|
+
const {
|
|
38
|
+
playgroundState,
|
|
39
|
+
advancedMode,
|
|
40
|
+
disableDragDrop = false,
|
|
41
|
+
enableDarkMode = false,
|
|
42
|
+
} = props;
|
|
43
|
+
|
|
44
|
+
const executeRawSQL = (): void => {
|
|
45
|
+
playgroundState.executeRawSQL();
|
|
46
|
+
};
|
|
47
|
+
const resultDescription = playgroundState.sqlExecutionResult
|
|
48
|
+
? `query ran in ${prettyDuration(
|
|
49
|
+
playgroundState.sqlExecutionResult.sqlDuration,
|
|
50
|
+
{
|
|
51
|
+
ms: true,
|
|
52
|
+
},
|
|
53
|
+
)}`
|
|
54
|
+
: undefined;
|
|
55
|
+
const toggleLocalMode = (): void => {
|
|
56
|
+
playgroundState.toggleIsLocalModeEnabled();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<ResizablePanelGroup orientation="horizontal">
|
|
61
|
+
<ResizablePanel>
|
|
62
|
+
<div className="panel sql-playground__sql-editor">
|
|
63
|
+
<ResizablePanelGroup orientation="horizontal">
|
|
64
|
+
<ResizablePanel>
|
|
65
|
+
<PlaygroundSQLCodeEditor
|
|
66
|
+
playgroundState={playgroundState}
|
|
67
|
+
advancedMode={advancedMode}
|
|
68
|
+
disableDragDrop={disableDragDrop}
|
|
69
|
+
enableDarkMode={enableDarkMode}
|
|
70
|
+
/>
|
|
71
|
+
</ResizablePanel>
|
|
72
|
+
<ResizablePanelSplitter>
|
|
73
|
+
<ResizablePanelSplitterLine color="var(--color-dark-grey-250)" />
|
|
74
|
+
</ResizablePanelSplitter>
|
|
75
|
+
<ResizablePanel size={300}>
|
|
76
|
+
<div className="panel__header">
|
|
77
|
+
<div className="panel__header__title">
|
|
78
|
+
<div className="panel__header__title__label">result</div>
|
|
79
|
+
|
|
80
|
+
{playgroundState.executeRawSQLState.isInProgress && (
|
|
81
|
+
<div className="panel__header__title__label__status">
|
|
82
|
+
Running SQL...
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
|
|
86
|
+
<div className="query-builder__result__analytics">
|
|
87
|
+
{resultDescription ?? ''}
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div className={!enableDarkMode ? 'light-mode' : ''}>
|
|
91
|
+
<div className="panel__header__actions query-builder__result__header__actions">
|
|
92
|
+
{advancedMode && (
|
|
93
|
+
<div className="query-builder__result__advanced__mode">
|
|
94
|
+
<div className="query-builder__result__advanced__mode__label">
|
|
95
|
+
Local Mode
|
|
96
|
+
</div>
|
|
97
|
+
<button
|
|
98
|
+
className={clsx(
|
|
99
|
+
'query-builder__result__advanced__mode__toggler__btn',
|
|
100
|
+
{
|
|
101
|
+
'query-builder__result__advanced__mode__toggler__btn--toggled':
|
|
102
|
+
playgroundState.isLocalModeEnabled,
|
|
103
|
+
},
|
|
104
|
+
)}
|
|
105
|
+
onClick={toggleLocalMode}
|
|
106
|
+
tabIndex={-1}
|
|
107
|
+
>
|
|
108
|
+
{playgroundState.isLocalModeEnabled ? (
|
|
109
|
+
<CheckSquareIcon />
|
|
110
|
+
) : (
|
|
111
|
+
<SquareIcon />
|
|
112
|
+
)}
|
|
113
|
+
</button>
|
|
114
|
+
</div>
|
|
115
|
+
)}
|
|
116
|
+
<div className="query-builder__result__execute-btn btn__dropdown-combo btn__dropdown-combo--primary">
|
|
117
|
+
<button
|
|
118
|
+
className="btn__dropdown-combo__label"
|
|
119
|
+
onClick={executeRawSQL}
|
|
120
|
+
disabled={
|
|
121
|
+
playgroundState.executeRawSQLState.isInProgress
|
|
122
|
+
}
|
|
123
|
+
tabIndex={-1}
|
|
124
|
+
>
|
|
125
|
+
<PlayIcon className="btn__dropdown-combo__label__icon" />
|
|
126
|
+
<div className="btn__dropdown-combo__label__title">
|
|
127
|
+
Run Query
|
|
128
|
+
</div>
|
|
129
|
+
</button>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
{playgroundState.sqlExecutionResult !== undefined && (
|
|
135
|
+
<PlayGroundSQLExecutionResultGrid
|
|
136
|
+
result={playgroundState.sqlExecutionResult.value}
|
|
137
|
+
useAdvancedGrid={advancedMode}
|
|
138
|
+
useLocalMode={playgroundState.isLocalModeEnabled}
|
|
139
|
+
enableDarkMode={enableDarkMode}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
{playgroundState.sqlExecutionResult === undefined && <div />}
|
|
143
|
+
</ResizablePanel>
|
|
144
|
+
</ResizablePanelGroup>
|
|
145
|
+
</div>
|
|
146
|
+
</ResizablePanel>
|
|
147
|
+
</ResizablePanelGroup>
|
|
148
|
+
);
|
|
149
|
+
},
|
|
150
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export * from './store/AbstractSQLPlaygroundState.js';
|
|
18
|
+
export * from './SQLPlaygroundPanel.js';
|
|
19
|
+
export * from './SQLPlaygroundGrid.js';
|
|
20
|
+
export * from './SQLPlaygroundEditor.js';
|
|
@@ -0,0 +1,152 @@
|
|
|
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 { ActionState, type GeneratorFn } from '@finos/legend-shared';
|
|
18
|
+
import * as monaco from 'monaco-editor';
|
|
19
|
+
import type { CommandRegistrar } from '@finos/legend-application';
|
|
20
|
+
import {
|
|
21
|
+
CODE_EDITOR_LANGUAGE,
|
|
22
|
+
moveCursorToPosition,
|
|
23
|
+
} from '@finos/legend-code-editor';
|
|
24
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
25
|
+
|
|
26
|
+
export type SQLPlaygroundTheme = 'light' | 'dark';
|
|
27
|
+
export interface SQL_ExecutionResult {
|
|
28
|
+
value: string;
|
|
29
|
+
sqlDuration: number;
|
|
30
|
+
}
|
|
31
|
+
const SQL_KEYWORDS = [
|
|
32
|
+
'AND',
|
|
33
|
+
'AS',
|
|
34
|
+
'ASC',
|
|
35
|
+
'BETWEEN',
|
|
36
|
+
'DESC',
|
|
37
|
+
'DISTINCT',
|
|
38
|
+
'EXEC',
|
|
39
|
+
'EXISTS',
|
|
40
|
+
'FROM',
|
|
41
|
+
'FULL OUTER JOIN',
|
|
42
|
+
'GROUP BY',
|
|
43
|
+
'HAVING',
|
|
44
|
+
'IN',
|
|
45
|
+
'INNER JOIN',
|
|
46
|
+
'IS NULL',
|
|
47
|
+
'IS NOT NULL',
|
|
48
|
+
'JOIN',
|
|
49
|
+
'LEFT JOIN',
|
|
50
|
+
'LIKE',
|
|
51
|
+
'LIMIT',
|
|
52
|
+
'NOT',
|
|
53
|
+
'NOT NULL',
|
|
54
|
+
'OR',
|
|
55
|
+
'ORDER BY',
|
|
56
|
+
'OUTER JOIN',
|
|
57
|
+
'RIGHT JOIN',
|
|
58
|
+
'SELECT',
|
|
59
|
+
'SELECT DISTINCT',
|
|
60
|
+
'SELECT INTO',
|
|
61
|
+
'SELECT TOP',
|
|
62
|
+
'TOP',
|
|
63
|
+
'UNION',
|
|
64
|
+
'UNION ALL',
|
|
65
|
+
'UNIQUE',
|
|
66
|
+
'WHERE',
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
export abstract class AbstractSQLPlaygroundState implements CommandRegistrar {
|
|
70
|
+
theme: SQLPlaygroundTheme;
|
|
71
|
+
sqlText = '';
|
|
72
|
+
executeRawSQLState: ActionState;
|
|
73
|
+
sqlExecutionResult?: SQL_ExecutionResult | undefined;
|
|
74
|
+
sqlEditorViewState: monaco.editor.ICodeEditorViewState | undefined;
|
|
75
|
+
sqlEditorTextModel: monaco.editor.ITextModel;
|
|
76
|
+
sqlEditor?: monaco.editor.IStandaloneCodeEditor | undefined;
|
|
77
|
+
isLocalModeEnabled: boolean;
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
this.sqlEditorTextModel = monaco.editor.createModel(
|
|
81
|
+
this.sqlText,
|
|
82
|
+
CODE_EDITOR_LANGUAGE.SQL,
|
|
83
|
+
);
|
|
84
|
+
this.isLocalModeEnabled = false;
|
|
85
|
+
this.executeRawSQLState = ActionState.create();
|
|
86
|
+
this.theme = 'light';
|
|
87
|
+
makeObservable(this, {
|
|
88
|
+
sqlExecutionResult: observable,
|
|
89
|
+
isLocalModeEnabled: observable,
|
|
90
|
+
sqlText: observable,
|
|
91
|
+
executeRawSQLState: observable,
|
|
92
|
+
stopExecuteSQL: action,
|
|
93
|
+
setSQLEditor: action,
|
|
94
|
+
setSQLEditorViewState: action,
|
|
95
|
+
setSQLText: action,
|
|
96
|
+
setTheme: action,
|
|
97
|
+
toggleIsLocalModeEnabled: action,
|
|
98
|
+
sqlEditorViewState: observable.ref,
|
|
99
|
+
sqlEditor: observable.ref,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
abstract executeRawSQL(): GeneratorFn<void>;
|
|
104
|
+
abstract registerCommands(): void;
|
|
105
|
+
abstract deregisterCommands(): void;
|
|
106
|
+
|
|
107
|
+
getCodeCompletionSuggestions(): string[] {
|
|
108
|
+
return SQL_KEYWORDS;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
stopExecuteSQL(): void {
|
|
112
|
+
this.sqlExecutionResult = undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setSQLText(val: string): void {
|
|
116
|
+
this.sqlText = val;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setTheme(val: SQLPlaygroundTheme): void {
|
|
120
|
+
this.theme = val;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setSQLEditorViewState(
|
|
124
|
+
state: monaco.editor.ICodeEditorViewState | undefined,
|
|
125
|
+
): void {
|
|
126
|
+
this.sqlEditorViewState = state;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
setSQLEditor(val: monaco.editor.IStandaloneCodeEditor | undefined): void {
|
|
130
|
+
this.sqlEditor = val;
|
|
131
|
+
if (val) {
|
|
132
|
+
const lines = this.sqlText.split('\n');
|
|
133
|
+
moveCursorToPosition(val, {
|
|
134
|
+
lineNumber: lines.length,
|
|
135
|
+
column: lines.at(-1)?.length ?? 0,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
toggleIsLocalModeEnabled(): void {
|
|
141
|
+
this.isLocalModeEnabled = !this.isLocalModeEnabled;
|
|
142
|
+
this.sqlExecutionResult = undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get isExecuting(): boolean {
|
|
146
|
+
return this.executeRawSQLState.isInProgress;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get hasResult(): boolean {
|
|
150
|
+
return this.sqlExecutionResult !== undefined;
|
|
151
|
+
}
|
|
152
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -55,6 +55,8 @@
|
|
|
55
55
|
"./src/graph-editor/index.ts",
|
|
56
56
|
"./src/model-documentation/ModelDocumentationAnalysis.ts",
|
|
57
57
|
"./src/model-documentation/index.ts",
|
|
58
|
+
"./src/sql-playground/index.ts",
|
|
59
|
+
"./src/sql-playground/store/AbstractSQLPlaygroundState.ts",
|
|
58
60
|
"./src/application/ActivityBar.tsx",
|
|
59
61
|
"./src/application/DocumentationLink.tsx",
|
|
60
62
|
"./src/application/FuzzySearchAdvancedConfigMenu.tsx",
|
|
@@ -68,7 +70,10 @@
|
|
|
68
70
|
"./src/graph-editor/ElementIconUtils.tsx",
|
|
69
71
|
"./src/graph-editor/PackageableElementOption.tsx",
|
|
70
72
|
"./src/model-documentation/ModelDocumentationState.tsx",
|
|
71
|
-
"./src/model-documentation/ModelDocumentationViewer.tsx"
|
|
73
|
+
"./src/model-documentation/ModelDocumentationViewer.tsx",
|
|
74
|
+
"./src/sql-playground/SQLPlaygroundEditor.tsx",
|
|
75
|
+
"./src/sql-playground/SQLPlaygroundGrid.tsx",
|
|
76
|
+
"./src/sql-playground/SQLPlaygroundPanel.tsx"
|
|
72
77
|
],
|
|
73
78
|
"include": [
|
|
74
79
|
"src/**/*.ts",
|