/*
* 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, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link, useHistory, useLocation } from "react-router-dom";
import classNames from "classnames";
import styled from "styled-components";
import { urls } from "@scm-manager/ui-api";
import { Branch, File, Repository } from "@scm-manager/ui-types";
import { binder, ExtensionPoint, extensionPoints } from "@scm-manager/ui-extensions";
import copyToClipboard from "./CopyToClipboard";
import { devices } from "./devices";
import { Icon, Tooltip } from "@scm-manager/ui-core";
type Props = {
repository: Repository;
branch?: Branch;
defaultBranch?: Branch;
clickable?: boolean;
revision: string;
path: string;
baseUrl: string;
sources: File;
preButtons?: React.ReactNode;
permalink: string | null;
};
const PermaLinkWrapper = styled.span`
width: 16px;
height: 16px;
font-size: 13px;
@media screen and (min-width: ${devices.tablet.width}px) {
margin-left: 0.25rem;
}
@media screen and (max-width: ${devices.mobile.width}px) {
margin-left: auto;
}
i {
color: #dbdbdb;
opacity: 0.75;
}
&:hover i {
color: #b5b5b5;
opacity: 1;
}
`;
const BreadcrumbNav = styled.nav`
flex: 1;
@media screen and (max-width: ${devices.mobile.width}px) {
flex-wrap: wrap;
}
/* move slash to end */
li + li::before {
content: none;
}
li:first-child {
margin-left: 0.75rem;
}
/* sizing of each item */
li {
max-width: 375px;
a {
display: initial;
}
}
`;
const HomeIcon = styled(Icon)`
line-height: 1.5rem;
`;
const ActionBar = styled.div`
/* ensure space between action bar items */
& > * {
/*
* We have to use important, because plugins could use field or control classes like the editor-plugin does.
* Those classes overwrite the margin which is ok, if the plugin is the only one which is using the actionbar.
* But it looks terrible if another plugin use the actionbar, which does not use field and control classes.
*/
margin: 0 0.75rem 0 0 !important;
}
`;
const BreadcrumbNode: FC<{ clickable: boolean; text: string; url: string; current?: boolean }> = ({
clickable,
text,
url,
current,
}) => {
if (clickable) {
return (
{text}
);
} else {
return (
{text}
);
}
};
const Breadcrumb: FC = ({
repository,
branch,
defaultBranch,
revision,
path,
baseUrl,
sources,
permalink,
preButtons,
clickable = true,
}) => {
const location = useLocation();
const history = useHistory();
const [copying, setCopying] = useState(false);
const [t] = useTranslation("commons");
const pathSection = () => {
if (path) {
const paths = path.split("/");
return paths.map((pathFragment, index) => {
const decodedPathFragment = decodeURIComponent(pathFragment);
let currPath = paths
.slice(0, index + 1)
.map(encodeURIComponent)
.join("/");
if (!currPath.endsWith("/")) {
currPath = currPath + "/";
}
if (paths.length - 1 === index) {
return (