2019-06-26 15:06:59 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2019-09-25 09:15:33 +02:00
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
|
import { translate } from "react-i18next";
|
2019-06-26 15:17:16 +02:00
|
|
|
import injectSheet from "react-jss";
|
2019-08-28 12:18:44 +02:00
|
|
|
import classNames from "classnames";
|
2019-09-25 09:15:33 +02:00
|
|
|
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import type { Branch, Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import Icon from "./Icon";
|
2019-06-26 15:06:59 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-09-05 10:46:27 +02:00
|
|
|
repository: Repository,
|
2019-09-02 11:48:53 +02:00
|
|
|
branch: Branch,
|
|
|
|
|
defaultBranch: Branch,
|
2019-09-04 11:52:38 +02:00
|
|
|
branches: Branch[],
|
2019-06-27 13:54:04 +02:00
|
|
|
revision: string,
|
2019-06-26 15:06:59 +02:00
|
|
|
path: string,
|
2019-06-26 15:17:16 +02:00
|
|
|
baseUrl: string,
|
2019-09-25 09:15:33 +02:00
|
|
|
|
|
|
|
|
// Context props
|
|
|
|
|
classes: any,
|
|
|
|
|
t: string => string
|
2019-06-26 15:17:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const styles = {
|
2019-06-27 17:56:26 +02:00
|
|
|
noMargin: {
|
|
|
|
|
margin: "0"
|
2019-08-28 12:18:44 +02:00
|
|
|
},
|
|
|
|
|
flexRow: {
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: "row"
|
|
|
|
|
},
|
|
|
|
|
flexStart: {
|
|
|
|
|
flex: "1"
|
|
|
|
|
},
|
2019-09-25 09:18:59 +02:00
|
|
|
homeIcon: {
|
|
|
|
|
lineHeight: "1.5rem"
|
|
|
|
|
},
|
2019-08-28 12:18:44 +02:00
|
|
|
buttonGroup: {
|
|
|
|
|
alignSelf: "center",
|
|
|
|
|
paddingRight: "1rem"
|
2019-06-26 15:17:16 +02:00
|
|
|
}
|
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) {
|
|
|
|
|
const paths = path.split("/");
|
2019-06-27 17:56:26 +02:00
|
|
|
const map = paths.map((path, index) => {
|
|
|
|
|
const currPath = paths.slice(0, index + 1).join("/");
|
|
|
|
|
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}>
|
|
|
|
|
<Link to={baseUrl + "/" + revision + "/" + currPath}>{path}</Link>
|
|
|
|
|
</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-09-10 16:36:32 +02:00
|
|
|
const {
|
|
|
|
|
baseUrl,
|
|
|
|
|
branch,
|
|
|
|
|
defaultBranch,
|
|
|
|
|
branches,
|
|
|
|
|
revision,
|
|
|
|
|
path,
|
2019-09-25 09:15:33 +02:00
|
|
|
repository,
|
|
|
|
|
classes,
|
|
|
|
|
t
|
2019-09-10 16:36:32 +02:00
|
|
|
} = this.props;
|
2019-06-27 17:56:26 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-08-28 12:18:44 +02:00
|
|
|
<div className={classes.flexRow}>
|
2019-09-10 16:36:32 +02:00
|
|
|
<nav
|
|
|
|
|
className={classNames(
|
|
|
|
|
classes.flexStart,
|
|
|
|
|
"breadcrumb sources-breadcrumb"
|
|
|
|
|
)}
|
|
|
|
|
aria-label="breadcrumbs"
|
|
|
|
|
>
|
2019-09-25 09:15:33 +02:00
|
|
|
<ul>
|
|
|
|
|
<li>
|
|
|
|
|
<Link to={baseUrl + "/" + revision + "/"}>
|
|
|
|
|
<Icon
|
2019-09-25 09:18:59 +02:00
|
|
|
className={classes.homeIcon}
|
2019-09-25 09:15:33 +02:00
|
|
|
title={t("breadcrumb.home")}
|
|
|
|
|
name="home"
|
|
|
|
|
color="inherit"
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
{this.renderPath()}
|
|
|
|
|
</ul>
|
2019-08-28 12:18:44 +02:00
|
|
|
</nav>
|
2019-09-10 16:36:32 +02:00
|
|
|
{binder.hasExtension("repos.sources.actionbar") && (
|
2019-08-28 12:18:44 +02:00
|
|
|
<div className={classes.buttonGroup}>
|
2019-09-10 16:36:32 +02:00
|
|
|
<ExtensionPoint
|
|
|
|
|
name="repos.sources.actionbar"
|
|
|
|
|
props={{
|
|
|
|
|
baseUrl,
|
|
|
|
|
branch: branch ? branch : defaultBranch,
|
|
|
|
|
path,
|
|
|
|
|
isBranchUrl:
|
|
|
|
|
branches &&
|
|
|
|
|
branches.filter(
|
|
|
|
|
b => b.name.replace("/", "%2F") === revision
|
|
|
|
|
).length > 0,
|
|
|
|
|
repository
|
|
|
|
|
}}
|
|
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
2019-08-28 12:18:44 +02:00
|
|
|
</div>
|
2019-09-10 16:36:32 +02:00
|
|
|
)}
|
2019-08-28 12:18:44 +02:00
|
|
|
</div>
|
2019-06-27 17:56:26 +02:00
|
|
|
<hr className={classes.noMargin} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2019-06-26 15:06:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-25 09:15:33 +02:00
|
|
|
export default translate("commons")(injectSheet(styles)(Breadcrumb));
|