Commit da36d6e8 authored by Tom Quirk's avatar Tom Quirk

Handle DesignDestroyer errors in parents

Design Destroyer is used both on the Issue page,
and in the "design detail" page, and errors need to be
flashed in each respective place.

Previously, Design Destroyer flashed errors within it.
Now, this has been removed and parent components
are responsible for flashing errors
parent dbb10821
...@@ -4,8 +4,6 @@ import createFlash from '~/flash'; ...@@ -4,8 +4,6 @@ import createFlash from '~/flash';
import projectQuery from '../graphql/queries/project.query.graphql'; import projectQuery from '../graphql/queries/project.query.graphql';
import destroyDesignMutation from '../graphql/mutations/destroyDesign.mutation.graphql'; import destroyDesignMutation from '../graphql/mutations/destroyDesign.mutation.graphql';
import { updateStoreAfterDesignsDelete } from '../utils/cache_update'; import { updateStoreAfterDesignsDelete } from '../utils/cache_update';
import { designDeletionError } from '../utils/error_messages';
import { createDesignDetailFlash } from '../utils/design_management_utils';
export default { export default {
components: { components: {
...@@ -34,10 +32,6 @@ export default { ...@@ -34,10 +32,6 @@ export default {
}, },
}, },
methods: { methods: {
onError() {
const errorMessage = designDeletionError(this.filenames.length === 1);
createDesignDetailFlash(errorMessage);
},
updateStoreAfterDelete( updateStoreAfterDelete(
store, store,
{ {
...@@ -66,7 +60,6 @@ export default { ...@@ -66,7 +60,6 @@ export default {
iid, iid,
}" }"
:update="updateStoreAfterDelete" :update="updateStoreAfterDelete"
@error="onError"
v-on="$listeners" v-on="$listeners"
> >
<slot v-bind="{ mutate, loading, error }"></slot> <slot v-bind="{ mutate, loading, error }"></slot>
......
...@@ -20,7 +20,11 @@ import { ...@@ -20,7 +20,11 @@ import {
createDesignDetailFlash, createDesignDetailFlash,
} from '../../utils/design_management_utils'; } from '../../utils/design_management_utils';
import { updateStoreAfterAddImageDiffNote } from '../../utils/cache_update'; import { updateStoreAfterAddImageDiffNote } from '../../utils/cache_update';
import { ADD_DISCUSSION_COMMENT_ERROR, DESIGN_NOT_FOUND_ERROR } from '../../utils/error_messages'; import {
ADD_DISCUSSION_COMMENT_ERROR,
DESIGN_NOT_FOUND_ERROR,
designDeletionError,
} from '../../utils/error_messages';
import DESIGN_DETAIL_CONTAINER_CLASS from '../../utils/constants'; import DESIGN_DETAIL_CONTAINER_CLASS from '../../utils/constants';
export default { export default {
...@@ -185,6 +189,12 @@ export default { ...@@ -185,6 +189,12 @@ export default {
query: this.$route.query, query: this.$route.query,
}); });
}, },
onDesignDeleteError() {
const errorMessage = designDeletionError({ singular: true });
createDesignDetailFlash(errorMessage);
this.$router.push({ name: 'designs' });
},
}, },
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
this.closeCommentForm(); this.closeCommentForm();
...@@ -209,7 +219,7 @@ export default { ...@@ -209,7 +219,7 @@ export default {
:project-path="projectPath" :project-path="projectPath"
:iid="issueIid" :iid="issueIid"
@done="$router.push({ name: 'designs' })" @done="$router.push({ name: 'designs' })"
@error="$router.push({ name: 'designs' })" @error="onDesignDeleteError"
> >
<template v-slot="{ mutate, loading, error }"> <template v-slot="{ mutate, loading, error }">
<toolbar <toolbar
......
...@@ -11,7 +11,7 @@ import uploadDesignMutation from '../graphql/mutations/uploadDesign.mutation.gra ...@@ -11,7 +11,7 @@ import uploadDesignMutation from '../graphql/mutations/uploadDesign.mutation.gra
import permissionsQuery from '../graphql/queries/permissions.query.graphql'; import permissionsQuery from '../graphql/queries/permissions.query.graphql';
import projectQuery from '../graphql/queries/project.query.graphql'; import projectQuery from '../graphql/queries/project.query.graphql';
import allDesignsMixin from '../mixins/all_designs'; import allDesignsMixin from '../mixins/all_designs';
import { UPLOAD_DESIGN_ERROR } from '../utils/error_messages'; import { UPLOAD_DESIGN_ERROR, designDeletionError } from '../utils/error_messages';
import { updateStoreAfterUploadDesign } from '../utils/cache_update'; import { updateStoreAfterUploadDesign } from '../utils/cache_update';
import { designUploadOptimisticResponse } from '../utils/design_management_utils'; import { designUploadOptimisticResponse } from '../utils/design_management_utils';
...@@ -178,6 +178,10 @@ export default { ...@@ -178,6 +178,10 @@ export default {
this.selectedDesigns = []; this.selectedDesigns = [];
if (this.$route.query.version) this.$router.push({ name: 'designs' }); if (this.$route.query.version) this.$router.push({ name: 'designs' });
}, },
onDesignDeleteError() {
const errorMessage = designDeletionError({ singular: this.selectedDesigns.length === 1 });
createFlash(errorMessage);
},
}, },
beforeRouteUpdate(to, from, next) { beforeRouteUpdate(to, from, next) {
this.selectedDesigns = []; this.selectedDesigns = [];
...@@ -205,6 +209,7 @@ export default { ...@@ -205,6 +209,7 @@ export default {
:project-path="projectPath" :project-path="projectPath"
:iid="issueIid" :iid="issueIid"
@done="onDesignDelete" @done="onDesignDelete"
@error="onDesignDeleteError"
> >
<delete-button <delete-button
v-if="isLatestVersion" v-if="isLatestVersion"
......
...@@ -179,7 +179,7 @@ const onError = (data, message) => { ...@@ -179,7 +179,7 @@ const onError = (data, message) => {
*/ */
export const updateStoreAfterDesignsDelete = (store, data, query, designs) => { export const updateStoreAfterDesignsDelete = (store, data, query, designs) => {
if (data.errors) { if (data.errors) {
onError(data, designDeletionError(designs.length === 1)); onError(data, designDeletionError({ singular: designs.length === 1 }));
} else { } else {
deleteDesignsFromStore(store, query, designs); deleteDesignsFromStore(store, query, designs);
addNewVersionToStore(store, query, data.version); addNewVersionToStore(store, query, data.version);
......
import { __, s__, sprintf } from '~/locale'; import { __, s__, sprintf } from '~/locale';
export const designDeletionError = (singular = true) => { export const designDeletionError = ({ singular = true } = {}) => {
const design = singular ? __('a design') : __('designs'); const design = singular ? __('a design') : __('designs');
return sprintf(s__('DesignManagement|We could not delete %{design}. Please try again.'), { return sprintf(s__('DesignManagement|We could not delete %{design}. Please try again.'), {
design, design,
......
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