Fix deeply nested kcl

This commit is contained in:
49lf
2024-08-02 11:21:22 -04:00
parent 80ecf800aa
commit e7aeed4053
3 changed files with 16 additions and 8 deletions

View File

@ -44,7 +44,7 @@ function RenameForm({
data: { data: {
oldName: fileOrDir.name || '', oldName: fileOrDir.name || '',
newName: inputRef.current?.value || fileOrDir.name || '', newName: inputRef.current?.value || fileOrDir.name || '',
isDir: fileOrDir.children !== undefined, isDir: fileOrDir.children !== null,
}, },
}) })
} }
@ -90,7 +90,7 @@ function DeleteFileTreeItemDialog({
const { send } = useFileContext() const { send } = useFileContext()
return ( return (
<DeleteConfirmationDialog <DeleteConfirmationDialog
title={`Delete ${fileOrDir.children !== undefined ? 'folder' : 'file'}`} title={`Delete ${fileOrDir.children !== null ? 'folder' : 'file'}`}
onDismiss={() => setIsOpen(false)} onDismiss={() => setIsOpen(false)}
onConfirm={() => { onConfirm={() => {
send({ type: 'Delete file', data: fileOrDir }) send({ type: 'Delete file', data: fileOrDir })
@ -99,7 +99,7 @@ function DeleteFileTreeItemDialog({
> >
<p className="my-4"> <p className="my-4">
This will permanently delete "{fileOrDir.name || 'this file'}" This will permanently delete "{fileOrDir.name || 'this file'}"
{fileOrDir.children !== undefined ? ' and all of its contents. ' : '. '} {fileOrDir.children !== null ? ' and all of its contents. ' : '. '}
</p> </p>
<p className="my-4"> <p className="my-4">
Are you sure you want to delete "{fileOrDir.name || 'this file'} Are you sure you want to delete "{fileOrDir.name || 'this file'}
@ -165,7 +165,7 @@ const FileTreeItem = ({
} }
function handleClick() { function handleClick() {
if (fileOrDir.children !== undefined) return // Don't open directories if (fileOrDir.children !== null) return // Don't open directories
if (fileOrDir.name?.endsWith(FILE_EXT) === false && project?.path) { if (fileOrDir.name?.endsWith(FILE_EXT) === false && project?.path) {
// Import non-kcl files // Import non-kcl files
@ -194,7 +194,7 @@ const FileTreeItem = ({
return ( return (
<div className="contents" ref={itemRef}> <div className="contents" ref={itemRef}>
{fileOrDir.children === undefined ? ( {fileOrDir.children === null ? (
<li <li
className={ className={
'group m-0 p-0 border-solid border-0 hover:bg-primary/5 focus-within:bg-primary/5 dark:hover:bg-primary/20 dark:focus-within:bg-primary/20 ' + 'group m-0 p-0 border-solid border-0 hover:bg-primary/5 focus-within:bg-primary/5 dark:hover:bg-primary/20 dark:focus-within:bg-primary/20 ' +

View File

@ -209,6 +209,14 @@ const collectAllFilesRecursiveFrom = async (path: string) => {
const entries = await window.electron.readdir(path) const entries = await window.electron.readdir(path)
// Sort all entries so files come first and directories last
// so a top-most KCL file is returned first.
entries.sort((a: string, b: string) => {
if (a.endsWith(".kcl") && !b.endsWith(".kcl")) { return -1 }
if (!a.endsWith(".kcl") && b.endsWith(".kcl")) { return 1 }
return 0
})
for (let e of entries) { for (let e of entries) {
// ignore hidden files and directories (starting with a dot) // ignore hidden files and directories (starting with a dot)
if (e.indexOf('.') === 0) { if (e.indexOf('.') === 0) {

View File

@ -30,9 +30,9 @@ export function sortProject(project: FileEntry[]): FileEntry[] {
return -1 return -1
} else if (b.name === PROJECT_ENTRYPOINT) { } else if (b.name === PROJECT_ENTRYPOINT) {
return 1 return 1
} else if (a.children === undefined && b.children !== undefined) { } else if (a.children === null && b.children !== null) {
return -1 return -1
} else if (a.children !== undefined && b.children === undefined) { } else if (a.children !== null && b.children === null) {
return 1 return 1
} else if (a.name && b.name) { } else if (a.name && b.name) {
return a.name.localeCompare(b.name) return a.name.localeCompare(b.name)
@ -42,7 +42,7 @@ export function sortProject(project: FileEntry[]): FileEntry[] {
}) })
return sortedProject.map((fileOrDir: FileEntry) => { return sortedProject.map((fileOrDir: FileEntry) => {
if ('children' in fileOrDir && fileOrDir.children !== undefined) { if ('children' in fileOrDir && fileOrDir.children !== null) {
return { return {
...fileOrDir, ...fileOrDir,
children: sortProject(fileOrDir.children || []), children: sortProject(fileOrDir.children || []),