// @flow import * as React from 'react'; import I18nMessage from 'component/i18nMessage'; type Props = { // --- select --- diskSpace: DiskSpace, // KB viewHostingLimit: number, // MB autoHostingLimit: number, viewBlobSpace: number, autoBlobSpace: number, privateBlobSpace: number, }; function StorageViz(props: Props) { const { diskSpace, viewHostingLimit, autoHostingLimit, viewBlobSpace, autoBlobSpace, privateBlobSpace } = props; if (!diskSpace || !diskSpace.total) { return (
{__('Cannot get disk space information.')}
); } const totalMB = diskSpace && Math.floor(diskSpace.total / 1024); const freeMB = diskSpace && Math.floor(diskSpace.free / 1024); const otherMB = totalMB - (freeMB + viewBlobSpace + autoBlobSpace + privateBlobSpace); const autoFree = autoHostingLimit - autoBlobSpace; const viewFree = viewHostingLimit > 0 ? viewHostingLimit - viewBlobSpace : freeMB - autoFree; const unallocFree = freeMB - viewFree - autoFree; const viewLimit = viewHostingLimit === 0 ? freeMB - (autoHostingLimit - autoBlobSpace) + viewBlobSpace : viewHostingLimit + viewBlobSpace; const getPercent = (val, lim = totalMB) => (val / lim) * 100; const getGB = (val) => (Number(val) / 1024).toFixed(2); const otherPercent = getPercent(otherMB); const privatePercent = getPercent(privateBlobSpace); const autoLimitPercent = getPercent(autoHostingLimit); const viewLimitPercent = getPercent(viewLimit); const viewUsedPercentOfLimit = getPercent(viewBlobSpace, viewLimit); const autoUsedPercentOfLimit = getPercent(autoBlobSpace, autoHostingLimit); return (
{viewHostingLimit !== 0 &&
}
{`${getGB(privateBlobSpace)} GB`}
{autoHostingLimit === 0 ? ( __('Disabled') ) : ( %spaceUsed% of %limit% GB )}
{viewHostingLimit === 1 ? ( __('Disabled') ) : ( %spaceUsed% of %limit% Free GB )}
{viewHostingLimit !== 0 && (
{`${getGB(unallocFree)} GB`}
)}
); } export default StorageViz;