2019-10-19 16:38:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { translate } from 'react-i18next';
|
|
|
|
|
import { Repository } from '@scm-manager/ui-types';
|
2019-02-06 10:42:25 +01:00
|
|
|
import {
|
|
|
|
|
Subtitle,
|
|
|
|
|
DeleteButton,
|
2019-02-06 11:17:06 +01:00
|
|
|
confirmAlert,
|
2019-10-19 16:38:07 +02:00
|
|
|
ErrorNotification,
|
|
|
|
|
} from '@scm-manager/ui-components';
|
2019-02-06 11:44:03 +01:00
|
|
|
import {
|
|
|
|
|
deleteRepo,
|
|
|
|
|
getDeleteRepoFailure,
|
2019-10-19 16:38:07 +02:00
|
|
|
isDeleteRepoPending,
|
|
|
|
|
} from '../modules/repos';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
|
import { History } from 'history';
|
2018-08-06 10:08:28 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
repository: Repository;
|
|
|
|
|
confirmDialog?: boolean;
|
|
|
|
|
deleteRepo: (p1: Repository, p2: () => void) => void;
|
2019-01-23 12:07:28 +01:00
|
|
|
|
2018-08-06 10:08:28 +02:00
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
history: History;
|
|
|
|
|
t: (p: string) => string;
|
2018-08-06 10:08:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-01-23 10:08:15 +01:00
|
|
|
class DeleteRepo extends React.Component<Props> {
|
2018-08-06 10:08:28 +02:00
|
|
|
static defaultProps = {
|
2019-10-19 16:38:07 +02:00
|
|
|
confirmDialog: true,
|
2018-08-06 10:08:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-02-06 11:44:03 +01:00
|
|
|
deleted = () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
this.props.history.push('/repos/');
|
2019-02-06 11:44:03 +01:00
|
|
|
};
|
|
|
|
|
|
2019-01-23 13:20:57 +01:00
|
|
|
deleteRepo = () => {
|
2019-02-06 11:44:03 +01:00
|
|
|
this.props.deleteRepo(this.props.repository, this.deleted);
|
2018-08-06 10:08:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
confirmDelete = () => {
|
|
|
|
|
const { t } = this.props;
|
|
|
|
|
confirmAlert({
|
2019-10-19 16:38:07 +02:00
|
|
|
title: t('deleteRepo.confirmAlert.title'),
|
|
|
|
|
message: t('deleteRepo.confirmAlert.message'),
|
2018-08-06 10:08:28 +02:00
|
|
|
buttons: [
|
|
|
|
|
{
|
2019-10-19 16:38:07 +02:00
|
|
|
label: t('deleteRepo.confirmAlert.submit'),
|
|
|
|
|
onClick: () => this.deleteRepo(),
|
2018-08-06 10:08:28 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-19 16:38:07 +02:00
|
|
|
label: t('deleteRepo.confirmAlert.cancel'),
|
|
|
|
|
onClick: () => null,
|
|
|
|
|
},
|
|
|
|
|
],
|
2018-08-06 10:08:28 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isDeletable = () => {
|
|
|
|
|
return this.props.repository._links.delete;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-02-06 10:42:25 +01:00
|
|
|
const { loading, error, confirmDialog, t } = this.props;
|
2019-01-23 13:20:57 +01:00
|
|
|
const action = confirmDialog ? this.confirmDelete : this.deleteRepo;
|
2018-08-06 10:08:28 +02:00
|
|
|
|
|
|
|
|
if (!this.isDeletable()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-01-18 17:28:38 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-04-04 16:56:35 +02:00
|
|
|
<hr />
|
2019-10-19 16:38:07 +02:00
|
|
|
<Subtitle subtitle={t('deleteRepo.subtitle')} />
|
2019-02-06 10:42:25 +01:00
|
|
|
<ErrorNotification error={error} />
|
2019-01-18 17:28:38 +01:00
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
|
|
|
|
<DeleteButton
|
2019-10-19 16:38:07 +02:00
|
|
|
label={t('deleteRepo.button')}
|
2019-01-18 17:28:38 +01:00
|
|
|
action={action}
|
2019-02-06 10:42:25 +01:00
|
|
|
loading={loading}
|
2019-01-18 17:28:38 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
2018-08-06 10:08:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 10:42:25 +01:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const { namespace, name } = ownProps.repository;
|
|
|
|
|
const loading = isDeleteRepoPending(state, namespace, name);
|
|
|
|
|
const error = getDeleteRepoFailure(state, namespace, name);
|
|
|
|
|
return {
|
|
|
|
|
loading,
|
2019-10-19 16:38:07 +02:00
|
|
|
error,
|
2019-02-06 10:42:25 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-06 11:44:03 +01:00
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
deleteRepo: (repo: Repository, callback: () => void) => {
|
|
|
|
|
dispatch(deleteRepo(repo, callback));
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
2019-02-06 11:44:03 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
2019-10-19 16:38:07 +02:00
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(withRouter(translate('repos')(DeleteRepo)));
|