Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e84d893

Browse files
fix(site): fix template editor filetree navigation (coder#11260)
Close coder#11203
1 parent ff61475 commit e84d893

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

site/src/pages/TemplateVersionEditorPage/FileTreeView.tsx

+17-21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { type CSSProperties, type FC, useState } from "react";
88
import { css } from "@emotion/react";
99
import { FileTree } from "utils/filetree";
1010
import { DockerIcon } from "components/Icons/DockerIcon";
11+
import FormatAlignLeftOutlined from "@mui/icons-material/FormatAlignLeftOutlined";
1112

1213
const sortFileTree = (fileTree: FileTree) => (a: string, b: string) => {
1314
const contentA = fileTree[a];
@@ -43,14 +44,17 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
4344
onSelect,
4445
}) => {
4546
const [contextMenu, setContextMenu] = useState<ContextMenu | undefined>();
46-
4747
const buildTreeItems = (
4848
filename: string,
4949
content?: FileTree | string,
5050
parentPath?: string,
5151
): JSX.Element => {
5252
const currentPath = parentPath ? `${parentPath}/${filename}` : filename;
53-
let icon: JSX.Element | null = null;
53+
const isFolder = typeof content === "object";
54+
let icon: JSX.Element | null = isFolder ? null : (
55+
<FormatAlignLeftOutlined />
56+
);
57+
5458
if (filename.endsWith(".tf")) {
5559
icon = <FileTypeTerraform />;
5660
}
@@ -69,39 +73,31 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
6973
css={(theme) => css`
7074
overflow: hidden;
7175
user-select: none;
72-
height: 32px;
73-
74-
&:focus:not(.active) > .MuiTreeItem-content {
75-
background: ${theme.palette.action.hover};
76-
color: ${theme.palette.text.primary};
77-
}
78-
79-
&:not(:focus):not(.active) > .MuiTreeItem-content:hover {
80-
background: ${theme.palette.action.hover};
81-
color: ${theme.palette.text.primary};
82-
}
8376
8477
& > .MuiTreeItem-content {
8578
padding: 2px 16px;
8679
color: ${theme.palette.text.secondary};
80+
height: 32px;
8781
8882
& svg {
89-
width: 16px;
90-
height: 16px;
83+
width: 12px;
84+
height: 12px;
85+
color: ${theme.palette.text.secondary};
9186
}
9287
9388
& > .MuiTreeItem-label {
9489
margin-left: 4px;
9590
font-size: 13px;
9691
color: inherit;
9792
}
98-
}
9993
100-
&.active {
101-
& > .MuiTreeItem-content {
94+
&.Mui-selected {
10295
color: ${theme.palette.text.primary};
10396
background: ${theme.colors.gray[14]};
104-
pointer-events: none;
97+
}
98+
99+
&.Mui-focused {
100+
box-shadow: inset 0 0 0 1px ${theme.palette.primary.main};
105101
}
106102
}
107103
@@ -114,7 +110,6 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
114110
}
115111
}
116112
`}
117-
className={currentPath === activePath ? "active" : ""}
118113
onClick={() => {
119114
onSelect(currentPath);
120115
}}
@@ -138,7 +133,7 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
138133
} as CSSProperties
139134
}
140135
>
141-
{typeof content === "object" ? (
136+
{isFolder ? (
142137
Object.keys(content)
143138
.sort(sortFileTree(content))
144139
.map((filename) => {
@@ -157,6 +152,7 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
157152
defaultCollapseIcon={<ExpandMoreIcon />}
158153
defaultExpandIcon={<ChevronRightIcon />}
159154
aria-label="Files"
155+
defaultSelected={activePath}
160156
>
161157
{Object.keys(fileTree)
162158
.sort(sortFileTree(fileTree))

0 commit comments

Comments
 (0)