Skip to content

Commit

Permalink
[DUOS-2811][risk=no] Enable data submitter dataset deletion via the U…
Browse files Browse the repository at this point in the history
…I on data submissions (#2442)
  • Loading branch information
aarohinadkarni authored Feb 13, 2024
1 parent 149d5ec commit fcb7cc6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/pages/researcher_console/DatasetSubmissions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import DatasetSubmissionsTable from './DatasetSubmissionsTable';
import {Storage} from '../../libs/storage';
import styles from './DatasetTerms.module.css';

export default function DatasetSubmissions() {
export default function DatasetSubmissions(props) {

const {history} = props;
const [terms, setTerms] = useState([]);
const [filteredTerms, setFilteredTerms] = useState([]);
const [isLoading, setIsLoading] = useState(true);
Expand Down Expand Up @@ -142,7 +143,7 @@ export default function DatasetSubmissions() {
</div>
</div>
<div className={styles['term-table-container']}>
<DatasetSubmissionsTable terms={filteredTerms} isLoading={isLoading}/>
<DatasetSubmissionsTable terms={filteredTerms} isLoading={isLoading} history={history}/>
</div>
</div>
);
Expand Down
59 changes: 54 additions & 5 deletions src/pages/researcher_console/DatasetSubmissionsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import {useCallback, useEffect, useState} from 'react';
import {Notifications} from '../../libs/utils';
import loadingIndicator from '../../images/loading-indicator.svg';
import SortableTable from '../../components/sortable_table/SortableTable';
import {concat, isNil, join} from 'lodash/fp';
import {cloneDeep, concat, findIndex, join, isNil} from 'lodash/fp';
import Button from '@mui/material/Button';
import { Link } from 'react-router-dom';
import {DataSet} from '../../libs/ajax';
import { ConfirmationDialog } from '../..//components/modals/ConfirmationDialog';


export default function DatasetSubmissionsTable(props) {
Expand Down Expand Up @@ -65,11 +68,39 @@ export default function DatasetSubmissionsTable(props) {
];

const [terms, setTerms] = useState([]);
const [selectedTerm, setSelectedTerm] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [rows, setRows] = useState([]);
const [open, setOpen] = useState(false);

const handleClick = (term) => {
setOpen(true);
setSelectedTerm(term);
};

const handleClose = () => {
setOpen(false);
};

const removeDataset = async (termToDelete) => {
const termName = termToDelete.datasetName;
const termId = termToDelete.datasetId;
setOpen(false);
try {
DataSet.deleteDataset(termId).then(() => {
Notifications.showSuccess({
text: `Removed dataset '${termName}' successfully.`,
});
props.history.push('/datalibrary');});
} catch (error) {
Notifications.showError({
text: `Error removing ${termName} as a dataset`,
});
}
};

// Datasets can be filtered from the parent component and redrawn frequently.
const redrawRows = useCallback(() => {
const redrawRows = useCallback((open, selectedTerm) => {
const rows = terms.map((term) => {
const status = isNil(term.dacApproval) ? 'Pending' : (term.dacApproval ? 'Accepted' : 'Rejected');
const primaryCodes = term.dataUse?.primary?.map(du => du.code);
Expand All @@ -89,6 +120,24 @@ export default function DatasetSubmissionsTable(props) {
Edit
</Button>
</div>;
const deleteButton = (status !== 'Accepted' && term.deletable) ?
<div>
<Link
style={{marginLeft: '15px'}}
id={`${term.datasetId}_delete`}
className={'glyphicon glyphicon-trash'}
onClick={() => handleClick(term)}
to={`#`}
/>
<ConfirmationDialog
title="Delete dataset"
openState={open}
close={handleClose}
action={() => removeDataset(selectedTerm)}
description={`Are you sure you want to delete the dataset '${selectedTerm.datasetIdentifier}'?`}
/>
</div> :
<div/>;
const custodians = join(', ')(term.study?.dataCustodianEmail);
return {
datasetIdentifier: term.datasetIdentifier,
Expand All @@ -98,7 +147,7 @@ export default function DatasetSubmissionsTable(props) {
dac: term.dac?.dacName,
dataUse: join(', ')(concat(primaryCodes)(secondaryCodes)),
status: status,
actions: editButton
actions: editButton, deleteButton
};
});
setRows(rows);
Expand All @@ -109,13 +158,13 @@ export default function DatasetSubmissionsTable(props) {
try {
setTerms(props.terms);
setIsLoading(props.isLoading);
redrawRows();
redrawRows(open,selectedTerm);
} catch (error) {
Notifications.showError({text: 'Error: Unable to retrieve datasets from server'});
}
};
init();
}, [props, redrawRows]);
}, [props, redrawRows, open, selectedTerm]);

const sortableTable = <SortableTable
headCells={columns}
Expand Down

0 comments on commit fcb7cc6

Please sign in to comment.