extract logic of AdminGroupTable, AdminUserTable and ProxyExcludesTable in to ArrayConfigTable

This commit is contained in:
Sebastian Sdorra
2018-08-30 10:12:01 +02:00
parent dd76a00aa1
commit 5eb55a9baa
4 changed files with 87 additions and 87 deletions

View File

@@ -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<Props, State> {
render() {
const { t, disabled } = this.props;
const { t, disabled, adminGroups } = this.props;
return (
<div>
<label className="label">{t("admin-settings.admin-groups")}</label>
<table className="table is-hoverable is-fullwidth">
<tbody>
{this.props.adminGroups.map(group => {
return (
<tr key={group}>
<td key={group}>{group}</td>
<td>
<RemoveEntryOfTableButton
entryname={group}
removeEntry={this.removeEntry}
<ArrayConfigTable
items={adminGroups}
label={t("admin-settings.admin-groups")}
removeLabel={t("admin-settings.remove-group-button")}
onRemove={this.removeEntry}
disabled={disabled}
label={t("admin-settings.remove-group-button")}
/>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}
removeEntry = (groupname: string) => {
const newGroups = this.props.adminGroups.filter(name => name !== groupname);
removeEntry = (newGroups: string[]) => {
this.props.onChange(true, newGroups, "adminGroups");
};
}

View File

@@ -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<Props, State> {
class AdminUserTable extends React.Component<Props> {
render() {
const { t, disabled } = this.props;
const { adminUsers, t, disabled } = this.props;
return (
<div>
<label className="label">{t("admin-settings.admin-users")}</label>
<table className="table is-hoverable is-fullwidth">
<tbody>
{this.props.adminUsers.map(user => {
return (
<tr key={user}>
<td key={user}>{user}</td>
<td>
<RemoveEntryOfTableButton
entryname={user}
removeEntry={this.removeEntry}
<ArrayConfigTable
items={adminUsers}
label={t("admin-settings.admin-users")}
removeLabel={t("admin-settings.remove-user-button")}
onRemove={this.removeEntry}
disabled={disabled}
label={t("admin-settings.remove-user-button")}
/>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}
removeEntry = (username: string) => {
const newUsers = this.props.adminUsers.filter(name => name !== username);
removeEntry = (newUsers: string[]) => {
this.props.onChange(true, newUsers, "adminUsers");
};
}

View File

@@ -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<Props> {
render() {
const { label, disabled, removeLabel, items } = this.props;
return (
<div>
<label className="label">{label}</label>
<table className="table is-hoverable is-fullwidth">
<tbody>
{items.map(item => {
return (
<tr key={item}>
<td>{item}</td>
<td>
<RemoveEntryOfTableButton
entryname={item}
removeEntry={this.removeEntry}
disabled={disabled}
label={removeLabel}
/>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}
removeEntry = (item: string) => {
const newItems = this.props.items.filter(name => name !== item);
this.props.onRemove(newItems, item);
};
}
export default ArrayConfigTable;

View File

@@ -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<Props, State> {
render() {
const { t } = this.props;
const { proxyExcludes, disabled, t } = this.props;
return (
<div>
<label className="label">{t("proxy-settings.proxy-excludes")}</label>
<table className="table is-hoverable is-fullwidth">
<tbody>
{this.props.proxyExcludes.map(excludes => {
return (
<tr key={excludes}>
<td key={excludes}>{excludes}</td>
<td>
<RemoveEntryOfTableButton
entryname={excludes}
removeEntry={this.removeEntry}
disabled={this.props.disabled}
label={t("proxy-settings.remove-proxy-exclude-button")}
<ArrayConfigTable
items={proxyExcludes}
label={t("proxy-settings.proxy-excludes")}
removeLabel={t("proxy-settings.remove-proxy-exclude-button")}
onRemove={this.removeEntry}
disabled={disabled}
/>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
}
removeEntry = (excludename: string) => {
const newExcludes = this.props.proxyExcludes.filter(
name => name !== excludename
);
removeEntry = (newExcludes: string[]) => {
this.props.onChange(true, newExcludes, "proxyExcludes");
};
}