Skip to content

Commit 0c2ffc9

Browse files
committed
Add edit button
1 parent 2353ea9 commit 0c2ffc9

File tree

3 files changed

+39
-58
lines changed

3 files changed

+39
-58
lines changed

site/src/modules/templates/TemplateFiles/TemplateFiles.tsx

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import RadioButtonCheckedOutlined from "@mui/icons-material/RadioButtonCheckedOu
66
import { FileTree } from "utils/filetree";
77
import set from "lodash/fp/set";
88
import { TemplateFileTree } from "./TemplateFileTree";
9+
import { Link } from "react-router-dom";
10+
import EditOutlined from "@mui/icons-material/EditOutlined";
911

1012
const languageByExtension: Record<string, string> = {
1113
tf: "hcl",
@@ -24,11 +26,15 @@ interface TemplateFilesProps {
2426
* Files used to compare with current files
2527
*/
2628
baseFiles?: TemplateVersionFiles;
29+
versionName: string;
30+
templateName: string;
2731
}
2832

2933
export const TemplateFiles: FC<TemplateFilesProps> = ({
3034
currentFiles,
3135
baseFiles,
36+
versionName,
37+
templateName,
3238
}) => {
3339
const filenames = Object.keys(currentFiles);
3440
const theme = useTheme();
@@ -48,10 +54,6 @@ export const TemplateFiles: FC<TemplateFilesProps> = ({
4854
[baseFiles, currentFiles],
4955
);
5056

51-
const filesWithDiff = filenames.filter(
52-
(filename) => fileInfo(filename).hasDiff && false,
53-
);
54-
5557
const fileTree: FileTree = useMemo(() => {
5658
let tree: FileTree = {};
5759
for (const filename of filenames) {
@@ -63,58 +65,6 @@ export const TemplateFiles: FC<TemplateFilesProps> = ({
6365

6466
return (
6567
<div>
66-
{filesWithDiff.length > 0 && (
67-
<div
68-
css={{
69-
display: "flex",
70-
alignItems: "center",
71-
gap: 16,
72-
marginBottom: 24,
73-
}}
74-
>
75-
<span
76-
css={(theme) => ({
77-
fontSize: 13,
78-
fontWeight: 500,
79-
color: theme.roles.warning.fill.outline,
80-
})}
81-
>
82-
{filesWithDiff.length} files have changes
83-
</span>
84-
<ul
85-
css={{
86-
listStyle: "none",
87-
margin: 0,
88-
padding: 0,
89-
display: "flex",
90-
alignItems: "center",
91-
gap: 4,
92-
}}
93-
>
94-
{filesWithDiff.map((filename) => (
95-
<li key={filename}>
96-
<a
97-
href={`#${encodeURIComponent(filename)}`}
98-
css={{
99-
textDecoration: "none",
100-
color: theme.roles.warning.fill.text,
101-
fontSize: 13,
102-
fontWeight: 500,
103-
backgroundColor: theme.roles.warning.background,
104-
display: "inline-block",
105-
padding: "0 8px",
106-
borderRadius: 4,
107-
border: `1px solid ${theme.roles.warning.fill.solid}`,
108-
lineHeight: "1.6",
109-
}}
110-
>
111-
{filename}
112-
</a>
113-
</li>
114-
))}
115-
</ul>
116-
</div>
117-
)}
11868
<div css={{ display: "flex", alignItems: "flex-start", gap: 32 }}>
11969
<div css={styles.sidebar}>
12070
<TemplateFileTree
@@ -162,6 +112,27 @@ export const TemplateFiles: FC<TemplateFilesProps> = ({
162112
}}
163113
/>
164114
)}
115+
116+
<div css={{ marginLeft: "auto" }}>
117+
<Link
118+
to={`/templates/${templateName}/versions/${versionName}/edit?path=${filename}`}
119+
css={{
120+
display: "flex",
121+
gap: 4,
122+
alignItems: "center",
123+
fontSize: 14,
124+
color: theme.palette.text.secondary,
125+
textDecoration: "none",
126+
127+
"&:hover": {
128+
color: theme.palette.text.primary,
129+
},
130+
}}
131+
>
132+
<EditOutlined css={{ fontSize: "inherit" }} />
133+
Edit
134+
</Link>
135+
</div>
165136
</header>
166137
<SyntaxHighlighter
167138
language={

site/src/pages/TemplatePage/TemplateFilesPage/TemplateFilesPage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ const TemplateFilesPage: FC = () => {
2929
</Helmet>
3030

3131
{previousFiles && currentFiles ? (
32-
<TemplateFiles currentFiles={currentFiles} baseFiles={previousFiles} />
32+
<TemplateFiles
33+
currentFiles={currentFiles}
34+
baseFiles={previousFiles}
35+
versionName={activeVersion.name}
36+
templateName={template.name}
37+
/>
3338
) : (
3439
<Loader />
3540
)}

site/src/pages/TemplateVersionPage/TemplateVersionPageView.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ export const TemplateVersionPageView: FC<TemplateVersionPageViewProps> = ({
9797
/>
9898
</Stats>
9999

100-
<TemplateFiles currentFiles={currentFiles} baseFiles={baseFiles} />
100+
<TemplateFiles
101+
currentFiles={currentFiles}
102+
baseFiles={baseFiles}
103+
templateName={templateName}
104+
versionName={versionName}
105+
/>
101106
</>
102107
)}
103108
</Stack>

0 commit comments

Comments
 (0)