/* * MIT License * * Copyright (c) 2020-present Cloudogu GmbH and Contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import React, { FC, ReactNode, useState } from "react"; import { useTranslation } from "react-i18next"; import classNames from "classnames"; import styled from "styled-components"; import { ExtensionPoint } from "@scm-manager/ui-extensions"; import { File, Repository } from "@scm-manager/ui-types"; import { DateFromNow, ErrorNotification, FileSize, Icon, OpenInFullscreenButton } from "@scm-manager/ui-components"; import FileButtonAddons from "../components/content/FileButtonAddons"; import SourcesView from "./SourcesView"; import HistoryView from "./HistoryView"; import AnnotateView from "./AnnotateView"; type Props = { file: File; repository: Repository; revision: string; breadcrumb: React.ReactNode; error?: Error; }; const HeaderWrapper = styled.div` border-bottom: solid 1px #dbdbdb; font-size: 1.25em; font-weight: 300; line-height: 1.25; padding: 0.5em 0.75em; `; const BorderBottom = styled.div` border-bottom: solid 1px #dbdbdb; `; const FullWidthTitleHeader = styled.div` max-width: 100%; `; const BorderLessDiv = styled.div` margin: -1.25rem; border: none; box-shadow: none; `; export type SourceViewSelection = "source" | "annotations" | "history"; const Content: FC = ({ file, repository, revision, breadcrumb, error }) => { const [t] = useTranslation("repos"); const [collapsed, setCollapsed] = useState(true); const [selected, setSelected] = useState("source"); const [errorFromExtension, setErrorFromExtension] = useState(); const wrapContent = (content: ReactNode) => { return ( <>
{breadcrumb} {content}
); }; const toggleCollapse = () => { setCollapsed(!collapsed); }; const showHeader = (content: ReactNode) => { let icon; if (collapsed) { icon = ( ); } else { icon = ( ); } const selector = file._links.history ? ( setSelected("source")} showAnnotations={() => setSelected("annotations")} showHistory={() => setSelected("history")} /> ) : null; return (
{icon} {file.name}
{selector} {content}} tooltipStyle="htmlTitle" />
); }; const showMoreInformation = () => { const fileSize = file.directory ? null : ; const description = file.description ? (

{file.description.split("\n").map((item, key) => { return ( {item}
); })}

) : null; if (!collapsed) { return ( <>
{t("sources.content.path")} {file.path}
{t("sources.content.branch")} {revision}
{t("sources.content.size")} {fileSize}
{t("sources.content.commitDate")}
{t("sources.content.description")} {description}
); } return null; }; if (!file || error) { return wrapContent(); } let body; switch (selected) { case "source": body = ; break; case "annotations": body = ; break; case "history": body = ; } const header = showHeader(body); const moreInformation = showMoreInformation(); return wrapContent( <> {header} {moreInformation} {body} ); }; export default Content;