2018-09-27 16:32:37 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import type { Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import { NavLink } from "@scm-manager/ui-components";
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
repository: Repository,
|
|
|
|
|
to: string,
|
|
|
|
|
label: string,
|
2018-09-28 11:31:38 +02:00
|
|
|
linkName: string,
|
|
|
|
|
activeOnlyWhenExact: boolean
|
2018-09-27 16:32:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Component renders only if the repository contains the link with the given name.
|
|
|
|
|
*/
|
|
|
|
|
class RepositoryNavLink extends React.Component<Props> {
|
|
|
|
|
render() {
|
2018-09-28 11:31:38 +02:00
|
|
|
const { linkName, to, label, repository, activeOnlyWhenExact } = this.props;
|
2018-09-27 16:32:37 +02:00
|
|
|
|
|
|
|
|
if (!repository._links[linkName]) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 11:31:38 +02:00
|
|
|
return (
|
|
|
|
|
<NavLink
|
|
|
|
|
to={to}
|
|
|
|
|
label={label}
|
|
|
|
|
activeOnlyWhenExact={activeOnlyWhenExact}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2018-09-27 16:32:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default RepositoryNavLink;
|