@finos/legend-extension-dsl-data-space 10.4.2 → 10.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. package/lib/components/DSL_DataSpace_LegendApplicationPlugin.d.ts +1 -1
  2. package/lib/components/DSL_DataSpace_LegendApplicationPlugin.d.ts.map +1 -1
  3. package/lib/components/DSL_DataSpace_LegendApplicationPlugin.js +3 -4
  4. package/lib/components/DSL_DataSpace_LegendApplicationPlugin.js.map +1 -1
  5. package/lib/components/query-builder/DataSpaceQueryBuilder.d.ts.map +1 -1
  6. package/lib/components/query-builder/DataSpaceQueryBuilder.js +6 -20
  7. package/lib/components/query-builder/DataSpaceQueryBuilder.js.map +1 -1
  8. package/lib/components/query-builder/DataSpaceQueryBuilderTemplateQueryPanelContent.js +1 -1
  9. package/lib/components/query-builder/DataSpaceQueryBuilderTemplateQueryPanelContent.js.map +1 -1
  10. package/lib/graph-manager/index.d.ts +0 -1
  11. package/lib/graph-manager/index.d.ts.map +1 -1
  12. package/lib/graph-manager/index.js +0 -1
  13. package/lib/graph-manager/index.js.map +1 -1
  14. package/lib/graph-manager/protocol/pure/DSL_DataSpace_PureGraphManagerExtension.d.ts +2 -6
  15. package/lib/graph-manager/protocol/pure/DSL_DataSpace_PureGraphManagerExtension.d.ts.map +1 -1
  16. package/lib/graph-manager/protocol/pure/DSL_DataSpace_PureGraphManagerExtension.js.map +1 -1
  17. package/lib/graph-manager/protocol/pure/v1/V1_DSL_DataSpace_PureGraphManagerExtension.d.ts +3 -15
  18. package/lib/graph-manager/protocol/pure/v1/V1_DSL_DataSpace_PureGraphManagerExtension.d.ts.map +1 -1
  19. package/lib/graph-manager/protocol/pure/v1/V1_DSL_DataSpace_PureGraphManagerExtension.js +48 -185
  20. package/lib/graph-manager/protocol/pure/v1/V1_DSL_DataSpace_PureGraphManagerExtension.js.map +1 -1
  21. package/lib/index.css +1 -1
  22. package/lib/package.json +1 -1
  23. package/lib/stores/query-builder/DataSpaceQueryBuilderState.d.ts +11 -5
  24. package/lib/stores/query-builder/DataSpaceQueryBuilderState.d.ts.map +1 -1
  25. package/lib/stores/query-builder/DataSpaceQueryBuilderState.js +30 -19
  26. package/lib/stores/query-builder/DataSpaceQueryBuilderState.js.map +1 -1
  27. package/package.json +6 -6
  28. package/src/components/DSL_DataSpace_LegendApplicationPlugin.tsx +8 -6
  29. package/src/components/query-builder/DataSpaceQueryBuilder.tsx +9 -40
  30. package/src/components/query-builder/DataSpaceQueryBuilderTemplateQueryPanelContent.tsx +1 -1
  31. package/src/graph-manager/index.ts +0 -4
  32. package/src/graph-manager/protocol/pure/DSL_DataSpace_PureGraphManagerExtension.ts +1 -19
  33. package/src/graph-manager/protocol/pure/v1/V1_DSL_DataSpace_PureGraphManagerExtension.ts +79 -359
  34. package/src/stores/query-builder/DataSpaceQueryBuilderState.ts +40 -32
@@ -19,8 +19,6 @@ import {
19
19
  type AbstractPureGraphManager,
20
20
  type PureProtocolProcessorPlugin,
21
21
  type MappingModelCoverageAnalysisResult,
22
- type GraphManagerOperationReport,
23
- type FunctionAnalysisInfo,
24
22
  PureModel,
25
23
  V1_PureGraphManager,
26
24
  PureClientVersion,
@@ -38,13 +36,8 @@ import {
38
36
  V1_deserializePackageableElement,
39
37
  QueryDataSpaceExecutionContextInfo,
40
38
  V1_RemoteEngine,
41
- LegendSDLC,
42
- PackageableElementPointerType,
43
- V1_PackageableElementPointer,
44
- V1_ConcreteFunctionDefinition,
45
- V1_buildFunctionInfoAnalysis,
46
39
  } from '@finos/legend-graph';
47
- import type { Entity, ProjectGAVCoordinates } from '@finos/legend-storage';
40
+ import type { Entity } from '@finos/legend-storage';
48
41
  import {
49
42
  type PlainObject,
50
43
  ActionState,
@@ -63,7 +56,6 @@ import {
63
56
  } from '../../../../graph/metamodel/pure/model/packageableElements/dataSpace/DSL_DataSpace_DataSpace.js';
64
57
  import {
65
58
  V1_DataSpace,
66
- V1_DataSpaceExecutionContext,
67
59
  V1_DataSpaceSupportCombinedInfo,
68
60
  V1_DataSpaceSupportEmail,
69
61
  V1_DataSpaceTemplateExecutable,
@@ -104,7 +96,6 @@ import {
104
96
  V1_DataSpaceFunctionPointerExecutableInfo,
105
97
  } from './engine/analytics/V1_DataSpaceAnalysis.js';
106
98
  import { getDiagram } from '@finos/legend-extension-dsl-diagram/graph';
107
- import { resolveVersion } from '@finos/legend-server-depot';
108
99
 
109
100
  const ANALYZE_DATA_SPACE_TRACE = 'analyze data space';
110
101
  const TEMPORARY__TDS_SAMPLE_VALUES__DELIMETER = '-- e.g.';
@@ -228,112 +219,6 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
228
219
  );
229
220
  }
230
221
 
231
- retrieveExecutionContextFromTemplateQueryId(
232
- dataSpaceAnalysisResult: PlainObject<V1_DataSpaceAnalysisResult>,
233
- templateQueryId: string,
234
- plugins: PureProtocolProcessorPlugin[],
235
- ): string | undefined {
236
- const analysisResult = V1_deserializeDataSpaceAnalysisResult(
237
- dataSpaceAnalysisResult,
238
- plugins,
239
- );
240
- let execContext = undefined;
241
- const info = analysisResult.executables.find(
242
- (ex) => ex.info?.id === templateQueryId,
243
- )?.info;
244
- if (info) {
245
- execContext =
246
- info.executionContextKey ?? analysisResult.defaultExecutionContext;
247
- }
248
- return execContext;
249
- }
250
-
251
- async analyzeDataSpaceCoverage(
252
- dataSpacePath: string,
253
- entitiesRetriever: () => Promise<Entity[]>,
254
- entitiesWithClassifierRetriever: () => Promise<
255
- [PlainObject<Entity>[], PlainObject<Entity>[]]
256
- >,
257
- cacheRetriever?: () => Promise<PlainObject<DataSpaceAnalysisResult>>,
258
- actionState?: ActionState,
259
- graphReport?: GraphManagerOperationReport | undefined,
260
- pureGraph?: PureModel | undefined,
261
- executionContext?: string | undefined,
262
- mappingPath?: string | undefined,
263
- projectInfo?: ProjectGAVCoordinates,
264
- templateQueryId?: string,
265
- ): Promise<DataSpaceAnalysisResult> {
266
- const cacheResult = cacheRetriever
267
- ? await this.fetchDataSpaceAnalysisFromCache(cacheRetriever, actionState)
268
- : undefined;
269
- const engineClient = guaranteeType(
270
- this.graphManager.engine,
271
- V1_RemoteEngine,
272
- 'analyzeDataSpaceCoverage is only supported by remote engine',
273
- ).getEngineServerClient();
274
- let analysisResult: PlainObject<V1_DataSpaceAnalysisResult>;
275
- let cachedAnalysisResult;
276
- if (cacheResult) {
277
- cachedAnalysisResult = V1_deserializeDataSpaceAnalysisResult(
278
- cacheResult,
279
- this.graphManager.pluginManager.getPureProtocolProcessorPlugins(),
280
- );
281
- }
282
- if (
283
- cacheResult &&
284
- cachedAnalysisResult?.executionContexts.every(
285
- (e) =>
286
- e.mappingModelCoverageAnalysisResult?.model !== undefined ||
287
- cachedAnalysisResult.mappingToMappingCoverageResult?.get(e.mapping)
288
- ?.model !== undefined,
289
- )
290
- ) {
291
- analysisResult = cacheResult;
292
- } else {
293
- actionState?.setMessage('Fetching project entities and dependencies...');
294
- const entities = await entitiesRetriever();
295
- actionState?.setMessage('Analyzing data space...');
296
- analysisResult = await engineClient.postWithTracing<
297
- PlainObject<V1_DataSpaceAnalysisResult>
298
- >(
299
- engineClient.getTraceData(ANALYZE_DATA_SPACE_TRACE),
300
- `${engineClient._pure()}/analytics/dataSpace/coverage`,
301
- {
302
- clientVersion: V1_PureGraphManager.DEV_PROTOCOL_VERSION,
303
- dataSpace: dataSpacePath,
304
- model: {
305
- _type: V1_PureModelContextType.DATA,
306
- elements: entities.map((entity) => entity.content),
307
- },
308
- },
309
- {},
310
- undefined,
311
- undefined,
312
- { enableCompression: true },
313
- );
314
- }
315
- const plugins =
316
- this.graphManager.pluginManager.getPureProtocolProcessorPlugins();
317
- return this.buildDataSpaceAnalytics(
318
- analysisResult,
319
- plugins,
320
- graphReport,
321
- pureGraph,
322
- executionContext
323
- ? executionContext
324
- : templateQueryId
325
- ? this.retrieveExecutionContextFromTemplateQueryId(
326
- analysisResult,
327
- templateQueryId,
328
- plugins,
329
- )
330
- : undefined,
331
- mappingPath,
332
- projectInfo,
333
- entitiesWithClassifierRetriever,
334
- );
335
- }
336
-
337
222
  async retrieveDataSpaceAnalysisFromCache(
338
223
  cacheRetriever: () => Promise<PlainObject<DataSpaceAnalysisResult>>,
339
224
  actionState?: ActionState,
@@ -370,78 +255,11 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
370
255
  return cacheResult;
371
256
  }
372
257
 
373
- // build function analysis info by fetching functions within this project from metadata when building minimal graph
374
- async processFunctionForMinimalGraph(
375
- entitiesWithClassifierRetriever: () => Promise<
376
- [PlainObject<Entity>[], PlainObject<Entity>[]]
377
- >,
378
- graph: PureModel,
379
- dataSpaceAnalysisResult: DataSpaceAnalysisResult,
380
- plugins: PureProtocolProcessorPlugin[],
381
- ): Promise<void> {
382
- const [functionEntities, dependencyFunctionEntities]: [
383
- PlainObject<Entity>[],
384
- PlainObject<Entity>[],
385
- ] = await entitiesWithClassifierRetriever();
386
- const functionProtocols = functionEntities.map((func) =>
387
- guaranteeType(
388
- V1_deserializePackageableElement(
389
- (func.entity as Entity).content,
390
- plugins,
391
- ),
392
- V1_ConcreteFunctionDefinition,
393
- ),
394
- );
395
- const dependencyFunctionProtocols = dependencyFunctionEntities.map((func) =>
396
- guaranteeType(
397
- V1_deserializePackageableElement(
398
- (func.entity as Entity).content,
399
- plugins,
400
- ),
401
- V1_ConcreteFunctionDefinition,
402
- ),
403
- );
404
- const functionInfos = V1_buildFunctionInfoAnalysis(
405
- functionProtocols,
406
- graph,
407
- );
408
- const dependencyFunctionInfos = V1_buildFunctionInfoAnalysis(
409
- dependencyFunctionProtocols,
410
- graph,
411
- );
412
- if (functionInfos.length > 0) {
413
- const functionInfoMap = new Map<string, FunctionAnalysisInfo>();
414
- functionInfos.forEach((funcInfo) => {
415
- functionInfoMap.set(funcInfo.functionPath, funcInfo);
416
- });
417
- dataSpaceAnalysisResult.functionInfos = functionInfoMap;
418
- }
419
- if (dependencyFunctionInfos.length > 0) {
420
- const dependencyFunctionInfoMap = new Map<string, FunctionAnalysisInfo>();
421
- functionInfos.forEach((funcInfo) => {
422
- dependencyFunctionInfoMap.set(funcInfo.functionPath, funcInfo);
423
- });
424
- dataSpaceAnalysisResult.dependencyFunctionInfos =
425
- dependencyFunctionInfoMap;
426
- }
427
- }
428
-
429
258
  async buildDataSpaceAnalytics(
430
- analytics: PlainObject<V1_DataSpaceAnalysisResult>,
259
+ json: PlainObject<V1_DataSpaceAnalysisResult>,
431
260
  plugins: PureProtocolProcessorPlugin[],
432
- graphReport?: GraphManagerOperationReport | undefined,
433
- pureGraph?: PureModel | undefined,
434
- executionContext?: string | undefined,
435
- mappingPath?: string | undefined,
436
- projectInfo?: ProjectGAVCoordinates,
437
- entitiesWithClassifierRetriever?: () => Promise<
438
- [PlainObject<Entity>[], PlainObject<Entity>[]]
439
- >,
440
261
  ): Promise<DataSpaceAnalysisResult> {
441
- const analysisResult = V1_deserializeDataSpaceAnalysisResult(
442
- analytics,
443
- plugins,
444
- );
262
+ const analysisResult = V1_deserializeDataSpaceAnalysisResult(json, plugins);
445
263
  const result = new DataSpaceAnalysisResult();
446
264
  result.name = analysisResult.name;
447
265
  result.package = analysisResult.package;
@@ -488,30 +306,26 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
488
306
  // NOTE: we will relax the check and not throw here for unknown support info type
489
307
  }
490
308
 
491
- let graphEntities;
492
- let graph: PureModel;
493
- let minialGraph = false;
494
- if (pureGraph) {
495
- graph = pureGraph;
496
- } else {
497
- // create an empty graph
498
- const extensionElementClasses =
499
- this.graphManager.pluginManager.getPureGraphPlugins();
500
- const systemModel = new SystemModel(extensionElementClasses);
501
- const coreModel = new CoreModel(extensionElementClasses);
502
- await this.graphManager.buildSystem(
503
- coreModel,
504
- systemModel,
505
- ActionState.create(),
506
- {},
507
- );
508
- systemModel.initializeAutoImports();
509
- graph = new PureModel(
510
- coreModel,
511
- systemModel,
512
- this.graphManager.pluginManager.getPureGraphPlugins(),
513
- );
514
- }
309
+ // create an empty graph
310
+ const systemModel = new SystemModel(
311
+ this.graphManager.pluginManager.getPureGraphPlugins(),
312
+ );
313
+ const coreModel = new CoreModel(
314
+ this.graphManager.pluginManager.getPureGraphPlugins(),
315
+ );
316
+ await this.graphManager.buildSystem(
317
+ coreModel,
318
+ systemModel,
319
+ ActionState.create(),
320
+ {},
321
+ );
322
+ systemModel.initializeAutoImports();
323
+ const graph = new PureModel(
324
+ coreModel,
325
+ systemModel,
326
+ this.graphManager.pluginManager.getPureGraphPlugins(),
327
+ );
328
+
515
329
  // Create dummy mappings and runtimes
516
330
  // TODO?: these stubbed mappings and runtimes are not really useful that useful, so either we should
517
331
  // simplify the model here or potentially refactor the backend analytics endpoint to return these as model
@@ -541,142 +355,55 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
541
355
  return runtime;
542
356
  });
543
357
 
544
- // The DataSpace entity is excluded from AnalyticsResult.Json to reduce the JSON size
545
- // because all its information can be found in V1_DataSpaceAnalysisResult.
546
- // Therefore, we are building a simple v1_DataSpace entity based on V1_DataSpaceAnalysisResult.
547
- const dataspaceEntity = new V1_DataSpace();
548
- dataspaceEntity.name = analysisResult.name;
549
- dataspaceEntity.package = analysisResult.package;
550
- dataspaceEntity.supportInfo = analysisResult.supportInfo;
551
- dataspaceEntity.executionContexts = analysisResult.executionContexts.map(
552
- (execContext) => {
553
- const contextProtocol = new V1_DataSpaceExecutionContext();
554
- contextProtocol.name = execContext.name;
555
- contextProtocol.title = execContext.title;
556
- contextProtocol.description = execContext.description;
557
- contextProtocol.mapping = new V1_PackageableElementPointer(
558
- PackageableElementPointerType.MAPPING,
559
- execContext.mapping,
560
- );
561
- contextProtocol.defaultRuntime = new V1_PackageableElementPointer(
562
- PackageableElementPointerType.RUNTIME,
563
- execContext.defaultRuntime,
564
- );
565
- return contextProtocol;
566
- },
567
- );
568
- dataspaceEntity.defaultExecutionContext =
569
- analysisResult.defaultExecutionContext;
570
- dataspaceEntity.title = analysisResult.title;
571
- dataspaceEntity.description = analysisResult.description;
572
-
573
- const resolvedMappingPath =
574
- mappingPath ??
575
- analysisResult.executionContexts.find(
576
- (value) =>
577
- value.name ===
578
- (executionContext ?? analysisResult.defaultExecutionContext),
579
- )?.mapping;
580
- let pmcd;
581
- if (resolvedMappingPath) {
582
- const mappingModelCoverageAnalysisResult =
583
- analysisResult.mappingToMappingCoverageResult?.get(resolvedMappingPath);
584
- pmcd = mappingModelCoverageAnalysisResult?.model;
585
- }
586
- if (pmcd && projectInfo) {
587
- graphEntities = pmcd.elements
588
- .concat(mappingModels)
589
- .concat(runtimeModels)
590
- .concat(dataspaceEntity)
591
- // NOTE: if an element could be found in the graph already it means it comes from system
592
- // so we could rid of it
593
- .filter((el) => !graph.getNullableElement(el.path, false))
594
- .map((el) => this.graphManager.elementProtocolToEntity(el));
595
- await this.graphManager.buildGraph(
596
- graph,
597
- graphEntities,
598
- ActionState.create(),
599
- {
600
- origin: new LegendSDLC(
601
- projectInfo.groupId,
602
- projectInfo.artifactId,
603
- resolveVersion(projectInfo.versionId),
604
- ),
605
- },
606
- graphReport,
607
- );
608
- if (entitiesWithClassifierRetriever) {
609
- try {
610
- await this.processFunctionForMinimalGraph(
611
- entitiesWithClassifierRetriever,
612
- graph,
613
- result,
614
- plugins,
615
- );
616
- } catch {
617
- //do nothing
618
- }
619
- }
620
- minialGraph = true;
621
- } else {
622
- const elements = analysisResult.model.elements
623
- // NOTE: this is a temporary hack to fix a problem with data space analytics
624
- // where the classes for properties are not properly surveyed
625
- // We need to wait for the actual fix in backend to be merged and released
626
- // See https://github.com/finos/legend-engine/pull/836
627
- .concat(
628
- uniq(
629
- analysisResult.model.elements.flatMap((element) => {
630
- if (element instanceof V1_Class) {
631
- return element.derivedProperties
632
- .map((prop) => prop.returnType)
633
- .concat(element.properties.map((prop) => prop.type));
634
- }
635
- return [];
636
- }),
637
- )
638
- // make sure to not include types already returned by the analysis
639
- .filter(
640
- (path) =>
641
- !analysisResult.model.elements
642
- .map((el) => el.path)
643
- .includes(path),
644
- )
645
- .map((path) => {
646
- const [pkgPath, name] = resolvePackagePathAndElementName(path);
647
- if (!pkgPath) {
648
- // exclude package-less elements (i.e. primitive types)
649
- return undefined;
650
- }
651
- const _class = new V1_Class();
652
- _class.name = name;
653
- _class.package = pkgPath;
654
- return _class;
655
- })
656
- .filter(isNonNullable),
358
+ // prepare the model context data
359
+ const graphEntities = analysisResult.model.elements
360
+ // NOTE: this is a temporary hack to fix a problem with data space analytics
361
+ // where the classes for properties are not properly surveyed
362
+ // We need to wait for the actual fix in backend to be merged and released
363
+ // See https://github.com/finos/legend-engine/pull/836
364
+ .concat(
365
+ uniq(
366
+ analysisResult.model.elements.flatMap((element) => {
367
+ if (element instanceof V1_Class) {
368
+ return element.derivedProperties
369
+ .map((prop) => prop.returnType)
370
+ .concat(element.properties.map((prop) => prop.type));
371
+ }
372
+ return [];
373
+ }),
657
374
  )
658
- .concat(mappingModels)
659
- .concat(runtimeModels);
660
- const alreadyContainsDataspace = elements.find(
661
- (e) => e.path === dataspaceEntity.path,
662
- );
663
- let allElements = elements;
664
- if (!alreadyContainsDataspace) {
665
- allElements = elements.concat(dataspaceEntity);
666
- }
667
- // prepare the model context data
668
- graphEntities = allElements
669
- // NOTE: if an element could be found in the graph already it means it comes from system
670
- // so we could rid of it
671
- .filter((el) => !graph.getNullableElement(el.path, false))
672
- .map((el) => this.graphManager.elementProtocolToEntity(el));
673
-
674
- await this.graphManager.buildGraph(
675
- graph,
676
- graphEntities,
677
- ActionState.create(),
678
- );
679
- }
375
+ // make sure to not include types already returned by the analysis
376
+ .filter(
377
+ (path) =>
378
+ !analysisResult.model.elements
379
+ .map((el) => el.path)
380
+ .includes(path),
381
+ )
382
+ .map((path) => {
383
+ const [pkgPath, name] = resolvePackagePathAndElementName(path);
384
+ if (!pkgPath) {
385
+ // exclude package-less elements (i.e. primitive types)
386
+ return undefined;
387
+ }
388
+ const _class = new V1_Class();
389
+ _class.name = name;
390
+ _class.package = pkgPath;
391
+ return _class;
392
+ })
393
+ .filter(isNonNullable),
394
+ )
395
+ .concat(mappingModels)
396
+ .concat(runtimeModels)
397
+ // NOTE: if an element could be found in the graph already it means it comes from system
398
+ // so we could rid of it
399
+ .filter((el) => !graph.getNullableElement(el.path, false))
400
+ .map((el) => this.graphManager.elementProtocolToEntity(el));
401
+
402
+ await this.graphManager.buildGraph(
403
+ graph,
404
+ graphEntities,
405
+ ActionState.create(),
406
+ );
680
407
 
681
408
  const mappingToMappingCoverageResult = new Map<
682
409
  string,
@@ -687,11 +414,7 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
687
414
  ([key, value]) => {
688
415
  mappingToMappingCoverageResult.set(
689
416
  key,
690
- V1_buildModelCoverageAnalysisResult(
691
- value,
692
- this.graphManager,
693
- graph.getMapping(key),
694
- ),
417
+ V1_buildModelCoverageAnalysisResult(value, graph.getMapping(key)),
695
418
  );
696
419
  },
697
420
  );
@@ -732,7 +455,6 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
732
455
  context.mapping,
733
456
  V1_buildModelCoverageAnalysisResult(
734
457
  context.mappingModelCoverageAnalysisResult,
735
- this.graphManager,
736
458
  contextAnalysisResult.mapping,
737
459
  ),
738
460
  );
@@ -864,15 +586,13 @@ export class V1_DSL_DataSpace_PureGraphManagerExtension extends DSL_DataSpace_Pu
864
586
  });
865
587
 
866
588
  // diagrams
867
- result.diagrams = (minialGraph ? [] : analysisResult.diagrams).map(
868
- (diagramProtocol) => {
869
- const diagram = new DataSpaceDiagramAnalysisResult();
870
- diagram.title = diagramProtocol.title;
871
- diagram.description = diagramProtocol.description;
872
- diagram.diagram = getDiagram(diagramProtocol.diagram, graph);
873
- return diagram;
874
- },
875
- );
589
+ result.diagrams = analysisResult.diagrams.map((diagramProtocol) => {
590
+ const diagram = new DataSpaceDiagramAnalysisResult();
591
+ diagram.title = diagramProtocol.title;
592
+ diagram.description = diagramProtocol.description;
593
+ diagram.diagram = getDiagram(diagramProtocol.diagram, graph);
594
+ return diagram;
595
+ });
876
596
 
877
597
  // executables
878
598
  result.executables = analysisResult.executables.map(
@@ -34,6 +34,7 @@ import {
34
34
  Package,
35
35
  QueryDataSpaceExecutionContext,
36
36
  elementBelongsToPackage,
37
+ RuntimePointer,
37
38
  } from '@finos/legend-graph';
38
39
  import {
39
40
  type DepotServerClient,
@@ -46,6 +47,7 @@ import {
46
47
  ActionState,
47
48
  assertErrorThrown,
48
49
  filterByType,
50
+ getNullableFirstEntry,
49
51
  } from '@finos/legend-shared';
50
52
  import { action, flow, makeObservable, observable } from 'mobx';
51
53
  import { renderDataSpaceQueryBuilderSetupPanelContent } from '../../components/query-builder/DataSpaceQueryBuilder.js';
@@ -86,34 +88,11 @@ export const resolveUsableDataSpaceClasses = (
86
88
  dataSpace: DataSpace,
87
89
  mapping: Mapping,
88
90
  graphManagerState: GraphManagerState,
89
- queryBuilderState?: DataSpaceQueryBuilderState,
90
91
  ): Class[] => {
91
- let compatibleClasses = getMappingCompatibleClasses(
92
+ const compatibleClasses = getMappingCompatibleClasses(
92
93
  mapping,
93
94
  graphManagerState.usableClasses,
94
95
  );
95
- const mappingModelCoverageAnalysisResult =
96
- queryBuilderState?.dataSpaceAnalysisResult?.mappingToMappingCoverageResult?.get(
97
- mapping.path,
98
- );
99
- if (
100
- // This check is to make sure that we have `info` field present in `MappedEntity` which
101
- // contains information about the mapped class path
102
- mappingModelCoverageAnalysisResult?.mappedEntities.some(
103
- (m) => m.info !== undefined,
104
- )
105
- ) {
106
- const compatibleClassPaths =
107
- mappingModelCoverageAnalysisResult.mappedEntities.map(
108
- (e) => e.info?.classPath,
109
- );
110
- const uniqueCompatibleClasses = compatibleClassPaths.filter(
111
- (val, index) => compatibleClassPaths.indexOf(val) === index,
112
- );
113
- compatibleClasses = graphManagerState.graph.classes.filter((c) =>
114
- uniqueCompatibleClasses.includes(c.path),
115
- );
116
- }
117
96
  if (dataSpace.elements?.length) {
118
97
  const elements = dataSpace.elements;
119
98
  return compatibleClasses.filter((_class) => {
@@ -356,7 +335,7 @@ export class DataSpacesDepotRepository extends DataSpacesBuilderRepoistory {
356
335
  }
357
336
 
358
337
  export class DataSpaceQueryBuilderState extends QueryBuilderState {
359
- readonly onDataSpaceChange: (val: DataSpaceInfo) => Promise<void>;
338
+ readonly onDataSpaceChange: (val: DataSpaceInfo) => void;
360
339
  readonly onExecutionContextChange?:
361
340
  | ((val: DataSpaceExecutionContext) => void)
362
341
  | undefined;
@@ -372,7 +351,6 @@ export class DataSpaceQueryBuilderState extends QueryBuilderState {
372
351
  executionContext!: DataSpaceExecutionContext;
373
352
  showRuntimeSelector = false;
374
353
  isTemplateQueryDialogOpen = false;
375
- isLightGraphEnabled!: boolean;
376
354
  displayedTemplateQueries: DataSpaceExecutableAnalysisResult[] | undefined;
377
355
 
378
356
  constructor(
@@ -382,9 +360,8 @@ export class DataSpaceQueryBuilderState extends QueryBuilderState {
382
360
  actionConfig: QueryBuilderActionConfig,
383
361
  dataSpace: DataSpace,
384
362
  executionContext: DataSpaceExecutionContext,
385
- isLightGraphEnabled: boolean,
386
363
  dataSpaceRepo: DataSpacesBuilderRepoistory | undefined,
387
- onDataSpaceChange: (val: DataSpaceInfo) => Promise<void>,
364
+ onDataSpaceChange: (val: DataSpaceInfo) => void,
388
365
  dataSpaceAnalysisResult?: DataSpaceAnalysisResult | undefined,
389
366
  onExecutionContextChange?:
390
367
  | ((val: DataSpaceExecutionContext) => void)
@@ -400,12 +377,10 @@ export class DataSpaceQueryBuilderState extends QueryBuilderState {
400
377
  executionContext: observable,
401
378
  showRuntimeSelector: observable,
402
379
  isTemplateQueryDialogOpen: observable,
403
- isLightGraphEnabled: observable,
404
380
  displayedTemplateQueries: observable,
405
381
  setExecutionContext: action,
406
382
  setShowRuntimeSelector: action,
407
383
  setTemplateQueryDialogOpen: action,
408
- setIsLightGraphEnabled: action,
409
384
  intialize: flow,
410
385
  });
411
386
 
@@ -450,8 +425,41 @@ export class DataSpaceQueryBuilderState extends QueryBuilderState {
450
425
  this.showRuntimeSelector = val;
451
426
  }
452
427
 
453
- setIsLightGraphEnabled(val: boolean): void {
454
- this.isLightGraphEnabled = val;
428
+ /**
429
+ * Propagation after changing the execution context:
430
+ * - The mapping will be updated to the mapping of the execution context
431
+ * - The runtime will be updated to the default runtime of the execution context
432
+ * - If no class is chosen, try to choose a compatible class
433
+ * - If the chosen class is compatible with the new selected execution context mapping, do nothing, otherwise, try to choose a compatible class
434
+ */
435
+ propagateExecutionContextChange(
436
+ executionContext: DataSpaceExecutionContext,
437
+ ): void {
438
+ const mapping = executionContext.mapping.value;
439
+ this.changeMapping(mapping);
440
+ const mappingModelCoverageAnalysisResult =
441
+ this.dataSpaceAnalysisResult?.mappingToMappingCoverageResult?.get(
442
+ mapping.path,
443
+ );
444
+ if (mappingModelCoverageAnalysisResult) {
445
+ this.explorerState.mappingModelCoverageAnalysisResult =
446
+ mappingModelCoverageAnalysisResult;
447
+ }
448
+ this.changeRuntime(new RuntimePointer(executionContext.defaultRuntime));
449
+
450
+ const compatibleClasses = resolveUsableDataSpaceClasses(
451
+ this.dataSpace,
452
+ mapping,
453
+ this.graphManagerState,
454
+ );
455
+ // if there is no chosen class or the chosen one is not compatible
456
+ // with the mapping then pick a compatible class if possible
457
+ if (!this.class || !compatibleClasses.includes(this.class)) {
458
+ const possibleNewClass = getNullableFirstEntry(compatibleClasses);
459
+ if (possibleNewClass) {
460
+ this.changeClass(possibleNewClass);
461
+ }
462
+ }
455
463
  }
456
464
 
457
465
  override buildFunctionAnalysisInfo():