@finos/legend-application-query 13.4.21 → 13.5.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.
Files changed (64) hide show
  1. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.d.ts +1 -1
  2. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.d.ts.map +1 -1
  3. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.js +4 -4
  4. package/lib/__lib__/DSL_DataSpace_LegendQueryNavigation.js.map +1 -1
  5. package/lib/__lib__/LegendQueryNavigation.d.ts +1 -0
  6. package/lib/__lib__/LegendQueryNavigation.d.ts.map +1 -1
  7. package/lib/__lib__/LegendQueryNavigation.js +1 -0
  8. package/lib/__lib__/LegendQueryNavigation.js.map +1 -1
  9. package/lib/components/Core_LegendQueryApplicationPlugin.d.ts.map +1 -1
  10. package/lib/components/Core_LegendQueryApplicationPlugin.js +20 -11
  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 +15 -14
  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 +2 -1
  17. package/lib/components/QueryEditor.js.map +1 -1
  18. package/lib/components/data-space/DataSpaceQueryCreator.d.ts.map +1 -1
  19. package/lib/components/data-space/DataSpaceQueryCreator.js +25 -8
  20. package/lib/components/data-space/DataSpaceQueryCreator.js.map +1 -1
  21. package/lib/components/data-space/DataSpaceQuerySetup.d.ts +0 -3
  22. package/lib/components/data-space/DataSpaceQuerySetup.d.ts.map +1 -1
  23. package/lib/components/data-space/DataSpaceQuerySetup.js +2 -12
  24. package/lib/components/data-space/DataSpaceQuerySetup.js.map +1 -1
  25. package/lib/index.css +1 -1
  26. package/lib/index.d.ts +2 -1
  27. package/lib/index.d.ts.map +1 -1
  28. package/lib/index.js +2 -1
  29. package/lib/index.js.map +1 -1
  30. package/lib/package.json +4 -3
  31. package/lib/stores/QueryEditorStore.d.ts +3 -4
  32. package/lib/stores/QueryEditorStore.d.ts.map +1 -1
  33. package/lib/stores/QueryEditorStore.js +54 -62
  34. package/lib/stores/QueryEditorStore.js.map +1 -1
  35. package/lib/stores/data-space/DataSpaceQueryBuilderHelper.d.ts +23 -0
  36. package/lib/stores/data-space/DataSpaceQueryBuilderHelper.d.ts.map +1 -0
  37. package/lib/stores/data-space/DataSpaceQueryBuilderHelper.js +39 -0
  38. package/lib/stores/data-space/DataSpaceQueryBuilderHelper.js.map +1 -0
  39. package/lib/stores/data-space/DataSpaceQueryCreatorStore.d.ts +35 -12
  40. package/lib/stores/data-space/DataSpaceQueryCreatorStore.d.ts.map +1 -1
  41. package/lib/stores/data-space/DataSpaceQueryCreatorStore.js +189 -86
  42. package/lib/stores/data-space/DataSpaceQueryCreatorStore.js.map +1 -1
  43. package/lib/stores/data-space/DataSpaceQuerySetupState.d.ts +3 -20
  44. package/lib/stores/data-space/DataSpaceQuerySetupState.d.ts.map +1 -1
  45. package/lib/stores/data-space/DataSpaceQuerySetupState.js +8 -81
  46. package/lib/stores/data-space/DataSpaceQuerySetupState.js.map +1 -1
  47. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.d.ts.map +1 -1
  48. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.js +8 -8
  49. package/lib/stores/data-space/DataSpaceTemplateQueryCreatorStore.js.map +1 -1
  50. package/package.json +14 -13
  51. package/src/__lib__/DSL_DataSpace_LegendQueryNavigation.ts +6 -4
  52. package/src/__lib__/LegendQueryNavigation.ts +1 -0
  53. package/src/components/Core_LegendQueryApplicationPlugin.tsx +25 -17
  54. package/src/components/LegendQueryWebApplication.tsx +30 -27
  55. package/src/components/QueryEditor.tsx +2 -1
  56. package/src/components/data-space/DataSpaceQueryCreator.tsx +36 -18
  57. package/src/components/data-space/DataSpaceQuerySetup.tsx +2 -36
  58. package/src/index.ts +4 -2
  59. package/src/stores/QueryEditorStore.ts +109 -157
  60. package/src/stores/data-space/DataSpaceQueryBuilderHelper.ts +107 -0
  61. package/src/stores/data-space/DataSpaceQueryCreatorStore.ts +302 -173
  62. package/src/stores/data-space/DataSpaceQuerySetupState.ts +8 -156
  63. package/src/stores/data-space/DataSpaceTemplateQueryCreatorStore.ts +11 -19
  64. package/tsconfig.json +1 -0
@@ -19,8 +19,6 @@ import {
19
19
  extractElementNameFromPath,
20
20
  RuntimePointer,
21
21
  PackageableElementExplicitReference,
22
- type Runtime,
23
- type Class,
24
22
  type RawLambda,
25
23
  } from '@finos/legend-graph';
26
24
  import {
@@ -31,16 +29,17 @@ import {
31
29
  import {
32
30
  LogEvent,
33
31
  assertErrorThrown,
32
+ assertTrue,
34
33
  guaranteeNonNullable,
35
- guaranteeType,
36
34
  returnUndefOnError,
37
35
  uuid,
36
+ type GeneratorFn,
38
37
  } from '@finos/legend-shared';
39
38
  import {
40
- type QueryBuilderState,
41
39
  QueryBuilderDataBrowserWorkflow,
40
+ type QueryBuilderState,
42
41
  } from '@finos/legend-query-builder';
43
- import type { ProjectGAVCoordinates } from '@finos/legend-storage';
42
+ import type { Entity, ProjectGAVCoordinates } from '@finos/legend-storage';
44
43
  import {
45
44
  type DataSpaceExecutionContext,
46
45
  DSL_DataSpace_getGraphManagerExtension,
@@ -50,87 +49,251 @@ import {
50
49
  import {
51
50
  QueryBuilderActionConfig_QueryApplication,
52
51
  QueryEditorStore,
53
- createViewProjectHandler,
54
- createViewSDLCProjectHandler,
55
52
  type QueryPersistConfiguration,
56
53
  } from '../QueryEditorStore.js';
57
54
  import type { LegendQueryApplicationStore } from '../LegendQueryBaseStore.js';
58
55
  import {
59
- DataSpaceProjectInfo,
60
56
  DataSpaceQueryBuilderState,
61
57
  createQueryClassTaggedValue,
62
58
  type DataSpaceInfo,
63
59
  } from '@finos/legend-extension-dsl-data-space/application';
64
- import { generateDataSpaceQueryCreatorRoute } from '../../__lib__/DSL_DataSpace_LegendQueryNavigation.js';
65
60
  import { LegendQueryUserDataHelper } from '../../__lib__/LegendQueryUserDataHelper.js';
66
61
  import {
67
62
  createVisitedDataSpaceId,
68
63
  hasDataSpaceInfoBeenVisited,
69
64
  createSimpleVisitedDataspace,
65
+ type VisitedDataspace,
70
66
  } from '../../__lib__/LegendQueryUserDataSpaceHelper.js';
71
67
  import { LEGEND_QUERY_APP_EVENT } from '../../__lib__/LegendQueryEvent.js';
68
+ import {
69
+ action,
70
+ computed,
71
+ flow,
72
+ flowResult,
73
+ makeObservable,
74
+ observable,
75
+ } from 'mobx';
76
+ import { DataSpaceQuerySetupState } from './DataSpaceQuerySetupState.js';
77
+ import {
78
+ createDataSpaceDepoRepo,
79
+ createViewProjectHandler,
80
+ createViewSDLCProjectHandler,
81
+ } from './DataSpaceQueryBuilderHelper.js';
82
+
83
+ export type QueryableDataSpace = {
84
+ groupId: string;
85
+ artifactId: string;
86
+ versionId: string;
87
+ dataSpacePath: string;
88
+ executionContext: string;
89
+ runtimePath?: string | undefined;
90
+ classPath?: string | undefined;
91
+ };
92
+
93
+ type DataSpaceVisitedEntity = {
94
+ visited: VisitedDataspace;
95
+ entity: Entity;
96
+ };
72
97
 
73
98
  export class DataSpaceQueryCreatorStore extends QueryEditorStore {
74
- readonly groupId: string;
75
- readonly artifactId: string;
76
- readonly versionId: string;
77
- readonly dataSpacePath: string;
78
- readonly executionContext: string;
79
- readonly runtimePath: string | undefined;
80
- readonly classPath: string | undefined;
99
+ queryableDataSpace: QueryableDataSpace | undefined;
100
+ dataSpaceCache: DataSpaceInfo[] | undefined;
101
+ declare queryBuilderState?: DataSpaceQueryBuilderState | undefined;
81
102
 
82
103
  constructor(
83
104
  applicationStore: LegendQueryApplicationStore,
84
105
  depotServerClient: DepotServerClient,
85
- groupId: string,
86
- artifactId: string,
87
- versionId: string,
88
- dataSpacePath: string,
89
- executionContext: string,
90
- runtimePath: string | undefined,
91
- executionKey: string | undefined,
106
+ queryableDataSpace: QueryableDataSpace | undefined,
92
107
  ) {
93
108
  super(applicationStore, depotServerClient);
109
+ makeObservable(this, {
110
+ changeDataSpace: flow,
111
+ dataSpaceCache: observable,
112
+ queryableDataSpace: observable,
113
+ setDataSpaceCache: action,
114
+ setQueryableDataSpace: action,
115
+ canPersistToSavedQuery: computed,
116
+ });
117
+ this.queryableDataSpace = queryableDataSpace;
118
+ }
94
119
 
95
- this.groupId = groupId;
96
- this.artifactId = artifactId;
97
- this.versionId = versionId;
98
- this.dataSpacePath = dataSpacePath;
99
- this.executionContext = executionContext;
100
- this.runtimePath = runtimePath;
101
- this.classPath = executionKey;
120
+ override get canPersistToSavedQuery(): boolean {
121
+ return Boolean(this.queryableDataSpace);
102
122
  }
103
123
 
104
- getProjectInfo(): ProjectGAVCoordinates {
105
- return {
106
- groupId: this.groupId,
107
- artifactId: this.artifactId,
108
- versionId: this.versionId,
109
- };
124
+ override get isViewProjectActionDisabled(): boolean {
125
+ return !this.queryableDataSpace;
126
+ }
127
+
128
+ getProjectInfo(): ProjectGAVCoordinates | undefined {
129
+ return this.queryableDataSpace;
130
+ }
131
+
132
+ setDataSpaceCache(val: DataSpaceInfo[]): void {
133
+ this.dataSpaceCache = val;
134
+ }
135
+
136
+ setQueryableDataSpace(val: QueryableDataSpace | undefined): void {
137
+ this.queryableDataSpace = val;
138
+ }
139
+
140
+ reConfigureWithDataSpaceInfo(info: DataSpaceInfo): boolean {
141
+ if (
142
+ info.groupId &&
143
+ info.artifactId &&
144
+ info.versionId &&
145
+ info.defaultExecutionContext
146
+ ) {
147
+ this.queryableDataSpace = {
148
+ groupId: info.groupId,
149
+ artifactId: info.artifactId,
150
+ versionId: LATEST_VERSION_ALIAS,
151
+ dataSpacePath: info.path,
152
+ executionContext: info.defaultExecutionContext,
153
+ };
154
+ return true;
155
+ }
156
+ return false;
157
+ }
158
+
159
+ override *initialize(): GeneratorFn<void> {
160
+ if (!this.queryableDataSpace) {
161
+ const hydrated = (yield flowResult(this.redirectIfPossible())) as
162
+ | DataSpaceVisitedEntity
163
+ | undefined;
164
+ if (hydrated) {
165
+ this.setQueryableDataSpace({
166
+ groupId: hydrated.visited.groupId,
167
+ artifactId: hydrated.visited.artifactId,
168
+ versionId: hydrated.visited.versionId ?? LATEST_VERSION_ALIAS,
169
+ dataSpacePath: hydrated.visited.path,
170
+ executionContext: hydrated.entity.content
171
+ .defaultExecutionContext as string,
172
+ });
173
+ }
174
+ }
175
+ super.initialize();
110
176
  }
111
177
 
112
178
  async initializeQueryBuilderState(): Promise<QueryBuilderState> {
179
+ if (this.queryableDataSpace) {
180
+ return this.initializeQueryBuilderStateWithQueryableDataSpace(
181
+ this.queryableDataSpace,
182
+ );
183
+ } else {
184
+ const queryBuilderState = new DataSpaceQuerySetupState(
185
+ this,
186
+ this.applicationStore,
187
+ this.graphManagerState,
188
+ this.depotServerClient,
189
+ (dataSpaceInfo: DataSpaceInfo) => {
190
+ if (dataSpaceInfo.defaultExecutionContext) {
191
+ this.changeDataSpace(dataSpaceInfo);
192
+ } else {
193
+ this.applicationStore.notificationService.notifyWarning(
194
+ `Can't switch data space: default execution context not specified`,
195
+ );
196
+ }
197
+ },
198
+ createViewProjectHandler(this.applicationStore),
199
+ createViewSDLCProjectHandler(
200
+ this.applicationStore,
201
+ this.depotServerClient,
202
+ ),
203
+ this.applicationStore.config.options.queryBuilderConfig,
204
+ );
205
+ if (this.dataSpaceCache?.length) {
206
+ queryBuilderState.configureDataSpaceOptions(this.dataSpaceCache);
207
+ }
208
+ return queryBuilderState;
209
+ }
210
+ }
211
+
212
+ async redirectIfPossible(): Promise<DataSpaceVisitedEntity | undefined> {
213
+ const visitedQueries =
214
+ LegendQueryUserDataHelper.getRecentlyVisitedDataSpaces(
215
+ this.applicationStore.userDataService,
216
+ );
217
+ let redirect: DataSpaceVisitedEntity | undefined = undefined;
218
+ for (let i = 0; i < visitedQueries.length; i++) {
219
+ const visited = visitedQueries[i];
220
+ if (visited) {
221
+ const hydrated = await this.hyrdateVisitedDataSpace(visited);
222
+ if (hydrated) {
223
+ redirect = hydrated;
224
+ break;
225
+ }
226
+ }
227
+ }
228
+ return redirect;
229
+ }
230
+
231
+ async hyrdateVisitedDataSpace(
232
+ visited: VisitedDataspace,
233
+ ): Promise<DataSpaceVisitedEntity | undefined> {
234
+ try {
235
+ const entity = (await this.depotServerClient.getVersionEntity(
236
+ visited.groupId,
237
+ visited.artifactId,
238
+ visited.versionId ?? LATEST_VERSION_ALIAS,
239
+ visited.path,
240
+ )) as unknown as Entity;
241
+ const content = entity.content as {
242
+ executionContexts: { name: string }[];
243
+ };
244
+ if (visited.execContext) {
245
+ const found = content.executionContexts.find(
246
+ (e) => e.name === visited.execContext,
247
+ );
248
+ if (!found) {
249
+ visited.execContext = undefined;
250
+ return {
251
+ visited,
252
+ entity,
253
+ };
254
+ }
255
+ }
256
+ return {
257
+ visited,
258
+ entity,
259
+ };
260
+ } catch (error) {
261
+ assertErrorThrown(error);
262
+ LegendQueryUserDataHelper.removeRecentlyViewedDataSpace(
263
+ this.applicationStore.userDataService,
264
+ visited.id,
265
+ );
266
+ }
267
+ return undefined;
268
+ }
269
+
270
+ async initializeQueryBuilderStateWithQueryableDataSpace(
271
+ queryableDataSpace: QueryableDataSpace,
272
+ ): Promise<QueryBuilderState> {
113
273
  const dataSpace = getDataSpace(
114
- this.dataSpacePath,
274
+ queryableDataSpace.dataSpacePath,
115
275
  this.graphManagerState.graph,
116
276
  );
117
277
  const executionContext = guaranteeNonNullable(
118
278
  dataSpace.executionContexts.find(
119
- (context) => context.name === this.executionContext,
279
+ (context) => context.name === queryableDataSpace.executionContext,
120
280
  ),
121
- `Can't find execution context '${this.executionContext}'`,
281
+ `Can't find execution context '${queryableDataSpace.executionContext}'`,
122
282
  );
123
283
  let dataSpaceAnalysisResult;
124
284
  try {
125
285
  const project = StoreProjectData.serialization.fromJson(
126
- await this.depotServerClient.getProject(this.groupId, this.artifactId),
286
+ await this.depotServerClient.getProject(
287
+ queryableDataSpace.groupId,
288
+ queryableDataSpace.artifactId,
289
+ ),
127
290
  );
128
291
  dataSpaceAnalysisResult = await DSL_DataSpace_getGraphManagerExtension(
129
292
  this.graphManagerState.graphManager,
130
293
  ).retrieveDataSpaceAnalysisFromCache(() =>
131
294
  retrieveAnalyticsResultCache(
132
295
  project,
133
- this.versionId,
296
+ queryableDataSpace.versionId,
134
297
  dataSpace.path,
135
298
  this.depotServerClient,
136
299
  ),
@@ -138,20 +301,10 @@ export class DataSpaceQueryCreatorStore extends QueryEditorStore {
138
301
  } catch {
139
302
  // do nothing
140
303
  }
141
- const projectInfo = new DataSpaceProjectInfo(
142
- this.groupId,
143
- this.artifactId,
144
- this.versionId,
145
- createViewProjectHandler(this.applicationStore),
146
- createViewSDLCProjectHandler(
147
- this.applicationStore,
148
- this.depotServerClient,
149
- ),
150
- );
151
304
  const sourceInfo = {
152
- groupId: projectInfo.groupId,
153
- artifactId: projectInfo.artifactId,
154
- versionId: projectInfo.versionId,
305
+ groupId: queryableDataSpace.groupId,
306
+ artifactId: queryableDataSpace.artifactId,
307
+ versionId: queryableDataSpace.versionId,
155
308
  dataSpace: dataSpace.path,
156
309
  };
157
310
  const visitedDataSpaces =
@@ -161,142 +314,112 @@ export class DataSpaceQueryCreatorStore extends QueryEditorStore {
161
314
  const queryBuilderState = new DataSpaceQueryBuilderState(
162
315
  this.applicationStore,
163
316
  this.graphManagerState,
164
- this.depotServerClient,
165
317
  QueryBuilderDataBrowserWorkflow.INSTANCE,
166
318
  new QueryBuilderActionConfig_QueryApplication(this),
167
319
  dataSpace,
168
320
  executionContext,
321
+ createDataSpaceDepoRepo(
322
+ this,
323
+ queryableDataSpace.groupId,
324
+ queryableDataSpace.artifactId,
325
+ queryableDataSpace.versionId,
326
+ (dataSpaceInfo: DataSpaceInfo) =>
327
+ hasDataSpaceInfoBeenVisited(dataSpaceInfo, visitedDataSpaces),
328
+ ),
169
329
  (dataSpaceInfo: DataSpaceInfo) => {
170
- if (dataSpaceInfo.defaultExecutionContext) {
171
- this.applicationStore.navigationService.navigator.goToLocation(
172
- generateDataSpaceQueryCreatorRoute(
173
- guaranteeNonNullable(dataSpaceInfo.groupId),
174
- guaranteeNonNullable(dataSpaceInfo.artifactId),
175
- LATEST_VERSION_ALIAS, //always default to latest
176
- dataSpaceInfo.path,
177
- dataSpaceInfo.defaultExecutionContext,
178
- undefined,
179
- undefined,
180
- ),
181
- );
182
- } else {
183
- this.applicationStore.notificationService.notifyWarning(
184
- `Can't switch data space: default execution context not specified`,
185
- );
186
- }
330
+ flowResult(this.changeDataSpace(dataSpaceInfo)).catch(
331
+ this.applicationStore.alertUnhandledError,
332
+ );
187
333
  },
188
- true,
189
334
  dataSpaceAnalysisResult,
190
335
  (ec: DataSpaceExecutionContext) => {
191
- // runtime should already be set
192
- const runtimePointer = guaranteeType(
193
- queryBuilderState.executionContextState.runtimeValue,
194
- RuntimePointer,
195
- );
196
- this.applicationStore.navigationService.navigator.updateCurrentLocation(
197
- generateDataSpaceQueryCreatorRoute(
198
- this.groupId,
199
- this.artifactId,
200
- this.versionId,
201
- dataSpace.path,
202
- ec.name,
203
- runtimePointer.packageableRuntime.value ===
204
- queryBuilderState.executionContext.defaultRuntime.value
205
- ? undefined
206
- : runtimePointer.packageableRuntime.value.path,
207
- queryBuilderState.class?.path,
208
- ),
209
- );
210
336
  returnUndefOnError(() =>
211
337
  LegendQueryUserDataHelper.updateVisitedDataSpaceExecContext(
212
338
  this.applicationStore.userDataService,
213
- this.groupId,
214
- this.artifactId,
339
+ queryableDataSpace.groupId,
340
+ queryableDataSpace.artifactId,
215
341
  dataSpace.path,
216
342
  ec.name,
217
343
  ),
218
344
  );
219
345
  },
220
- (runtimeValue: Runtime) => {
221
- const runtimePointer = guaranteeType(runtimeValue, RuntimePointer);
222
- queryBuilderState.applicationStore.navigationService.navigator.updateCurrentLocation(
223
- generateDataSpaceQueryCreatorRoute(
224
- guaranteeNonNullable(queryBuilderState.projectInfo).groupId,
225
- guaranteeNonNullable(queryBuilderState.projectInfo).artifactId,
226
- guaranteeNonNullable(queryBuilderState.projectInfo).versionId,
227
- queryBuilderState.dataSpace.path,
228
- queryBuilderState.executionContext.name,
229
- runtimePointer.packageableRuntime.value ===
230
- queryBuilderState.executionContext.defaultRuntime.value
231
- ? undefined
232
- : runtimePointer.packageableRuntime.value.path,
233
- queryBuilderState.class?.path,
234
- ),
235
- );
236
- },
237
- (_class: Class) => {
238
- // runtime should already be set
239
- const runtimePointer = guaranteeType(
240
- queryBuilderState.executionContextState.runtimeValue,
241
- RuntimePointer,
242
- );
243
- queryBuilderState.applicationStore.navigationService.navigator.updateCurrentLocation(
244
- generateDataSpaceQueryCreatorRoute(
245
- guaranteeNonNullable(queryBuilderState.projectInfo).groupId,
246
- guaranteeNonNullable(queryBuilderState.projectInfo).artifactId,
247
- guaranteeNonNullable(queryBuilderState.projectInfo).versionId,
248
- queryBuilderState.dataSpace.path,
249
- queryBuilderState.executionContext.name,
250
- runtimePointer.packageableRuntime.value ===
251
- queryBuilderState.executionContext.defaultRuntime.value
252
- ? undefined
253
- : runtimePointer.packageableRuntime.value.path,
254
- _class.path,
255
- ),
256
- );
257
- },
258
- projectInfo,
346
+ undefined,
347
+ undefined,
259
348
  this.applicationStore.config.options.queryBuilderConfig,
260
349
  sourceInfo,
261
- (dataSpaceInfo: DataSpaceInfo) =>
262
- hasDataSpaceInfoBeenVisited(dataSpaceInfo, visitedDataSpaces),
263
350
  );
351
+ if (this.dataSpaceCache?.length) {
352
+ queryBuilderState.dataSpaceRepo.configureDataSpaceOptions(
353
+ this.dataSpaceCache,
354
+ );
355
+ }
264
356
  queryBuilderState.setExecutionContext(executionContext);
265
357
  queryBuilderState.propagateExecutionContextChange(executionContext);
266
358
 
267
359
  // set runtime if already chosen
268
- if (this.runtimePath) {
360
+ if (queryableDataSpace.runtimePath) {
269
361
  queryBuilderState.changeRuntime(
270
362
  new RuntimePointer(
271
363
  PackageableElementExplicitReference.create(
272
- this.graphManagerState.graph.getRuntime(this.runtimePath),
364
+ this.graphManagerState.graph.getRuntime(
365
+ queryableDataSpace.runtimePath,
366
+ ),
273
367
  ),
274
368
  ),
275
369
  );
276
370
  }
277
371
 
278
372
  // set class if already chosen
279
- if (this.classPath) {
373
+ if (queryableDataSpace.classPath) {
280
374
  queryBuilderState.changeClass(
281
- this.graphManagerState.graph.getClass(this.classPath),
375
+ this.graphManagerState.graph.getClass(queryableDataSpace.classPath),
282
376
  );
283
377
  }
284
378
 
285
379
  // add to visited dataspaces
286
- this.addVisitedDataSpace(executionContext.name);
380
+ this.addVisitedDataSpace(queryableDataSpace);
287
381
  return queryBuilderState;
288
382
  }
289
383
 
290
- addVisitedDataSpace(execName: string | undefined): void {
384
+ *changeDataSpace(val: DataSpaceInfo): GeneratorFn<void> {
385
+ try {
386
+ assertTrue(
387
+ this.reConfigureWithDataSpaceInfo(val),
388
+ 'Dataspace selected does not contain valid inputs, groupId, artifactId, and version',
389
+ );
390
+ this.initState.inProgress();
391
+ if (
392
+ this.queryBuilderState instanceof DataSpaceQueryBuilderState &&
393
+ this.queryBuilderState.dataSpaceRepo.dataSpaces?.length
394
+ ) {
395
+ this.setDataSpaceCache(this.queryBuilderState.dataSpaceRepo.dataSpaces);
396
+ }
397
+ this.graphManagerState.resetGraph();
398
+ yield flowResult(this.buildGraph());
399
+ this.queryBuilderState =
400
+ (yield this.initializeQueryBuilderState()) as DataSpaceQueryBuilderState;
401
+ this.queryLoaderState.initialize(this.queryBuilderState);
402
+ this.initState.pass();
403
+ } catch (error) {
404
+ assertErrorThrown(error);
405
+ this.applicationStore.notificationService.notify(
406
+ `Unable to change dataspace: ${error.message}`,
407
+ );
408
+ this.onInitializeFailure();
409
+ this.initState.fail();
410
+ }
411
+ }
412
+
413
+ addVisitedDataSpace(queryableDataSpace: QueryableDataSpace): void {
291
414
  try {
292
415
  LegendQueryUserDataHelper.addVisitedDatspace(
293
416
  this.applicationStore.userDataService,
294
417
  createSimpleVisitedDataspace(
295
- this.groupId,
296
- this.artifactId,
297
- this.versionId,
298
- this.dataSpacePath,
299
- execName,
418
+ queryableDataSpace.groupId,
419
+ queryableDataSpace.artifactId,
420
+ queryableDataSpace.versionId,
421
+ queryableDataSpace.dataSpacePath,
422
+ queryableDataSpace.executionContext,
300
423
  ),
301
424
  );
302
425
  } catch (error) {
@@ -311,35 +434,41 @@ export class DataSpaceQueryCreatorStore extends QueryEditorStore {
311
434
  getPersistConfiguration(
312
435
  lambda: RawLambda,
313
436
  options?: { update?: boolean | undefined },
314
- ): QueryPersistConfiguration {
315
- return {
316
- defaultName: options?.update
317
- ? `${extractElementNameFromPath(this.dataSpacePath)}`
318
- : `New Query for ${extractElementNameFromPath(this.dataSpacePath)}[${
319
- this.executionContext
320
- }]`,
321
- decorator: (query: Query): void => {
322
- query.id = uuid();
323
- query.groupId = this.groupId;
324
- query.artifactId = this.artifactId;
325
- query.versionId = this.versionId;
326
- if (this.queryBuilderState?.class) {
327
- query.taggedValues = [
328
- createQueryClassTaggedValue(this.queryBuilderState.class.path),
329
- ];
330
- }
331
- },
332
- };
437
+ ): QueryPersistConfiguration | undefined {
438
+ const queryableDataSpace = this.queryableDataSpace;
439
+ if (queryableDataSpace) {
440
+ return {
441
+ defaultName: options?.update
442
+ ? `${extractElementNameFromPath(queryableDataSpace.dataSpacePath)}`
443
+ : `New Query for ${extractElementNameFromPath(queryableDataSpace.dataSpacePath)}[${
444
+ queryableDataSpace.executionContext
445
+ }]`,
446
+ decorator: (query: Query): void => {
447
+ query.id = uuid();
448
+ query.groupId = queryableDataSpace.groupId;
449
+ query.artifactId = queryableDataSpace.artifactId;
450
+ query.versionId = queryableDataSpace.versionId;
451
+ if (this.queryBuilderState?.class) {
452
+ query.taggedValues = [
453
+ createQueryClassTaggedValue(this.queryBuilderState.class.path),
454
+ ];
455
+ }
456
+ },
457
+ };
458
+ }
459
+ return undefined;
333
460
  }
334
461
 
335
462
  override onInitializeFailure(): void {
336
- LegendQueryUserDataHelper.removeRecentlyViewedDataSpace(
337
- this.applicationStore.userDataService,
338
- createVisitedDataSpaceId(
339
- this.groupId,
340
- this.artifactId,
341
- this.dataSpacePath,
342
- ),
343
- );
463
+ if (this.queryableDataSpace) {
464
+ LegendQueryUserDataHelper.removeRecentlyViewedDataSpace(
465
+ this.applicationStore.userDataService,
466
+ createVisitedDataSpaceId(
467
+ this.queryableDataSpace.groupId,
468
+ this.queryableDataSpace.artifactId,
469
+ this.queryableDataSpace.dataSpacePath,
470
+ ),
471
+ );
472
+ }
344
473
  }
345
474
  }