Merged in feature/ui-abstraction-repository-config (pull request #110)

Feature/ui abstraction repository config
This commit is contained in:
René Pfeuffer
2018-11-21 13:06:41 +00:00
7 changed files with 55 additions and 22 deletions

View File

@@ -11,8 +11,8 @@ import {
type RenderProps = {
readOnly: boolean,
initialConfiguration: Configuration,
onConfigurationChange: (Configuration, boolean) => void
initialConfiguration: ConfigurationType,
onConfigurationChange: (ConfigurationType, boolean) => void
};
type Props = {
@@ -23,7 +23,7 @@ type Props = {
t: (string) => string
};
type Configuration = {
type ConfigurationType = {
_links: Links
} & Object;
@@ -33,8 +33,8 @@ type State = {
modifying: boolean,
contentType?: string,
configuration?: Configuration,
modifiedConfiguration?: Configuration,
configuration?: ConfigurationType,
modifiedConfiguration?: ConfigurationType,
valid: boolean
};
@@ -42,7 +42,7 @@ type State = {
* GlobalConfiguration uses the render prop pattern to encapsulate the logic for
* synchronizing the configuration with the backend.
*/
class GlobalConfiguration extends React.Component<Props, State> {
class Configuration extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
@@ -84,7 +84,7 @@ class GlobalConfiguration extends React.Component<Props, State> {
});
};
loadConfig = (configuration: Configuration) => {
loadConfig = (configuration: ConfigurationType) => {
this.setState({
configuration,
fetching: false,
@@ -107,7 +107,7 @@ class GlobalConfiguration extends React.Component<Props, State> {
return !modificationUrl;
};
configurationChanged = (configuration: Configuration, valid: boolean) => {
configurationChanged = (configuration: ConfigurationType, valid: boolean) => {
this.setState({
modifiedConfiguration: configuration,
valid
@@ -159,4 +159,4 @@ class GlobalConfiguration extends React.Component<Props, State> {
}
export default translate("config")(GlobalConfiguration);
export default translate("config")(Configuration);

View File

@@ -9,6 +9,16 @@ class ConfigurationBinder {
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) {
// create predicate based on the link name of the index resource
@@ -19,25 +29,48 @@ class ConfigurationBinder {
// create NavigationLink with translated label
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
binder.bind("config.navigation", ConfigNavLink, configPredicate);
// route for global configuration, passes the link from the index resource to component
const ConfigRoute = ({ url, links }) => {
const link = links[linkName].href;
return <Route path={url + to}
render={() => <ConfigurationComponent link={link}/>}
exact/>;
return this.route(url + to, <ConfigurationComponent link={link}/>);
};
// bind config route to extension point
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();

View File

@@ -1,3 +1,3 @@
// @flow
export { default as ConfigurationBinder } from "./ConfigurationBinder";
export { default as GlobalConfiguration } from "./GlobalConfiguration";
export { default as Configuration } from "./Configuration";