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 = (
|
export const calculateBytes = (
|
||||||
x: string,
|
x: string | number,
|
||||||
showDecimals = false,
|
showDecimals = false,
|
||||||
roundFloor = true,
|
roundFloor = true,
|
||||||
k8sUnit = false
|
k8sUnit = false
|
||||||
) => {
|
) => {
|
||||||
const bytes = parseInt(x, 10);
|
let bytes;
|
||||||
|
|
||||||
|
if (typeof x === "string") {
|
||||||
|
bytes = parseInt(x, 10);
|
||||||
|
} else {
|
||||||
|
bytes = x;
|
||||||
|
}
|
||||||
|
|
||||||
if (bytes === 0) {
|
if (bytes === 0) {
|
||||||
return { total: 0, unit: units[0] };
|
return { total: 0, unit: units[0] };
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ const BucketSummary = ({
|
|||||||
iamScopes={[IAM_SCOPES.S3_PUT_BUCKET_VERSIONING]}
|
iamScopes={[IAM_SCOPES.S3_PUT_BUCKET_VERSIONING]}
|
||||||
resourceName={bucketName}
|
resourceName={bucketName}
|
||||||
property={"Current Status:"}
|
property={"Current Status:"}
|
||||||
value={isVersioned ? "Enabled" : "Unversioned (Default)"}
|
value={isVersioned ? "Versioned" : "Unversioned (Default)"}
|
||||||
onEdit={setBucketVersioning}
|
onEdit={setBucketVersioning}
|
||||||
isLoading={loadingVersioning}
|
isLoading={loadingVersioning}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import createStyles from "@mui/styles/createStyles";
|
|||||||
import withStyles from "@mui/styles/withStyles";
|
import withStyles from "@mui/styles/withStyles";
|
||||||
import Grid from "@mui/material/Grid";
|
import Grid from "@mui/material/Grid";
|
||||||
import {
|
import {
|
||||||
|
calculateBytes,
|
||||||
getBytes,
|
getBytes,
|
||||||
k8sScalarUnitsExcluding,
|
k8sScalarUnitsExcluding,
|
||||||
units,
|
|
||||||
} from "../../../../common/utils";
|
} from "../../../../common/utils";
|
||||||
import { BucketQuota } from "../types";
|
import { BucketQuota } from "../types";
|
||||||
import { setModalErrorSnackMessage } from "../../../../actions";
|
import { setModalErrorSnackMessage } from "../../../../actions";
|
||||||
@@ -68,28 +68,16 @@ const EnableQuota = ({
|
|||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [quotaEnabled, setQuotaEnabled] = useState<boolean>(false);
|
const [quotaEnabled, setQuotaEnabled] = useState<boolean>(false);
|
||||||
const [quotaSize, setQuotaSize] = useState<string>("1");
|
const [quotaSize, setQuotaSize] = useState<string>("1");
|
||||||
const [quotaUnit, setQuotaUnit] = useState<string>("TiB");
|
const [quotaUnit, setQuotaUnit] = useState<string>("Ti");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
setQuotaEnabled(true);
|
setQuotaEnabled(true);
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
setQuotaSize(`${cfg.quota}`);
|
const unitCalc = calculateBytes(cfg.quota, false, false, true);
|
||||||
setQuotaUnit(`Gi`);
|
|
||||||
|
|
||||||
let maxUnit = "B";
|
setQuotaSize(unitCalc.total.toString());
|
||||||
let maxQuota = cfg.quota;
|
setQuotaUnit(unitCalc.unit);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [enabled, cfg]);
|
}, [enabled, cfg]);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const BucketQuotaSize = ({ quota }: { quota: any }) => {
|
|||||||
>
|
>
|
||||||
{quota?.type} Quota
|
{quota?.type} Quota
|
||||||
</label>
|
</label>
|
||||||
<label> {niceBytes(`${quota?.quota}`)}</label>
|
<label> {niceBytes(`${quota?.quota}`, true)}</label>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user