Skip to content

Commit

Permalink
disallows downloading button if disk is not ready
Browse files Browse the repository at this point in the history
Signed-off-by: scures <scurescu@suse.com>
  • Loading branch information
scures authored and David Ko committed Dec 26, 2023
1 parent 31f7400 commit d916e44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/routes/backingImage/BackingImageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import { Modal } from 'antd'
import { DropOption } from '../../components'
import { hasReadyBackingDisk } from '../../utils/status'
const confirm = Modal.confirm

function actions({ selected, deleteBackingImage, cleanUpDiskMap, downloadBackingImage }) {
Expand All @@ -26,9 +27,11 @@ function actions({ selected, deleteBackingImage, cleanUpDiskMap, downloadBacking
}
}

const disableDownloadAction = !hasReadyBackingDisk(selected)

const availableActions = [
{ key: 'delete', name: 'Delete' },
{ key: 'download', name: 'Download' },
{ key: 'download', name: 'Download', disabled: disableDownloadAction, tooltip: disableDownloadAction ? 'Missing disk with ready state' : '' },
{ key: 'cleanUp', name: 'Clean Up' },
]

Expand Down
14 changes: 14 additions & 0 deletions src/utils/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ export function statusUpgradingEngine(volume) {
}
return ''
}

/** Check if any of the disk is in a ready state.
* @param {*} data v1/backingimages response object.
* @returns {boolean} true if any disk is ready.
*/
export function hasReadyBackingDisk(data) {
try {
return Object.keys(data.diskFileStatusMap).some(
(key) => data.diskFileStatusMap[key]?.state === 'ready'
)
} catch (error) {
return false
}
}

0 comments on commit d916e44

Please sign in to comment.