Skip to content

Commit d9c37b2

Browse files
committed
Remove channel file summary when channel is deleted
1 parent 7cae315 commit d9c37b2

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

kolibri/plugins/management/assets/src/state/manageContentActions.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export function refreshChannelList() {
2020
* @returns {Promise}
2121
*/
2222
export function deleteChannel(store, channelId) {
23-
return ChannelResource.getModel(channelId).delete().then(refreshChannelList);
23+
return ChannelResource.getModel(channelId).delete()
24+
.then(() => {
25+
store.dispatch(mutationTypes.REMOVE_CHANNEL_FILE_SUMMARY, channelId);
26+
})
27+
.then(refreshChannelList)
2428
}
2529

2630
/**
@@ -54,6 +58,7 @@ export function addChannelFileSummary(store, channelId) {
5458
*/
5559
export function addChannelFileSummaries(store, channelIds) {
5660
channelIds.forEach(channelId => {
61+
if (store.state.pageState[channelId]) return;
5762
addChannelFileSummary(store, channelId);
5863
});
5964
}
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1+
import Vue from 'vue';
12
import { PageNames } from '../constants';
23

34
export const mutationTypes = {
45
ADD_CHANNEL_FILE_SUMMARY: 'MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY',
6+
REMOVE_CHANNEL_FILE_SUMMARY: 'MANAGE_CONTENT_REMOVE_CHANNEL_FILE_SUMMARY',
57
};
68

79
function isManageContentPage(state) {
810
return state.pageName === PageNames.CONTENT_MGMT_PAGE;
911
}
1012

11-
const mutations = {
12-
MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY: (state, fileSummary) => {
13-
if (isManageContentPage(state)) {
14-
state.pageState.channelFileSummaries[fileSummary.channel_id] = {
15-
totalFileSizeInBytes: fileSummary.total_file_size,
16-
numberOfFiles: fileSummary.total_files,
17-
};
18-
}
19-
},
20-
};
13+
function MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY(state, fileSummary) {
14+
if (isManageContentPage(state)) {
15+
state.pageState.channelFileSummaries[fileSummary.channel_id] = {
16+
totalFileSizeInBytes: fileSummary.total_file_size,
17+
numberOfFiles: fileSummary.total_files,
18+
};
19+
}
20+
}
2121

22-
export { mutations as default };
22+
function MANAGE_CONTENT_REMOVE_CHANNEL_FILE_SUMMARY(state, channelId) {
23+
if (isManageContentPage(state)) {
24+
Vue.delete(state.pageState.channelFileSummaries, channelId);
25+
}
26+
}
27+
28+
export default {
29+
MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY,
30+
MANAGE_CONTENT_REMOVE_CHANNEL_FILE_SUMMARY,
31+
}

kolibri/plugins/management/assets/src/views/manage-content-page/channels-grid.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
this.addChannelFileSummaries(map(this.channelList, 'id'));
111111
},
112112
watch: {
113-
channelList(val, newVal) {
114-
this.addChannelFileSummaries(map(newVal, 'id'));
113+
channelList(val) {
114+
this.addChannelFileSummaries(map(val, 'id'));
115115
},
116116
},
117117
methods: {

0 commit comments

Comments
 (0)