/** * 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 { useRef, useState, useEffect } from 'react'; import { observer } from 'mobx-react-lite'; import { ELEMENT_PATH_DELIMITER, resolvePackagePathAndElementName, Package, } from '@finos/legend-graph'; import type { ElementFileGenerationState } from '../../../../stores/editor/editor-state/element-editor-state/ElementFileGenerationState.js'; import type { ElementEditorState } from '../../../../stores/editor/editor-state/element-editor-state/ElementEditorState.js'; import { guaranteeType } from '@finos/legend-shared'; import { FileGenerationConfigurationEditor } from './FileGenerationEditor.js'; import { flowResult } from 'mobx'; import { Dialog, ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, ResizablePanelSplitterLine, ArrowCircleLeftIcon, } from '@finos/legend-art'; import { useEditorStore } from '../../EditorStoreProvider.js'; import { useApplicationStore } from '@finos/legend-application'; import { FileSystemViewer } from './FileSystemViewer.js'; const NewFileGenerationModal = observer( (props: { currentElementState: ElementEditorState; elementGenerationState: ElementFileGenerationState; }) => { const { elementGenerationState, currentElementState } = props; const applicationStore = useApplicationStore(); const isReadOnly = currentElementState.isReadOnly; const element = currentElementState.element; const mappingPackage = guaranteeType(element.package, Package); const nameRef = useRef(null); const editorStore = useEditorStore(); const defaultFileGenerationName = `${element.path}_${elementGenerationState.fileGenerationType}`; const [servicePath, setServicePath] = useState( defaultFileGenerationName, ); const [packagePath, serviceName] = resolvePackagePathAndElementName( servicePath, mappingPackage.path, ); const close = (): void => elementGenerationState.setShowNewFileGenerationModal(false); const handleEnter = (): void => nameRef.current?.focus(); const elementAlreadyExists = editorStore.graphManagerState.graph.allOwnElements .map((el) => el.path) .includes(packagePath + ELEMENT_PATH_DELIMITER + serviceName); const promoteToFileGeneration = async (): Promise => { if (servicePath && !isReadOnly && !elementAlreadyExists) { await flowResult( elementGenerationState.promoteToFileGeneration( packagePath, serviceName, ), ); close(); } }; const changeValue: React.ChangeEventHandler = (event) => setServicePath(event.target.value); return (
{ event.preventDefault(); promoteToFileGeneration().catch( applicationStore.alertUnhandledError, ); }} className="modal search-modal modal--dark" >
Promote file generation specification
{elementAlreadyExists && (
Element with same path already exists
)}
); }, ); export const ElementGenerationEditor = observer( (props: { currentElementState: ElementEditorState; elementGenerationState: ElementFileGenerationState; }) => { const { elementGenerationState, currentElementState } = props; const applicationStore = useApplicationStore(); const isReadOnly = currentElementState.isReadOnly; const leaveElementGenerationView = (): void => currentElementState.setGenerationModeState(undefined); useEffect(() => { flowResult(elementGenerationState.regenerate()).catch( applicationStore.alertUnhandledError, ); }, [applicationStore, currentElementState, elementGenerationState]); return (
); }, );