Skip to content

Commit 0384dbc

Browse files
committed
Users are now prevented from creating subdirectories outside of root
1 parent 7e852fd commit 0384dbc

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/renderer/components/filetree/ContextMenuItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {IconType} from 'react-icons/lib/cjs/iconBase';
66
type ContextMenuItemProps = {
77
onClick?: () => void,
88
icon: IconType,
9-
children: string,
10-
color?: string
9+
color?: string,
10+
children: string
1111
};
1212

1313
export const ContextMenuItem = ({onClick, icon, color, children}: ContextMenuItemProps) => <MenuItem onClick={onClick}>

src/renderer/components/filetree/FileTreeContextMenu.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const FileTreeContextMenu = () => {
3535
const expanded = path ? expandedDirectories[path] : undefined;
3636
const selectedTseprojFile = selectedFile?.name.includes('.tseproj');
3737
const isRootDirectory = path === root.path;
38+
const selectedRootDirectory = root.path === selectedFile?.path;
3839

3940
const [menuProps, toggleMenu] = useMenuState();
4041

@@ -75,6 +76,14 @@ export const FileTreeContextMenu = () => {
7576

7677
const handleCreateDirectory = async () => {
7778
if (!path) return;
79+
if (!selectedRootDirectory) {
80+
showNotification({
81+
title: 'Unable to create directory',
82+
message: 'Subdirectories will cause the build to break, and are not currently supported.',
83+
color: 'red'
84+
})
85+
return;
86+
}
7887

7988
const directoryPath = await MainProcess.createDirectory(path);
8089

@@ -159,7 +168,7 @@ export const FileTreeContextMenu = () => {
159168
>
160169
{isDirectory &&
161170
<SubMenu label={() => <Text size="xs"><Center inline><AiOutlinePlus /><Space w="xs"/>New</Center></Text>}>
162-
<ContextMenuItem icon={AiOutlineFolder} onClick={handleCreateDirectory}>Directory</ContextMenuItem>
171+
<ContextMenuItem icon={AiOutlineFolder} onClick={handleCreateDirectory} color={selectedRootDirectory ? 'black' : 'dimmed'}>Directory</ContextMenuItem>
163172
<ContextMenuItem icon={AiFillFile} onClick={handleCreateFile}>Script</ContextMenuItem>
164173
<ContextMenuItem icon={AiFillFile} onClick={handleCreateScript}>File</ContextMenuItem>
165174
</SubMenu>

0 commit comments

Comments
 (0)