2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import { Permission } from '@scm-manager/ui-types';
|
|
|
|
|
import { confirmAlert } from '@scm-manager/ui-components';
|
2018-08-30 09:49:36 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
permission: Permission;
|
|
|
|
|
namespace: string;
|
|
|
|
|
repoName: string;
|
|
|
|
|
confirmDialog?: boolean;
|
|
|
|
|
t: (p: string) => string;
|
2018-08-30 11:33:49 +02:00
|
|
|
deletePermission: (
|
|
|
|
|
permission: Permission,
|
|
|
|
|
namespace: string,
|
2019-10-19 16:38:07 +02:00
|
|
|
repoName: string,
|
|
|
|
|
) => void;
|
|
|
|
|
loading: boolean;
|
2018-08-30 09:49:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DeletePermissionButton extends React.Component<Props> {
|
|
|
|
|
static defaultProps = {
|
2019-10-19 16:38:07 +02:00
|
|
|
confirmDialog: true,
|
2018-08-30 09:49:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
deletePermission = () => {
|
2018-08-30 11:33:49 +02:00
|
|
|
this.props.deletePermission(
|
|
|
|
|
this.props.permission,
|
|
|
|
|
this.props.namespace,
|
2019-10-19 16:38:07 +02:00
|
|
|
this.props.repoName,
|
2018-08-30 11:33:49 +02:00
|
|
|
);
|
2018-08-30 09:49:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
confirmDelete = () => {
|
|
|
|
|
const { t } = this.props;
|
|
|
|
|
confirmAlert({
|
2019-10-19 16:38:07 +02:00
|
|
|
title: t('permission.delete-permission-button.confirm-alert.title'),
|
|
|
|
|
message: t('permission.delete-permission-button.confirm-alert.message'),
|
2018-08-30 09:49:36 +02:00
|
|
|
buttons: [
|
|
|
|
|
{
|
2019-10-19 16:38:07 +02:00
|
|
|
label: t('permission.delete-permission-button.confirm-alert.submit'),
|
|
|
|
|
onClick: () => this.deletePermission(),
|
2018-08-30 09:49:36 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-19 16:38:07 +02:00
|
|
|
label: t('permission.delete-permission-button.confirm-alert.cancel'),
|
|
|
|
|
onClick: () => null,
|
|
|
|
|
},
|
|
|
|
|
],
|
2018-08-30 09:49:36 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isDeletable = () => {
|
|
|
|
|
return this.props.permission._links.delete;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-02-01 15:31:14 +01:00
|
|
|
const { confirmDialog } = this.props;
|
2018-08-30 09:49:36 +02:00
|
|
|
const action = confirmDialog ? this.confirmDelete : this.deletePermission;
|
|
|
|
|
|
|
|
|
|
if (!this.isDeletable()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2018-08-30 11:33:49 +02:00
|
|
|
return (
|
2019-02-01 15:31:14 +01:00
|
|
|
<a className="level-item" onClick={action}>
|
|
|
|
|
<span className="icon is-small">
|
|
|
|
|
<i className="fas fa-trash" />
|
|
|
|
|
</span>
|
|
|
|
|
</a>
|
2018-08-30 11:33:49 +02:00
|
|
|
);
|
2018-08-30 09:49:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-19 16:38:07 +02:00
|
|
|
export default translate('repos')(DeletePermissionButton);
|