Commit 0ac6a152 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'ntepluhina-fix-labels' into 'master'

Fix GraphQL Boards labels setting

See merge request gitlab-org/gitlab!67030
parents 666010c3 9b2eab6e
...@@ -25,6 +25,8 @@ export default { ...@@ -25,6 +25,8 @@ export default {
data() { data() {
return { return {
loading: false, loading: false,
oldIid: null,
isEditing: false,
}; };
}, },
computed: { computed: {
...@@ -72,6 +74,15 @@ export default { ...@@ -72,6 +74,15 @@ export default {
return this.labelsFetchPath || projectLabelsFetchPath; return this.labelsFetchPath || projectLabelsFetchPath;
}, },
}, },
watch: {
activeBoardItem(_, oldVal) {
if (this.isEditing) {
this.oldIid = oldVal.iid;
} else {
this.oldIid = null;
}
},
},
methods: { methods: {
...mapActions(['setActiveBoardItemLabels', 'setError']), ...mapActions(['setActiveBoardItemLabels', 'setError']),
async setLabels(payload) { async setLabels(payload) {
...@@ -84,8 +95,14 @@ export default { ...@@ -84,8 +95,14 @@ export default {
.filter((label) => !payload.find((selected) => selected.id === label.id)) .filter((label) => !payload.find((selected) => selected.id === label.id))
.map((label) => label.id); .map((label) => label.id);
const input = { addLabelIds, removeLabelIds, projectPath: this.projectPathForActiveIssue }; const input = {
addLabelIds,
removeLabelIds,
projectPath: this.projectPathForActiveIssue,
iid: this.oldIid,
};
await this.setActiveBoardItemLabels(input); await this.setActiveBoardItemLabels(input);
this.oldIid = null;
} catch (e) { } catch (e) {
this.setError({ error: e, message: __('An error occurred while updating labels.') }); this.setError({ error: e, message: __('An error occurred while updating labels.') });
} finally { } finally {
...@@ -115,6 +132,8 @@ export default { ...@@ -115,6 +132,8 @@ export default {
:title="__('Labels')" :title="__('Labels')"
:loading="loading" :loading="loading"
data-testid="sidebar-labels" data-testid="sidebar-labels"
@open="isEditing = true"
@close="isEditing = false"
> >
<template #collapsed> <template #collapsed>
<gl-label <gl-label
......
...@@ -575,7 +575,7 @@ export default { ...@@ -575,7 +575,7 @@ export default {
mutation: issueSetLabelsMutation, mutation: issueSetLabelsMutation,
variables: { variables: {
input: { input: {
iid: String(activeBoardItem.iid), iid: input.iid || String(activeBoardItem.iid),
addLabelIds: input.addLabelIds ?? [], addLabelIds: input.addLabelIds ?? [],
removeLabelIds: input.removeLabelIds ?? [], removeLabelIds: input.removeLabelIds ?? [],
projectPath: input.projectPath, projectPath: input.projectPath,
...@@ -588,7 +588,7 @@ export default { ...@@ -588,7 +588,7 @@ export default {
} }
commit(types.UPDATE_BOARD_ITEM_BY_ID, { commit(types.UPDATE_BOARD_ITEM_BY_ID, {
itemId: activeBoardItem.id, itemId: getIdFromGraphQLId(data.updateIssue?.issue?.id) || activeBoardItem.id,
prop: 'labels', prop: 'labels',
value: data.updateIssue.issue.labels.nodes, value: data.updateIssue.issue.labels.nodes,
}); });
......
...@@ -97,6 +97,7 @@ describe('~/boards/components/sidebar/board_sidebar_labels_select.vue', () => { ...@@ -97,6 +97,7 @@ describe('~/boards/components/sidebar/board_sidebar_labels_select.vue', () => {
addLabelIds: TEST_LABELS.map((label) => label.id), addLabelIds: TEST_LABELS.map((label) => label.id),
projectPath: TEST_ISSUE_FULLPATH, projectPath: TEST_ISSUE_FULLPATH,
removeLabelIds: [], removeLabelIds: [],
iid: null,
}); });
}); });
}); });
...@@ -121,6 +122,7 @@ describe('~/boards/components/sidebar/board_sidebar_labels_select.vue', () => { ...@@ -121,6 +122,7 @@ describe('~/boards/components/sidebar/board_sidebar_labels_select.vue', () => {
addLabelIds: [5, 7], addLabelIds: [5, 7],
removeLabelIds: [6], removeLabelIds: [6],
projectPath: TEST_ISSUE_FULLPATH, projectPath: TEST_ISSUE_FULLPATH,
iid: null,
}); });
}); });
}); });
......
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