UNPKG

@finos/legend-studio

Version:
76 lines 3.41 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 { observable, computed, action, makeObservable } from 'mobx'; import { guaranteeType } from '@finos/legend-shared'; import { UnsupportedServiceExecutionState, SingleServicePureExecutionState, MultiServicePureExecutionState, } from './ServiceExecutionState.js'; import { ServiceRegistrationState } from '../../../editor-state/element-editor-state/service/ServiceRegistrationState.js'; import { ElementEditorState } from '../../../editor-state/element-editor-state/ElementEditorState.js'; import { Service, PureSingleExecution, PureMultiExecution, } from '@finos/legend-graph'; import { ServiceTestableState } from './testable/ServiceTestableState.js'; export var SERVICE_TAB; (function (SERVICE_TAB) { SERVICE_TAB["GENERAL"] = "GENERAL"; SERVICE_TAB["EXECUTION"] = "EXECUTION"; SERVICE_TAB["TEST"] = "TEST"; SERVICE_TAB["REGISTRATION"] = "REGISTRATION"; })(SERVICE_TAB = SERVICE_TAB || (SERVICE_TAB = {})); export const MINIMUM_SERVICE_OWNERS = 2; export class ServiceEditorState extends ElementEditorState { executionState; registrationState; testableState; selectedTab = SERVICE_TAB.GENERAL; constructor(editorStore, element) { super(editorStore, element); makeObservable(this, { executionState: observable, registrationState: observable, selectedTab: observable, setSelectedTab: action, resetExecutionState: action, service: computed, reprocess: action, }); this.executionState = this.buildExecutionState(); this.registrationState = new ServiceRegistrationState(editorStore, this); this.testableState = new ServiceTestableState(editorStore, this); } setSelectedTab(tab) { this.selectedTab = tab; } resetExecutionState() { this.executionState = this.buildExecutionState(); } buildExecutionState() { const execution = this.service.execution; if (execution instanceof PureSingleExecution) { return new SingleServicePureExecutionState(this.editorStore, this, execution); } else if (execution instanceof PureMultiExecution) { return new MultiServicePureExecutionState(this.editorStore, this, execution); } return new UnsupportedServiceExecutionState(this.editorStore, this, this.service.execution); } get service() { return guaranteeType(this.element, Service, 'Element inside service editor state must be a service'); } reprocess(newElement, editorStore) { const serviceEditorState = new ServiceEditorState(editorStore, newElement); serviceEditorState.selectedTab = this.selectedTab; return serviceEditorState; } } //# sourceMappingURL=ServiceEditorState.js.map