Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix account-info quota rendering #6923

Merged
merged 2 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __fixtures__/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
free: 37883293696,
used: 7546347,
total: 37890840043,
relative: 0,
relative: 0.02,
definition: 'default'
},
email: {},
Expand All @@ -21,7 +21,7 @@ export default {
free: 37883293696,
used: 7546347,
total: 37890840043,
relative: 0,
relative: 0.02,
definition: 'default'
},
email: {},
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-respect-unlimited-quota
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Respect quota definition of none/unlimited

We have fixed an UI glitch where the UI stopped working if the backend reports a unlimited storage quota.

https://github.com/owncloud/web/pull/6923
https://github.com/owncloud/web/issues/6913
40 changes: 21 additions & 19 deletions packages/web-runtime/src/components/Topbar/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@
<oc-icon name="cloud" fill-type="line" class="oc-p-xs" />
<div class="storage-wrapper-text">
<p class="oc-my-rm">
<span v-text="personalStorageLabel" />
<br />
<template v-if="limitedPersonalStorage">
<span v-text="personalStorageLabel" />
<br />
</template>
<span class="oc-text-small" v-text="personalStorageDetailsLabel" />
</p>
<oc-progress
:value="parseInt(quotaUsagePercent)"
v-if="limitedPersonalStorage"
:value="quota.relative"
:max="100"
size="small"
:variation="quotaProgressVariant"
Expand Down Expand Up @@ -95,30 +98,29 @@ export default {
},
personalStorageLabel() {
return this.$gettextInterpolate(this.$gettext('Personal storage (%{percentage}% used)'), {
percentage: this.quotaUsagePercent
percentage: this.quota.relative || 0
})
},
personalStorageDetailsLabel() {
return this.$gettextInterpolate(this.$gettext('%{used} of %{total} used'), {
used: this.quotaUsed,
total: this.quotaTotal
})
const total = this.quota.definition === 'none' ? 0 : this.quota.total || 0
const used = this.quota.used
return this.$gettextInterpolate(
total ? this.$gettext('%{used} of %{total} used') : this.$gettext('%{used} used'),
{
used: filesize(used),
total: filesize(total)
}
)
},
limitedPersonalStorage() {
return !isNaN(this.quota.relative) && this.quota.definition !== 'none'
},
quotaEnabled() {
return !!this.quota
},
quotaTotal() {
return filesize(this.quota.total)
},
quotaUsed() {
return filesize(this.quota.used)
},
quotaUsagePercent() {
return ((this.quota.used / this.quota.total) * 100).toFixed(1)
},
quotaProgressVariant() {
if (this.quotaUsagePercent < 80) return 'primary'
if (this.quotaUsagePercent < 90) return 'warning'
if ((this.quota.relative || 0) < 80) return 'primary'
if ((this.quota.relative || 0) < 90) return 'warning'
return 'danger'
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/src/store/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const mutations = {
SET_QUOTA(state, quota) {
// Turn strings into ints
quota.free = parseInt(quota.free)
quota.relative = parseInt(quota.relative)
quota.relative = parseFloat(quota.relative)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fschade took me a bit longer because I needed to investigate why the relative used storage (which the backend reports correctly) always ends up as 0 in the store 💩 also fixed the fixtures where this was reflected, too

quota.used = parseInt(quota.used)
quota.total = parseInt(quota.total)

Expand Down
54 changes: 49 additions & 5 deletions packages/web-runtime/tests/unit/components/Topbar/UserMenu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@ localVue.use(GetTextPlugin, {
silent: true
})

const totalQuota = 1000
const basicQuota = 300
const warningQuota = 810
const dangerQuota = 910

const basicRelativeQuota = (basicQuota / totalQuota) * 100
const warningRelativeQuota = (warningQuota / totalQuota) * 100
const dangerRelativeQuota = (dangerQuota / totalQuota) * 100

const noEmail = ''
const email = 'test@test.de'

describe('User Menu component', () => {
describe('when quota and no email is set', () => {
it('renders a navigation without email', () => {
const wrapper = getMountedWrapper({ used: basicQuota, total: 1000 }, noEmail)
const wrapper = getMountedWrapper(
{ used: basicQuota, total: totalQuota, relative: basicRelativeQuota },
noEmail
)
expect(wrapper).toMatchSnapshot()
})
})
Expand All @@ -41,19 +49,55 @@ describe('User Menu component', () => {
})
describe('when quota is below 80%', () => {
it('renders a primary quota progress bar', () => {
const wrapper = getMountedWrapper({ used: basicQuota, total: 1000 }, email)
const wrapper = getMountedWrapper(
{
used: basicQuota,
total: totalQuota,
relative: basicRelativeQuota,
definition: 'default'
},
email
)
expect(wrapper).toMatchSnapshot()
})
})
describe('when quota is above 80% and below 90%', () => {
it('renders a warning quota progress bar', () => {
const wrapper = getMountedWrapper({ used: warningQuota, total: 1000 }, email)
const wrapper = getMountedWrapper(
{
used: warningQuota,
total: totalQuota,
relative: warningRelativeQuota,
definition: 'default'
},
email
)
expect(wrapper).toMatchSnapshot()
})
})
describe('when basic quota is set', () => {
describe('when quota is above 90%', () => {
it('renders a danger quota progress bar', () => {
const wrapper = getMountedWrapper({ used: dangerQuota, total: 1000 }, email)
const wrapper = getMountedWrapper(
{
used: dangerQuota,
total: totalQuota,
relative: dangerRelativeQuota,
definition: 'default'
},
email
)
expect(wrapper).toMatchSnapshot()
})
})
describe('when quota is unlimited', () => {
it('renders no percentag of total and no progress bar', () => {
const wrapper = getMountedWrapper(
{
used: basicQuota,
definition: 'none'
},
email
)
expect(wrapper).toMatchSnapshot()
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`User Menu component when basic quota is set renders a danger quota progress bar 1`] = `
exports[`User Menu component when no quota and email is set the user menu does not contain a quota 1`] = `
<nav aria-label="Account menu">
<oc-button-stub type="button" size="medium" arialabel="User Menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="_userMenuButton" class="oc-topbar-personal">
<avatar-image-stub width="32" userid="einstein" class="oc-topbar-personal-avatar oc-flex-inline oc-flex-center oc-flex-middle"></avatar-image-stub>
Expand All @@ -26,19 +26,13 @@ exports[`User Menu component when basic quota is set renders a danger quota prog
<translate-stub tag="span">Log out</translate-stub>
</oc-button-stub>
</li>
<li class="storage-wrapper oc-pl-s">
<oc-icon-stub name="cloud" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<div class="storage-wrapper-text">
<p class="oc-my-rm"><span>Personal storage (91.0% used)</span> <br> <span class="oc-text-small">910 B of 1 kB used</span></p>
<oc-progress-stub value="91" max="100" size="small" variation="danger"></oc-progress-stub>
</div>
</li>
<!---->
</oc-list-stub>
</oc-drop-stub>
</nav>
`;

exports[`User Menu component when no quota and email is set the user menu does not contain a quota 1`] = `
exports[`User Menu component when no quota and no email is set the user menu does not contain a quota 1`] = `
<nav aria-label="Account menu">
<oc-button-stub type="button" size="medium" arialabel="User Menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="_userMenuButton" class="oc-topbar-personal">
<avatar-image-stub width="32" userid="einstein" class="oc-topbar-personal-avatar oc-flex-inline oc-flex-center oc-flex-middle"></avatar-image-stub>
Expand Down Expand Up @@ -70,7 +64,7 @@ exports[`User Menu component when no quota and email is set the user menu does n
</nav>
`;

exports[`User Menu component when no quota and no email is set the user menu does not contain a quota 1`] = `
exports[`User Menu component when quota and no email is set renders a navigation without email 1`] = `
<nav aria-label="Account menu">
<oc-button-stub type="button" size="medium" arialabel="User Menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="_userMenuButton" class="oc-topbar-personal">
<avatar-image-stub width="32" userid="einstein" class="oc-topbar-personal-avatar oc-flex-inline oc-flex-center oc-flex-middle"></avatar-image-stub>
Expand All @@ -96,13 +90,19 @@ exports[`User Menu component when no quota and no email is set the user menu doe
<translate-stub tag="span">Log out</translate-stub>
</oc-button-stub>
</li>
<!---->
<li class="storage-wrapper oc-pl-s">
<oc-icon-stub name="cloud" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<div class="storage-wrapper-text">
<p class="oc-my-rm"><span>Personal storage (30% used)</span> <br> <span class="oc-text-small">300 B of 1 kB used</span></p>
<oc-progress-stub value="30" max="100" size="small" variation="primary"></oc-progress-stub>
</div>
</li>
</oc-list-stub>
</oc-drop-stub>
</nav>
`;

exports[`User Menu component when quota and no email is set renders a navigation without email 1`] = `
exports[`User Menu component when quota is above 80% and below 90% renders a warning quota progress bar 1`] = `
<nav aria-label="Account menu">
<oc-button-stub type="button" size="medium" arialabel="User Menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="_userMenuButton" class="oc-topbar-personal">
<avatar-image-stub width="32" userid="einstein" class="oc-topbar-personal-avatar oc-flex-inline oc-flex-center oc-flex-middle"></avatar-image-stub>
Expand Down Expand Up @@ -131,16 +131,16 @@ exports[`User Menu component when quota and no email is set renders a navigation
<li class="storage-wrapper oc-pl-s">
<oc-icon-stub name="cloud" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<div class="storage-wrapper-text">
<p class="oc-my-rm"><span>Personal storage (30.0% used)</span> <br> <span class="oc-text-small">300 B of 1 kB used</span></p>
<oc-progress-stub value="30" max="100" size="small" variation="primary"></oc-progress-stub>
<p class="oc-my-rm"><span>Personal storage (81% used)</span> <br> <span class="oc-text-small">810 B of 1 kB used</span></p>
<oc-progress-stub value="81" max="100" size="small" variation="warning"></oc-progress-stub>
</div>
</li>
</oc-list-stub>
</oc-drop-stub>
</nav>
`;

exports[`User Menu component when quota is above 80% and below 90% renders a warning quota progress bar 1`] = `
exports[`User Menu component when quota is above 90% renders a danger quota progress bar 1`] = `
<nav aria-label="Account menu">
<oc-button-stub type="button" size="medium" arialabel="User Menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="_userMenuButton" class="oc-topbar-personal">
<avatar-image-stub width="32" userid="einstein" class="oc-topbar-personal-avatar oc-flex-inline oc-flex-center oc-flex-middle"></avatar-image-stub>
Expand Down Expand Up @@ -169,8 +169,8 @@ exports[`User Menu component when quota is above 80% and below 90% renders a war
<li class="storage-wrapper oc-pl-s">
<oc-icon-stub name="cloud" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<div class="storage-wrapper-text">
<p class="oc-my-rm"><span>Personal storage (81.0% used)</span> <br> <span class="oc-text-small">810 B of 1 kB used</span></p>
<oc-progress-stub value="81" max="100" size="small" variation="warning"></oc-progress-stub>
<p class="oc-my-rm"><span>Personal storage (91% used)</span> <br> <span class="oc-text-small">910 B of 1 kB used</span></p>
<oc-progress-stub value="91" max="100" size="small" variation="danger"></oc-progress-stub>
</div>
</li>
</oc-list-stub>
Expand Down Expand Up @@ -207,11 +207,51 @@ exports[`User Menu component when quota is below 80% renders a primary quota pro
<li class="storage-wrapper oc-pl-s">
<oc-icon-stub name="cloud" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<div class="storage-wrapper-text">
<p class="oc-my-rm"><span>Personal storage (30.0% used)</span> <br> <span class="oc-text-small">300 B of 1 kB used</span></p>
<p class="oc-my-rm"><span>Personal storage (30% used)</span> <br> <span class="oc-text-small">300 B of 1 kB used</span></p>
<oc-progress-stub value="30" max="100" size="small" variation="primary"></oc-progress-stub>
</div>
</li>
</oc-list-stub>
</oc-drop-stub>
</nav>
`;

exports[`User Menu component when quota is unlimited renders no percentag of total and no progress bar 1`] = `
<nav aria-label="Account menu">
<oc-button-stub type="button" size="medium" arialabel="User Menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="_userMenuButton" class="oc-topbar-personal">
<avatar-image-stub width="32" userid="einstein" class="oc-topbar-personal-avatar oc-flex-inline oc-flex-center oc-flex-middle"></avatar-image-stub>
</oc-button-stub>
<oc-drop-stub dropid="account-info-container" toggle="#_userMenuButton" position="bottom-start" mode="click" closeonclick="true" paddingsize="small">
<oc-list-stub class="user-menu-list">
<li>
<oc-button-stub type="router-link" size="medium" to="[object Object]" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="oc-topbar-account-manage">
<avatar-image-stub width="32" userid="einstein"></avatar-image-stub> <span class="profile-info-wrapper oc-py-xs"><span></span>
<!---->
<!----></span>
</oc-button-stub>
</li>
<li>
<oc-button-stub type="router-link" size="medium" to="[object Object]" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium">
<oc-icon-stub name="application" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<translate-stub tag="span">Settings</translate-stub>
</oc-button-stub>
</li>
<li>
<oc-button-stub type="button" size="medium" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="oc-topbar-account-logout">
<oc-icon-stub name="logout-box-r" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<translate-stub tag="span">Log out</translate-stub>
</oc-button-stub>
</li>
<li class="storage-wrapper oc-pl-s">
<oc-icon-stub name="cloud" filltype="line" accessiblelabel="" type="span" size="medium" variation="passive" color="" class="oc-p-xs"></oc-icon-stub>
<div class="storage-wrapper-text">
<p class="oc-my-rm">
<!----> <span class="oc-text-small">300 B used</span>
</p>
<!---->
</div>
</li>
</oc-list-stub>
</oc-drop-stub>
</nav>
`;