2019-06-26 15:06:59 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { Link } from "react-router-dom";
|
2019-09-05 10:46:27 +02:00
|
|
|
import type { Branch, Repository } from "@scm-manager/ui-types";
|
2019-06-26 15:17:16 +02:00
|
|
|
import injectSheet from "react-jss";
|
2019-08-28 12:18:44 +02:00
|
|
|
import { ExtensionPoint, binder } from "@scm-manager/ui-extensions";
|
|
|
|
|
import {ButtonGroup} from "./buttons";
|
|
|
|
|
import classNames from "classnames";
|
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,
|
|
|
|
|
classes: any
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
},
|
|
|
|
|
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}>
|
|
|
|
|
<Link to={"#"} aria-current="page">
|
|
|
|
|
{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-06-27 17:56:26 +02:00
|
|
|
return <li />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-09-05 10:46:27 +02:00
|
|
|
const { classes, baseUrl, branch, defaultBranch, branches, revision, path, repository } = this.props;
|
2019-06-27 17:56:26 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-08-28 12:18:44 +02:00
|
|
|
<div className={classes.flexRow}>
|
|
|
|
|
<nav className={classNames(classes.flexStart, "breadcrumb sources-breadcrumb")} aria-label="breadcrumbs">
|
|
|
|
|
<ul>{this.renderPath()}</ul>
|
|
|
|
|
</nav>
|
|
|
|
|
{
|
2019-09-02 13:52:06 +02:00
|
|
|
binder.hasExtension("repos.sources.actionbar") &&
|
2019-08-28 12:18:44 +02:00
|
|
|
<div className={classes.buttonGroup}>
|
|
|
|
|
<ButtonGroup>
|
|
|
|
|
<ExtensionPoint
|
2019-09-02 13:52:06 +02:00
|
|
|
name="repos.sources.actionbar"
|
2019-09-05 10:46:27 +02:00
|
|
|
props={{
|
|
|
|
|
baseUrl,
|
|
|
|
|
branch: branch ? branch : defaultBranch,
|
|
|
|
|
path,
|
|
|
|
|
isBranchUrl: branches &&
|
|
|
|
|
branches.filter(b => b.name.replace("/", "%2F") === revision).length > 0,
|
|
|
|
|
repository
|
|
|
|
|
}}
|
2019-08-28 12:18:44 +02:00
|
|
|
renderAll={true}
|
|
|
|
|
/>
|
|
|
|
|
</ButtonGroup>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
</div>
|
2019-06-27 17:56:26 +02:00
|
|
|
<hr className={classes.noMargin} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
2019-06-26 15:06:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 15:17:16 +02:00
|
|
|
export default injectSheet(styles)(Breadcrumb);
|