Commit 71f2d4bb authored by Nick Kipling's avatar Nick Kipling Committed by Nathan Friend

Updating FE to use new bulk_destroy endpoint

parent 0426d15c
...@@ -45,6 +45,9 @@ export default { ...@@ -45,6 +45,9 @@ export default {
}; };
}, },
computed: { computed: {
bulkDeletePath() {
return this.repo.tagsPath ? this.repo.tagsPath.replace('?format=json', '/bulk_destroy') : '';
},
shouldRenderPagination() { shouldRenderPagination() {
return this.repo.pagination.total > this.repo.pagination.perPage; return this.repo.pagination.total > this.repo.pagination.perPage;
}, },
...@@ -78,7 +81,7 @@ export default { ...@@ -78,7 +81,7 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['fetchList', 'deleteItem']), ...mapActions(['fetchList', 'deleteItems']),
layers(item) { layers(item) {
return item.layers ? n__('%d layer', '%d layers', item.layers) : ''; return item.layers ? n__('%d layer', '%d layers', item.layers) : '';
}, },
...@@ -101,18 +104,16 @@ export default { ...@@ -101,18 +104,16 @@ export default {
itemsToBeDeleted = [singleItemToBeDeleted]; itemsToBeDeleted = [singleItemToBeDeleted];
} }
const deleteActions = itemsToBeDeleted.map( if (this.bulkDeletePath) {
x => this.deleteItems({
new Promise((resolve, reject) => { path: this.bulkDeletePath,
this.deleteItem(this.repo.list[x]) items: itemsToBeDeleted.map(x => this.repo.list[x].tag),
.then(resolve) })
.catch(reject); .then(() => this.fetchList({ repo: this.repo }))
}), .catch(() => this.showError(errorMessagesTypes.DELETE_REGISTRY));
); } else {
this.showError(errorMessagesTypes.DELETE_REGISTRY);
Promise.all(deleteActions) }
.then(() => this.fetchList({ repo: this.repo }))
.catch(() => this.showError(errorMessagesTypes.DELETE_REGISTRY));
}, },
onPageChange(pageNumber) { onPageChange(pageNumber) {
this.fetchList({ repo: this.repo, page: pageNumber }).catch(() => this.fetchList({ repo: this.repo, page: pageNumber }).catch(() =>
......
...@@ -36,6 +36,7 @@ export const fetchList = ({ commit }, { repo, page }) => { ...@@ -36,6 +36,7 @@ export const fetchList = ({ commit }, { repo, page }) => {
}; };
export const deleteItem = (_, item) => axios.delete(item.destroyPath); export const deleteItem = (_, item) => axios.delete(item.destroyPath);
export const deleteItems = (_, { path, items }) => axios.delete(path, { params: { ids: items } });
export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data); export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data);
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_MAIN_LOADING); export const toggleLoading = ({ commit }) => commit(types.TOGGLE_MAIN_LOADING);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment