Skip to content

Commit

Permalink
EDSC-4246: Disable the EDD button when a harmony job is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
macrouch committed Nov 12, 2024
1 parent 0f5d735 commit 3525ad5
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 50 deletions.
5 changes: 3 additions & 2 deletions static/src/js/components/OrderStatus/OrderStatusItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -689,15 +689,16 @@ export class OrderStatusItem extends PureComponent {
>
<DownloadFilesPanel
accessMethodType={accessMethodType}
collectionIsCSDA={collectionIsCSDA}
disableEddInProgress={accessMethodType.toLowerCase() === 'harmony' && progressPercentage < 100}
downloadLinks={downloadUrls}
eddLink={this.buildEddLink('data', downloadUrls)}
granuleCount={granuleCount}
granuleLinksIsLoading={granuleLinksIsLoading}
percentDoneDownloadLinks={percentDoneDownloadLinks}
retrievalId={retrievalId}
retrievalCollectionId={retrievalCollectionId}
retrievalId={retrievalId}
showTextWindowActions={!isEsi}
collectionIsCSDA={collectionIsCSDA}
/>
</Tab>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ import './DownloadFilesPanel.scss'
* Renders DownloadFilesPanel.
* @param {Object} arg0 - The props passed into the component.
* @param {String} arg0.accessMethodType - The retrieval collection access method.
* @param {Boolean} arg0.collectionIsCSDA - A flag set when the collection is CSDA.
* @param {Boolean} arg0.disableEddInProgress - Disables EDD button when a job is still in progress (e.g. a Harmony job still in progress).
* @param {Array} arg0.downloadLinks - The download links.
* @param {String} arg0.retrievalId - The retrieval id.
* @param {String} arg0.eddLink - The EDD link.
* @param {Number} arg0.granuleCount - The retrieval collection granule count.
* @param {Boolean} arg0.granuleLinksIsLoading - A flag set when the granule links are loading.
* @param {Boolean} arg0.percentDoneDownloadLinks - Percentage of the download links that have been fetched.
* @param {String} arg0.retrievalId - The retrieval id.
* @param {Boolean} arg0.showTextWindowActions - A flag set when the text window actions should be set.
* @param {Boolean} arg0.collectionIsCSDA - A flag set when the collection is CSDA.
*/
export const DownloadFilesPanel = ({
accessMethodType,
collectionIsCSDA,
disableEddInProgress,
downloadLinks,
eddLink,
granuleCount,
granuleLinksIsLoading,
percentDoneDownloadLinks,
retrievalId,
eddLink,
showTextWindowActions,
collectionIsCSDA
showTextWindowActions
}) => {
const downloadFileName = `${retrievalId}-${accessMethodType}.txt`

Expand All @@ -54,15 +57,16 @@ export const DownloadFilesPanel = ({
}
</div>
<TextWindowActions
id={`links-${retrievalId}`}
clipboardContents={downloadLinks.join('\n')}
disableCopy={!showTextWindowActions}
disableEddInProgress={disableEddInProgress}
disableSave={!showTextWindowActions}
eddLink={eddLink}
fileContents={downloadLinks.join('\n')}
fileName={downloadFileName}
clipboardContents={downloadLinks.join('\n')}
hideEdd={collectionIsCSDA}
id={`links-${retrievalId}`}
modalTitle="Download Files"
disableCopy={!showTextWindowActions}
disableSave={!showTextWindowActions}
disableEdd={collectionIsCSDA}
>
<ul className="download-files-panel__list">
{
Expand All @@ -88,24 +92,24 @@ export const DownloadFilesPanel = ({
}

DownloadFilesPanel.defaultProps = {
percentDoneDownloadLinks: null,
showTextWindowActions: true,
collectionIsCSDA: false,
eddLink: null
disableEddInProgress: false,
eddLink: null,
percentDoneDownloadLinks: null,
showTextWindowActions: true
}

DownloadFilesPanel.propTypes = {
accessMethodType: PropTypes.string.isRequired,
downloadLinks: PropTypes.arrayOf(
PropTypes.string
).isRequired,
retrievalId: PropTypes.string.isRequired,
collectionIsCSDA: PropTypes.bool,
disableEddInProgress: PropTypes.bool,
downloadLinks: PropTypes.arrayOf(PropTypes.string).isRequired,
eddLink: PropTypes.string,
granuleCount: PropTypes.number.isRequired,
granuleLinksIsLoading: PropTypes.bool.isRequired,
percentDoneDownloadLinks: PropTypes.string,
showTextWindowActions: PropTypes.bool,
collectionIsCSDA: PropTypes.bool
retrievalId: PropTypes.string.isRequired,
showTextWindowActions: PropTypes.bool
}

export default DownloadFilesPanel
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('DownloadFilesPanel', () => {
)

const windowActions = enzymeWrapper.find(TextWindowActions)
expect(windowActions.props().disableEdd).toEqual(true)
expect(windowActions.props().hideEdd).toEqual(true)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ describe('OrderStatusItem', () => {
expect(linksTab.childAt(0).props().percentDoneDownloadLinks).toEqual('50')
expect(linksTab.childAt(0).props().downloadLinks).toEqual([])
expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3D42%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=shortName_versionId&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const scriptTab = tabs.childAt(1)
expect(scriptTab.props().title).toEqual('Download Script')
Expand Down Expand Up @@ -436,6 +437,7 @@ describe('OrderStatusItem', () => {
expect(linksTab.childAt(0).props().percentDoneDownloadLinks).toEqual('50')
expect(linksTab.childAt(0).props().downloadLinks).toEqual([])
expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3D42%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=shortName_versionId&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const scriptTab = tabs.childAt(1)
expect(scriptTab.props().title).toEqual('Download Script')
Expand Down Expand Up @@ -596,6 +598,7 @@ describe('OrderStatusItem', () => {
expect(linksTab.childAt(0).props().granuleCount).toEqual(100)
expect(linksTab.childAt(0).props().downloadLinks).toEqual(['http://example.com'])
expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3D42%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=shortName_versionId&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const scriptTab = tabs.childAt(1)
expect(scriptTab.props().title).toEqual('Download Script')
Expand Down Expand Up @@ -1806,6 +1809,7 @@ describe('OrderStatusItem', () => {
])

expect(linksTab.childAt(0).props().eddLink).toEqual(null)
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(true)

const stacLinksTab = tabs.childAt(1)
expect(stacLinksTab.childAt(0).props().granuleCount).toEqual(100)
Expand Down Expand Up @@ -1931,6 +1935,7 @@ describe('OrderStatusItem', () => {
])

expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3D42%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=testDataset_1&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const stacLinksTab = tabs.childAt(1)
expect(stacLinksTab.childAt(0).props().granuleCount).toEqual(100)
Expand Down Expand Up @@ -2059,6 +2064,7 @@ describe('OrderStatusItem', () => {
])

expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3D42%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=testDataset_1&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const stacLinksTab = tabs.childAt(1)
expect(stacLinksTab.childAt(0).props().granuleCount).toEqual(100)
Expand Down Expand Up @@ -2481,9 +2487,8 @@ describe('OrderStatusItem', () => {
expect(linksTab.childAt(0).props().granuleCount).toEqual(10)
expect(linksTab.childAt(0).props().downloadLinks).toEqual([])

expect(linksTab.childAt(0).props().eddLink).toEqual(
'earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3Dundefined%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=undefined&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback'
)
expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3Dundefined%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=undefined&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const orderStatusTab = tabs.childAt(1)
expect(orderStatusTab.props().title).toEqual('Order Status')
Expand Down Expand Up @@ -2574,6 +2579,7 @@ describe('OrderStatusItem', () => {
])

expect(linksTab.childAt(0).props().eddLink).toEqual('earthdata-download://startDownload?getLinks=http%3A%2F%2Flocalhost%3A3000%2Fgranule_links%3Fid%3Dundefined%26flattenLinks%3Dtrue%26linkTypes%3Ddata%26ee%3Dprod&downloadId=undefined&clientId=eed-default-test-serverless-client&token=Bearer mock-token&authUrl=http%3A%2F%2Flocalhost%3A3000%2Flogin%3Fee%3Dprod%26eddRedirect%3Dearthdata-download%253A%252F%252FauthCallback&eulaRedirectUrl=http%3A%2F%2Flocalhost%3A8080%2Fauth_callback%3FeddRedirect%3Dearthdata-download%253A%252F%252FeulaCallback')
expect(linksTab.childAt(0).props().disableEddInProgress).toEqual(false)

const orderStatusTab = tabs.childAt(1)
expect(orderStatusTab.props().title).toEqual('Order Status')
Expand Down
42 changes: 27 additions & 15 deletions static/src/js/components/TextWindowActions/TextWindowActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,30 @@ import './TextWindowActions.scss'
* Renders TextWindowActions.
* @param {Node} children - React children to display in the text window
* @param {String} clipboardContents - An string that will be copied to the users clipboard.
* @param {Boolean} disableCopy - Disables the copy functionality.
* @param {Boolean} disableEddInProgress - Disables EDD button when a job is still in progress (e.g. a Harmony job still in progress).
* @param {Boolean} disableSave - Disables the save functionality.
* @param {String} eddLink - The EDD link.
* @param {String} fileContents - An optional string to be saved to the users computer.
* @param {String} fileName - An optional string to to set the name for the file saved to the users computer.
* @param {Boolean} hideEdd - A flag to hide the EDD button completely.
* @param {String} id - The id to use for the bootstrap modal.
* @param {String} modalTitle - The title for the modal.
* @param {Boolean} disableCopy - Disables the copy functionality.
* @param {Boolean} disableSave - Disables the save functionality.
* @param {Boolean} disableEdd - Disables EDD button.
*/
export const TextWindowActions = ({
children,
clipboardContents,
disableEdd,
disableCopy,
disableEddInProgress,
disableSave,
eddLink,
fileContents,
fileName,
hideEdd,
id,
modalTitle,
eddLink
modalTitle
}) => {
const { disableEddDownload } = getApplicationConfig()
const { disableEddInProgressDownload: hideEddFromSettings } = getApplicationConfig()

const supportsClipboard = document.queryCommandSupported('copy')
const textareaElRef = useRef(null)
Expand Down Expand Up @@ -83,20 +86,27 @@ export const TextWindowActions = ({
}
}

let eddTooltipMessage = 'Download files with Earthdata Download'
if (disableEddInProgress) {
// If the EDD button is disabled when a job is still in progress, add a note to the tooltip
eddTooltipMessage += ' when the job is complete'
}

return (
<div className="text-window-actions">
<header className="text-window-actions__actions">
{
(!disableEdd && disableEddDownload !== 'true' && eddLink) && (
(!hideEdd && hideEddFromSettings !== 'true' && (eddLink || disableEddInProgress)) && (
<Button
disabled={disableEddInProgress}
className="text-window-actions__action text-window-actions__action--edd"
bootstrapSize="sm"
icon={Download}
bootstrapVariant="primary"
onClick={handleEddModalOpen}
tooltipId={`text-window-actions__tooltip--${id}`}
tooltip={(
<span>Download files with Earthdata Download</span>
<span>{eddTooltipMessage}</span>
)}
>
Download Files
Expand Down Expand Up @@ -292,26 +302,28 @@ export const TextWindowActions = ({

TextWindowActions.defaultProps = {
children: null,
disableEdd: false,
clipboardContents: '',
disableCopy: false,
disableEddInProgress: false,
disableSave: false,
clipboardContents: '',
eddLink: null,
fileContents: null,
fileName: null,
hideEdd: false,
id: null,
modalTitle: null,
eddLink: null
modalTitle: null
}

TextWindowActions.propTypes = {
children: PropTypes.node,
clipboardContents: PropTypes.string,
disableEdd: PropTypes.bool,
disableCopy: PropTypes.bool,
disableEddInProgress: PropTypes.bool,
disableSave: PropTypes.bool,
eddLink: PropTypes.string,
fileContents: PropTypes.string,
fileName: PropTypes.string,
eddLink: PropTypes.string,
hideEdd: PropTypes.bool,
id: PropTypes.string,
modalTitle: PropTypes.string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,25 +357,30 @@ describe('TextWindowActions component', () => {
})
})

describe('when disabling the edd button', () => {
describe('when hiding the edd button', () => {
const { enzymeWrapper } = setup({
disableEdd: true
hideEdd: true
})

test('hides the edd button', () => {
expect(enzymeWrapper.find('.text-window-actions__action--edd').length).toEqual(0)
})
})

describe('when the modal is open', () => {
const expandButton = enzymeWrapper.find('.text-window-actions__action--expand').filter(Button)
expandButton.simulate('click')
describe('when disabling the edd button while a job is in progress', () => {
const { enzymeWrapper } = setup({
eddLink: null,
disableEddInProgress: true
})

const linksModal = enzymeWrapper.find(EDSCModalContainer).at(0)
expect(linksModal.props().isOpen).toEqual(true)
test('disables the button and displays the correct tooltip message', () => {
const button = enzymeWrapper.find('.text-window-actions__action--edd')
expect(button.length).toEqual(1)

test('hides the edd button', () => {
expect(enzymeWrapper.find('.text-window-actions__modal-action--edd').length).toEqual(0)
})
expect(button.props().disabled).toEqual(true)
expect(button.props().tooltip).toEqual((
<span>Download files with Earthdata Download when the job is complete</span>
))
})
})
})
Expand Down

0 comments on commit 3525ad5

Please sign in to comment.