Skip to content

Commit aa2468b

Browse files
fix(site): Handle rename a folder to a file (#7063)
1 parent e5c6ebd commit aa2468b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

site/src/components/TemplateVersionEditor/FileDialog.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Stack } from "components/Stack/Stack"
44
import { ChangeEvent, FC, useState } from "react"
55
import Typography from "@material-ui/core/Typography"
66
import { allowedExtensions, isAllowedFile } from "util/templateVersion"
7-
import { FileTree, validatePath } from "util/filetree"
7+
import { FileTree, isFolder, validatePath } from "util/filetree"
88

99
export const CreateFileDialog: FC<{
1010
onClose: () => void
@@ -142,6 +142,12 @@ export const RenameFileDialog: FC<{
142142
)
143143
return
144144
}
145+
//Check if a folder is renamed to a file
146+
const [_, extension] = pathValue.split(".")
147+
if (isFolder(filename, fileTree) && extension) {
148+
setError(`A folder can't be renamed to a file.`)
149+
return
150+
}
145151
const pathError = validatePath(pathValue, fileTree)
146152
if (pathError) {
147153
setError(pathError)

site/src/components/TemplateVersionEditor/FileTreeView.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import TreeView from "@material-ui/lab/TreeView"
55
import TreeItem from "@material-ui/lab/TreeItem"
66
import Menu from "@material-ui/core/Menu"
77
import MenuItem from "@material-ui/core/MenuItem"
8-
import { FC, useState } from "react"
8+
import { CSSProperties, FC, useState } from "react"
99
import { FileTree } from "util/filetree"
1010
import { DockerIcon } from "components/Icons/DockerIcon"
1111
import { colors } from "theme/colors"
@@ -80,6 +80,11 @@ export const FileTreeView: FC<{
8080
)
8181
}}
8282
icon={icon}
83+
style={
84+
{
85+
"--level": parentPath ? parentPath.split("/").length : 0,
86+
} as CSSProperties
87+
}
8388
>
8489
{typeof content === "object" ? (
8590
Object.keys(content)
@@ -200,7 +205,7 @@ const useStyles = makeStyles((theme) => ({
200205

201206
// We need to find a better way to recursive padding here
202207
"& .MuiTreeItem-content": {
203-
paddingLeft: theme.spacing(5),
208+
paddingLeft: `calc(var(--level) * ${theme.spacing(5)}px)`,
204209
},
205210
},
206211
},

0 commit comments

Comments
 (0)