From a52cd625b87fb7250d4b4b5c67a29cc956ab0a92 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Fri, 17 May 2019 08:50:32 +0200 Subject: [PATCH] add DeleteRepositoryRole --- scm-ui/public/locales/en/config.json | 10 ++ .../roles/containers/DeleteRepositoryRole.js | 113 ++++++++++++++++++ .../roles/containers/EditRepositoryRole.js | 3 + 3 files changed, 126 insertions(+) create mode 100644 scm-ui/src/config/roles/containers/DeleteRepositoryRole.js diff --git a/scm-ui/public/locales/en/config.json b/scm-ui/public/locales/en/config.json index bdb245544a..44da3c1be2 100644 --- a/scm-ui/public/locales/en/config.json +++ b/scm-ui/public/locales/en/config.json @@ -33,6 +33,16 @@ "name": "Name", "system": "System" }, + "deleteRole" : { + "button": "Delete", + "subtitle": "Delete Permission Role", + "confirmAlert": { + "title": "Delete Permission Role", + "message": "Do you really want to delete this permission role? All users who own this role will lose their permissions.", + "submit": "Yes", + "cancel": "No" + } + }, "config-form": { "submit": "Submit", "submit-success-notification": "Configuration changed successfully!", diff --git a/scm-ui/src/config/roles/containers/DeleteRepositoryRole.js b/scm-ui/src/config/roles/containers/DeleteRepositoryRole.js new file mode 100644 index 0000000000..a00cc21840 --- /dev/null +++ b/scm-ui/src/config/roles/containers/DeleteRepositoryRole.js @@ -0,0 +1,113 @@ +// @flow +import React from "react"; +import { translate } from "react-i18next"; +import type { RepositoryRole } from "@scm-manager/ui-types"; +import { + Subtitle, + DeleteButton, + confirmAlert, + ErrorNotification +} from "@scm-manager/ui-components"; +import { connect } from "react-redux"; +import { withRouter } from "react-router-dom"; +import type { History } from "history"; +import { + deleteRole, + getDeleteRoleFailure, + isDeleteRolePending +} from "../modules/roles"; + +type Props = { + loading: boolean, + error: Error, + role: RepositoryRole, + confirmDialog?: boolean, + deleteRole: (role: RepositoryRole, callback?: () => void) => void, + + // context props + history: History, + t: string => string +}; + +class DeleteRepositoryRole extends React.Component { + static defaultProps = { + confirmDialog: true + }; + + roleDeleted = () => { + this.props.history.push("/config/roles/"); + }; + + deleteRole = () => { + this.props.deleteRole(this.props.role, this.roleDeleted); + }; + + confirmDelete = () => { + const { t } = this.props; + confirmAlert({ + title: t("deleteRole.confirmAlert.title"), + message: t("deleteRole.confirmAlert.message"), + buttons: [ + { + label: t("deleteRole.confirmAlert.submit"), + onClick: () => this.deleteRole() + }, + { + label: t("deleteRole.confirmAlert.cancel"), + onClick: () => null + } + ] + }); + }; + + isDeletable = () => { + return this.props.role._links.delete; + }; + + render() { + const { loading, error, confirmDialog, t } = this.props; + const action = confirmDialog ? this.confirmDelete : this.deleteRole; + + if (!this.isDeletable()) { + return null; + } + + return ( + <> + +
+
+ + +
+
+ + ); + } +} + +const mapStateToProps = (state, ownProps) => { + const loading = isDeleteRolePending(state, ownProps.role.name); + const error = getDeleteRoleFailure(state, ownProps.role.name); + return { + loading, + error + }; +}; + +const mapDispatchToProps = dispatch => { + return { + deleteRole: (role: RepositoryRole, callback?: () => void) => { + dispatch(deleteRole(role, callback)); + } + }; +}; + +export default connect( + mapStateToProps, + mapDispatchToProps +)(withRouter(translate("config")(DeleteRepositoryRole))); diff --git a/scm-ui/src/config/roles/containers/EditRepositoryRole.js b/scm-ui/src/config/roles/containers/EditRepositoryRole.js index deb0a77583..f63a2f3e50 100644 --- a/scm-ui/src/config/roles/containers/EditRepositoryRole.js +++ b/scm-ui/src/config/roles/containers/EditRepositoryRole.js @@ -10,6 +10,7 @@ import { } from "../modules/roles"; import { ErrorNotification } from "@scm-manager/ui-components"; import type { RepositoryRole } from "@scm-manager/ui-types"; +import DeleteRepositoryRole from "./DeleteRepositoryRole"; type Props = { disabled: boolean, @@ -49,6 +50,8 @@ class EditRepositoryRole extends React.Component { role={this.props.role} submitForm={role => this.updateRepositoryRole(role)} /> +
+ ); }