Commit 0ada9436 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Delete dataset

parent a55a5e68
......@@ -14,6 +14,7 @@ interface IStepNavigationProps extends React.ClassAttributes<any> {
disabled: boolean;
onPublish: () => void;
onGotoStep: (i: number) => () => void;
onDelete: () => void;
showStepName: boolean;
topDivider: boolean;
bottomDivider: boolean;
......@@ -44,6 +45,7 @@ const styles = (theme) => ({
},
btnBlue: theme.buttons.blue,
btnReturn: theme.buttons.return,
btnDelete: theme.buttons.default,
});
class StepNavigation extends React.Component<IStepNavigationProps, any> {
......@@ -71,7 +73,7 @@ class StepNavigation extends React.Component<IStepNavigationProps, any> {
public render() {
const {classes, disabled, steps, showStepName, topDivider, bottomDivider, onGotoStep, onPublish} = this.props;
const {classes, disabled, steps, showStepName, topDivider, bottomDivider, onGotoStep, onDelete, onPublish} = this.props;
return (
<Grid container spacing={ 0 } className={ classes.root }>
......@@ -83,6 +85,12 @@ class StepNavigation extends React.Component<IStepNavigationProps, any> {
}
</h3>
<div className={ classes.flexGrow }/>
{ this.state.id === 1 && (
<Button onClick={ onDelete } className={ classes.btnDelete }>
Delete dataset
</Button>
)
}
{ this.state.id > 1 && (
<Button onClick={ onGotoStep(this.state.id - 1) } className={ classes.btnReturn }>
Return
......
......@@ -4,12 +4,13 @@ import {bindActionCreators} from 'redux';
import Grid from 'material-ui/Grid';
import {log} from 'utilities/debug';
import confirm from 'utilities/confirmAlert';
import ProgressMenu from './progress-menu';
import TopSection from './TopSection';
import BottomSection from './BottomSection';
import {navigateTo} from 'actions/navigation';
import {loadDataset, publishDataset} from 'actions/dataset';
import {loadDataset, publishDataset, deleteDataset} from 'actions/dataset';
import {Dataset} from 'model/dataset.model';
import StepNavigation from './StepNavigation';
import Loading from 'ui/common/Loading';
......@@ -68,6 +69,7 @@ interface IDatasetProps extends React.ClassAttributes<any> {
dataset: Dataset;
loadDataset: (uuid: string) => Promise<Dataset>;
publishDataset: (dataset: Dataset) => void;
deleteDataset: (dataset: Dataset) => Promise<Dataset>;
navigateTo: (path: string) => void;
}
......@@ -100,6 +102,20 @@ class DatasetStepper extends React.Component<IDatasetProps, any> {
}
}
protected onDelete = (e) => {
const {dataset, deleteDataset, navigateTo} = this.props;
log('Removing dataset', dataset);
confirm(<span>Delete <b>{ dataset.title }</b>?</span>, {
description: `Deleting the dartaset will remove all related data.`,
confirmLabel: 'Delete',
abortLabel: 'Cancel',
}).then(() => {
deleteDataset(dataset).then(() => navigateTo(`/dashboard`));
}).catch(() => {
// don't delete
});
}
public onPublish = (e) => {
const {dataset, publishDataset} = this.props;
log('Publishing dataset', dataset);
......@@ -126,7 +142,7 @@ class DatasetStepper extends React.Component<IDatasetProps, any> {
<TopSection/>
<Grid item xs={ 12 } md={ 9 } xl={ 10 } className="back-gray p-20">
<Grid container spacing={ 0 } className="back-white">
<StepNavigation disabled={ !(dataset && dataset.uuid) } onGotoStep={ this.gotoStep } steps={ steps } location={ location } showStepName bottomDivider onPublish={ this.onPublish } />
<StepNavigation disabled={ !(dataset && dataset.uuid) } onGotoStep={ this.gotoStep } onDelete={ this.onDelete } steps={ steps } location={ location } showStepName bottomDivider onPublish={ this.onPublish } />
<Grid item xs={ 12 }>
{ stillLoading ? <Loading /> :
<div>
......@@ -134,7 +150,7 @@ class DatasetStepper extends React.Component<IDatasetProps, any> {
</div>
}
</Grid>
<StepNavigation disabled={ !(dataset && dataset.uuid) } onGotoStep={ this.gotoStep } steps={ steps } location={ location } topDivider onPublish={ this.onPublish } />
<StepNavigation disabled={ !(dataset && dataset.uuid) } onGotoStep={ this.gotoStep } onDelete={ this.onDelete } steps={ steps } location={ location } topDivider onPublish={ this.onPublish } />
</Grid>
</Grid>
<Grid item xs={ 12 } md={ 3 } xl={ 2 }>
......@@ -156,6 +172,7 @@ const mapStateToProps = (state, ownProps) => ({
const mapDispatchToProps = (dispatch) => bindActionCreators({
loadDataset,
publishDataset,
deleteDataset,
navigateTo,
}, dispatch);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment