@finos/legend-application-data-cube 0.3.60 → 0.4.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/lib/components/builder/LegendDataCubeBuilder.d.ts.map +1 -1
- package/lib/components/builder/LegendDataCubeBuilder.js +7 -0
- package/lib/components/builder/LegendDataCubeBuilder.js.map +1 -1
- package/lib/components/builder/LegendDataCubeBuilderStoreProvider.d.ts.map +1 -1
- package/lib/components/builder/LegendDataCubeBuilderStoreProvider.js +1 -1
- package/lib/components/builder/LegendDataCubeBuilderStoreProvider.js.map +1 -1
- package/lib/components/builder/LegendDataCubeQueryEditor.d.ts +19 -0
- package/lib/components/builder/LegendDataCubeQueryEditor.d.ts.map +1 -0
- package/lib/components/builder/LegendDataCubeQueryEditor.js +50 -0
- package/lib/components/builder/LegendDataCubeQueryEditor.js.map +1 -0
- package/lib/index.css +1 -1
- package/lib/package.json +1 -1
- package/lib/stores/LegendDataCubeDataCubeEngine.d.ts +3 -1
- package/lib/stores/LegendDataCubeDataCubeEngine.d.ts.map +1 -1
- package/lib/stores/LegendDataCubeDataCubeEngine.js +92 -2
- package/lib/stores/LegendDataCubeDataCubeEngine.js.map +1 -1
- package/lib/stores/builder/LegendDataCubeBuilderStore.d.ts +2 -0
- package/lib/stores/builder/LegendDataCubeBuilderStore.d.ts.map +1 -1
- package/lib/stores/builder/LegendDataCubeBuilderStore.js +8 -1
- package/lib/stores/builder/LegendDataCubeBuilderStore.js.map +1 -1
- package/lib/stores/builder/LegendDataCubeCodeEditorState.d.ts +32 -0
- package/lib/stores/builder/LegendDataCubeCodeEditorState.d.ts.map +1 -0
- package/lib/stores/builder/LegendDataCubeCodeEditorState.js +127 -0
- package/lib/stores/builder/LegendDataCubeCodeEditorState.js.map +1 -0
- package/package.json +10 -10
- package/src/components/builder/LegendDataCubeBuilder.tsx +7 -0
- package/src/components/builder/LegendDataCubeBuilderStoreProvider.tsx +1 -0
- package/src/components/builder/LegendDataCubeQueryEditor.tsx +96 -0
- package/src/stores/LegendDataCubeDataCubeEngine.ts +139 -0
- package/src/stores/builder/LegendDataCubeBuilderStore.tsx +13 -0
- package/src/stores/builder/LegendDataCubeCodeEditorState.tsx +156 -0
- package/tsconfig.json +2 -0
|
@@ -0,0 +1,156 @@
|
|
|
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 { setErrorMarkers } from '@finos/legend-code-editor';
|
|
18
|
+
import {
|
|
19
|
+
_lambda,
|
|
20
|
+
DataCubeCodeEditorState,
|
|
21
|
+
type DataCubeEngine,
|
|
22
|
+
type DataCubeAlertService,
|
|
23
|
+
type DataCubeSource,
|
|
24
|
+
} from '@finos/legend-data-cube';
|
|
25
|
+
import { EngineError, type V1_Lambda } from '@finos/legend-graph';
|
|
26
|
+
import { ActionState, assertErrorThrown, uuid } from '@finos/legend-shared';
|
|
27
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
28
|
+
|
|
29
|
+
export class LegendDataCubeCodeEditorState extends DataCubeCodeEditorState {
|
|
30
|
+
protected override readonly uuid = uuid();
|
|
31
|
+
readonly validationState = ActionState.create();
|
|
32
|
+
readonly alertService: DataCubeAlertService;
|
|
33
|
+
|
|
34
|
+
queryLambda: () => V1_Lambda;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
engine: DataCubeEngine,
|
|
38
|
+
alertService: DataCubeAlertService,
|
|
39
|
+
model: DataCubeSource | undefined,
|
|
40
|
+
) {
|
|
41
|
+
super(engine);
|
|
42
|
+
makeObservable(this, {
|
|
43
|
+
editor: observable.ref,
|
|
44
|
+
setEditor: action,
|
|
45
|
+
|
|
46
|
+
codeError: observable.ref,
|
|
47
|
+
showError: action,
|
|
48
|
+
clearError: action,
|
|
49
|
+
|
|
50
|
+
returnType: observable,
|
|
51
|
+
setReturnType: action,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.engine = engine;
|
|
55
|
+
this.alertService = alertService;
|
|
56
|
+
this.model = model;
|
|
57
|
+
this.queryLambda = this.buildDataCubeQuery;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
alertHandler = (error: Error): void => {
|
|
61
|
+
this.alertService.alertUnhandledError(error);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
initialize(query: string) {
|
|
65
|
+
this.code = query;
|
|
66
|
+
this.editorModel.setValue(this.code);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
showError(error: EngineError) {
|
|
70
|
+
this.codeError = error;
|
|
71
|
+
if (error.sourceInformation) {
|
|
72
|
+
setErrorMarkers(
|
|
73
|
+
this.editorModel,
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
message: error.message,
|
|
77
|
+
startLineNumber: error.sourceInformation.startLine,
|
|
78
|
+
startColumn: error.sourceInformation.startColumn,
|
|
79
|
+
endLineNumber: error.sourceInformation.endLine,
|
|
80
|
+
endColumn: error.sourceInformation.endColumn,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
this.uuid,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
buildDataCubeQuery = () => {
|
|
89
|
+
let parsedLambda: V1_Lambda = _lambda([], []);
|
|
90
|
+
this.engine
|
|
91
|
+
.parseValueSpecification(this.code)
|
|
92
|
+
.then((lambda) => {
|
|
93
|
+
parsedLambda = _lambda([], [lambda]);
|
|
94
|
+
})
|
|
95
|
+
.catch((error) => {
|
|
96
|
+
assertErrorThrown(error);
|
|
97
|
+
if (error instanceof EngineError) {
|
|
98
|
+
this.validationState.fail();
|
|
99
|
+
// correct the source information since we added prefix to the code
|
|
100
|
+
// and reveal error in the editor
|
|
101
|
+
if (error.sourceInformation) {
|
|
102
|
+
error.sourceInformation.startColumn -=
|
|
103
|
+
error.sourceInformation.startLine === 1
|
|
104
|
+
? this.codePrefix.length
|
|
105
|
+
: 0;
|
|
106
|
+
error.sourceInformation.endColumn -=
|
|
107
|
+
error.sourceInformation.endLine === 1
|
|
108
|
+
? this.codePrefix.length
|
|
109
|
+
: 0;
|
|
110
|
+
const fullRange = this.editorModel.getFullModelRange();
|
|
111
|
+
if (
|
|
112
|
+
error.sourceInformation.startLine < 1 ||
|
|
113
|
+
(error.sourceInformation.startLine === 1 &&
|
|
114
|
+
error.sourceInformation.startColumn < 1) ||
|
|
115
|
+
error.sourceInformation.endLine > fullRange.endLineNumber ||
|
|
116
|
+
(error.sourceInformation.endLine === fullRange.endLineNumber &&
|
|
117
|
+
error.sourceInformation.endColumn > fullRange.endColumn)
|
|
118
|
+
) {
|
|
119
|
+
error.sourceInformation.startColumn = fullRange.startColumn;
|
|
120
|
+
error.sourceInformation.startLine = fullRange.startLineNumber;
|
|
121
|
+
error.sourceInformation.endColumn = fullRange.endColumn;
|
|
122
|
+
error.sourceInformation.endLine = fullRange.endLineNumber;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
this.showError(error);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return parsedLambda;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
async getReturnType() {
|
|
132
|
+
this.validationState.inProgress();
|
|
133
|
+
|
|
134
|
+
// properly reset the error state before revalidating
|
|
135
|
+
this.clearError();
|
|
136
|
+
this.setReturnType(undefined);
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
this.buildDataCubeQuery();
|
|
140
|
+
return undefined;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
assertErrorThrown(error);
|
|
143
|
+
this.alertHandler(error);
|
|
144
|
+
} finally {
|
|
145
|
+
this.validationState.complete();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
close() {
|
|
152
|
+
// dispose the editor and its model to avoid memory leak
|
|
153
|
+
this.editorModel.dispose();
|
|
154
|
+
this.editor?.dispose();
|
|
155
|
+
}
|
|
156
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
"./src/components/builder/LegendDataCubeCreator.tsx",
|
|
86
86
|
"./src/components/builder/LegendDataCubeDeleteConfirmation.tsx",
|
|
87
87
|
"./src/components/builder/LegendDataCubeLoader.tsx",
|
|
88
|
+
"./src/components/builder/LegendDataCubeQueryEditor.tsx",
|
|
88
89
|
"./src/components/builder/LegendDataCubeSaver.tsx",
|
|
89
90
|
"./src/components/builder/LegendDataCubeSourceViewer.tsx",
|
|
90
91
|
"./src/components/builder/source/FreeformTDSExpressionDataCubeSourceBuilder.tsx",
|
|
@@ -95,6 +96,7 @@
|
|
|
95
96
|
"./src/components/builder/source/LocalFileDataCubeSourceLoader.tsx",
|
|
96
97
|
"./src/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.tsx",
|
|
97
98
|
"./src/stores/builder/LegendDataCubeBuilderStore.tsx",
|
|
99
|
+
"./src/stores/builder/LegendDataCubeCodeEditorState.tsx",
|
|
98
100
|
"./src/stores/builder/LegendDataCubeCreatorState.tsx",
|
|
99
101
|
"./src/stores/builder/LegendDataCubeLoaderState.tsx",
|
|
100
102
|
"./src/stores/builder/source/FreeformExpressionCodeEditorState.tsx",
|