mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
fix(settings): Reactive UI updates for app group limitations
The "Limit app usage to groups" functionality previously required a page refresh to display changes when adding or removing group limitations. This occurred due to store synchronization issues between the Pinia and Vuex stores used by different components. Signed-off-by: nfebe <fenn25.fn@gmail.com>
This commit is contained in:
parent
2043e0e140
commit
9bb583c8a3
3 changed files with 50 additions and 3 deletions
|
|
@ -160,21 +160,35 @@ export default {
|
|||
},
|
||||
addGroupLimitation(groupArray) {
|
||||
if (this.app?.app_api) {
|
||||
return // not supported for app_api apps
|
||||
return
|
||||
}
|
||||
const group = groupArray.pop()
|
||||
const groups = this.app.groups.concat([]).concat([group.id])
|
||||
|
||||
if (this.store && this.store.updateAppGroups) {
|
||||
this.store.updateAppGroups(this.app.id, groups)
|
||||
}
|
||||
|
||||
this.$store.dispatch('enableApp', { appId: this.app.id, groups })
|
||||
},
|
||||
removeGroupLimitation(group) {
|
||||
if (this.app?.app_api) {
|
||||
return // not supported for app_api apps
|
||||
return
|
||||
}
|
||||
const currentGroups = this.app.groups.concat([])
|
||||
const index = currentGroups.indexOf(group.id)
|
||||
if (index > -1) {
|
||||
currentGroups.splice(index, 1)
|
||||
}
|
||||
|
||||
if (this.store && this.store.updateAppGroups) {
|
||||
this.store.updateAppGroups(this.app.id, currentGroups)
|
||||
}
|
||||
|
||||
if (currentGroups.length === 0) {
|
||||
this.groupCheckedAppsData = false
|
||||
}
|
||||
|
||||
this.$store.dispatch('enableApp', { appId: this.app.id, groups: currentGroups })
|
||||
},
|
||||
forceEnable(appId) {
|
||||
|
|
|
|||
|
|
@ -83,5 +83,12 @@ export const useAppsStore = defineStore('settings-apps', {
|
|||
getAppById(appId: string): IAppstoreApp|null {
|
||||
return this.apps.find(({ id }) => id === appId) ?? null
|
||||
},
|
||||
|
||||
updateAppGroups(appId: string, groups: string[]) {
|
||||
const app = this.apps.find(({ id }) => id === appId)
|
||||
if (app) {
|
||||
app.groups = [...groups]
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ const mutations = {
|
|||
enableApp(state, { appId, groups }) {
|
||||
const app = state.apps.find(app => app.id === appId)
|
||||
app.active = true
|
||||
app.groups = groups
|
||||
Vue.set(app, 'groups', [...groups])
|
||||
if (app.id === 'app_api') {
|
||||
state.appApiEnabled = true
|
||||
}
|
||||
|
|
@ -183,6 +183,19 @@ const actions = {
|
|||
return api.requireAdmin().then((response) => {
|
||||
context.commit('startLoading', apps)
|
||||
context.commit('startLoading', 'install')
|
||||
|
||||
const previousState = {}
|
||||
apps.forEach((_appId) => {
|
||||
const app = context.state.apps.find((app) => app.id === _appId)
|
||||
if (app) {
|
||||
previousState[_appId] = {
|
||||
active: app.active,
|
||||
groups: [...(app.groups || [])],
|
||||
}
|
||||
context.commit('enableApp', { appId: _appId, groups })
|
||||
}
|
||||
})
|
||||
|
||||
return api.post(generateUrl('settings/apps/enable'), { appIds: apps, groups })
|
||||
.then((response) => {
|
||||
context.commit('stopLoading', apps)
|
||||
|
|
@ -225,6 +238,19 @@ const actions = {
|
|||
.catch((error) => {
|
||||
context.commit('stopLoading', apps)
|
||||
context.commit('stopLoading', 'install')
|
||||
|
||||
apps.forEach((_appId) => {
|
||||
if (previousState[_appId]) {
|
||||
context.commit('enableApp', {
|
||||
appId: _appId,
|
||||
groups: previousState[_appId].groups,
|
||||
})
|
||||
if (!previousState[_appId].active) {
|
||||
context.commit('disableApp', _appId)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
context.commit('setError', {
|
||||
appId: apps,
|
||||
error: error.response.data.data.message,
|
||||
|
|
|
|||
Loading…
Reference in a new issue