From bc7848fcafd42bf03ad8053b0fbf96c9363a3ea8 Mon Sep 17 00:00:00 2001 From: Yaroslav Vorobiov Date: Fri, 5 Apr 2019 14:24:34 +0300 Subject: [PATCH] add project usage to web app (#1669) --- web/satellite/src/api/usage.ts | 43 +++++++++ .../src/components/project/UsageReport.vue | 91 ++++++++++++------- web/satellite/src/store/index.ts | 4 +- web/satellite/src/store/modules/usage.ts | 36 ++++++++ web/satellite/src/store/mutationConstants.ts | 5 + web/satellite/src/types/projects.d.ts | 9 ++ .../src/utils/constants/actionNames.ts | 5 + web/satellite/src/views/Dashboard.vue | 12 ++- 8 files changed, 171 insertions(+), 34 deletions(-) create mode 100644 web/satellite/src/api/usage.ts create mode 100644 web/satellite/src/store/modules/usage.ts diff --git a/web/satellite/src/api/usage.ts b/web/satellite/src/api/usage.ts new file mode 100644 index 000000000..f5d4b5517 --- /dev/null +++ b/web/satellite/src/api/usage.ts @@ -0,0 +1,43 @@ +// Copyright (C) 2019 Storj Labs, Inc. +// See LICENSE for copying information. + +import apollo from '@/utils/apolloManager'; +import gql from 'graphql-tag'; + +// fetchProjectUsage retrieves total project usage for a given period +export async function fetchProjectUsage(projectID: string, since: Date, before: Date): Promise> { + let result: RequestResponse = { + errorMessage: '', + isSuccess: false, + data: {} as ProjectUsage + }; + + let response: any = await apollo.query( + { + query: gql(` + query { + project(id: "${projectID}") { + usage(since: "${since.toISOString()}", before: "${before.toISOString()}") { + storage, + egress, + objectsCount, + since, + before + } + } + }` + ), + fetchPolicy: 'no-cache', + errorPolicy: 'all' + } + ); + + if (response.errors) { + result.errorMessage = response.errors[0].message; + } else { + result.isSuccess = true; + result.data = response.data.project.usage; + } + + return result; +} diff --git a/web/satellite/src/components/project/UsageReport.vue b/web/satellite/src/components/project/UsageReport.vue index 707b1528f..cc8b542ec 100644 --- a/web/satellite/src/components/project/UsageReport.vue +++ b/web/satellite/src/components/project/UsageReport.vue @@ -32,16 +32,16 @@
-

Storage GB/H

-

200.23

+

Storage GB*H

+

{{storage}}

-

Egress GB/H

-

944.23

+

Egress GB

+

{{egress}}

-

Objects Count/H

-

30 223

+

Objects Count*H

+

{{objectsCount}}