mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
refactoring
This commit is contained in:
@@ -9,6 +9,16 @@ class ConfigurationBinder {
|
|||||||
|
|
||||||
i18nNamespace: string = "plugins";
|
i18nNamespace: string = "plugins";
|
||||||
|
|
||||||
|
navLink(to: string, labelI18nKey: string, t: any){
|
||||||
|
return <NavLink to={to} label={t(labelI18nKey)} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
route(path: string, Component: any){
|
||||||
|
return <Route path={path}
|
||||||
|
render={() => Component}
|
||||||
|
exact/>;
|
||||||
|
}
|
||||||
|
|
||||||
bindGlobal(to: string, labelI18nKey: string, linkName: string, ConfigurationComponent: any) {
|
bindGlobal(to: string, labelI18nKey: string, linkName: string, ConfigurationComponent: any) {
|
||||||
|
|
||||||
// create predicate based on the link name of the index resource
|
// create predicate based on the link name of the index resource
|
||||||
@@ -17,27 +27,51 @@ class ConfigurationBinder {
|
|||||||
return props.links && props.links[linkName];
|
return props.links && props.links[linkName];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// create NavigationLink with translated label and bind link to extensionPoint
|
||||||
// create NavigationLink with translated label
|
// create NavigationLink with translated label
|
||||||
const ConfigNavLink = translate(this.i18nNamespace)(({t}) => {
|
const ConfigNavLink = translate(this.i18nNamespace)(({t}) => {
|
||||||
return <NavLink to={"/config" + to} label={t(labelI18nKey)} />;
|
return this.navLink("/config" + to, labelI18nKey, t);
|
||||||
});
|
});
|
||||||
|
|
||||||
// bind navigation link to extension point
|
// bind navigation link to extension point
|
||||||
binder.bind("config.navigation", ConfigNavLink, configPredicate);
|
binder.bind("config.navigation", ConfigNavLink, configPredicate);
|
||||||
|
|
||||||
|
|
||||||
// route for global configuration, passes the link from the index resource to component
|
// route for global configuration, passes the link from the index resource to component
|
||||||
const ConfigRoute = ({ url, links }) => {
|
const ConfigRoute = ({ url, links }) => {
|
||||||
const link = links[linkName].href;
|
const link = links[linkName].href;
|
||||||
return <Route path={url + to}
|
return this.route(url + to, <ConfigurationComponent link={link}/>);
|
||||||
render={() => <ConfigurationComponent link={link}/>}
|
|
||||||
exact/>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// bind config route to extension point
|
// bind config route to extension point
|
||||||
binder.bind("config.route", ConfigRoute, configPredicate);
|
binder.bind("config.route", ConfigRoute, configPredicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bindRepository(to: string, labelI18nKey: string, linkName: string, RepositoryComponent: any) {
|
||||||
|
|
||||||
|
// create predicate based on the link name of the current repository route
|
||||||
|
// if the linkname is not available, the navigation link and the route are not bound to the extension points
|
||||||
|
const repoPredicate = (props: Object) => {
|
||||||
|
return props.repository && props.repository._links && props.repository._links[linkName];
|
||||||
|
};
|
||||||
|
|
||||||
|
// create NavigationLink with translated label
|
||||||
|
const RepoNavLink = translate(this.i18nNamespace)(({t, url}) => {
|
||||||
|
return this.navLink(url + to, labelI18nKey, t);
|
||||||
|
});
|
||||||
|
|
||||||
|
// bind navigation link to extension point
|
||||||
|
binder.bind("repository.navigation", RepoNavLink, repoPredicate);
|
||||||
|
|
||||||
|
|
||||||
|
// route for global configuration, passes the current repository to component
|
||||||
|
const RepoRoute = ({ url, repository }) => {
|
||||||
|
return this.route(url + to, <RepositoryComponent repository={repository}/>);
|
||||||
|
};
|
||||||
|
|
||||||
|
// bind config route to extension point
|
||||||
|
binder.bind("repository.route", RepoRoute, repoPredicate);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new ConfigurationBinder();
|
export default new ConfigurationBinder();
|
||||||
|
|||||||
Reference in New Issue
Block a user