/* * Copyright (c) 2020 - present Cloudogu GmbH * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ import React, { FC } from "react"; import { Link } from "react-router-dom"; import { useTranslation } from "react-i18next"; import classNames from "classnames"; import { FileChangeType, FileTree } from "@scm-manager/ui-types"; import { FileDiffContent, StackedSpan, StyledIcon } from "./styledElements"; import { FileTreeNodeWrapper } from "../DiffTypes"; type Props = { tree: FileTree; currentFile: string; setCurrentFile: (path: string) => void; gap?: number; FileTreeNodeWrapper?: FileTreeNodeWrapper; }; const DiffFileTree: FC = ({ tree, currentFile, setCurrentFile, gap = 15, FileTreeNodeWrapper }) => { return ( {Object.keys(tree.children).map((key) => ( ))} ); }; export default DiffFileTree; type NodeProps = { node: FileTree; parentPath: string; currentFile: string; setCurrentFile: (path: string) => void; FileTreeNodeWrapper?: FileTreeNodeWrapper; }; const addPath = (parentPath: string, path: string) => { if ("" === parentPath) { return path; } return parentPath + "/" + path; }; const TreeNode: FC = ({ node, parentPath, currentFile, setCurrentFile, FileTreeNodeWrapper }) => { const [t] = useTranslation("repos"); FileTreeNodeWrapper = FileTreeNodeWrapper || (({ children }) => <>{children}); const label =
{node.nodeName}
; const icon = folder; return (
  • {Object.keys(node.children).length > 0 ? (
    • {icon} {label}
    • {Object.keys(node.children).map((key) => ( ))}
    ) : ( )}
  • ); }; const getColor = (changeType: FileChangeType) => { switch (changeType) { case "add": return "success"; case "modify": case "rename": case "copy": return "info"; case "delete": return "danger"; } }; const getIcon = (changeType: FileChangeType) => { switch (changeType) { case "add": case "copy": return "plus"; case "modify": case "rename": return "circle"; case "delete": return "minus"; } }; type FileProps = { changeType: FileChangeType; path: string; parentPath: string; currentFile: string; setCurrentFile: (path: string) => void; FileTreeNodeWrapper: FileTreeNodeWrapper; }; const TreeFile: FC = ({ changeType, path, parentPath, currentFile, setCurrentFile, FileTreeNodeWrapper, }) => { const [t] = useTranslation("repos"); const completePath = addPath(parentPath, path); const isCurrentFile = () => { return currentFile === completePath; }; const iconName = getIcon(changeType); const icon = ( file {iconName} ); const label =
    {path}
    ; return ( setCurrentFile(completePath)} to={`#diff-${encodeURIComponent(completePath)}`} > {icon} {label} ); };