Skip to content

Commit

Permalink
fix(dcellar-web-ui): fix remaining quota error (#404)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
devinxl authored Dec 26, 2024
1 parent 2d53b8e commit 2ce5f05
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
12 changes: 12 additions & 0 deletions apps/dcellar-web-ui/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 8 additions & 1 deletion apps/dcellar-web-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions apps/dcellar-web-ui/src/facade/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -68,8 +69,9 @@ export const DownloadObjectOperation = memo<DownloadObjectOperationProps>(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);
Expand Down
11 changes: 11 additions & 0 deletions apps/dcellar-web-ui/src/modules/object/utils/getRemainingQuota.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 2ce5f05

Please sign in to comment.