Commit 9b2eab6e authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Vitaly Slobodin

Fix GraphQL Boards labels setting

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