2018-11-08 19:23:39 +05:30
|
|
|
<script>
|
2020-10-24 23:57:45 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2019-12-04 20:38:33 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } from '../../../flash';
|
2018-12-13 13:39:08 +05:30
|
|
|
import { __ } from '../../../locale';
|
|
|
|
import boardsStore from '../../stores/boards_store';
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
export default {
|
2020-10-24 23:57:45 +05:30
|
|
|
components: {
|
|
|
|
GlButton,
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
props: {
|
|
|
|
issue: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
list: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
updateUrl() {
|
|
|
|
return this.issue.path;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
removeIssue() {
|
|
|
|
const { issue } = this;
|
|
|
|
const lists = issue.getLists();
|
|
|
|
const req = this.buildPatchRequest(issue, lists);
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
const data = {
|
|
|
|
issue: this.seedPatchRequest(issue, req),
|
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
if (data.issue.label_ids.length === 0) {
|
|
|
|
data.issue.label_ids = [''];
|
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
// Post the remove data
|
2019-12-04 20:38:33 +05:30
|
|
|
axios.patch(this.updateUrl, data).catch(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
Flash(__('Failed to remove issue from board, please try again.'));
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
lists.forEach(list => {
|
2018-12-13 13:39:08 +05:30
|
|
|
list.addIssue(issue);
|
2018-11-08 19:23:39 +05:30
|
|
|
});
|
2018-12-13 13:39:08 +05:30
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
// Remove from the frontend store
|
|
|
|
lists.forEach(list => {
|
|
|
|
list.removeIssue(issue);
|
|
|
|
});
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
boardsStore.clearDetailIssue();
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Build the default patch request.
|
|
|
|
*/
|
|
|
|
buildPatchRequest(issue, lists) {
|
|
|
|
const listLabelIds = lists.map(list => list.label.id);
|
|
|
|
|
|
|
|
const labelIds = issue.labels.map(label => label.id).filter(id => !listLabelIds.includes(id));
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
return {
|
|
|
|
label_ids: labelIds,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Seed the given patch request.
|
|
|
|
*
|
|
|
|
* (This is overridden in EE)
|
|
|
|
*/
|
|
|
|
seedPatchRequest(issue, req) {
|
|
|
|
return req;
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2019-12-04 20:38:33 +05:30
|
|
|
};
|
2018-11-08 19:23:39 +05:30
|
|
|
</script>
|
|
|
|
<template>
|
2019-02-15 15:39:39 +05:30
|
|
|
<div class="block list">
|
2020-10-24 23:57:45 +05:30
|
|
|
<gl-button variant="default" category="secondary" block="block" @click="removeIssue">
|
2019-09-30 21:07:59 +05:30
|
|
|
{{ __('Remove from board') }}
|
2020-10-24 23:57:45 +05:30
|
|
|
</gl-button>
|
2018-11-08 19:23:39 +05:30
|
|
|
</div>
|
|
|
|
</template>
|