Skip to content

Commit 9bb583c

Browse files
nfebeAndyScherzinger
authored andcommitted
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 <[email protected]>
1 parent 2043e0e commit 9bb583c

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

apps/settings/src/mixins/AppManagement.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,35 @@ export default {
160160
},
161161
addGroupLimitation(groupArray) {
162162
if (this.app?.app_api) {
163-
return // not supported for app_api apps
163+
return
164164
}
165165
const group = groupArray.pop()
166166
const groups = this.app.groups.concat([]).concat([group.id])
167+
168+
if (this.store && this.store.updateAppGroups) {
169+
this.store.updateAppGroups(this.app.id, groups)
170+
}
171+
167172
this.$store.dispatch('enableApp', { appId: this.app.id, groups })
168173
},
169174
removeGroupLimitation(group) {
170175
if (this.app?.app_api) {
171-
return // not supported for app_api apps
176+
return
172177
}
173178
const currentGroups = this.app.groups.concat([])
174179
const index = currentGroups.indexOf(group.id)
175180
if (index > -1) {
176181
currentGroups.splice(index, 1)
177182
}
183+
184+
if (this.store && this.store.updateAppGroups) {
185+
this.store.updateAppGroups(this.app.id, currentGroups)
186+
}
187+
188+
if (currentGroups.length === 0) {
189+
this.groupCheckedAppsData = false
190+
}
191+
178192
this.$store.dispatch('enableApp', { appId: this.app.id, groups: currentGroups })
179193
},
180194
forceEnable(appId) {

apps/settings/src/store/apps-store.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,12 @@ export const useAppsStore = defineStore('settings-apps', {
8383
getAppById(appId: string): IAppstoreApp|null {
8484
return this.apps.find(({ id }) => id === appId) ?? null
8585
},
86+
87+
updateAppGroups(appId: string, groups: string[]) {
88+
const app = this.apps.find(({ id }) => id === appId)
89+
if (app) {
90+
app.groups = [...groups]
91+
}
92+
},
8693
},
8794
})

apps/settings/src/store/apps.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const mutations = {
7171
enableApp(state, { appId, groups }) {
7272
const app = state.apps.find(app => app.id === appId)
7373
app.active = true
74-
app.groups = groups
74+
Vue.set(app, 'groups', [...groups])
7575
if (app.id === 'app_api') {
7676
state.appApiEnabled = true
7777
}
@@ -183,6 +183,19 @@ const actions = {
183183
return api.requireAdmin().then((response) => {
184184
context.commit('startLoading', apps)
185185
context.commit('startLoading', 'install')
186+
187+
const previousState = {}
188+
apps.forEach((_appId) => {
189+
const app = context.state.apps.find((app) => app.id === _appId)
190+
if (app) {
191+
previousState[_appId] = {
192+
active: app.active,
193+
groups: [...(app.groups || [])],
194+
}
195+
context.commit('enableApp', { appId: _appId, groups })
196+
}
197+
})
198+
186199
return api.post(generateUrl('settings/apps/enable'), { appIds: apps, groups })
187200
.then((response) => {
188201
context.commit('stopLoading', apps)
@@ -225,6 +238,19 @@ const actions = {
225238
.catch((error) => {
226239
context.commit('stopLoading', apps)
227240
context.commit('stopLoading', 'install')
241+
242+
apps.forEach((_appId) => {
243+
if (previousState[_appId]) {
244+
context.commit('enableApp', {
245+
appId: _appId,
246+
groups: previousState[_appId].groups,
247+
})
248+
if (!previousState[_appId].active) {
249+
context.commit('disableApp', _appId)
250+
}
251+
}
252+
})
253+
228254
context.commit('setError', {
229255
appId: apps,
230256
error: error.response.data.data.message,

0 commit comments

Comments
 (0)