Skip to content

Commit

Permalink
feat(downloadVariableMetadataButton): reverted login button changes t…
Browse files Browse the repository at this point in the history
…o ActionButtons per discussion with stakeholders
  • Loading branch information
jarvisraymond-uchicago committed Feb 23, 2024
1 parent df69887 commit db53b47
Showing 1 changed file with 59 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Col, Row, Button, Popover } from 'antd';
import {
Col, Row, Button, Popover,
} from 'antd';
import { useHistory, useLocation } from 'react-router-dom';
import { DiscoveryConfig } from '../../../DiscoveryConfig';
import { DiscoveryResource } from '../../../Discovery';
Expand Down Expand Up @@ -34,28 +36,26 @@ const ActionButtons = ({
const history = useHistory();
const location = useLocation();

const studyMetadataFieldNameReference: string | undefined =
discoveryConfig?.features.exportToWorkspace.studyMetadataFieldName;
const manifestFieldName: string | undefined =
discoveryConfig?.features.exportToWorkspace.manifestFieldName;
const studyMetadataFieldNameReference: string | undefined = discoveryConfig?.features.exportToWorkspace.studyMetadataFieldName;
const manifestFieldName: string | undefined = discoveryConfig?.features.exportToWorkspace.manifestFieldName;
const showDownloadStudyLevelMetadataButton = Boolean(
discoveryConfig?.features.exportToWorkspace.enableDownloadStudyMetadata &&
studyMetadataFieldNameReference &&
resourceInfo?.[studyMetadataFieldNameReference]
discoveryConfig?.features.exportToWorkspace.enableDownloadStudyMetadata
&& studyMetadataFieldNameReference
&& resourceInfo?.[studyMetadataFieldNameReference],
);
const showDownloadFileManifestButtons = Boolean(
discoveryConfig?.features.exportToWorkspace.enableDownloadManifest
discoveryConfig?.features.exportToWorkspace.enableDownloadManifest,
);
const showDownloadAllFilesButtons = Boolean(
discoveryConfig?.features.exportToWorkspace.enableDownloadZip
discoveryConfig?.features.exportToWorkspace.enableDownloadZip,
);
const verifyExternalLoginsNeeded = Boolean(
discoveryConfig?.features.exportToWorkspace.verifyExternalLogins
discoveryConfig?.features.exportToWorkspace.verifyExternalLogins,
);

const showDownloadVariableMetadataButton = Boolean(
discoveryConfig.features.exportToWorkspace.variableMetadataFieldName &&
discoveryConfig.features.exportToWorkspace.enableDownloadVariableMetadata
discoveryConfig.features.exportToWorkspace.variableMetadataFieldName
&& discoveryConfig.features.exportToWorkspace.enableDownloadVariableMetadata,
);
const [dataDictionaryInfo, setDataDictionaryInfo] = useState({
noVariableLevelMetadata: true,
Expand All @@ -67,18 +67,17 @@ const ActionButtons = ({
discoveryConfig,
resourceInfo,
showDownloadVariableMetadataButton,
setDataDictionaryInfo
setDataDictionaryInfo,
);
}, [resourceInfo]);

const ConditionalPopover = ({ children }) =>
noData ? (
<Popover title={'This file is not available for the selected study'}>
{children}
</Popover>
) : (
children
);
const ConditionalPopover = ({ children }) => (noData ? (
<Popover title={'This file is not available for the selected study'}>
{children}
</Popover>
) : (
children
));

return (
<div className='discovery-modal_buttons-row' data-testid='actionButtons'>
Expand All @@ -89,77 +88,42 @@ const ActionButtons = ({
<Row className='row'>
{showDownloadVariableMetadataButton && (
<Col flex='1 0 auto'>
{isUserLoggedIn && !healLoginNeeded && (
<Button
className='discovery-action-bar-button'
disabled={Boolean(
downloadStatus.inProgress ||
dataDictionaryInfo.noVariableLevelMetadata
)}
loading={
downloadStatus.inProgress === 'DownloadVariableMetadata'
}
onClick={() => {
DownloadVariableMetadata(
dataDictionaryInfo.dataDictionaries,
resourceInfo,
setDownloadStatus
);
}}
>
Download <br />
Variable-Level Metadata
</Button>
)}
{!dataDictionaryInfo.noVariableLevelMetadata &&
(!isUserLoggedIn || healLoginNeeded) && (
<Button
className='discovery-action-bar-button'
disabled={Boolean(noData || downloadStatus.inProgress)}
onClick={() => {
HandleRedirectToLoginClick(resourceInfo, discoveryConfig);
}}
>
Login to Download
<br />
Variable Level Metadata
</Button>
<Button
className='discovery-action-bar-button'
disabled={Boolean(
downloadStatus.inProgress
|| dataDictionaryInfo.noVariableLevelMetadata,
)}
loading={downloadStatus.inProgress === 'DownloadVariableMetadata'}
onClick={() => {
DownloadVariableMetadata(
dataDictionaryInfo.dataDictionaries,
resourceInfo,
setDownloadStatus,
);
}}
>
Download <br />
Variable-Level Metadata
</Button>
</Col>
)}
{showDownloadStudyLevelMetadataButton && (
<Col flex='1 0 auto'>
{isUserLoggedIn && !healLoginNeeded && (
<ConditionalPopover>
<Button
className='discovery-action-bar-button'
disabled={Boolean(noData || downloadStatus.inProgress)}
onClick={() =>
DownloadJsonFile(
'study-level-metadata',
studyMetadataFieldNameReference &&
resourceInfo[studyMetadataFieldNameReference]
)
}
>
Download <br />
Study-Level Metadata
</Button>
</ConditionalPopover>
)}
{(!isUserLoggedIn || healLoginNeeded) && (
<ConditionalPopover>
<Button
className='discovery-action-bar-button'
disabled={Boolean(noData || downloadStatus.inProgress)}
onClick={() => {
HandleRedirectToLoginClick(resourceInfo, discoveryConfig);
}}
onClick={() => DownloadJsonFile(
'study-level-metadata',
studyMetadataFieldNameReference
&& resourceInfo[studyMetadataFieldNameReference],
)}
>
Login to Download
<br />
Download <br />
Study-Level Metadata
</Button>
)}
</ConditionalPopover>
</Col>
)}
{showDownloadFileManifestButtons && (
Expand All @@ -173,7 +137,7 @@ const ActionButtons = ({
HandleDownloadManifestClick(
discoveryConfig,
[resourceInfo],
healLoginNeeded
healLoginNeeded,
);
}}
>
Expand All @@ -189,7 +153,7 @@ const ActionButtons = ({
HandleRedirectToLoginClick(
resourceInfo,
discoveryConfig,
'manifest'
'manifest',
);
}}
>
Expand All @@ -207,18 +171,16 @@ const ActionButtons = ({
className='discovery-action-bar-button'
disabled={Boolean(noData || downloadStatus.inProgress)}
loading={downloadStatus.inProgress === 'DownloadAllFiles'}
onClick={() =>
DownloadAllFiles(
resourceInfo,
downloadStatus,
setDownloadStatus,
history,
location,
healLoginNeeded,
verifyExternalLoginsNeeded,
manifestFieldName
)
}
onClick={() => DownloadAllFiles(
resourceInfo,
downloadStatus,
setDownloadStatus,
history,
location,
healLoginNeeded,
verifyExternalLoginsNeeded,
manifestFieldName,
)}
>
Download All Files
</Button>
Expand All @@ -232,7 +194,7 @@ const ActionButtons = ({
HandleRedirectToLoginClick(
resourceInfo,
discoveryConfig,
'download'
'download',
);
}}
>
Expand Down

0 comments on commit db53b47

Please sign in to comment.