UNPKG

@finos/legend-extension-dsl-data-space-studio

Version:
88 lines 4.02 kB
/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { action, computed, makeObservable, observable } from 'mobx'; import { ElementEditorState, } from '@finos/legend-application-studio'; import { Package, Class, Enumeration, Association, Service, ConcreteFunctionDefinition, } from '@finos/legend-graph'; import { Diagram } from '@finos/legend-extension-dsl-diagram/graph'; import { DataSpace, DataSpacePackageableElementExecutable, } from '@finos/legend-extension-dsl-data-space/graph'; import { guaranteeType } from '@finos/legend-shared'; import { DataSpaceExecutionContextState } from './DataSpaceExecutionContextState.js'; export class DataSpaceEditorState extends ElementEditorState { executionContextState; constructor(editorStore, element) { super(editorStore, element); makeObservable(this, { executionContextState: observable, dataSpace: computed, reprocess: action, isValidDataSpaceElement: action, getDataSpaceElementOptions: action, getDiagramOptions: action, getDataSpaceExecutableOptions: action, }); this.executionContextState = new DataSpaceExecutionContextState(this); } isValidDataSpaceElement(element) { return (element instanceof Package || element instanceof Class || element instanceof Enumeration || element instanceof Association); } getDataSpaceElementOptions() { const currentElements = this.dataSpace.elements?.map((elementPointer) => elementPointer.element.value) ?? []; return this.editorStore.graphManagerState.graph.allOwnElements .filter((element) => this.isValidDataSpaceElement(element)) .filter((element) => !currentElements.includes(element)) .map((element) => ({ label: element.path, value: element, })); } getDataSpaceExecutableOptions() { const currentExecutables = this.dataSpace.executables?.map((executablePointer) => { if (executablePointer instanceof DataSpacePackageableElementExecutable) { return executablePointer.executable.value; } return undefined; }) ?? []; return this.editorStore.graphManagerState.graph.allOwnElements .filter((element) => element instanceof Service || element instanceof ConcreteFunctionDefinition) .filter((executable) => !currentExecutables.includes(executable)) .map((executable) => ({ label: executable.path, value: executable, })); } getDiagramOptions() { const currentDiagrams = this.dataSpace.diagrams?.map((diagramPointer) => diagramPointer.diagram.value) ?? []; return this.editorStore.graphManagerState.graph.allOwnElements .filter((element) => element instanceof Diagram) .filter((diagram) => !currentDiagrams.includes(diagram)) .map((diagram) => ({ label: diagram.path, value: diagram, })); } get dataSpace() { return guaranteeType(this.element, DataSpace, 'Element inside DataSpace editor state must be a DataSpace element'); } reprocess(newElement, editorStore) { const newState = new DataSpaceEditorState(editorStore, newElement); return newState; } } //# sourceMappingURL=DataSpaceEditorState.js.map