@finos/legend-application-query 13.4.1 → 13.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/lib/__lib__/DSL_DataSpace_LegendQueryDocumentation.d.ts +19 -0
  2. package/lib/__lib__/DSL_DataSpace_LegendQueryDocumentation.d.ts.map +1 -0
  3. package/lib/__lib__/DSL_DataSpace_LegendQueryDocumentation.js +20 -0
  4. package/lib/__lib__/DSL_DataSpace_LegendQueryDocumentation.js.map +1 -0
  5. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.d.ts +53 -0
  6. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.d.ts.map +1 -0
  7. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.js +59 -0
  8. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.js.map +1 -0
  9. package/lib/components/Core_LegendQueryApplicationPlugin.d.ts.map +1 -1
  10. package/lib/components/Core_LegendQueryApplicationPlugin.js +14 -1
  11. package/lib/components/Core_LegendQueryApplicationPlugin.js.map +1 -1
  12. package/lib/components/LegendQueryWebApplication.d.ts.map +1 -1
  13. package/lib/components/LegendQueryWebApplication.js +18 -10
  14. package/lib/components/LegendQueryWebApplication.js.map +1 -1
  15. package/lib/components/QueryEditor.d.ts.map +1 -1
  16. package/lib/components/QueryEditor.js +47 -18
  17. package/lib/components/QueryEditor.js.map +1 -1
  18. package/lib/components/data-space/DataSpaceQueryCreator.d.ts +19 -0
  19. package/lib/components/data-space/DataSpaceQueryCreator.d.ts.map +1 -0
  20. package/lib/components/data-space/DataSpaceQueryCreator.js +43 -0
  21. package/lib/components/data-space/DataSpaceQueryCreator.js.map +1 -0
  22. package/lib/components/data-space/DataSpaceQuerySetup.d.ts +21 -0
  23. package/lib/components/data-space/DataSpaceQuerySetup.d.ts.map +1 -0
  24. package/lib/components/data-space/DataSpaceQuerySetup.js +64 -0
  25. package/lib/components/data-space/DataSpaceQuerySetup.js.map +1 -0
  26. package/lib/components/data-space/DataSpaceTemplateQueryCreator.d.ts +19 -0
  27. package/lib/components/data-space/DataSpaceTemplateQueryCreator.d.ts.map +1 -0
  28. package/lib/components/data-space/DataSpaceTemplateQueryCreator.js +39 -0
  29. package/lib/components/data-space/DataSpaceTemplateQueryCreator.js.map +1 -0
  30. package/lib/components/data-space/QueryDataSpaceUtil.d.ts +19 -0
  31. package/lib/components/data-space/QueryDataSpaceUtil.d.ts.map +1 -0
  32. package/lib/components/data-space/QueryDataSpaceUtil.js +25 -0
  33. package/lib/components/data-space/QueryDataSpaceUtil.js.map +1 -0
  34. package/lib/index.css +1 -1
  35. package/lib/package.json +2 -1
  36. package/lib/stores/LegendQueryApplicationPlugin.d.ts +0 -16
  37. package/lib/stores/LegendQueryApplicationPlugin.d.ts.map +1 -1
  38. package/lib/stores/LegendQueryApplicationPlugin.js.map +1 -1
  39. package/lib/stores/QueryEditorStore.d.ts +2 -0
  40. package/lib/stores/QueryEditorStore.d.ts.map +1 -1
  41. package/lib/stores/QueryEditorStore.js +96 -11
  42. package/lib/stores/QueryEditorStore.js.map +1 -1
  43. package/lib/stores/data-space/DataSpaceQueryCreatorStore.d.ts +37 -0
  44. package/lib/stores/data-space/DataSpaceQueryCreatorStore.d.ts.map +1 -0
  45. package/lib/stores/data-space/DataSpaceQueryCreatorStore.js +132 -0
  46. package/lib/stores/data-space/DataSpaceQueryCreatorStore.js.map +1 -0
  47. package/lib/stores/data-space/DataSpaceQuerySetupState.d.ts +51 -0
  48. package/lib/stores/data-space/DataSpaceQuerySetupState.d.ts.map +1 -0
  49. package/lib/stores/data-space/DataSpaceQuerySetupState.js +107 -0
  50. package/lib/stores/data-space/DataSpaceQuerySetupState.js.map +1 -0
  51. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.d.ts +36 -0
  52. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.d.ts.map +1 -0
  53. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.js +104 -0
  54. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.js.map +1 -0
  55. package/package.json +6 -5
  56. package/src/__lib__/DSL_DataSpace_LegendQueryDocumentation.ts +19 -0
  57. package/src/__lib__/DSL_DataSpace_LegendQueryNavigation.ts +123 -0
  58. package/src/components/Core_LegendQueryApplicationPlugin.tsx +18 -0
  59. package/src/components/LegendQueryWebApplication.tsx +48 -12
  60. package/src/components/QueryEditor.tsx +112 -24
  61. package/src/components/data-space/DataSpaceQueryCreator.tsx +99 -0
  62. package/src/components/data-space/DataSpaceQuerySetup.tsx +165 -0
  63. package/src/components/data-space/DataSpaceTemplateQueryCreator.tsx +82 -0
  64. package/src/components/data-space/QueryDataSpaceUtil.ts +34 -0
  65. package/src/stores/LegendQueryApplicationPlugin.ts +0 -22
  66. package/src/stores/QueryEditorStore.ts +187 -12
  67. package/src/stores/data-space/DataSpaceQueryCreatorStore.ts +286 -0
  68. package/src/stores/data-space/DataSpaceQuerySetupState.ts +208 -0
  69. package/src/stores/data-space/DataSpaceTemplateQueryCreatorStore.ts +204 -0
  70. package/tsconfig.json +10 -1
@@ -0,0 +1,286 @@
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 {
18
+ type Query,
19
+ extractElementNameFromPath,
20
+ RuntimePointer,
21
+ PackageableElementExplicitReference,
22
+ type Runtime,
23
+ type Class,
24
+ type RawLambda,
25
+ } from '@finos/legend-graph';
26
+ import {
27
+ type DepotServerClient,
28
+ StoreProjectData,
29
+ LATEST_VERSION_ALIAS,
30
+ } from '@finos/legend-server-depot';
31
+ import {
32
+ guaranteeNonNullable,
33
+ guaranteeType,
34
+ uuid,
35
+ } from '@finos/legend-shared';
36
+ import type { QueryBuilderState } from '@finos/legend-query-builder';
37
+ import type { ProjectGAVCoordinates } from '@finos/legend-storage';
38
+ import {
39
+ type DataSpaceExecutionContext,
40
+ DSL_DataSpace_getGraphManagerExtension,
41
+ getDataSpace,
42
+ retrieveAnalyticsResultCache,
43
+ } from '@finos/legend-extension-dsl-data-space/graph';
44
+ import {
45
+ QueryEditorStore,
46
+ createViewProjectHandler,
47
+ createViewSDLCProjectHandler,
48
+ type QueryPersistConfiguration,
49
+ } from '../QueryEditorStore.js';
50
+ import type { LegendQueryApplicationStore } from '../LegendQueryBaseStore.js';
51
+ import {
52
+ DataSpaceProjectInfo,
53
+ DataSpaceQueryBuilderState,
54
+ createQueryClassTaggedValue,
55
+ createQueryDataSpaceTaggedValue,
56
+ type DataSpaceInfo,
57
+ } from '@finos/legend-extension-dsl-data-space/application';
58
+ import { generateDataSpaceQueryCreatorRoute } from '../../__lib__/DSL_DataSpace_LegendQueryNavigation.js';
59
+
60
+ export class DataSpaceQueryCreatorStore extends QueryEditorStore {
61
+ readonly groupId: string;
62
+ readonly artifactId: string;
63
+ readonly versionId: string;
64
+ readonly dataSpacePath: string;
65
+ readonly executionContext: string;
66
+ readonly runtimePath: string | undefined;
67
+ readonly classPath: string | undefined;
68
+
69
+ constructor(
70
+ applicationStore: LegendQueryApplicationStore,
71
+ depotServerClient: DepotServerClient,
72
+ groupId: string,
73
+ artifactId: string,
74
+ versionId: string,
75
+ dataSpacePath: string,
76
+ executionContext: string,
77
+ runtimePath: string | undefined,
78
+ executionKey: string | undefined,
79
+ ) {
80
+ super(applicationStore, depotServerClient);
81
+
82
+ this.groupId = groupId;
83
+ this.artifactId = artifactId;
84
+ this.versionId = versionId;
85
+ this.dataSpacePath = dataSpacePath;
86
+ this.executionContext = executionContext;
87
+ this.runtimePath = runtimePath;
88
+ this.classPath = executionKey;
89
+ }
90
+
91
+ getProjectInfo(): ProjectGAVCoordinates {
92
+ return {
93
+ groupId: this.groupId,
94
+ artifactId: this.artifactId,
95
+ versionId: this.versionId,
96
+ };
97
+ }
98
+
99
+ async initializeQueryBuilderState(): Promise<QueryBuilderState> {
100
+ const dataSpace = getDataSpace(
101
+ this.dataSpacePath,
102
+ this.graphManagerState.graph,
103
+ );
104
+ const executionContext = guaranteeNonNullable(
105
+ dataSpace.executionContexts.find(
106
+ (context) => context.name === this.executionContext,
107
+ ),
108
+ `Can't find execution context '${this.executionContext}'`,
109
+ );
110
+ let dataSpaceAnalysisResult;
111
+ try {
112
+ const project = StoreProjectData.serialization.fromJson(
113
+ await this.depotServerClient.getProject(this.groupId, this.artifactId),
114
+ );
115
+ dataSpaceAnalysisResult = await DSL_DataSpace_getGraphManagerExtension(
116
+ this.graphManagerState.graphManager,
117
+ ).retrieveDataSpaceAnalysisFromCache(() =>
118
+ retrieveAnalyticsResultCache(
119
+ project,
120
+ this.versionId,
121
+ dataSpace.path,
122
+ this.depotServerClient,
123
+ ),
124
+ );
125
+ } catch {
126
+ // do nothing
127
+ }
128
+ const projectInfo = new DataSpaceProjectInfo(
129
+ this.groupId,
130
+ this.artifactId,
131
+ this.versionId,
132
+ createViewProjectHandler(this.applicationStore),
133
+ createViewSDLCProjectHandler(
134
+ this.applicationStore,
135
+ this.depotServerClient,
136
+ ),
137
+ );
138
+ const sourceInfo = {
139
+ groupId: projectInfo.groupId,
140
+ artifactId: projectInfo.artifactId,
141
+ versionId: projectInfo.versionId,
142
+ dataSpace: dataSpace.path,
143
+ };
144
+ const queryBuilderState = new DataSpaceQueryBuilderState(
145
+ this.applicationStore,
146
+ this.graphManagerState,
147
+ this.depotServerClient,
148
+ dataSpace,
149
+ executionContext,
150
+ (dataSpaceInfo: DataSpaceInfo) => {
151
+ if (dataSpaceInfo.defaultExecutionContext) {
152
+ this.applicationStore.navigationService.navigator.goToLocation(
153
+ generateDataSpaceQueryCreatorRoute(
154
+ guaranteeNonNullable(dataSpaceInfo.groupId),
155
+ guaranteeNonNullable(dataSpaceInfo.artifactId),
156
+ LATEST_VERSION_ALIAS, //always default to latest
157
+ dataSpaceInfo.path,
158
+ dataSpaceInfo.defaultExecutionContext,
159
+ undefined,
160
+ undefined,
161
+ ),
162
+ );
163
+ } else {
164
+ this.applicationStore.notificationService.notifyWarning(
165
+ `Can't switch data space: default execution context not specified`,
166
+ );
167
+ }
168
+ },
169
+ true,
170
+ dataSpaceAnalysisResult,
171
+ (ec: DataSpaceExecutionContext) => {
172
+ // runtime should already be set
173
+ const runtimePointer = guaranteeType(
174
+ queryBuilderState.executionContextState.runtimeValue,
175
+ RuntimePointer,
176
+ );
177
+ this.applicationStore.navigationService.navigator.updateCurrentLocation(
178
+ generateDataSpaceQueryCreatorRoute(
179
+ this.groupId,
180
+ this.artifactId,
181
+ this.versionId,
182
+ dataSpace.path,
183
+ ec.name,
184
+ runtimePointer.packageableRuntime.value ===
185
+ queryBuilderState.executionContext.defaultRuntime.value
186
+ ? undefined
187
+ : runtimePointer.packageableRuntime.value.path,
188
+ queryBuilderState.class?.path,
189
+ ),
190
+ );
191
+ },
192
+ (runtimeValue: Runtime) => {
193
+ const runtimePointer = guaranteeType(runtimeValue, RuntimePointer);
194
+ queryBuilderState.applicationStore.navigationService.navigator.updateCurrentLocation(
195
+ generateDataSpaceQueryCreatorRoute(
196
+ guaranteeNonNullable(queryBuilderState.projectInfo).groupId,
197
+ guaranteeNonNullable(queryBuilderState.projectInfo).artifactId,
198
+ guaranteeNonNullable(queryBuilderState.projectInfo).versionId,
199
+ queryBuilderState.dataSpace.path,
200
+ queryBuilderState.executionContext.name,
201
+ runtimePointer.packageableRuntime.value ===
202
+ queryBuilderState.executionContext.defaultRuntime.value
203
+ ? undefined
204
+ : runtimePointer.packageableRuntime.value.path,
205
+ queryBuilderState.class?.path,
206
+ ),
207
+ );
208
+ },
209
+ (_class: Class) => {
210
+ // runtime should already be set
211
+ const runtimePointer = guaranteeType(
212
+ queryBuilderState.executionContextState.runtimeValue,
213
+ RuntimePointer,
214
+ );
215
+ queryBuilderState.applicationStore.navigationService.navigator.updateCurrentLocation(
216
+ generateDataSpaceQueryCreatorRoute(
217
+ guaranteeNonNullable(queryBuilderState.projectInfo).groupId,
218
+ guaranteeNonNullable(queryBuilderState.projectInfo).artifactId,
219
+ guaranteeNonNullable(queryBuilderState.projectInfo).versionId,
220
+ queryBuilderState.dataSpace.path,
221
+ queryBuilderState.executionContext.name,
222
+ runtimePointer.packageableRuntime.value ===
223
+ queryBuilderState.executionContext.defaultRuntime.value
224
+ ? undefined
225
+ : runtimePointer.packageableRuntime.value.path,
226
+ _class.path,
227
+ ),
228
+ );
229
+ },
230
+ projectInfo,
231
+ this.applicationStore.config.options.queryBuilderConfig,
232
+ sourceInfo,
233
+ );
234
+ queryBuilderState.setExecutionContext(executionContext);
235
+ queryBuilderState.propagateExecutionContextChange(executionContext);
236
+
237
+ // set runtime if already chosen
238
+ if (this.runtimePath) {
239
+ queryBuilderState.changeRuntime(
240
+ new RuntimePointer(
241
+ PackageableElementExplicitReference.create(
242
+ this.graphManagerState.graph.getRuntime(this.runtimePath),
243
+ ),
244
+ ),
245
+ );
246
+ }
247
+
248
+ // set class if already chosen
249
+ if (this.classPath) {
250
+ queryBuilderState.changeClass(
251
+ this.graphManagerState.graph.getClass(this.classPath),
252
+ );
253
+ }
254
+
255
+ return queryBuilderState;
256
+ }
257
+
258
+ getPersistConfiguration(
259
+ lambda: RawLambda,
260
+ options?: { update?: boolean | undefined },
261
+ ): QueryPersistConfiguration {
262
+ return {
263
+ defaultName: options?.update
264
+ ? `${extractElementNameFromPath(this.dataSpacePath)}`
265
+ : `New Query for ${extractElementNameFromPath(this.dataSpacePath)}[${
266
+ this.executionContext
267
+ }]`,
268
+ decorator: (query: Query): void => {
269
+ query.id = uuid();
270
+ query.groupId = this.groupId;
271
+ query.artifactId = this.artifactId;
272
+ query.versionId = this.versionId;
273
+ if (this.queryBuilderState?.class) {
274
+ query.taggedValues = [
275
+ createQueryDataSpaceTaggedValue(this.dataSpacePath),
276
+ createQueryClassTaggedValue(this.queryBuilderState.class.path),
277
+ ];
278
+ } else {
279
+ query.taggedValues = [
280
+ createQueryDataSpaceTaggedValue(this.dataSpacePath),
281
+ ];
282
+ }
283
+ },
284
+ };
285
+ }
286
+ }
@@ -0,0 +1,208 @@
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 {
18
+ DepotScope,
19
+ LATEST_VERSION_ALIAS,
20
+ type DepotServerClient,
21
+ type StoredEntity,
22
+ } from '@finos/legend-server-depot';
23
+ import type { GraphManagerState, RawLambda } from '@finos/legend-graph';
24
+ import { type GenericLegendApplicationStore } from '@finos/legend-application';
25
+ import { action, flow, makeObservable, observable } from 'mobx';
26
+ import {
27
+ type QueryBuilderConfig,
28
+ QueryBuilderState,
29
+ } from '@finos/legend-query-builder';
30
+ import type { ProjectGAVCoordinates } from '@finos/legend-storage';
31
+ import {
32
+ ActionState,
33
+ assertErrorThrown,
34
+ guaranteeNonNullable,
35
+ UnsupportedOperationError,
36
+ type GeneratorFn,
37
+ } from '@finos/legend-shared';
38
+ import {
39
+ extractDataSpaceInfo,
40
+ type DataSpaceInfo,
41
+ } from '@finos/legend-extension-dsl-data-space/application';
42
+ import { DATA_SPACE_ELEMENT_CLASSIFIER_PATH } from '@finos/legend-extension-dsl-data-space/graph';
43
+ import {
44
+ QueryEditorStore,
45
+ createViewProjectHandler,
46
+ createViewSDLCProjectHandler,
47
+ type QueryPersistConfiguration,
48
+ } from '../QueryEditorStore.js';
49
+ import { generateDataSpaceQueryCreatorRoute } from '../../__lib__/DSL_DataSpace_LegendQueryNavigation.js';
50
+ import { renderDataSpaceQuerySetupSetupPanelContent } from '../../components/data-space/DataSpaceQuerySetup.js';
51
+ import { DataSpaceAdvancedSearchState } from '@finos/legend-extension-dsl-data-space/application-query';
52
+
53
+ export class DataSpaceQuerySetupState extends QueryBuilderState {
54
+ readonly depotServerClient: DepotServerClient;
55
+ readonly loadDataSpacesState = ActionState.create();
56
+ readonly onDataSpaceChange: (val: DataSpaceInfo) => void;
57
+ readonly viewProject: (
58
+ groupId: string,
59
+ artifactId: string,
60
+ versionId: string,
61
+ entityPath: string | undefined,
62
+ ) => void;
63
+ readonly viewSDLCProject: (
64
+ groupId: string,
65
+ artifactId: string,
66
+ entityPath: string | undefined,
67
+ ) => Promise<void>;
68
+
69
+ override TEMPORARY__setupPanelContentRenderer = (): React.ReactNode =>
70
+ renderDataSpaceQuerySetupSetupPanelContent(this);
71
+
72
+ dataSpaces: DataSpaceInfo[] = [];
73
+ showRuntimeSelector = false;
74
+ advancedSearchState?: DataSpaceAdvancedSearchState | undefined;
75
+
76
+ constructor(
77
+ applicationStore: GenericLegendApplicationStore,
78
+ graphManagerState: GraphManagerState,
79
+ depotServerClient: DepotServerClient,
80
+ onDataSpaceChange: (val: DataSpaceInfo) => void,
81
+ viewProject: (
82
+ groupId: string,
83
+ artifactId: string,
84
+ versionId: string,
85
+ entityPath: string | undefined,
86
+ ) => void,
87
+ viewSDLCProject: (
88
+ groupId: string,
89
+ artifactId: string,
90
+ entityPath: string | undefined,
91
+ ) => Promise<void>,
92
+ config: QueryBuilderConfig | undefined,
93
+ ) {
94
+ super(applicationStore, graphManagerState, config);
95
+
96
+ makeObservable(this, {
97
+ dataSpaces: observable,
98
+ advancedSearchState: observable,
99
+ showAdvancedSearchPanel: action,
100
+ hideAdvancedSearchPanel: action,
101
+ loadDataSpaces: flow,
102
+ });
103
+
104
+ this.depotServerClient = depotServerClient;
105
+ this.onDataSpaceChange = onDataSpaceChange;
106
+ this.viewProject = viewProject;
107
+ this.viewSDLCProject = viewSDLCProject;
108
+ }
109
+
110
+ override get isResultPanelHidden(): boolean {
111
+ return true;
112
+ }
113
+
114
+ override get sideBarClassName(): string | undefined {
115
+ return 'query-builder__setup__data-space-setup';
116
+ }
117
+
118
+ showAdvancedSearchPanel(): void {
119
+ this.advancedSearchState = new DataSpaceAdvancedSearchState(
120
+ this.applicationStore,
121
+ this.graphManagerState,
122
+ this.depotServerClient,
123
+ {
124
+ viewProject: this.viewProject,
125
+ viewSDLCProject: this.viewSDLCProject,
126
+ },
127
+ );
128
+ }
129
+
130
+ hideAdvancedSearchPanel(): void {
131
+ this.advancedSearchState = undefined;
132
+ }
133
+
134
+ *loadDataSpaces(): GeneratorFn<void> {
135
+ this.loadDataSpacesState.inProgress();
136
+ try {
137
+ this.dataSpaces = (
138
+ (yield this.depotServerClient.getEntitiesByClassifier(
139
+ DATA_SPACE_ELEMENT_CLASSIFIER_PATH,
140
+ {
141
+ scope: DepotScope.RELEASES,
142
+ },
143
+ )) as StoredEntity[]
144
+ ).map((storedEntity) => extractDataSpaceInfo(storedEntity, false));
145
+ this.loadDataSpacesState.pass();
146
+ } catch (error) {
147
+ assertErrorThrown(error);
148
+ this.loadDataSpacesState.fail();
149
+ this.applicationStore.notificationService.notifyError(error);
150
+ }
151
+ }
152
+ }
153
+
154
+ export class DataSpaceQuerySetupStore extends QueryEditorStore {
155
+ override get isViewProjectActionDisabled(): boolean {
156
+ return true;
157
+ }
158
+
159
+ getProjectInfo(): ProjectGAVCoordinates {
160
+ throw new UnsupportedOperationError();
161
+ }
162
+
163
+ getPersistConfiguration(
164
+ lambda: RawLambda,
165
+ options?: { update?: boolean | undefined },
166
+ ): QueryPersistConfiguration {
167
+ throw new UnsupportedOperationError();
168
+ }
169
+
170
+ async initializeQueryBuilderState(): Promise<QueryBuilderState> {
171
+ const queryBuilderState = new DataSpaceQuerySetupState(
172
+ this.applicationStore,
173
+ this.graphManagerState,
174
+ this.depotServerClient,
175
+ (dataSpaceInfo: DataSpaceInfo) => {
176
+ if (dataSpaceInfo.defaultExecutionContext) {
177
+ this.applicationStore.navigationService.navigator.goToLocation(
178
+ generateDataSpaceQueryCreatorRoute(
179
+ guaranteeNonNullable(dataSpaceInfo.groupId),
180
+ guaranteeNonNullable(dataSpaceInfo.artifactId),
181
+ LATEST_VERSION_ALIAS, //always default to latest
182
+ dataSpaceInfo.path,
183
+ dataSpaceInfo.defaultExecutionContext,
184
+ undefined,
185
+ undefined,
186
+ ),
187
+ );
188
+ } else {
189
+ this.applicationStore.notificationService.notifyWarning(
190
+ `Can't switch data space: default execution context not specified`,
191
+ );
192
+ }
193
+ },
194
+ createViewProjectHandler(this.applicationStore),
195
+ createViewSDLCProjectHandler(
196
+ this.applicationStore,
197
+ this.depotServerClient,
198
+ ),
199
+ this.applicationStore.config.options.queryBuilderConfig,
200
+ );
201
+
202
+ return queryBuilderState;
203
+ }
204
+
205
+ override *buildGraph(): GeneratorFn<void> {
206
+ // do nothing
207
+ }
208
+ }
@@ -0,0 +1,204 @@
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 {
18
+ extractElementNameFromPath,
19
+ type Query,
20
+ type RawLambda,
21
+ } from '@finos/legend-graph';
22
+ import {
23
+ type DepotServerClient,
24
+ StoreProjectData,
25
+ } from '@finos/legend-server-depot';
26
+ import { filterByType, guaranteeNonNullable, uuid } from '@finos/legend-shared';
27
+ import type { QueryBuilderState } from '@finos/legend-query-builder';
28
+ import type { ProjectGAVCoordinates } from '@finos/legend-storage';
29
+ import {
30
+ QueryEditorStore,
31
+ createViewProjectHandler,
32
+ createViewSDLCProjectHandler,
33
+ type QueryPersistConfiguration,
34
+ } from '../QueryEditorStore.js';
35
+ import type { LegendQueryApplicationStore } from '../LegendQueryBaseStore.js';
36
+ import {
37
+ DSL_DataSpace_getGraphManagerExtension,
38
+ DataSpaceExecutableTemplate,
39
+ type DataSpaceExecutionContext,
40
+ getDataSpace,
41
+ retrieveAnalyticsResultCache,
42
+ } from '@finos/legend-extension-dsl-data-space/graph';
43
+ import {
44
+ DataSpaceProjectInfo,
45
+ DataSpaceQueryBuilderState,
46
+ createQueryClassTaggedValue,
47
+ createQueryDataSpaceTaggedValue,
48
+ type DataSpaceInfo,
49
+ } from '@finos/legend-extension-dsl-data-space/application';
50
+ import { generateDataSpaceTemplateQueryCreatorRoute } from '../../__lib__/DSL_DataSpace_LegendQueryNavigation.js';
51
+
52
+ export class DataSpaceTemplateQueryCreatorStore extends QueryEditorStore {
53
+ readonly groupId: string;
54
+ readonly artifactId: string;
55
+ readonly versionId: string;
56
+ readonly dataSpacePath: string;
57
+ readonly templateQueryId: string;
58
+ templateQueryTitle?: string;
59
+
60
+ constructor(
61
+ applicationStore: LegendQueryApplicationStore,
62
+ depotServerClient: DepotServerClient,
63
+ groupId: string,
64
+ artifactId: string,
65
+ versionId: string,
66
+ dataSpacePath: string,
67
+ templateQueryId: string,
68
+ ) {
69
+ super(applicationStore, depotServerClient);
70
+
71
+ this.groupId = groupId;
72
+ this.artifactId = artifactId;
73
+ this.versionId = versionId;
74
+ this.dataSpacePath = dataSpacePath;
75
+ this.templateQueryId = templateQueryId;
76
+ }
77
+
78
+ getProjectInfo(): ProjectGAVCoordinates {
79
+ return {
80
+ groupId: this.groupId,
81
+ artifactId: this.artifactId,
82
+ versionId: this.versionId,
83
+ };
84
+ }
85
+
86
+ async initializeQueryBuilderState(): Promise<QueryBuilderState> {
87
+ const dataSpace = getDataSpace(
88
+ this.dataSpacePath,
89
+ this.graphManagerState.graph,
90
+ );
91
+ const dataSpaceExecutableTemplate = guaranteeNonNullable(
92
+ dataSpace.executables
93
+ ?.filter(filterByType(DataSpaceExecutableTemplate))
94
+ .find((executable) => executable.id === this.templateQueryId),
95
+ `Can't find template query with id '${this.templateQueryId}'`,
96
+ );
97
+ const executionContext = guaranteeNonNullable(
98
+ dataSpaceExecutableTemplate.executionContextKey
99
+ ? dataSpace.executionContexts.filter(
100
+ (ec) => ec.name === dataSpaceExecutableTemplate.executionContextKey,
101
+ )[0]
102
+ : dataSpace.defaultExecutionContext,
103
+ `Can't find execution context '${dataSpaceExecutableTemplate.executionContextKey}'`,
104
+ );
105
+ this.templateQueryTitle = dataSpaceExecutableTemplate.title;
106
+ let dataSpaceAnalysisResult;
107
+ try {
108
+ const project = StoreProjectData.serialization.fromJson(
109
+ await this.depotServerClient.getProject(this.groupId, this.artifactId),
110
+ );
111
+ dataSpaceAnalysisResult = await DSL_DataSpace_getGraphManagerExtension(
112
+ this.graphManagerState.graphManager,
113
+ ).retrieveDataSpaceAnalysisFromCache(() =>
114
+ retrieveAnalyticsResultCache(
115
+ project,
116
+ this.versionId,
117
+ dataSpace.path,
118
+ this.depotServerClient,
119
+ ),
120
+ );
121
+ } catch {
122
+ // do nothing
123
+ }
124
+ const projectInfo = new DataSpaceProjectInfo(
125
+ this.groupId,
126
+ this.artifactId,
127
+ this.versionId,
128
+ createViewProjectHandler(this.applicationStore),
129
+ createViewSDLCProjectHandler(
130
+ this.applicationStore,
131
+ this.depotServerClient,
132
+ ),
133
+ );
134
+ const sourceInfo = {
135
+ groupId: projectInfo.groupId,
136
+ artifactId: projectInfo.artifactId,
137
+ versionId: projectInfo.versionId,
138
+ dataSpace: dataSpace.path,
139
+ };
140
+ const queryBuilderState = new DataSpaceQueryBuilderState(
141
+ this.applicationStore,
142
+ this.graphManagerState,
143
+ this.depotServerClient,
144
+ dataSpace,
145
+ executionContext,
146
+ (dataSpaceInfo: DataSpaceInfo) => {
147
+ this.applicationStore.notificationService.notifyWarning(
148
+ `Can't switch data space to visit current template query`,
149
+ );
150
+ },
151
+ true,
152
+ dataSpaceAnalysisResult,
153
+ (ec: DataSpaceExecutionContext) => {
154
+ this.applicationStore.navigationService.navigator.updateCurrentLocation(
155
+ generateDataSpaceTemplateQueryCreatorRoute(
156
+ this.groupId,
157
+ this.artifactId,
158
+ this.versionId,
159
+ dataSpace.path,
160
+ this.templateQueryId,
161
+ ),
162
+ );
163
+ },
164
+ undefined,
165
+ undefined,
166
+ projectInfo,
167
+ this.applicationStore.config.options.queryBuilderConfig,
168
+ sourceInfo,
169
+ );
170
+ queryBuilderState.setExecutionContext(executionContext);
171
+ queryBuilderState.propagateExecutionContextChange(executionContext);
172
+ queryBuilderState.initializeWithQuery(dataSpaceExecutableTemplate.query);
173
+ return queryBuilderState;
174
+ }
175
+
176
+ getPersistConfiguration(
177
+ lambda: RawLambda,
178
+ options?: { update?: boolean | undefined },
179
+ ): QueryPersistConfiguration {
180
+ return {
181
+ defaultName: options?.update
182
+ ? `${extractElementNameFromPath(this.dataSpacePath)}`
183
+ : `New Query for ${extractElementNameFromPath(this.dataSpacePath)}[${
184
+ this.templateQueryId
185
+ }]`,
186
+ decorator: (query: Query): void => {
187
+ query.id = uuid();
188
+ query.groupId = this.groupId;
189
+ query.artifactId = this.artifactId;
190
+ query.versionId = this.versionId;
191
+ if (this.queryBuilderState?.class) {
192
+ query.taggedValues = [
193
+ createQueryDataSpaceTaggedValue(this.dataSpacePath),
194
+ createQueryClassTaggedValue(this.queryBuilderState.class.path),
195
+ ];
196
+ } else {
197
+ query.taggedValues = [
198
+ createQueryDataSpaceTaggedValue(this.dataSpacePath),
199
+ ];
200
+ }
201
+ },
202
+ };
203
+ }
204
+ }