2019-10-20 16:59:02 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { Link } from "react-router-dom";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2019-10-20 16:59:02 +02:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { Branch, Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import Icon from "./Icon";
|
2019-06-26 15:06:59 +02:00
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
type Props = WithTranslation & {
|
2019-10-30 12:59:54 +01:00
|
|
|
repository: Repository;
|
2019-10-19 16:38:07 +02:00
|
|
|
branch: Branch;
|
|
|
|
|
defaultBranch: Branch;
|
|
|
|
|
revision: string;
|
|
|
|
|
path: string;
|
|
|
|
|
baseUrl: string;
|
2019-10-28 15:52:59 +01:00
|
|
|
sources: File;
|
2019-06-26 15:17:16 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-08 16:42:08 +02:00
|
|
|
const FlexStartNav = styled.nav`
|
|
|
|
|
flex: 1;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const HomeIcon = styled(Icon)`
|
|
|
|
|
line-height: 1.5rem;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const ActionWrapper = styled.div`
|
|
|
|
|
align-self: center;
|
|
|
|
|
padding-right: 1rem;
|
|
|
|
|
`;
|
2019-06-26 15:06:59 +02:00
|
|
|
|
|
|
|
|
class Breadcrumb extends React.Component<Props> {
|
2019-06-27 17:56:26 +02:00
|
|
|
renderPath() {
|
|
|
|
|
const { revision, path, baseUrl } = this.props;
|
2019-06-26 15:06:59 +02:00
|
|
|
|
|
|
|
|
if (path) {
|
2019-10-20 16:59:02 +02:00
|
|
|
const paths = path.split("/");
|
2019-06-27 17:56:26 +02:00
|
|
|
const map = paths.map((path, index) => {
|
2019-10-20 16:59:02 +02:00
|
|
|
const currPath = paths.slice(0, index + 1).join("/");
|
2019-06-27 17:56:26 +02:00
|
|
|
if (paths.length - 1 === index) {
|
|
|
|
|
return (
|
|
|
|
|
<li className="is-active" key={index}>
|
2019-09-25 09:15:33 +02:00
|
|
|
<Link to="#" aria-current="page">
|
2019-06-27 17:56:26 +02:00
|
|
|
{path}
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<li key={index}>
|
2019-10-20 16:59:02 +02:00
|
|
|
<Link to={baseUrl + "/" + revision + "/" + currPath}>{path}</Link>
|
2019-06-27 17:56:26 +02:00
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
return map;
|
2019-06-26 15:06:59 +02:00
|
|
|
}
|
2019-09-25 09:15:33 +02:00
|
|
|
return null;
|
2019-06-27 17:56:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-10-30 12:59:54 +01:00
|
|
|
const { repository, baseUrl, branch, defaultBranch, sources, revision, path, t } = this.props;
|
2019-06-27 17:56:26 +02:00
|
|
|
|
2019-10-25 12:38:48 +02:00
|
|
|
let homeUrl = baseUrl + "/";
|
|
|
|
|
if (revision) {
|
|
|
|
|
homeUrl += encodeURIComponent(revision) + "/";
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 17:56:26 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-08 16:42:08 +02:00
|
|
|
<div className="is-flex">
|
2019-10-21 10:57:56 +02:00
|
|
|
<FlexStartNav className={classNames("breadcrumb", "sources-breadcrumb")} aria-label="breadcrumbs">
|
2019-09-25 09:15:33 +02:00
|
|
|
<ul>
|
|
|
|
|
<li>
|
2019-10-25 12:38:48 +02:00
|
|
|
<Link to={homeUrl}>
|
2019-10-21 10:57:56 +02:00
|
|
|
<HomeIcon title={t("breadcrumb.home")} name="home" color="inherit" />
|
2019-09-25 09:15:33 +02:00
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
{this.renderPath()}
|
|
|
|
|
</ul>
|
2019-10-08 16:42:08 +02:00
|
|
|
</FlexStartNav>
|
2019-10-20 16:59:02 +02:00
|
|
|
{binder.hasExtension("repos.sources.actionbar") && (
|
2019-10-08 16:42:08 +02:00
|
|
|
<ActionWrapper>
|
2019-09-10 16:36:32 +02:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.sources.actionbar"
|
|
|
|
|
props={{
|
|
|
|
|
baseUrl,
|
2019-10-30 12:59:54 +01:00
|
|
|
revision,
|
2019-09-10 16:36:32 +02:00
|
|
|
branch: branch ? branch : defaultBranch,
|
|
|
|
|
path,
|
2019-10-30 12:59:54 +01:00
|
|
|
sources,
|
|
|
|
|
repository
|
2019-09-10 16:36:32 +02:00
|
|
|
}}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-10-08 16:42:08 +02:00
|
|
|
</ActionWrapper>
|
2019-09-10 16:36:32 +02:00
|
|
|
)}
|
2019-08-28 12:18:44 +02:00
|
|
|
</div>
|
2019-10-08 16:42:08 +02:00
|
|
|
<hr className="is-marginless" />
|
2019-06-27 17:56:26 +02:00
|
|
|
</>
|
|
|
|
|
);
|
2019-06-26 15:06:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
export default withTranslation("commons")(Breadcrumb);
|