From 969859ad7fcd7d8eb145a763f29ee9692b93bc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Tue, 13 Nov 2018 13:10:54 +0100 Subject: [PATCH] add globalBinder for config of repos --- .../config/RepositoryConfigurationBinder.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 scm-ui-components/packages/ui-components/src/config/RepositoryConfigurationBinder.js diff --git a/scm-ui-components/packages/ui-components/src/config/RepositoryConfigurationBinder.js b/scm-ui-components/packages/ui-components/src/config/RepositoryConfigurationBinder.js new file mode 100644 index 0000000000..be23c13eae --- /dev/null +++ b/scm-ui-components/packages/ui-components/src/config/RepositoryConfigurationBinder.js @@ -0,0 +1,43 @@ +// @flow +import * as React from "react"; +import { binder } from "@scm-manager/ui-extensions"; +import { NavLink } from "../navigation"; +import { Route } from "react-router-dom"; +import { translate } from "react-i18next"; + + +class RepositoryConfigurationBinder { + + i18nNamespace: string = "plugins"; + + bindGlobal(to: string, labelI18nKey: string, linkName: string, ConfigurationComponent: any) { + + // create predicate based on the link name of the index resource + // if the linkname is not available, the navigation link and the route are not bound to the extension points + const configPredicate = (props: Object) => { + return props.repository && props.repository._links && props.repository._links[linkName]; + }; + + // create NavigationLink with translated label + const ConfigNavLink = translate(this.i18nNamespace)(({t, url}) => { + return ; + }); + + // bind navigation link to extension point + binder.bind("repository.navigation", ConfigNavLink, configPredicate); + + + // route for global configuration, passes the current repository to component + const ConfigRoute = ({ url, repository }) => { + return } + exact/>; + }; + + // bind config route to extension point + binder.bind("repository.route", ConfigRoute, configPredicate); + } + +} + +export default new RepositoryConfigurationBinder();