Skip to content

Commit

Permalink
source version (hard) delete
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Jan 12, 2021
1 parent 94576b8 commit acbd8cf
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/components/common/ConceptContainerVersionList.jsx
@@ -1,12 +1,14 @@
import React from 'react';
import alertifyjs from 'alertifyjs';
import {
Accordion, AccordionSummary, AccordionDetails, Typography, Divider, Tooltip,
IconButton,
} from '@material-ui/core';
import { map, isEmpty, startCase, get } from 'lodash';
import {
ExpandMore as ExpandMoreIcon, Search as SearchIcon, Edit as EditIcon,
ExpandMore as ExpandMoreIcon, Search as SearchIcon, Edit as EditIcon, Delete as DeleteIcon
} from '@material-ui/icons';
import APIService from '../../services/APIService';
import { headFirst } from '../../common/utils';
import LastUpdatedOnLabel from './LastUpdatedOnLabel';
import ResourceVersionLabel from './ResourceVersionLabel';
Expand All @@ -33,8 +35,24 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit }) => {
setSelectedVersion(version)
setVersionForm(true)
}
const onEditCancel = () => {
setVersionForm(false)
const deleteVersion = version => {
APIService.new().overrideURL(version.version_url).delete().then(response => {
if(get(response, 'status') === 204)
alertifyjs.success('Source Version Deleted', 1, () => window.location.reload())
else
alertifyjs.error('Something bad happened!')
})
}
const onEditCancel = () => setVersionForm(false);
const onDeleteClick = version => {
const title = `Delete Version : ${version.short_code} [${version.id}]`;
const message = `Are you sure you want to permanently delete this source version ${version.id}? This action cannot be undone! This will delete the version and all of its details. Concepts and mappings in this source version will not be affected.`

const confirm = alertifyjs.confirm()
confirm.setHeader(title);
confirm.setMessage(message);
confirm.set('onok', () => deleteVersion(version));
confirm.show();
}

return (
Expand All @@ -55,7 +73,7 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit }) => {
map(sortedVersions, (version, index) => (
<div className='col-md-12 no-side-padding' key={index}>
<div className='col-md-12 no-side-padding flex-vertical-center' style={{margin: '10px 0'}}>
<div className='col-md-10 no-left-padding'>
<div className='col-md-9 no-left-padding'>
<div className='col-md-12 no-side-padding' style={{marginBottom: '5px'}}>
<ResourceVersionLabel {...version} />
</div>
Expand All @@ -70,14 +88,21 @@ const ConceptContainerVersionList = ({ versions, resource, canEdit }) => {
/>
</div>
</div>
<div className='col-md-2 no-right-padding' style={{textAlign: 'right'}}>
<div className='col-md-3 no-right-padding' style={{textAlign: 'right'}}>
{
canEdit && version.id.toLowerCase() !== 'head' &&
<Tooltip title='Edit Version'>
<IconButton onClick={() => onEditClick(version)}>
<EditIcon fontSize='inherit' />
</IconButton>
</Tooltip>
<React.Fragment>
<Tooltip title='Edit Version'>
<IconButton onClick={() => onEditClick(version)}>
<EditIcon fontSize='inherit' />
</IconButton>
</Tooltip>
<Tooltip title='Delete Version'>
<IconButton onClick={() => onDeleteClick(version)}>
<DeleteIcon fontSize='inherit' />
</IconButton>
</Tooltip>
</React.Fragment>
}
<Tooltip title='Version Link'>
<IconButton href={`#${version.concepts_url}`} color='primary'>
Expand Down

0 comments on commit acbd8cf

Please sign in to comment.