Fixed issues with Quota modal (#1911)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
@@ -585,12 +585,18 @@ export const getTimeFromTimestamp = (
|
||||
};
|
||||
|
||||
export const calculateBytes = (
|
||||
x: string,
|
||||
x: string | number,
|
||||
showDecimals = false,
|
||||
roundFloor = true,
|
||||
k8sUnit = false
|
||||
) => {
|
||||
const bytes = parseInt(x, 10);
|
||||
let bytes;
|
||||
|
||||
if (typeof x === "string") {
|
||||
bytes = parseInt(x, 10);
|
||||
} else {
|
||||
bytes = x;
|
||||
}
|
||||
|
||||
if (bytes === 0) {
|
||||
return { total: 0, unit: units[0] };
|
||||
|
||||
@@ -558,7 +558,7 @@ const BucketSummary = ({
|
||||
iamScopes={[IAM_SCOPES.S3_PUT_BUCKET_VERSIONING]}
|
||||
resourceName={bucketName}
|
||||
property={"Current Status:"}
|
||||
value={isVersioned ? "Enabled" : "Unversioned (Default)"}
|
||||
value={isVersioned ? "Versioned" : "Unversioned (Default)"}
|
||||
onEdit={setBucketVersioning}
|
||||
isLoading={loadingVersioning}
|
||||
/>
|
||||
|
||||
@@ -22,9 +22,9 @@ import createStyles from "@mui/styles/createStyles";
|
||||
import withStyles from "@mui/styles/withStyles";
|
||||
import Grid from "@mui/material/Grid";
|
||||
import {
|
||||
calculateBytes,
|
||||
getBytes,
|
||||
k8sScalarUnitsExcluding,
|
||||
units,
|
||||
} from "../../../../common/utils";
|
||||
import { BucketQuota } from "../types";
|
||||
import { setModalErrorSnackMessage } from "../../../../actions";
|
||||
@@ -68,28 +68,16 @@ const EnableQuota = ({
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [quotaEnabled, setQuotaEnabled] = useState<boolean>(false);
|
||||
const [quotaSize, setQuotaSize] = useState<string>("1");
|
||||
const [quotaUnit, setQuotaUnit] = useState<string>("TiB");
|
||||
const [quotaUnit, setQuotaUnit] = useState<string>("Ti");
|
||||
|
||||
useEffect(() => {
|
||||
if (enabled) {
|
||||
setQuotaEnabled(true);
|
||||
if (cfg) {
|
||||
setQuotaSize(`${cfg.quota}`);
|
||||
setQuotaUnit(`Gi`);
|
||||
const unitCalc = calculateBytes(cfg.quota, false, false, true);
|
||||
|
||||
let maxUnit = "B";
|
||||
let maxQuota = cfg.quota;
|
||||
|
||||
for (let i = 0; i < units.length; i++) {
|
||||
if (cfg.quota % Math.pow(1024, i) === 0) {
|
||||
maxQuota = cfg.quota / Math.pow(1024, i);
|
||||
maxUnit = units[i];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
setQuotaSize(`${maxQuota}`);
|
||||
setQuotaUnit(maxUnit);
|
||||
setQuotaSize(unitCalc.total.toString());
|
||||
setQuotaUnit(unitCalc.unit);
|
||||
}
|
||||
}
|
||||
}, [enabled, cfg]);
|
||||
|
||||
@@ -52,7 +52,7 @@ const BucketQuotaSize = ({ quota }: { quota: any }) => {
|
||||
>
|
||||
{quota?.type} Quota
|
||||
</label>
|
||||
<label> {niceBytes(`${quota?.quota}`)}</label>
|
||||
<label> {niceBytes(`${quota?.quota}`, true)}</label>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user