2018-09-03 16:17:36 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import PrimaryNavigationLink from "./PrimaryNavigationLink";
|
2019-01-02 11:53:51 +01:00
|
|
|
import type { Links } from "@scm-manager/ui-types";
|
2019-01-02 12:28:52 +01:00
|
|
|
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
|
2018-09-03 16:17:36 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2018-10-05 13:48:21 +02:00
|
|
|
t: string => string,
|
2019-01-02 11:53:51 +01:00
|
|
|
links: Links,
|
2018-09-03 16:17:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PrimaryNavigation extends React.Component<Props> {
|
2018-10-05 13:48:21 +02:00
|
|
|
|
2019-01-02 11:53:51 +01:00
|
|
|
createNavigationAppender = (navigationItems) => {
|
|
|
|
|
const { t, links } = this.props;
|
|
|
|
|
|
|
|
|
|
return (to: string, match: string, label: string, linkName: string) => {
|
|
|
|
|
const link = links[linkName];
|
|
|
|
|
if (link) {
|
|
|
|
|
const navigationItem = (
|
|
|
|
|
<PrimaryNavigationLink
|
|
|
|
|
to={to}
|
|
|
|
|
match={match}
|
|
|
|
|
label={t(label)}
|
|
|
|
|
key={linkName}
|
|
|
|
|
/>)
|
|
|
|
|
;
|
|
|
|
|
navigationItems.push(navigationItem);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-02 12:28:52 +01:00
|
|
|
appendLogout = (navigationItems, append) => {
|
2019-01-02 11:53:51 +01:00
|
|
|
const { t, links } = this.props;
|
|
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
|
links,
|
|
|
|
|
label: t("primary-navigation.logout")
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-02 12:28:52 +01:00
|
|
|
if (binder.hasExtension("primary-navigation.logout", props)) {
|
|
|
|
|
navigationItems.push(
|
|
|
|
|
<ExtensionPoint name="primary-navigation.logout" props={props} />
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
append("/logout", "/logout", "primary-navigation.logout", "logout");
|
|
|
|
|
}
|
2019-01-02 11:53:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
createNavigationItems = () => {
|
|
|
|
|
const navigationItems = [];
|
|
|
|
|
|
|
|
|
|
const append = this.createNavigationAppender(navigationItems);
|
|
|
|
|
append("/repos", "/(repo|repos)", "primary-navigation.repositories", "repositories");
|
|
|
|
|
append("/users", "/(user|users)", "primary-navigation.users", "users");
|
|
|
|
|
append("/groups", "/(group|groups)", "primary-navigation.groups", "groups");
|
|
|
|
|
append("/config", "/config", "primary-navigation.config", "config");
|
|
|
|
|
|
2019-01-07 10:10:06 +01:00
|
|
|
navigationItems.push(
|
|
|
|
|
<ExtensionPoint
|
|
|
|
|
name="primary-navigation"
|
|
|
|
|
renderAll={true}
|
|
|
|
|
props={{links: this.props.links}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2019-01-02 12:28:52 +01:00
|
|
|
this.appendLogout(navigationItems, append);
|
2019-01-02 11:53:51 +01:00
|
|
|
|
|
|
|
|
return navigationItems;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const navigationItems = this.createNavigationItems();
|
2018-10-05 13:48:21 +02:00
|
|
|
|
2018-09-03 16:17:36 +02:00
|
|
|
return (
|
|
|
|
|
<nav className="tabs is-boxed">
|
|
|
|
|
<ul>
|
2019-01-02 11:53:51 +01:00
|
|
|
{navigationItems}
|
2018-09-03 16:17:36 +02:00
|
|
|
</ul>
|
|
|
|
|
</nav>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate("commons")(PrimaryNavigation);
|