From 9407dbf387fb4d1ebb56375cdd8c85cd35527cd7 Mon Sep 17 00:00:00 2001
From: P R <25353498+BigUstad@users.noreply.github.com>
Date: Tue, 9 Jun 2020 15:05:39 -0700
Subject: [PATCH] display proper used space based on disk usage (#9551)
Fixes #9346
---
browser/app/js/browser/StorageInfo.js | 7 ++-----
browser/app/js/browser/__tests__/StorageInfo.test.js | 6 +++---
browser/app/js/browser/__tests__/actions.test.js | 6 ++++--
browser/app/js/browser/__tests__/reducer.test.js | 10 +++-------
browser/app/js/browser/actions.js | 3 +--
browser/app/js/browser/reducer.js | 2 +-
cmd/web-handlers.go | 7 ++++---
7 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/browser/app/js/browser/StorageInfo.js b/browser/app/js/browser/StorageInfo.js
index 67f51e238..06ff08a15 100644
--- a/browser/app/js/browser/StorageInfo.js
+++ b/browser/app/js/browser/StorageInfo.js
@@ -26,13 +26,10 @@ export class StorageInfo extends React.Component {
}
render() {
const { used } = this.props.storageInfo
-
- if (!used) {
+ if (!used || used == 0) {
return
}
- const totalUsed = used.reduce((v1, v2) => v1 + v2, 0)
-
return (
@@ -41,7 +38,7 @@ export class StorageInfo extends React.Component {
-
Used:
- {humanize.filesize(totalUsed)}
+ {humanize.filesize(used)}
diff --git a/browser/app/js/browser/__tests__/StorageInfo.test.js b/browser/app/js/browser/__tests__/StorageInfo.test.js
index 24af9af8b..c5005cc06 100644
--- a/browser/app/js/browser/__tests__/StorageInfo.test.js
+++ b/browser/app/js/browser/__tests__/StorageInfo.test.js
@@ -21,7 +21,7 @@ import { StorageInfo } from "../StorageInfo"
describe("StorageInfo", () => {
it("should render without crashing", () => {
shallow(
-
+
)
})
@@ -29,7 +29,7 @@ describe("StorageInfo", () => {
const fetchStorageInfo = jest.fn()
shallow(
)
@@ -40,7 +40,7 @@ describe("StorageInfo", () => {
const fetchStorageInfo = jest.fn()
const wrapper = shallow(
)
diff --git a/browser/app/js/browser/__tests__/actions.test.js b/browser/app/js/browser/__tests__/actions.test.js
index 5c4609942..cd7d894c5 100644
--- a/browser/app/js/browser/__tests__/actions.test.js
+++ b/browser/app/js/browser/__tests__/actions.test.js
@@ -20,7 +20,9 @@ import * as actionsCommon from "../actions"
jest.mock("../../web", () => ({
StorageInfo: jest.fn(() => {
- return Promise.resolve({ storageInfo: { Used: [60] } })
+ return Promise.resolve({
+ used: 60
+ })
}),
ServerInfo: jest.fn(() => {
return Promise.resolve({
@@ -39,7 +41,7 @@ describe("Common actions", () => {
it("creates common/SET_STORAGE_INFO after fetching the storage details ", () => {
const store = mockStore()
const expectedActions = [
- { type: "common/SET_STORAGE_INFO", storageInfo: { used: [60] } }
+ { type: "common/SET_STORAGE_INFO", storageInfo: { used: 60 } }
]
return store.dispatch(actionsCommon.fetchStorageInfo()).then(() => {
const actions = store.getActions()
diff --git a/browser/app/js/browser/__tests__/reducer.test.js b/browser/app/js/browser/__tests__/reducer.test.js
index 3fe08627d..52bf9daff 100644
--- a/browser/app/js/browser/__tests__/reducer.test.js
+++ b/browser/app/js/browser/__tests__/reducer.test.js
@@ -21,11 +21,7 @@ describe("common reducer", () => {
it("should return the initial state", () => {
expect(reducer(undefined, {})).toEqual({
sidebarOpen: false,
- storageInfo: {
- total: [0],
- free: [0],
- used: [0]
- },
+ storageInfo: {used: 0},
serverInfo: {}
})
})
@@ -62,11 +58,11 @@ describe("common reducer", () => {
{},
{
type: actionsCommon.SET_STORAGE_INFO,
- storageInfo: { total: [100], free: [40] }
+ storageInfo: { }
}
)
).toEqual({
- storageInfo: { total: [100], free: [40] }
+ storageInfo: { }
})
})
diff --git a/browser/app/js/browser/actions.js b/browser/app/js/browser/actions.js
index 3ea3bb72b..f6850481e 100644
--- a/browser/app/js/browser/actions.js
+++ b/browser/app/js/browser/actions.js
@@ -33,8 +33,7 @@ export const fetchStorageInfo = () => {
return function(dispatch) {
return web.StorageInfo().then(res => {
const storageInfo = {
- total: res.storageInfo.Total,
- used: res.storageInfo.Used
+ used: res.used
}
dispatch(setStorageInfo(storageInfo))
})
diff --git a/browser/app/js/browser/reducer.js b/browser/app/js/browser/reducer.js
index 345b46b1d..e60c988fb 100644
--- a/browser/app/js/browser/reducer.js
+++ b/browser/app/js/browser/reducer.js
@@ -19,7 +19,7 @@ import * as actionsCommon from "./actions"
export default (
state = {
sidebarOpen: false,
- storageInfo: { total: [0], free: [0], used: [0] },
+ storageInfo: {used: 0},
serverInfo: {}
},
action
diff --git a/cmd/web-handlers.go b/cmd/web-handlers.go
index b702f923e..4da5cf04c 100644
--- a/cmd/web-handlers.go
+++ b/cmd/web-handlers.go
@@ -114,8 +114,8 @@ func (web *webAPIHandlers) ServerInfo(r *http.Request, args *WebGenericArgs, rep
// StorageInfoRep - contains storage usage statistics.
type StorageInfoRep struct {
- StorageInfo StorageInfo `json:"storageInfo"`
- UIVersion string `json:"uiVersion"`
+ Used uint64 `json:"used"`
+ UIVersion string `json:"uiVersion"`
}
// StorageInfo - web call to gather storage usage statistics.
@@ -129,7 +129,8 @@ func (web *webAPIHandlers) StorageInfo(r *http.Request, args *WebGenericArgs, re
if authErr != nil {
return toJSONError(ctx, authErr)
}
- reply.StorageInfo, _ = objectAPI.StorageInfo(ctx, false)
+ dataUsageInfo, _ := loadDataUsageFromBackend(ctx, objectAPI)
+ reply.Used = dataUsageInfo.ObjectsTotalSize
reply.UIVersion = browser.UIVersion
return nil
}