/**
* 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 { Fragment } from 'react';
import { observer } from 'mobx-react-lite';
import { flowResult } from 'mobx';
import { guaranteeNonNullable } from '@finos/legend-shared';
import {
type TreeNodeContainerProps,
type TreeData,
type TreeNodeData,
ResizablePanelGroup,
ResizablePanel,
ResizablePanelSplitter,
ResizablePanelSplitterLine,
clsx,
TreeView,
BlankPanelContent,
PanelLoadingIndicator,
RefreshIcon,
ChevronDownIcon,
ChevronRightIcon,
FolderOpenIcon,
FolderIcon,
FileCodeIcon,
PanelContent,
PanelHeader,
PanelHeaderActionItem,
PanelHeaderActions,
Panel,
} from '@finos/legend-art';
import type { GeneratedFileStructureState } from '../../../../stores/editor/editor-state/FileGenerationState.js';
import {
type FileSystemTreeNodeData,
FileSystem_Directory,
FileSystem_File,
getFileSystemChildNodes,
} from '../../../../stores/editor/utils/FileSystemTreeUtils.js';
import { useApplicationStore } from '@finos/legend-application';
import type { DSL_Generation_LegendStudioApplicationPlugin_Extension } from '../../../../stores/extensions/DSL_Generation_LegendStudioApplicationPlugin_Extension.js';
import { CodeEditor } from '@finos/legend-lego/code-editor';
import {
getEditorLanguageForFormat,
getTextContent,
} from '../../../../stores/editor/editor-state/ArtifactGenerationViewerState.js';
export const FileSystemTreeNodeContainer: React.FC<
TreeNodeContainerProps<
FileSystemTreeNodeData,
{
selectedNode?: TreeNodeData | undefined;
}
>
> = (props) => {
const { node, level, stepPaddingInRem, onNodeSelect, innerProps } = props;
const { selectedNode } = innerProps;
const isSelected = selectedNode === node;
const isDirectory = node.fileNode instanceof FileSystem_Directory;
const expandIcon = !isDirectory ? (
) : node.isOpen ? (
) : (
);
const iconPackageColor = 'color--generated';
const nodeIcon = isDirectory ? (
node.isOpen ? (
) : (
)
) : (
);
const selectNode: React.MouseEventHandler = (event) => onNodeSelect?.(node);
return (
);
};
export const FileSystemTree = observer(
(props: {
selectedNode?: TreeNodeData | undefined;
directoryTreeData: TreeData;
onNodeSelect: (node: FileSystemTreeNodeData) => void;
getFileElementTreeChildNodes: (
node: FileSystemTreeNodeData,
) => FileSystemTreeNodeData[];
}) => {
const {
directoryTreeData,
onNodeSelect,
getFileElementTreeChildNodes,
selectedNode,
} = props;
return (
);
},
);
export const FileSystemExplorer = observer(
(props: { generatedFileState: GeneratedFileStructureState }) => {
const { generatedFileState } = props;
const fileSystemState = generatedFileState.fileSystemState;
const treeData = guaranteeNonNullable(fileSystemState.directoryTreeData);
const onNodeSelect = (node: FileSystemTreeNodeData): void =>
fileSystemState.onTreeNodeSelect(node, treeData);
const getMappingElementTreeChildNodes = (
node: FileSystemTreeNodeData,
): FileSystemTreeNodeData[] => getFileSystemChildNodes(node, treeData);
if (!treeData.nodes.size) {
return No content;
}
return (
);
},
);
export const FileSystemViewer = observer(
(props: { generatedFileState: GeneratedFileStructureState }) => {
const { generatedFileState } = props;
const applicationStore = useApplicationStore();
const selectedNode = generatedFileState.fileSystemState.selectedNode;
const fileNode = selectedNode?.fileNode;
const regenerate = applicationStore.guardUnhandledError(() =>
flowResult(generatedFileState.generate()),
);
const extraFileGenerationResultViewerActions =
fileNode instanceof FileSystem_File
? generatedFileState.editorStore.pluginManager
.getApplicationPlugins()
.flatMap(
(plugin) =>
(
plugin as DSL_Generation_LegendStudioApplicationPlugin_Extension
).getExtraFileGenerationResultViewerActionConfigurations?.() ??
[],
)
.map((config) => (
{config.renderer(generatedFileState)}
))
: null;
return (
{Boolean(
generatedFileState.fileSystemState.directoryTreeData,
) && (
)}
{Boolean(
!generatedFileState.fileSystemState.directoryTreeData,
) && (
Generation result not available
)}
{fileNode && !(fileNode instanceof FileSystem_Directory) && (
)}
{extraFileGenerationResultViewerActions}
{fileNode instanceof FileSystem_File && (
)}
{!(fileNode instanceof FileSystem_File) && (
No file selected
)}
);
},
);