@finos/legend-extension-external-language-morphir
Version:
Legend extension for Morphir external language
110 lines • 5.94 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
/**
* 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 packageJson from '../../package.json';
import { LegendStudioApplicationPlugin, } from '@finos/legend-application-studio';
import { NetworkClient, guaranteeNonEmptyString, assertErrorThrown, } from '@finos/legend-shared';
import { ConcreteFunctionDefinition, } from '@finos/legend-graph';
const MORPHIR_TYPE_NAME = `morphir`;
export class ELMorphir_LegendStudioApplicationPlugin extends LegendStudioApplicationPlugin {
networkClient;
_morphirVisualizerUrl;
_linterServerUrl;
_linterAppUrl;
constructor() {
super(packageJson.extensions.applicationStudioPlugin, packageJson.version);
this.networkClient = new NetworkClient();
}
configure(_configData) {
const configData = _configData;
this._morphirVisualizerUrl = guaranteeNonEmptyString(configData.visualizer.url, `Can't configure Morphir generator: 'visualizer.url' field is missing or empty`);
this._linterServerUrl = guaranteeNonEmptyString(configData.linterServer.url, `Can't configure Morphir generator: 'linterServer.url' field is missing or empty`);
this._linterAppUrl = guaranteeNonEmptyString(configData.linterApp.url, `Can't configure Morphir generator: 'linterApp.url' field is missing or empty`);
return this;
}
get morphirVisualizerUrl() {
return guaranteeNonEmptyString(this._morphirVisualizerUrl, `Morphir visualizer URL has not been configured`);
}
get linterServerUrl() {
return guaranteeNonEmptyString(this._linterServerUrl, `Morphir linter server URL has not been configured`);
}
get linterAppUrl() {
return guaranteeNonEmptyString(this._linterAppUrl, `Morphir linter application URL has not been configured`);
}
getExtraFileGenerationResultViewerActionConfigurations() {
return [
{
key: 'visualize-morphir-IR-action',
renderer: (fileGenerationState) => {
const fileNode = fileGenerationState.selectedNode
?.fileNode;
const applicationStore = fileGenerationState.editorStore.applicationStore;
const visualizeMorphir = (file) => async () => {
try {
await this.networkClient.post(this.morphirVisualizerUrl, file.content);
applicationStore.navigator.openNewWindow(this.morphirVisualizerUrl);
}
catch (error) {
assertErrorThrown(error);
applicationStore.notifyError(error);
}
};
if (fileGenerationState.fileGeneration.type.toLowerCase() ===
MORPHIR_TYPE_NAME) {
return (_jsx("div", { className: "panel__header__title__content generation-result-viewer__file__header__action", children: _jsx("button", { className: "panel__content__form__section__list__new-item__add-btn btn btn--dark", onClick: visualizeMorphir(fileNode), tabIndex: -1, children: "Visualize Generated IR" }) }));
}
return undefined;
},
},
{
key: 'view-bosque-feedback-action',
renderer: (fileGenerationState) => {
const fileNode = fileGenerationState.selectedNode
?.fileNode;
const applicationStore = fileGenerationState.editorStore.applicationStore;
const visualizeBosque = (fileGenState, file) => async () => {
try {
const code = fileGenState.editorStore.graphManagerState.graphManager.graphToPureCode(fileGenState.editorStore.graphManagerState.graph);
await this.networkClient.post(this.linterServerUrl, {
ir: file.content,
src: await code,
});
applicationStore.navigator.openNewWindow(this.linterAppUrl);
}
catch (error) {
assertErrorThrown(error);
applicationStore.notifyError(error);
}
};
if (fileGenerationState.fileGeneration.type.toLowerCase() ===
MORPHIR_TYPE_NAME) {
return (_jsx("div", { className: "panel__header__title__content generation-result-viewer__file__header__action", children: _jsx("button", { className: "panel__content__form__section__list__new-item__add-btn btn btn--dark", onClick: visualizeBosque(fileGenerationState, fileNode), tabIndex: -1, children: "View Bosque Feedback" }) }));
}
return undefined;
},
},
];
}
getExtraFileGenerationScopeFilterConfigurations() {
return [
{
type: MORPHIR_TYPE_NAME,
filter: (packageableElement) => packageableElement instanceof ConcreteFunctionDefinition,
},
];
}
}
//# sourceMappingURL=ELMorphir_LegendStudioApplicationPlugin.js.map