/** * 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 { useApplicationStore } from '@finos/legend-application'; import { ArrowCircleLeftIcon, PanelContent, PanelHeader, PanelHeaderActionItem, PanelHeaderActions, RefreshIcon, ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, ResizablePanelSplitterLine, } from '@finos/legend-art'; import type { GenerationProperty } from '@finos/legend-graph'; import { debounce } from '@finos/legend-shared'; import { flowResult } from 'mobx'; import { observer } from 'mobx-react-lite'; import { useEffect, useMemo } from 'react'; import type { ElementEditorState } from '../../../../stores/editor/editor-state/element-editor-state/ElementEditorState.js'; import type { ElementXTSchemaGenerationState } from '../../../../stores/editor/editor-state/element-editor-state/ElementExternalFormatGenerationState.js'; import { ModelUnitEditor } from '../external-format-editor/DSL_ExternalFormat_BindingElementEditor.js'; import { GenerationPropertyEditor } from './FileGenerationEditor.js'; import { FileSystemViewer } from './FileSystemViewer.js'; enum HIDDEN_CONFIGURATION_PROPERTIES { FORMAT = 'format', TARGET_SCHEMA_SET = 'targetSchemaSet', } export const ExternalFormatGeneratioConfigEditor = observer( (props: { isReadOnly: boolean; elementEditorState: ElementEditorState; xtState: ElementXTSchemaGenerationState; }) => { const { isReadOnly, xtState } = props; const xtGenerationState = xtState.xtGenerationState; const editorStore = xtState.editorStore; const applicationStore = editorStore.applicationStore; const configSpecification = xtState.xtGenerationState.configSpecification; const schemaGenerationProperties = xtState.description.schemaGenerationProperties; const debouncedRegenerate = useMemo( () => debounce(() => flowResult(xtState.xtGenerationState.generate()), 500), [xtState], ); const update = ( generationProperty: GenerationProperty, newValue: object, ): void => { debouncedRegenerate.cancel(); xtGenerationState.updateFileGenerationParameters( configSpecification, generationProperty, newValue, ); debouncedRegenerate()?.catch(applicationStore.alertUnhandledError); }; const resetDefaultConfiguration = (): void => { debouncedRegenerate.cancel(); xtGenerationState.resetGenerator(); debouncedRegenerate()?.catch(applicationStore.alertUnhandledError); }; const getConfigValue = (name: string): unknown => xtState.xtGenerationState.configSpecification.configurationProperties.find( (e) => e.name === name, )?.value; return (