MCPcopy Create free account
hub / github.com/coder/coder / TemplateFiles

Function TemplateFiles

site/src/modules/templates/TemplateFiles/TemplateFiles.tsx:24–148  ·  view source on GitHub ↗
({
	organizationName,
	templateName,
	versionName,
	currentFiles,
	baseFiles,
})

Source from the content-addressed store, hash-verified

22}
23
24export const TemplateFiles: FC<TemplateFilesProps> = ({
25 organizationName,
26 templateName,
27 versionName,
28 currentFiles,
29 baseFiles,
30}) => {
31 const getLink = useLinks();
32
33 const fileInfo = useCallback(
34 (filename: string) => {
35 const value = currentFiles[filename].trim();
36 const previousValue = baseFiles ? baseFiles[filename]?.trim() : undefined;
37 const hasDiff = previousValue && value !== previousValue;
38
39 return {
40 value,
41 previousValue,
42 hasDiff,
43 };
44 },
45 [baseFiles, currentFiles],
46 );
47
48 const fileTree: FileTree = useMemo(() => {
49 const tree: FileTree = {};
50 for (const filename of Object.keys(currentFiles)) {
51 const info = fileInfo(filename);
52 set(tree, filename.split("/"), info.value);
53 }
54 return tree;
55 }, [fileInfo, currentFiles]);
56
57 const versionLink = `${getLink(
58 linkToTemplate(organizationName, templateName),
59 )}/versions/${versionName}`;
60
61 return (
62 <div>
63 <div className="flex items-start gap-8">
64 <div className="sticky top-8 w-[240px] shrink-0 overflow-auto rounded-lg border border-solid border-surface-quaternary py-1">
65 <TemplateFileTree
66 fileTree={fileTree}
67 onSelect={(path: string) => {
68 location.hash = path;
69 document.getElementById(path)?.scrollIntoView({
70 behavior: "smooth",
71 block: "start",
72 });
73 }}
74 Label={({ path, filename, isFolder }) => {
75 if (isFolder) {
76 return <>{filename}</>;
77 }
78
79 const hasDiff = fileInfo(path).hasDiff;
80 return (
81 <span className={cn(hasDiff && "text-content-warning")}>

Callers

nothing calls this directly

Calls 7

useLinksFunction · 0.90
linkToTemplateFunction · 0.90
cnFunction · 0.90
getTemplateFileIconFunction · 0.90
setFunction · 0.85
getLanguageFunction · 0.85
numberOfLinesFunction · 0.85

Tested by

no test coverage detected