Commit f614f3fa authored by Jiaan Louw's avatar Jiaan Louw Committed by Vitaly Slobodin

Update compliance framework list deleting

This updates the compliance framework list to show loading
on multiple list items when they are being deleted.
parent f13d0250
...@@ -37,13 +37,14 @@ export default { ...@@ -37,13 +37,14 @@ export default {
this.reportDeleting(); this.reportDeleting();
try { try {
const { id } = this;
const { const {
data: { destroyComplianceFramework }, data: { destroyComplianceFramework },
} = await this.$apollo.mutate({ } = await this.$apollo.mutate({
mutation: deleteComplianceFrameworkMutation, mutation: deleteComplianceFrameworkMutation,
variables: { variables: {
input: { input: {
id: this.id, id,
}, },
}, },
awaitRefetchQueries: true, awaitRefetchQueries: true,
...@@ -62,7 +63,7 @@ export default { ...@@ -62,7 +63,7 @@ export default {
if (error) { if (error) {
this.reportError(new Error(error)); this.reportError(new Error(error));
} else { } else {
this.reportSuccess(); this.reportSuccess(id);
} }
} catch (error) { } catch (error) {
this.reportError(error); this.reportError(error);
...@@ -75,8 +76,8 @@ export default { ...@@ -75,8 +76,8 @@ export default {
Sentry.captureException(error); Sentry.captureException(error);
this.$emit('error'); this.$emit('error');
}, },
reportSuccess() { reportSuccess(id) {
this.$emit('delete'); this.$emit('delete', id);
}, },
show() { show() {
this.$refs.modal.show(); this.$refs.modal.show();
......
...@@ -39,7 +39,7 @@ export default { ...@@ -39,7 +39,7 @@ export default {
data() { data() {
return { return {
markedForDeletion: {}, markedForDeletion: {},
deletingFramework: null, deletingFrameworksIds: [],
complianceFrameworks: [], complianceFrameworks: [],
error: '', error: '',
message: '', message: '',
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
}, },
computed: { computed: {
isLoading() { isLoading() {
return this.$apollo.loading && !this.deletingFramework; return this.$apollo.loading && this.deletingFrameworksIds.length === 0;
}, },
hasLoaded() { hasLoaded() {
return !this.isLoading && !this.error; return !this.isLoading && !this.error;
...@@ -105,15 +105,18 @@ export default { ...@@ -105,15 +105,18 @@ export default {
onError() { onError() {
this.error = this.$options.i18n.deleteError; this.error = this.$options.i18n.deleteError;
}, },
onDelete() { onDelete(id) {
this.message = this.$options.i18n.deleteMessage; this.message = this.$options.i18n.deleteMessage;
this.deletingFramework = null; const idx = this.deletingFrameworksIds.indexOf(id);
if (idx > -1) {
this.deletingFrameworksIds.splice(idx, 1);
}
}, },
onDeleting() { onDeleting() {
this.deletingFramework = this.markedForDeletion; this.deletingFrameworksIds.push(this.markedForDeletion.id);
}, },
isDeleting(framework) { isDeleting(id) {
return this.deletingFramework === framework; return this.deletingFrameworksIds.includes(id);
}, },
}, },
i18n: { i18n: {
...@@ -153,7 +156,7 @@ export default { ...@@ -153,7 +156,7 @@ export default {
v-for="framework in complianceFrameworks" v-for="framework in complianceFrameworks"
:key="framework.parsedId" :key="framework.parsedId"
:framework="framework" :framework="framework"
:loading="isDeleting(framework)" :loading="isDeleting(framework.id)"
@delete="markForDeletion" @delete="markForDeletion"
/> />
</gl-tab> </gl-tab>
......
...@@ -117,7 +117,7 @@ describe('DeleteModal', () => { ...@@ -117,7 +117,7 @@ describe('DeleteModal', () => {
await waitForPromises(); await waitForPromises();
expect(wrapper.emitted('delete')).toHaveLength(1); expect(wrapper.emitted('delete')[0]).toEqual([frameworkFoundResponse.id]);
}); });
it('emits "error" event and reports to Sentry when there is a network error', async () => { it('emits "error" event and reports to Sentry when there is a network error', async () => {
......
...@@ -213,13 +213,18 @@ describe('List', () => { ...@@ -213,13 +213,18 @@ describe('List', () => {
expect(findDeleteModal().vm.show).toHaveBeenCalled(); expect(findDeleteModal().vm.show).toHaveBeenCalled();
}); });
describe('and the item is being deleted', () => { describe('and multiple items are being deleted', () => {
beforeEach(() => { beforeEach(() => {
findDeleteModal().vm.$emit('deleting'); findListItems().wrappers.forEach((listItem) => {
listItem.vm.$emit('delete', listItem.props('framework'));
findDeleteModal().vm.$emit('deleting');
});
}); });
it('sets "loading" to true on the marked list item', () => { it('sets "loading" to true on the deleting list items', () => {
expect(findListItem().props('loading')).toBe(true); expect(findListItems().wrappers.every((listItem) => listItem.props('loading'))).toBe(
true,
);
}); });
describe('and an error occurred', () => { describe('and an error occurred', () => {
...@@ -238,10 +243,14 @@ describe('List', () => { ...@@ -238,10 +243,14 @@ describe('List', () => {
describe('and the item was successfully deleted', () => { describe('and the item was successfully deleted', () => {
beforeEach(async () => { beforeEach(async () => {
findDeleteModal().vm.$emit('delete'); findDeleteModal().vm.$emit('delete', framework.id);
await waitForPromises(); await waitForPromises();
}); });
it('sets "loading" to false on the deleted list item', () => {
expect(findListItem().props('loading')).toBe(false);
});
it('shows the alert for the success message', () => { it('shows the alert for the success message', () => {
expect(findAlert().props('dismissible')).toBe(true); expect(findAlert().props('dismissible')).toBe(true);
expect(findAlert().props('variant')).toBe('info'); expect(findAlert().props('variant')).toBe('info');
......
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