@finos/legend-studio
Version:
74 lines • 3.27 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 { assertErrorThrown, guaranteeNonNullable, LogEvent, ActionState, } from '@finos/legend-shared';
import { flow, action, makeObservable, observable } from 'mobx';
import { LEGEND_STUDIO_APP_EVENT } from '../LegendStudioAppEvent.js';
export var EmbeddedDataType;
(function (EmbeddedDataType) {
EmbeddedDataType["EXTERNAL_FORMAT_DATA"] = "EXTERNAL_FORMAT";
EmbeddedDataType["MODEL_STORE_DATA"] = "MODEL_STORE";
EmbeddedDataType["RELATIONAL_CSV"] = "RELATIONAL";
EmbeddedDataType["DATA_ELEMENT"] = "DATA_ELEMENT";
})(EmbeddedDataType = EmbeddedDataType || (EmbeddedDataType = {}));
export class ExternalFormatState {
fetchingDescriptionsState = ActionState.create();
editorStore;
externalFormatsDescriptions = [];
constructor(editorStore) {
makeObservable(this, {
externalFormatsDescriptions: observable,
setExternalFormatsDescriptions: action,
fetchExternalFormatsDescriptions: flow,
});
this.editorStore = editorStore;
}
get formatTypes() {
return this.externalFormatsDescriptions.map((e) => e.name);
}
get formatTypeOptions() {
return this.externalFormatsDescriptions.map((e) => ({
value: e.name,
label: e.name,
}));
}
getFormatTypeForContentType(contentType) {
return this.externalFormatsDescriptions.find((externalFormatDescription) => externalFormatDescription.contentTypes[0] === contentType)?.name;
}
get formatContentTypes() {
return this.externalFormatsDescriptions.map((e) => e.contentTypes).flat();
}
setExternalFormatsDescriptions(externalFormatsDescriptions) {
this.externalFormatsDescriptions = externalFormatsDescriptions;
}
*fetchExternalFormatsDescriptions() {
try {
this.fetchingDescriptionsState.inProgress();
const externalFormatDescriptions = (yield this.editorStore.graphManagerState.graphManager.getAvailableExternalFormatsDescriptions());
this.setExternalFormatsDescriptions(externalFormatDescriptions);
this.fetchingDescriptionsState.complete();
}
catch (error) {
assertErrorThrown(error);
this.editorStore.applicationStore.log.error(LogEvent.create(LEGEND_STUDIO_APP_EVENT.EXTERNAL_FORMAT_FAILURE), error);
this.editorStore.applicationStore.notifyError(error);
this.fetchingDescriptionsState.fail();
}
}
getTypeDescription(type) {
return guaranteeNonNullable(this.externalFormatsDescriptions.find((e) => e.name === type));
}
}
//# sourceMappingURL=ExternalFormatState.js.map