@finos/legend-studio
Version:
65 lines • 2.49 kB
JavaScript
/**
* 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 { DataElement, } from '@finos/legend-graph';
import { guaranteeType, uuid } from '@finos/legend-shared';
import { action, computed, makeObservable, observable } from 'mobx';
import { ElementEditorState } from '../ElementEditorState.js';
import { buildEmbeddedDataEditorState, } from './EmbeddedDataState.js';
export var DATA_TAB_TYPE;
(function (DATA_TAB_TYPE) {
DATA_TAB_TYPE["GENERAL"] = "GENERAL";
DATA_TAB_TYPE["STEREOTYPES"] = "STEREOTYPES";
DATA_TAB_TYPE["TAGGED_VALUES"] = "TAGGED_VALUES";
})(DATA_TAB_TYPE = DATA_TAB_TYPE || (DATA_TAB_TYPE = {}));
export class EmbeddedDataEditorState {
/**
* NOTE: used to force component remount on state change
*/
uuid = uuid();
editorStore;
embeddedData;
embeddedDataState;
constructor(editorStore, embeddedData) {
this.editorStore = editorStore;
this.embeddedData = embeddedData;
this.embeddedDataState = buildEmbeddedDataEditorState(embeddedData, editorStore);
}
}
export class PackageableDataEditorState extends ElementEditorState {
embeddedDataState;
selectedTab = DATA_TAB_TYPE.GENERAL;
constructor(editorStore, element) {
super(editorStore, element);
makeObservable(this, {
data: computed,
selectedTab: observable,
setSelectedTab: action,
reprocess: action,
});
this.embeddedDataState = new EmbeddedDataEditorState(editorStore, this.data.data);
}
setSelectedTab(val) {
this.selectedTab = val;
}
get data() {
return guaranteeType(this.element, DataElement, `Element inside data editor state must be a DataElement`);
}
reprocess(newElement, editorStore) {
const editorState = new PackageableDataEditorState(editorStore, newElement);
return editorState;
}
}
//# sourceMappingURL=DataEditorState.js.map