@finos/legend-application-studio
Version:
Legend Studio application core
112 lines • 8.9 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } 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 { observer } from 'mobx-react-lite';
import { useEditorStore } from '../../EditorStoreProvider.js';
import { CheckCircleIcon, CopyIcon, Dialog, Modal, ModalBody, ModalFooter, ModalFooterButton, ModalHeader, ModalTitle, PanelContent, PanelHeader, PanelHeaderActions, RocketIcon, } from '@finos/legend-art';
import { generateUrlToDeployOnOpen, IngestDefinitionEditorState, } from '../../../../stores/editor/editor-state/element-editor-state/ingest/IngestDefinitionEditorState.js';
import { CodeEditor } from '@finos/legend-lego/code-editor';
import React, { useEffect } from 'react';
import { CODE_EDITOR_LANGUAGE } from '@finos/legend-code-editor';
import { flowResult } from 'mobx';
import { useAuth } from 'react-oidc-context';
import { IngestDefinitionDeploymentResponse, IngestDefinitionValidationResponse, } from '@finos/legend-server-lakehouse';
import { useApplicationNavigationContext } from '@finos/legend-application';
import { LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY } from '../../../../__lib__/LegendStudioApplicationNavigationContext.js';
const IngestValidationError = observer((props) => {
const { state, validateResponse } = props;
const applicationStore = state.editorStore.applicationStore;
const closeModal = () => state.setValidateAndDeployResponse(undefined);
return (_jsx(Dialog, { open: true, classes: {
root: 'editor-modal__root-container',
container: 'editor-modal__container',
paper: 'editor-modal__content',
}, onClose: closeModal, children: _jsxs(Modal, { darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, className: "editor-modal", children: [_jsx(ModalHeader, { children: _jsx(ModalTitle, { title: 'Validation Error' }) }), _jsx(ModalBody, { children: _jsx(PanelContent, { children: _jsx(CodeEditor, { inputValue: JSON.stringify(validateResponse, null, 2), isReadOnly: true, language: CODE_EDITOR_LANGUAGE.JSON }) }) }), _jsx(ModalFooter, { children: _jsx(ModalFooterButton, { onClick: closeModal, text: "Close", type: "secondary" }) })] }) }));
});
const IngestDeploymentResponseModal = observer((props) => {
const { closeModal, deploymentResponse, copyHandler } = props;
const copyURN = (text) => {
copyHandler(text, 'Ingest URN copied to clipboard');
};
return (_jsx(Dialog, { open: true, classes: {
root: 'ingestion-modal__root-container',
container: 'ingestion-modal__container',
paper: 'ingestion-modal__content',
}, children: _jsxs(Modal, { darkMode: true, className: "ingestion-modal", children: [_jsx(ModalHeader, { children: _jsx(ModalTitle, { icon: _jsx(CheckCircleIcon, { className: "ingestion-modal--success" }), title: "Deployment Response" }) }), _jsxs(ModalBody, { children: [_jsxs("div", { className: "ingestion-modal__urn", children: [_jsxs("div", { className: "ingestion-modal__urn__info", children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Deployment URN" }), _jsx("div", { className: "ingestion-modal__urn__value", children: deploymentResponse.ingestDefinitionUrn })] }), _jsx("div", { className: "ingestion-modal__urn__copy", children: _jsx("button", { className: "ingestion-modal__urn__copy--btn", tabIndex: -1, title: "Copy", onClick: () => {
copyURN(deploymentResponse.ingestDefinitionUrn);
}, children: _jsx(CopyIcon, {}) }) })] }), _jsxs("div", { className: "ingestion-modal__write", children: [_jsx("div", { className: "ingestion-modal__write__label", children: "Write Location" }), _jsx("div", { className: "ingestion-modal__write--value", children: deploymentResponse.write_location ? (_jsx(CodeEditor, { inputValue: JSON.stringify(deploymentResponse.write_location, null, 2), isReadOnly: true, language: CODE_EDITOR_LANGUAGE.JSON, extraEditorOptions: {
wordWrap: 'on',
}, hideActionBar: true })) : (_jsx("div", { className: "ingestion-modal__write--no-value", children: "No write location provided" })) })] })] }), _jsx(ModalFooter, { children: _jsx(ModalFooterButton, { onClick: closeModal, text: "Close", type: "secondary" }) })] }) }));
});
export const IngestDefinitionEditor = observer(() => {
const editorStore = useEditorStore();
const ingestDefinitionEditorState = editorStore.tabManagerState.getCurrentEditorState(IngestDefinitionEditorState);
const ingestDef = ingestDefinitionEditorState.ingest;
const auth = useAuth();
const deployIngest = () => {
// Trigger OAuth flow if not authenticated
if (!auth.isAuthenticated) {
// remove this redirect if we move to do oauth at the beginning of opening studio
auth
.signinRedirect({
state: generateUrlToDeployOnOpen(ingestDefinitionEditorState),
})
.catch(editorStore.applicationStore.alertUnhandledError);
return;
}
// Use the token for deployment
const token = auth.user?.access_token;
if (token) {
flowResult(ingestDefinitionEditorState.deploy(token)).catch(editorStore.applicationStore.alertUnhandledError);
}
else {
editorStore.applicationStore.notificationService.notifyError('Authentication failed. No token available.');
}
};
const renderDeploymentResponse = () => {
const response = ingestDefinitionEditorState.deploymentResponse;
if (response instanceof IngestDefinitionValidationResponse) {
return (_jsx(IngestValidationError, { state: ingestDefinitionEditorState, validateResponse: response }));
}
else if (response instanceof IngestDefinitionDeploymentResponse) {
const copyHanlder = (text, successMessage) => {
ingestDefinitionEditorState.editorStore.applicationStore.clipboardService
.copyTextToClipboard(text)
.then(() => ingestDefinitionEditorState.editorStore.applicationStore.notificationService.notifySuccess(successMessage, undefined, 2500))
.catch(ingestDefinitionEditorState.editorStore.applicationStore
.alertUnhandledError);
};
return (_jsx(IngestDeploymentResponseModal, { closeModal: () => ingestDefinitionEditorState.setValidateAndDeployResponse(undefined), deploymentResponse: response, copyHandler: copyHanlder }));
}
return null;
};
const isValid = ingestDefinitionEditorState.validForDeployment;
useEffect(() => {
ingestDefinitionEditorState.generateElementGrammar();
}, [ingestDefinitionEditorState]);
useApplicationNavigationContext(LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY.INGEST_DEFINITION_EDITOR);
useEffect(() => {
if (ingestDefinitionEditorState.deployOnOpen) {
flowResult(ingestDefinitionEditorState.init_with_deploy(auth)).catch(editorStore.applicationStore.alertUnhandledError);
}
}, [
auth,
editorStore.applicationStore.alertUnhandledError,
ingestDefinitionEditorState,
]);
return (_jsxs("div", { className: "data-product-editor", children: [_jsx(PanelHeader, { title: "Ingest", titleContent: ingestDef.name, darkMode: true, isReadOnly: true }), _jsxs(PanelContent, { children: [_jsx(PanelHeader, { title: "deployment", darkMode: true, children: _jsx(PanelHeaderActions, { children: _jsx("div", { className: "btn__dropdown-combo btn__dropdown-combo--primary", children: _jsxs("button", { className: "btn__dropdown-combo__label", onClick: deployIngest, title: ingestDefinitionEditorState.validationMessage, tabIndex: -1, disabled: !isValid, children: [_jsx(RocketIcon, { className: "btn__dropdown-combo__label__icon" }), _jsx("div", { className: "btn__dropdown-combo__label__title", children: "Deploy" })] }) }) }) }), _jsx(PanelContent, { children: _jsx(CodeEditor, { inputValue: ingestDefinitionEditorState.textContent, isReadOnly: true, language: CODE_EDITOR_LANGUAGE.PURE }) }), renderDeploymentResponse()] })] }));
});
//# sourceMappingURL=IngestDefinitionEditor.js.map