-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add status popover when storage is nearly full (#842)
* Add status popover when storage is nearly full * address comments * small update
- Loading branch information
1 parent
f830891
commit 0fbbb3d
Showing
11 changed files
with
257 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
frontend/src/pages/projects/screens/detail/storage/StorageWarningStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as React from 'react'; | ||
import { Bullseye, Button, Icon, Popover } from '@patternfly/react-core'; | ||
import { | ||
ExclamationCircleIcon, | ||
ExclamationTriangleIcon, | ||
InfoCircleIcon, | ||
} from '@patternfly/react-icons'; | ||
import { PersistentVolumeClaimKind } from '../../../../../k8sTypes'; | ||
import { usePVCFreeAmount } from '../../../../../api'; | ||
import { getPvcTotalSize } from '../../../utils'; | ||
import { bytesAsGB } from '../../../../../utilities/number'; | ||
import { getFullStatusFromPercentage } from './utils'; | ||
import useStorageStatusAlert from './useStorageStatusAlert'; | ||
|
||
type StorageWarningStatusProps = { | ||
obj: PersistentVolumeClaimKind; | ||
onAddPVC: () => void; | ||
onEditPVC: (pvc: PersistentVolumeClaimKind) => void; | ||
}; | ||
|
||
const StorageWarningStatus: React.FC<StorageWarningStatusProps> = ({ | ||
obj, | ||
onEditPVC, | ||
onAddPVC, | ||
}) => { | ||
const [inUseInBytes, loaded] = usePVCFreeAmount(obj); | ||
const percentage = loaded | ||
? Number(((bytesAsGB(inUseInBytes) / parseFloat(getPvcTotalSize(obj))) * 100).toFixed(2)) | ||
: NaN; | ||
useStorageStatusAlert(obj, percentage); | ||
|
||
const percentageStatus = getFullStatusFromPercentage(percentage); | ||
|
||
if (!percentageStatus) { | ||
return null; | ||
} | ||
|
||
let renderIcon: React.ReactNode; | ||
let popoverHeader: React.ReactNode; | ||
let popoverBody: React.ReactNode; | ||
if (percentageStatus === 'error') { | ||
renderIcon = ( | ||
<Icon status="danger"> | ||
<ExclamationCircleIcon /> | ||
</Icon> | ||
); | ||
popoverHeader = `Storage full`; | ||
popoverBody = 'Save actions will fail and you can no longer write new data.'; | ||
} else { | ||
popoverHeader = `Storage ${percentage}% full`; | ||
popoverBody = | ||
'Once storage is 100% full, you will no longer be able to write new data and save actions will fail.'; | ||
if (percentageStatus === 'warning') { | ||
renderIcon = ( | ||
<Icon status="warning"> | ||
<ExclamationTriangleIcon /> | ||
</Icon> | ||
); | ||
} else { | ||
renderIcon = ( | ||
<Icon status="info"> | ||
<InfoCircleIcon /> | ||
</Icon> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<Popover | ||
position="right" | ||
headerIcon={<Bullseye>{renderIcon}</Bullseye>} | ||
headerContent={popoverHeader} | ||
bodyContent={popoverBody} | ||
footerContent={(hide) => ( | ||
<> | ||
To increase available storage, delete files,{' '} | ||
<Button | ||
isInline | ||
variant="link" | ||
onClick={() => { | ||
hide(); | ||
onEditPVC(obj); | ||
}} | ||
> | ||
edit storage size | ||
</Button> | ||
, or{' '} | ||
<Button | ||
isInline | ||
variant="link" | ||
onClick={() => { | ||
hide(); | ||
onAddPVC(); | ||
}} | ||
> | ||
add new cluster storage | ||
</Button> | ||
. | ||
</> | ||
)} | ||
removeFindDomNode | ||
> | ||
<Bullseye>{renderIcon}</Bullseye> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default StorageWarningStatus; |
Oops, something went wrong.