Skip to content

Commit

Permalink
Refactor QuotaModal, Implement batch quota edit admin
Browse files Browse the repository at this point in the history
  • Loading branch information
lookacat committed Feb 8, 2023
1 parent ead3a3c commit 7ac9836
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<quota-modal
v-if="quotaModalIsOpen"
:cancel="closeQuotaModal"
:space="quotaModalSelectedSpace"
:spaces="items"
@space-quota-updated="spaceQuotaUpdated"
/>
</div>
Expand Down Expand Up @@ -77,8 +77,6 @@ export default defineComponent({
}
return sections
})
const quotaModalSelectedSpace = computed(() => instance.$data.$_editQuota_selectedSpace)
const quotaModalIsOpen = computed(() => instance.$data.$_editQuota_modalOpen)
const closeQuotaModal = () => {
instance.$_editQuota_closeModal()
Expand All @@ -88,7 +86,6 @@ export default defineComponent({
}
return {
menuSections,
quotaModalSelectedSpace,
quotaModalIsOpen,
closeQuotaModal,
spaceQuotaUpdated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<quota-modal
v-if="quotaModalIsOpen"
:cancel="closeQuotaModal"
:space="resources[0]"
:spaces="[resources[0]]"
@space-quota-updated="spaceQuotaUpdated"
/>
<oc-list id="oc-spaces-actions-sidebar" class-name="oc-mt-s">
Expand Down
6 changes: 2 additions & 4 deletions packages/web-app-admin-settings/src/views/Spaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<quota-modal
v-if="quotaModalIsOpen"
:cancel="closeQuotaModal"
:space="quotaModalSelectedSpace"
:spaces="selectedSpaces"
@space-quota-updated="spaceQuotaUpdated"
/>
<no-content-message
Expand Down Expand Up @@ -116,7 +116,7 @@ export default defineComponent({
NoContentMessage,
ContextActions,
SpaceInfo,
BatchActions,
BatchActions,
QuotaModal
},
mixins: [Delete, Disable, Restore, EditQuota],
Expand Down Expand Up @@ -270,7 +270,6 @@ export default defineComponent({
resizeObserver.unobserve(unref(appBarActionsRef))
})
const quotaModalSelectedSpace = computed(() => instance.$data.$_editQuota_selectedSpace)
const quotaModalIsOpen = computed(() => instance.$data.$_editQuota_modalOpen)
const closeQuotaModal = () => {
instance.$_editQuota_closeModal()
Expand Down Expand Up @@ -298,7 +297,6 @@ export default defineComponent({
limitedScreenSpace,
appBarActionsRef,
onResize,
quotaModalSelectedSpace,
quotaModalIsOpen,
closeQuotaModal,
spaceQuotaUpdated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:cancel="closeReadmeContentModal"
:space="resources[0]"
></readme-content-modal>
<quota-modal v-if="quotaModalIsOpen" :cancel="closeQuotaModal" :space="resources[0]" />
<quota-modal v-if="quotaModalIsOpen" :cancel="closeQuotaModal" :spaces="[resources[0]]" />
<input
id="space-image-upload-input"
ref="spaceImageInput"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<quota-modal
v-if="quotaModalIsOpen"
:cancel="closeQuotaModal"
:space="quotaModalSelectedSpace"
:spaces="quotaModalSelectedSpace"
/>
<readme-content-modal
v-if="readmeContentModalIsOpen"
Expand Down Expand Up @@ -74,7 +74,7 @@ export default defineComponent({
computed: {
quotaModalSelectedSpace() {
return this.$data.$_editQuota_selectedSpace
return [this.$data.$_editQuota_selectedSpace]
},
quotaModalIsOpen() {
return this.$data.$_editQuota_modalOpen
Expand Down
76 changes: 44 additions & 32 deletions packages/web-pkg/src/components/Spaces/QuotaModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default defineComponent({
QuotaSelect
},
props: {
space: {
type: Object,
spaces: {
type: Array,
required: true
},
cancel: {
Expand All @@ -53,16 +53,23 @@ export default defineComponent({
},
computed: {
confirmButtonDisabled() {
return this.space.spaceQuota.total === this.selectedOption
return !this.spaces.some((space) => space.spaceQuota.total !== this.selectedOption)
},
modalTitle() {
return this.$gettextInterpolate(this.$gettext('Change quota for space %{name}'), {
name: this.space.name
if (this.spaces.length === 1) {
return this.$gettext('Change quota for space %{name}', {
name: this.spaces[0].name
})
}
return this.$gettext('Change quota for %{count} spaces', {
count: this.spaces.length
})
}
},
mounted() {
this.selectedOption = this.space.spaceQuota.total || 0
console.log('==!!==')
console.log(this.spaces)
this.selectedOption = this.spaces[0].spaceQuota.total || 0
},
methods: {
...mapActions(['showMessage']),
Expand All @@ -73,34 +80,39 @@ export default defineComponent({
this.selectedOption = option.value
},
editQuota() {
return this.graphClient.drives
.updateDrive(this.space.id, { quota: { total: this.selectedOption } }, {})
.then(({ data }) => {
this.cancel()
if (unref(this.$router.currentRoute).name === 'admin-settings-spaces') {
this.$emit('spaceQuotaUpdated', data.quota)
}
this.UPDATE_SPACE_FIELD({
id: this.space.id,
field: 'spaceQuota',
value: data.quota
})
this.UPDATE_RESOURCE_FIELD({
id: this.space.id,
field: 'spaceQuota',
value: data.quota
})
this.showMessage({
title: this.$gettext('Space quota was changed successfully')
const requests = []
this.spaces.forEach((space) => {
const request = this.graphClient.drives
.updateDrive(space.id, { quota: { total: this.selectedOption } }, {})
.then(({ data }) => {
this.cancel()
if (unref(this.$router.currentRoute).name === 'admin-settings-spaces') {
this.$emit('spaceQuotaUpdated', data.quota)
}
this.UPDATE_SPACE_FIELD({
id: space.id,
field: 'spaceQuota',
value: data.quota
})
this.UPDATE_RESOURCE_FIELD({
id: space.id,
field: 'spaceQuota',
value: data.quota
})
this.showMessage({
title: this.$gettext('Space quota was changed successfully')
})
})
})
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to change space quota'),
status: 'danger'
.catch((error) => {
console.error(error)
this.showMessage({
title: this.$gettext('Failed to change space quota'),
status: 'danger'
})
})
})
requests.push(request)
})
return Promise.all(requests)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/mixins/spaces/editQuota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
},
handler: this.$_editQuota_trigger,
isEnabled: ({ resources }) => {
if (resources.some(r => r.spaceQuota === false)) {
if (resources.some((r) => r.spaceQuota === false)) {
return false
}

Expand Down

0 comments on commit 7ac9836

Please sign in to comment.