From 2ce5f05855f81eee8b126d3f99562ed5c153fa6e Mon Sep 17 00:00:00 2001 From: devinxl <94832688+devinxl@users.noreply.github.com> Date: Thu, 26 Dec 2024 10:39:53 +0800 Subject: [PATCH] fix(dcellar-web-ui): fix remaining quota error (#404) * fix(dcellar-web-ui): fix remaining quota error * chore(dcellar-web-ui): remove console.log * docs(dcellar-web-ui): update changelog * fix(dcellar-web-ui): change object-src values --- apps/dcellar-web-ui/CHANGELOG.json | 12 ++++++++++++ apps/dcellar-web-ui/CHANGELOG.md | 9 ++++++++- apps/dcellar-web-ui/package.json | 2 +- apps/dcellar-web-ui/src/facade/bucket.ts | 2 ++ apps/dcellar-web-ui/src/middleware.ts | 2 +- .../object/components/DownloadObjectOperation.tsx | 6 ++++-- .../src/modules/object/utils/getRemainingQuota.ts | 11 +++++++++++ 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 apps/dcellar-web-ui/src/modules/object/utils/getRemainingQuota.ts diff --git a/apps/dcellar-web-ui/CHANGELOG.json b/apps/dcellar-web-ui/CHANGELOG.json index edeaa488..31ee938c 100644 --- a/apps/dcellar-web-ui/CHANGELOG.json +++ b/apps/dcellar-web-ui/CHANGELOG.json @@ -1,6 +1,18 @@ { "name": "dcellar-web-ui", "entries": [ + { + "version": "1.9.2", + "tag": "dcellar-web-ui_v1.9.2", + "date": "Thu, 26 Dec 2024 02:37:36 GMT", + "comments": { + "patch": [ + { + "comment": "Fix remainingQuota display error" + } + ] + } + }, { "version": "1.9.1", "tag": "dcellar-web-ui_v1.9.1", diff --git a/apps/dcellar-web-ui/CHANGELOG.md b/apps/dcellar-web-ui/CHANGELOG.md index fd64f009..1071e31e 100644 --- a/apps/dcellar-web-ui/CHANGELOG.md +++ b/apps/dcellar-web-ui/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - dcellar-web-ui -This log was last generated on Tue, 03 Dec 2024 06:37:27 GMT and should not be manually modified. +This log was last generated on Thu, 26 Dec 2024 02:37:36 GMT and should not be manually modified. + +## 1.9.2 +Thu, 26 Dec 2024 02:37:36 GMT + +### Patches + +- Fix remainingQuota display error ## 1.9.1 Tue, 03 Dec 2024 06:37:27 GMT diff --git a/apps/dcellar-web-ui/package.json b/apps/dcellar-web-ui/package.json index 7cc85987..1979c954 100644 --- a/apps/dcellar-web-ui/package.json +++ b/apps/dcellar-web-ui/package.json @@ -1,6 +1,6 @@ { "name": "dcellar-web-ui", - "version": "1.9.1", + "version": "1.9.2", "private": false, "scripts": { "dev": "node ./scripts/dev.js -p 3200", diff --git a/apps/dcellar-web-ui/src/facade/bucket.ts b/apps/dcellar-web-ui/src/facade/bucket.ts index d2133496..ac7ca850 100644 --- a/apps/dcellar-web-ui/src/facade/bucket.ts +++ b/apps/dcellar-web-ui/src/facade/bucket.ts @@ -236,6 +236,8 @@ export const getObjectPolicies = async ( // todo using temp data export const getFolderPolicies = async (bucketId: string) => { const { data } = await axios.get<{ result: any[] }>(`/api/policies/${bucketId}`); + if (!data.result) return []; + return data.result .filter((i) => !i.Removed) .map((d) => { diff --git a/apps/dcellar-web-ui/src/middleware.ts b/apps/dcellar-web-ui/src/middleware.ts index e1b8a008..74d0210d 100644 --- a/apps/dcellar-web-ui/src/middleware.ts +++ b/apps/dcellar-web-ui/src/middleware.ts @@ -9,7 +9,7 @@ export function middleware(request: NextRequest) { img-src 'self' blob: data: https: https://www.google-analytics.com https://www.googletagmanager.com; font-src 'self' https://fonts.gstatic.com; connect-src *; - object-src 'none'; + object-src 'self' data:; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; diff --git a/apps/dcellar-web-ui/src/modules/object/components/DownloadObjectOperation.tsx b/apps/dcellar-web-ui/src/modules/object/components/DownloadObjectOperation.tsx index 2be9f21b..c3ba0ecc 100644 --- a/apps/dcellar-web-ui/src/modules/object/components/DownloadObjectOperation.tsx +++ b/apps/dcellar-web-ui/src/modules/object/components/DownloadObjectOperation.tsx @@ -12,6 +12,7 @@ import { Checkbox, Flex, ModalBody, ModalFooter, ModalHeader, Text } from '@node import { memo, useEffect, useState } from 'react'; import { OBJECT_ERROR_TYPES, ObjectErrorType } from '../ObjectError'; import { setSignatureAction } from '@/store/slices/global'; +import { getRemainingQuota } from '@/modules/object/utils/getRemainingQuota'; const renderProp = (key: string, value: string) => { return ( @@ -68,8 +69,9 @@ export const DownloadObjectOperation = memo(functi dispatch(setSignatureAction(errorData)); }; - const remainingQuota = +quotaData?.readQuota + +quotaData?.freeQuota - +quotaData?.consumedQuota; - const transformedRemainingQuota = remainingQuota ? formatBytes(remainingQuota, true) : '--'; + const remainingQuota = getRemainingQuota(quotaData); + + const transformedRemainingQuota = remainingQuota ? formatBytes(remainingQuota) : '--'; const onAction = async () => { setLoading(true); diff --git a/apps/dcellar-web-ui/src/modules/object/utils/getRemainingQuota.ts b/apps/dcellar-web-ui/src/modules/object/utils/getRemainingQuota.ts new file mode 100644 index 00000000..22f23c2f --- /dev/null +++ b/apps/dcellar-web-ui/src/modules/object/utils/getRemainingQuota.ts @@ -0,0 +1,11 @@ +import { IQuotaProps } from '@bnb-chain/greenfield-js-sdk'; + +export const getRemainingQuota = (quotaData: IQuotaProps) => { + if (!quotaData) return 0; + const { readQuota, freeQuota, consumedQuota, monthlyFreeQuota, monthlyQuotaConsumedSize } = + quotaData; + const remainingQuota = + freeQuota + readQuota + monthlyFreeQuota - consumedQuota - monthlyQuotaConsumedSize; + + return remainingQuota; +};