From 5eb55a9baa7b39e8e8fecc9ef216e74181acd753 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Thu, 30 Aug 2018 10:12:01 +0200 Subject: [PATCH] extract logic of AdminGroupTable, AdminUserTable and ProxyExcludesTable in to ArrayConfigTable --- .../components/table/AdminGroupTable.js | 42 ++++++---------- .../config/components/table/AdminUserTable.js | 46 ++++++------------ .../components/table/ArrayConfigTable.js | 48 +++++++++++++++++++ .../components/table/ProxyExcludesTable.js | 38 ++++----------- 4 files changed, 87 insertions(+), 87 deletions(-) create mode 100644 scm-ui/src/config/components/table/ArrayConfigTable.js diff --git a/scm-ui/src/config/components/table/AdminGroupTable.js b/scm-ui/src/config/components/table/AdminGroupTable.js index fc05c75f06..db9f83af84 100644 --- a/scm-ui/src/config/components/table/AdminGroupTable.js +++ b/scm-ui/src/config/components/table/AdminGroupTable.js @@ -1,48 +1,34 @@ //@flow import React from "react"; import { translate } from "react-i18next"; -import { RemoveEntryOfTableButton } from "../../../components/buttons"; +import ArrayConfigTable from "./ArrayConfigTable"; type Props = { adminGroups: string[], - t: string => string, onChange: (boolean, any, string) => void, - disabled: boolean + disabled: boolean, + + // context props + t: string => string }; type State = {}; class AdminGroupTable extends React.Component { render() { - const { t, disabled } = this.props; + const { t, disabled, adminGroups } = this.props; return ( -
- - - - {this.props.adminGroups.map(group => { - return ( - - - - - ); - })} - -
{group} - -
-
+ ); } - removeEntry = (groupname: string) => { - const newGroups = this.props.adminGroups.filter(name => name !== groupname); + removeEntry = (newGroups: string[]) => { this.props.onChange(true, newGroups, "adminGroups"); }; } diff --git a/scm-ui/src/config/components/table/AdminUserTable.js b/scm-ui/src/config/components/table/AdminUserTable.js index c622a0e027..d1f35e8424 100644 --- a/scm-ui/src/config/components/table/AdminUserTable.js +++ b/scm-ui/src/config/components/table/AdminUserTable.js @@ -1,48 +1,32 @@ //@flow import React from "react"; import { translate } from "react-i18next"; -import { RemoveEntryOfTableButton } from "../../../components/buttons"; +import ArrayConfigTable from "./ArrayConfigTable"; type Props = { adminUsers: string[], - t: string => string, onChange: (boolean, any, string) => void, - disabled: boolean + disabled: boolean, + + // context props + t: string => string }; -type State = {}; - -class AdminUserTable extends React.Component { +class AdminUserTable extends React.Component { render() { - const { t, disabled } = this.props; + const { adminUsers, t, disabled } = this.props; return ( -
- - - - {this.props.adminUsers.map(user => { - return ( - - - - - ); - })} - -
{user} - -
-
+ ); } - removeEntry = (username: string) => { - const newUsers = this.props.adminUsers.filter(name => name !== username); + removeEntry = (newUsers: string[]) => { this.props.onChange(true, newUsers, "adminUsers"); }; } diff --git a/scm-ui/src/config/components/table/ArrayConfigTable.js b/scm-ui/src/config/components/table/ArrayConfigTable.js new file mode 100644 index 0000000000..f47e6e9dca --- /dev/null +++ b/scm-ui/src/config/components/table/ArrayConfigTable.js @@ -0,0 +1,48 @@ +//@flow +import React from "react"; +import { RemoveEntryOfTableButton } from "../../../components/buttons"; + +type Props = { + items: string[], + label: string, + removeLabel: string, + onRemove: (string[], string) => void, + disabled: boolean +}; + +class ArrayConfigTable extends React.Component { + render() { + const { label, disabled, removeLabel, items } = this.props; + return ( +
+ + + + {items.map(item => { + return ( + + + + + ); + })} + +
{item} + +
+
+ ); + } + + removeEntry = (item: string) => { + const newItems = this.props.items.filter(name => name !== item); + this.props.onRemove(newItems, item); + }; +} + +export default ArrayConfigTable; diff --git a/scm-ui/src/config/components/table/ProxyExcludesTable.js b/scm-ui/src/config/components/table/ProxyExcludesTable.js index 4476442c48..a7849ffdf2 100644 --- a/scm-ui/src/config/components/table/ProxyExcludesTable.js +++ b/scm-ui/src/config/components/table/ProxyExcludesTable.js @@ -1,7 +1,7 @@ //@flow import React from "react"; import { translate } from "react-i18next"; -import { RemoveEntryOfTableButton } from "../../../components/buttons"; +import ArrayConfigTable from "./ArrayConfigTable"; type Props = { proxyExcludes: string[], @@ -14,37 +14,19 @@ type State = {}; class ProxyExcludesTable extends React.Component { render() { - const { t } = this.props; + const { proxyExcludes, disabled, t } = this.props; return ( -
- - - - {this.props.proxyExcludes.map(excludes => { - return ( - - - - - ); - })} - -
{excludes} - -
-
+ ); } - removeEntry = (excludename: string) => { - const newExcludes = this.props.proxyExcludes.filter( - name => name !== excludename - ); + removeEntry = (newExcludes: string[]) => { this.props.onChange(true, newExcludes, "proxyExcludes"); }; }