2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
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
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
repository: Repository;
|
|
|
|
|
branch: Branch;
|
|
|
|
|
defaultBranch: Branch;
|
|
|
|
|
branches: Branch[];
|
|
|
|
|
revision: string;
|
|
|
|
|
path: string;
|
|
|
|
|
baseUrl: string;
|
2019-09-25 09:15:33 +02:00
|
|
|
|
|
|
|
|
// Context props
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
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-19 16:38:07 +02:00
|
|
|
const paths = path.split('/');
|
2019-06-27 17:56:26 +02:00
|
|
|
const map = paths.map((path, index) => {
|
2019-10-19 16:38:07 +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-19 16:38:07 +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-09-10 16:36:32 +02:00
|
|
|
const {
|
|
|
|
|
baseUrl,
|
|
|
|
|
branch,
|
|
|
|
|
defaultBranch,
|
|
|
|
|
branches,
|
|
|
|
|
revision,
|
|
|
|
|
path,
|
2019-09-25 09:15:33 +02:00
|
|
|
repository,
|
2019-10-19 16:38:07 +02:00
|
|
|
t,
|
2019-09-10 16:36:32 +02:00
|
|
|
} = this.props;
|
2019-06-27 17:56:26 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-10-08 16:42:08 +02:00
|
|
|
<div className="is-flex">
|
|
|
|
|
<FlexStartNav
|
2019-10-19 16:38:07 +02:00
|
|
|
className={classNames('breadcrumb', 'sources-breadcrumb')}
|
2019-09-10 16:36:32 +02:00
|
|
|
aria-label="breadcrumbs"
|
|
|
|
|
>
|
2019-09-25 09:15:33 +02:00
|
|
|
<ul>
|
|
|
|
|
<li>
|
2019-10-19 16:38:07 +02:00
|
|
|
<Link to={baseUrl + '/' + revision + '/'}>
|
2019-10-08 16:42:08 +02:00
|
|
|
<HomeIcon
|
2019-10-19 16:38:07 +02:00
|
|
|
title={t('breadcrumb.home')}
|
2019-09-25 09:15:33 +02:00
|
|
|
name="home"
|
|
|
|
|
color="inherit"
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
{this.renderPath()}
|
|
|
|
|
</ul>
|
2019-10-08 16:42:08 +02:00
|
|
|
</FlexStartNav>
|
2019-10-19 16:38:07 +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,
|
|
|
|
|
branch: branch ? branch : defaultBranch,
|
|
|
|
|
path,
|
|
|
|
|
isBranchUrl:
|
|
|
|
|
branches &&
|
|
|
|
|
branches.filter(
|
2019-10-19 16:38:07 +02:00
|
|
|
b => b.name.replace('/', '%2F') === revision,
|
2019-09-10 16:36:32 +02:00
|
|
|
).length > 0,
|
2019-10-19 16:38:07 +02:00
|
|
|
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-19 16:38:07 +02:00
|
|
|
export default translate('commons')(Breadcrumb);
|