Skip to content

Commit de3a9ae

Browse files
committed
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 9b2e31b commit de3a9ae

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

apps/settings/src/mixins/AppManagement.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,35 @@ export default {
166166
},
167167
addGroupLimitation(groupArray) {
168168
if (this.app?.app_api) {
169-
return // not supported for app_api apps
169+
return
170170
}
171171
const group = groupArray.pop()
172172
const groups = this.app.groups.concat([]).concat([group.id])
173+
174+
if (this.store && this.store.updateAppGroups) {
175+
this.store.updateAppGroups(this.app.id, groups)
176+
}
177+
173178
this.$store.dispatch('enableApp', { appId: this.app.id, groups })
174179
},
175180
removeGroupLimitation(group) {
176181
if (this.app?.app_api) {
177-
return // not supported for app_api apps
182+
return
178183
}
179184
const currentGroups = this.app.groups.concat([])
180185
const index = currentGroups.indexOf(group.id)
181186
if (index > -1) {
182187
currentGroups.splice(index, 1)
183188
}
189+
190+
if (this.store && this.store.updateAppGroups) {
191+
this.store.updateAppGroups(this.app.id, currentGroups)
192+
}
193+
194+
if (currentGroups.length === 0) {
195+
this.groupCheckedAppsData = false
196+
}
197+
184198
this.$store.dispatch('enableApp', { appId: this.app.id, groups: currentGroups })
185199
},
186200
forceEnable(appId) {

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

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

apps/settings/src/store/apps.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const mutations = {
7272
enableApp(state, { appId, groups }) {
7373
const app = state.apps.find((app) => app.id === appId)
7474
app.active = true
75-
app.groups = groups
75+
Vue.set(app, 'groups', [...groups])
7676
if (app.id === 'app_api') {
7777
state.appApiEnabled = true
7878
}
@@ -183,13 +183,23 @@ const actions = {
183183
return api.requireAdmin().then(() => {
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)
189202
context.commit('stopLoading', 'install')
190-
apps.forEach((_appId) => {
191-
context.commit('enableApp', { appId: _appId, groups })
192-
})
193203

194204
// check for server health
195205
return axios.get(generateUrl('apps/files/'))
@@ -225,6 +235,19 @@ const actions = {
225235
.catch((error) => {
226236
context.commit('stopLoading', apps)
227237
context.commit('stopLoading', 'install')
238+
239+
apps.forEach((_appId) => {
240+
if (previousState[_appId]) {
241+
context.commit('enableApp', {
242+
appId: _appId,
243+
groups: previousState[_appId].groups,
244+
})
245+
if (!previousState[_appId].active) {
246+
context.commit('disableApp', _appId)
247+
}
248+
}
249+
})
250+
228251
context.commit('setError', {
229252
appId: apps,
230253
error: error.response.data.data.message,

0 commit comments

Comments
 (0)