Skip to content

fix(site): fix template editor filetree navigation #11260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions site/src/pages/TemplateVersionEditorPage/FileTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { type CSSProperties, type FC, useState } from "react";
import { css } from "@emotion/react";
import { FileTree } from "utils/filetree";
import { DockerIcon } from "components/Icons/DockerIcon";
import FormatAlignLeftOutlined from "@mui/icons-material/FormatAlignLeftOutlined";

const sortFileTree = (fileTree: FileTree) => (a: string, b: string) => {
const contentA = fileTree[a];
Expand Down Expand Up @@ -43,14 +44,17 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
onSelect,
}) => {
const [contextMenu, setContextMenu] = useState<ContextMenu | undefined>();

const buildTreeItems = (
filename: string,
content?: FileTree | string,
parentPath?: string,
): JSX.Element => {
const currentPath = parentPath ? `${parentPath}/${filename}` : filename;
let icon: JSX.Element | null = null;
const isFolder = typeof content === "object";
let icon: JSX.Element | null = isFolder ? null : (
<FormatAlignLeftOutlined />
);

if (filename.endsWith(".tf")) {
icon = <FileTypeTerraform />;
}
Expand All @@ -69,39 +73,31 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
css={(theme) => css`
overflow: hidden;
user-select: none;
height: 32px;

&:focus:not(.active) > .MuiTreeItem-content {
background: ${theme.palette.action.hover};
color: ${theme.palette.text.primary};
}

&:not(:focus):not(.active) > .MuiTreeItem-content:hover {
background: ${theme.palette.action.hover};
color: ${theme.palette.text.primary};
}

& > .MuiTreeItem-content {
padding: 2px 16px;
color: ${theme.palette.text.secondary};
height: 32px;

& svg {
width: 16px;
height: 16px;
width: 12px;
height: 12px;
color: ${theme.palette.text.secondary};
}

& > .MuiTreeItem-label {
margin-left: 4px;
font-size: 13px;
color: inherit;
}
}

&.active {
& > .MuiTreeItem-content {
&.Mui-selected {
color: ${theme.palette.text.primary};
background: ${theme.colors.gray[14]};
pointer-events: none;
}

&.Mui-focused {
box-shadow: inset 0 0 0 1px ${theme.palette.primary.main};
}
}

Expand All @@ -114,7 +110,6 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
}
}
`}
className={currentPath === activePath ? "active" : ""}
onClick={() => {
onSelect(currentPath);
}}
Expand All @@ -138,7 +133,7 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
} as CSSProperties
}
>
{typeof content === "object" ? (
{isFolder ? (
Object.keys(content)
.sort(sortFileTree(content))
.map((filename) => {
Expand All @@ -157,6 +152,7 @@ export const FileTreeView: FC<FileTreeViewProps> = ({
defaultCollapseIcon={<ExpandMoreIcon />}
defaultExpandIcon={<ChevronRightIcon />}
aria-label="Files"
defaultSelected={activePath}
>
{Object.keys(fileTree)
.sort(sortFileTree(fileTree))
Expand Down