diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index a3b94e22c1..42cd18619d 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -3,7 +3,7 @@ import {useIntl} from 'react-intl' import {TreeView, TreeViewItem} from '@remix-ui/tree-view' // eslint-disable-line import {FileExplorerMenu} from './file-explorer-menu' // eslint-disable-line import {FileExplorerContextMenu} from './file-explorer-context-menu' // eslint-disable-line -import {FileExplorerProps, WorkSpaceState} from '../types' +import {FileExplorerProps, FileType, WorkSpaceState} from '../types' import '../css/file-explorer.css' import {checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath} from '@remix-ui/helper' @@ -11,6 +11,7 @@ import {checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath} f import {FileRender} from './file-render' import {Drag} from '@remix-ui/drag-n-drop' import {ROOT_PATH} from '../utils/constants' +import { fileKeySort } from '../utils' export const FileExplorer = (props: FileExplorerProps) => { const intl = useIntl() @@ -32,6 +33,7 @@ export const FileExplorer = (props: FileExplorerProps) => { } = props const [state, setState] = useState(workspaceState) const treeRef = useRef(null) + const [childrenKeys, setChildrenKeys] = useState([]) useEffect(() => { if (contextMenuItems) { @@ -315,6 +317,16 @@ export const FileExplorer = (props: FileExplorerProps) => { } } + useEffect(() => { + if(files[ROOT_PATH]){ + const children: FileType[] = files[ROOT_PATH] as any + setChildrenKeys(fileKeySort(children)) + } else{ + setChildrenKeys([]) + } + }, [props]) + + return (
@@ -343,7 +355,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
{files[ROOT_PATH] && - Object.keys(files[ROOT_PATH]).map((key, index) => ( + childrenKeys.map((key, index) => ( { const [file, setFile] = useState({} as FileType) const [hover, setHover] = useState(false) const [icon, setIcon] = useState('') + const [childrenKeys, setChildrenKeys] = useState([]) useEffect(() => { if (props.file && props.file.path && props.file.type) { @@ -38,6 +40,17 @@ export const FileRender = (props: RenderFileProps) => { } }, [props.file]) + useEffect(() => { + + if(file.child){ + const children: FileType[] = file.child as any + setChildrenKeys(fileKeySort(children)) + } else { + setChildrenKeys([]) + } + + }, [file.child, props.expandPath, props.file]) + const labelClass = props.focusEdit.element === file.path ? 'bg-light' @@ -85,8 +98,8 @@ export const FileRender = (props: RenderFileProps) => { return ( @@ -108,7 +121,7 @@ export const FileRender = (props: RenderFileProps) => { > {file.child ? ( - {Object.keys(file.child).map((key, index) => ( + {childrenKeys.map((key, index) => ( { + const directories = Object.keys(children).filter((key: string) => children[key].isDirectory && children[key].name !== '') + + // sort case insensitive + directories.sort((a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase())) + + const fileKeys = Object.keys(children).filter((key: string) => !children[key].isDirectory && children[key].name !== '') + // sort case insensitive + fileKeys.sort((a: string, b: string) => a.toLowerCase().localeCompare(b.toLowerCase())) + + // find the children with a blank name + const blankChildren = Object.keys(children).filter((key: string) => children[key].name === '') + + const keys = [...directories, ...fileKeys, ...blankChildren] + return keys +} \ No newline at end of file