Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DUOS-2452] DAC Dataset Acceptance => Public Visibility #2305

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 29 additions & 116 deletions src/pages/DatasetCatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ const canApplyForDataset = (dataset) => {
return dataset.active && !isNil(dataset.dacId);
};

const extractDatasetProp = (propertyName, dataset) => {
const property = find({ propertyName })(dataset.properties);
return property?.propertyValue;
};

const isVisible = (dataset) => {
const openAccess = extractDatasetProp('Open Access', dataset);
if(!isNil(openAccess)){
// if open Access is false, dac approval required
return openAccess ? dataset.study.publicVisibility : (dataset.dacApproval && dataset.study.publicVisibility);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

study can be null, do we need null-safe traversal here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was since the openAccess is a property on a study, if openAccess is not null then the study must exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's true today, but the code doesn't enforce that currently and could be incorrect in the near future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Do you think that a good approach would be to just add dataset.study?.publicVisibility or do more thorough handling here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine for this case.

} else {
return dataset.active;
}
};

export default function DatasetCatalog(props) {

const {
Expand Down Expand Up @@ -61,9 +76,7 @@ export default function DatasetCatalog(props) {

// Modal States
const [showConnectDataset, setShowConnectDataset] = useState(false);
const [showDatasetDisable, setShowDatasetDisable] = useState(false);
const [showDatasetDelete, setShowDatasetDelete] = useState(false);
const [showDatasetEnable, setShowDatasetEnable] = useState(false);
const [showDatasetEdit, setShowDatasetEdit] = useState(false);
const [showTranslatedDULModal, setShowTranslatedDULModal] = useState(false);

Expand Down Expand Up @@ -225,16 +238,6 @@ export default function DatasetCatalog(props) {
setSelectedDatasetId(datasetId);
};

const openEnable = (datasetId) => () => {
setShowDatasetEnable(true);
setSelectedDatasetId(datasetId);
};

const openDisable = (datasetId) => () => {
setShowDatasetDisable(true);
setSelectedDatasetId(datasetId);
};

const dialogHandlerDelete = async (e) => {
const answer = getBooleanFromEventHtmlDataValue(e);
if (answer) {
Expand All @@ -253,42 +256,6 @@ export default function DatasetCatalog(props) {
}
};

const dialogHandlerEnable = async(e) => {
const answer = getBooleanFromEventHtmlDataValue(e);
if (answer) {
DataSet.disableDataset(selectedDatasetId, true).then(() => {
getDatasets();
setShowDatasetEnable(false);
}).catch(() => {
setShowDatasetEnable(true);
setErrorMessage('Please try again later.');
setErrorTitle('Something went wrong');
});
} else {
setShowDatasetEnable(false);
setErrorMessage(undefined);
setErrorTitle(undefined);
}
};

const dialogHandlerDisable = async (e) => {
const answer = getBooleanFromEventHtmlDataValue(e);
if (answer) {
DataSet.disableDataset(selectedDatasetId, false).then(() => {
getDatasets();
setShowDatasetDisable(false);
}).catch(() => {
setShowDatasetDisable(true);
setErrorMessage('Please try again later.');
setErrorTitle('Something went wrong');
});
} else {
setShowDatasetDisable(false);
setErrorMessage(undefined);
setErrorTitle(undefined);
}
};

const dialogHandlerEdit = async (e) => {
const answer = getBooleanFromEventHtmlDataValue(e);
if (answer) {
Expand Down Expand Up @@ -382,7 +349,7 @@ export default function DatasetCatalog(props) {
};

const inactiveCheckboxStyle = (dataset) => {
if (!dataset.active) {
if (!isVisible(dataset)) {
return {cursor: 'default', opacity: '50%'};
}
return {};
Expand Down Expand Up @@ -652,28 +619,6 @@ export default function DatasetCatalog(props) {
})
]),

a({
id: trIndex + '_btnDisable', name: 'btn_disable', isRendered: dataset.active,
onClick: openDisable(dataset.dataSetId),
disabled: !isEditDatasetEnabled(dataset)
}, [
span({
className: `cm-icon-button glyphicon glyphicon-ok-circle caret-margin ${color}-color`, 'aria-hidden': 'true',
'data-tip': 'Disable dataset', 'data-for': 'tip_disable'
})
]),

a({
id: trIndex + '_btnEnable', name: 'btn_enable', isRendered: !dataset.active,
onClick: openEnable(dataset.dataSetId),
disabled: !isEditDatasetEnabled(dataset)
}, [
span({
className: 'cm-icon-button glyphicon glyphicon-ban-circle caret-margin cancel-color', 'aria-hidden': 'true',
'data-tip': 'Enable dataset', 'data-for': 'tip_enable'
})
]),

a({
isRendered: currentUser.isAdmin,
id: trIndex + '_btnConnect', name: 'btn_connect',
Expand All @@ -690,94 +635,94 @@ export default function DatasetCatalog(props) {

td({
id: dataset.datasetIdentifier + '_dataset', name: 'datasetIdentifier',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
dataset['Dataset ID']
]),

td({
id: trIndex + '_datasetName', name: 'datasetName',
className: 'cell-size ' + (!dataset.active ? !!'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? !!'dataset-disabled' : ''),
style: tableBody
}, [findPropertyValue(dataset, 'Dataset Name')]),

td({
id: trIndex + '_dac', name: 'dac',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
dataset['Data Access Committee']
]),

td({
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
getLinkDisplay(dataset, trIndex)
]),

td({
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
a({
id: trIndex + '_linkTranslatedDul', name: 'link_translatedDul',
onClick: () => openTranslatedDUL(dataset.dataUse),
className: (!dataset.active ? 'dataset-disabled' : 'enabled')
className: (!isVisible(dataset) ? 'dataset-disabled' : 'enabled')
}, dataset.codeList)
]),

td({
id: trIndex + '_dataType', name: 'dataType',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
findPropertyValue(dataset, 'Data Type')
]),

td({
id: trIndex + '_phenotype', name: 'phenotype',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
dataset['Disease Studied']
]),

td({
id: trIndex + '_pi', name: 'pi', className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
id: trIndex + '_pi', name: 'pi', className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
dataset['Principal Investigator (PI)']
]),

td({
id: trIndex + '_participants', name: 'participants',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
dataset['# of Participants']
]),

td({
id: trIndex + '_description', name: 'description',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
findPropertyValue(dataset, 'Description')
]),

td({
id: trIndex + '_species', name: 'species',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
findPropertyValue(dataset, 'Species')
]),

td({
id: trIndex + '_depositor', name: 'depositor',
className: 'cell-size ' + (!dataset.active ? 'dataset-disabled' : ''),
className: 'cell-size ' + (!isVisible(dataset) ? 'dataset-disabled' : ''),
style: tableBody
}, [
dataset['Data Custodian']
Expand Down Expand Up @@ -841,24 +786,6 @@ export default function DatasetCatalog(props) {
action: { label: 'Yes', handler: () => dialogHandlerDelete }
}, [div({ className: 'dialog-description' }, ['Are you sure you want to delete this Dataset?']),]),

ConfirmationDialog({
title: 'Disable Dataset Confirmation?',
color: 'dataset',
showModal: showDatasetDisable,
alertMessage: errorMessage,
alertTitle: errorTitle,
action: { label: 'Yes', handler: () => dialogHandlerDisable }
}, [div({ className: 'dialog-description' }, ['If you disable a Dataset, Researchers won\'t be able to request access on it from now on. New Access elections related to this dataset won\'t be available but opened ones will continue.']),]),

ConfirmationDialog({
title: 'Enable Dataset Confirmation?',
color: 'dataset',
alertMessage: errorMessage,
alertTitle: errorTitle,
showModal: showDatasetEnable,
action: { label: 'Yes', handler: () => dialogHandlerEnable }
}, [div({ className: 'dialog-description' }, ['If you enable a Dataset, Researchers will be able to request access on it from now on.']),]),

ConfirmationDialog({
title: 'Edit Dataset Confirmation?',
color: 'dataset',
Expand All @@ -882,20 +809,6 @@ export default function DatasetCatalog(props) {
multiline: true,
className: 'tooltip-wrapper'
}),
h(ReactTooltip, {
id: 'tip_disable',
place: 'right',
effect: 'solid',
multiline: true,
className: 'tooltip-wrapper'
}),
h(ReactTooltip, {
id: 'tip_enable',
place: 'right',
effect: 'solid',
multiline: true,
className: 'tooltip-wrapper'
}),
h(ReactTooltip, {
id: 'tip_connect',
place: 'right',
Expand Down
Loading