diff --git a/.changeset/dull-pandas-unite.md b/.changeset/dull-pandas-unite.md new file mode 100644 index 0000000000..4a64bbf878 --- /dev/null +++ b/.changeset/dull-pandas-unite.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-graph': patch +--- + +Change ordering of usable elements to own, system, dependency except for types/profiles. \ No newline at end of file diff --git a/.changeset/dull-pandas-united.md b/.changeset/dull-pandas-united.md new file mode 100644 index 0000000000..9a3a0da634 --- /dev/null +++ b/.changeset/dull-pandas-united.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-extension-dsl-data-space': minor +--- + +Use dataSpace `elements` to filter on explorer classes. diff --git a/packages/legend-extension-dsl-data-space/src/components/query/DataSpaceQueryBuilder.tsx b/packages/legend-extension-dsl-data-space/src/components/query/DataSpaceQueryBuilder.tsx index 827e3cd6b7..7e64d41f96 100644 --- a/packages/legend-extension-dsl-data-space/src/components/query/DataSpaceQueryBuilder.tsx +++ b/packages/legend-extension-dsl-data-space/src/components/query/DataSpaceQueryBuilder.tsx @@ -38,17 +38,30 @@ import { } from '@finos/legend-query-builder'; import { type Runtime, + type GraphManagerState, + type Mapping, getMappingCompatibleClasses, getMappingCompatibleRuntimes, PackageableElementExplicitReference, RuntimePointer, + Class, + Package, + getDescendantsOfPackage, } from '@finos/legend-graph'; import type { DataSpaceInfo } from '../../stores/query/DataSpaceInfo.js'; import { generateGAVCoordinates } from '@finos/legend-storage'; import { useEffect, useMemo, useState } from 'react'; -import { debounce, guaranteeType } from '@finos/legend-shared'; +import { + debounce, + filterByType, + guaranteeType, + uniq, +} from '@finos/legend-shared'; import { flowResult } from 'mobx'; -import type { DataSpaceExecutionContext } from '../../graph/metamodel/pure/model/packageableElements/dataSpace/DSL_DataSpace_DataSpace.js'; +import type { + DataSpace, + DataSpaceExecutionContext, +} from '../../graph/metamodel/pure/model/packageableElements/dataSpace/DSL_DataSpace_DataSpace.js'; import { DataSpaceIcon } from '../DSL_DataSpace_Icon.js'; import { DataSpaceAdvancedSearchModal } from './DataSpaceAdvancedSearchModal.js'; @@ -89,6 +102,25 @@ export const formatDataSpaceOptionLabel = ( ); +const resolveDataSpaceClasses = ( + dataSpace: DataSpace, + mapping: Mapping, + graphManagerState: GraphManagerState, +): Class[] => { + if (dataSpace.elements?.length) { + const dataSpaceElements = dataSpace.elements.map((ep) => ep.element.value); + return uniq([ + ...dataSpaceElements.filter(filterByType(Class)), + ...dataSpaceElements + .filter(filterByType(Package)) + .map((_package) => Array.from(getDescendantsOfPackage(_package))) + .flat() + .filter(filterByType(Class)), + ]); + } + return getMappingCompatibleClasses(mapping, graphManagerState.usableClasses); +}; + type ExecutionContextOption = { label: string; value: DataSpaceExecutionContext; @@ -204,9 +236,10 @@ const DataSpaceQueryBuilderSetupPanelContent = observer( }); // class - const classes = getMappingCompatibleClasses( + const classes = resolveDataSpaceClasses( + queryBuilderState.dataSpace, queryBuilderState.executionContext.mapping.value, - queryBuilderState.graphManagerState.usableClasses, + queryBuilderState.graphManagerState, ); useEffect(() => { diff --git a/packages/legend-graph/src/graph-manager/GraphManagerState.ts b/packages/legend-graph/src/graph-manager/GraphManagerState.ts index 09e0028862..353120ffe0 100644 --- a/packages/legend-graph/src/graph-manager/GraphManagerState.ts +++ b/packages/legend-graph/src/graph-manager/GraphManagerState.ts @@ -159,7 +159,11 @@ export class GraphManagerState extends BasicGraphManagerState { this.pluginManager.getPureGraphPlugins(), ); } - + /** + * NOTE: for all elements the ordering of usable elements will be own elements, system elements, dependency elements. + * Exception is made for types and profiles where we will show primitive and system elements first as those will be + * leveraged most by users + */ get usableClassPropertyTypes(): Type[] { return [ ...this.graph.primitiveTypes.filter( @@ -179,147 +183,147 @@ export class GraphManagerState extends BasicGraphManagerState { ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownProfiles, ), - ...this.graph.dependencyManager.profiles, ...this.graph.ownProfiles, + ...this.graph.dependencyManager.profiles, ]; } get usableEnumerations(): Enumeration[] { return [ + ...this.graph.ownEnumerations, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownEnumerations, ), ...this.graph.dependencyManager.enumerations, - ...this.graph.ownEnumerations, ]; } get usableMeasures(): Measure[] { return [ + ...this.graph.ownMeasures, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownMeasures, ), ...this.graph.dependencyManager.measures, - ...this.graph.ownMeasures, ]; } get usableClasses(): Class[] { return [ + ...this.graph.ownClasses, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownClasses, ), ...this.graph.dependencyManager.classes, - ...this.graph.ownClasses, ]; } get usableAssociationPropertyClasses(): Class[] { - return [...this.graph.dependencyManager.classes, ...this.graph.ownClasses]; + return [...this.graph.ownClasses, ...this.graph.dependencyManager.classes]; } get usableAssociations(): Association[] { return [ + ...this.graph.ownAssociations, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownAssociations, ), ...this.graph.dependencyManager.associations, - ...this.graph.ownAssociations, ]; } get usableFunctions(): ConcreteFunctionDefinition[] { return [ + ...this.graph.ownFunctions, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownFunctions, ), ...this.graph.dependencyManager.functions, - ...this.graph.ownFunctions, ]; } get usableStores(): Store[] { return [ + ...this.graph.ownStores, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownStores, ), ...this.graph.dependencyManager.stores, - ...this.graph.ownStores, ]; } get usableDatabases(): Database[] { return [ + ...this.graph.ownDatabases, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownDatabases, ), ...this.graph.dependencyManager.databases, - ...this.graph.ownDatabases, ]; } get usableMappings(): Mapping[] { return [ + ...this.graph.ownMappings, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownMappings, ), ...this.graph.dependencyManager.mappings, - ...this.graph.ownMappings, ]; } get usableServices(): Service[] { return [ + ...this.graph.ownServices, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownServices, ), ...this.graph.dependencyManager.services, - ...this.graph.ownServices, ]; } get usableRuntimes(): PackageableRuntime[] { return [ + ...this.graph.ownRuntimes, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownRuntimes, ), ...this.graph.dependencyManager.runtimes, - ...this.graph.ownRuntimes, ]; } get usableConnections(): PackageableConnection[] { return [ + ...this.graph.ownConnections, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownConnections, ), ...this.graph.dependencyManager.connections, - ...this.graph.ownConnections, ]; } get usableDataElements(): DataElement[] { return [ + ...this.graph.ownDataElements, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownDataElements, ), ...this.graph.dependencyManager.dataElements, - ...this.graph.ownDataElements, ]; } get usableGenerationSpecifications(): GenerationSpecification[] { return [ + ...this.graph.ownGenerationSpecifications, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownGenerationSpecifications, ), ...this.graph.dependencyManager.generationSpecifications, - ...this.graph.ownGenerationSpecifications, ]; } get usableFileGenerations(): FileGenerationSpecification[] { return [ + ...this.graph.ownFileGenerations, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.ownFileGenerations, ), ...this.graph.dependencyManager.fileGenerations, - ...this.graph.ownFileGenerations, ]; } get usableElements(): PackageableElement[] { return [ + ...this.graph.ownMeasures, ...this.graphManager.collectExposedSystemElements( this.graph.systemModel.allOwnElements, ), ...this.graph.dependencyManager.allOwnElements, - ...this.graph.ownMeasures, ]; } }