Commit 07712ad7 authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Simon Knox

Fix assignees on GraphQL boards

parent c3fc49e9
...@@ -105,7 +105,7 @@ export default Vue.extend({ ...@@ -105,7 +105,7 @@ export default Vue.extend({
closeSidebar() { closeSidebar() {
this.detail.issue = {}; this.detail.issue = {};
}, },
setAssignees(assignees) { setAssignees({ assignees }) {
boardsStore.detail.issue.setAssignees(assignees); boardsStore.detail.issue.setAssignees(assignees);
}, },
showScopedLabels(label) { showScopedLabels(label) {
......
...@@ -472,11 +472,11 @@ export default { ...@@ -472,11 +472,11 @@ export default {
} }
}, },
setAssignees: ({ commit, getters }, assigneeUsernames) => { setAssignees: ({ commit }, { id, assignees }) => {
commit('UPDATE_BOARD_ITEM_BY_ID', { commit('UPDATE_BOARD_ITEM_BY_ID', {
itemId: getters.activeBoardItem.id, itemId: id,
prop: 'assignees', prop: 'assignees',
value: assigneeUsernames, value: assignees,
}); });
}, },
......
...@@ -3,6 +3,7 @@ import { GlDropdownItem } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlDropdownItem } from '@gitlab/ui';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import Vue from 'vue'; import Vue from 'vue';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { IssuableType } from '~/issue_show/constants'; import { IssuableType } from '~/issue_show/constants';
import { __, n__ } from '~/locale'; import { __, n__ } from '~/locale';
import SidebarAssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue'; import SidebarAssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
...@@ -80,6 +81,8 @@ export default { ...@@ -80,6 +81,8 @@ export default {
selected: [], selected: [],
isSettingAssignees: false, isSettingAssignees: false,
isDirty: false, isDirty: false,
oldIid: null,
oldSelected: null,
}; };
}, },
apollo: { apollo: {
...@@ -142,6 +145,14 @@ export default { ...@@ -142,6 +145,14 @@ export default {
return this.currentUser.username !== undefined; return this.currentUser.username !== undefined;
}, },
}, },
watch: {
iid(_, oldIid) {
if (this.isDirty) {
this.oldIid = oldIid;
this.oldSelected = this.selected;
}
},
},
created() { created() {
assigneesWidget.updateAssignees = this.updateAssignees; assigneesWidget.updateAssignees = this.updateAssignees;
}, },
...@@ -157,10 +168,14 @@ export default { ...@@ -157,10 +168,14 @@ export default {
variables: { variables: {
...this.queryVariables, ...this.queryVariables,
assigneeUsernames, assigneeUsernames,
iid: this.oldIid || this.iid,
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
this.$emit('assignees-updated', data.issuableSetAssignees.issuable.assignees.nodes); this.$emit('assignees-updated', {
id: getIdFromGraphQLId(data.issuableSetAssignees.issuable.id),
assignees: data.issuableSetAssignees.issuable.assignees.nodes,
});
return data; return data;
}) })
.catch(() => { .catch(() => {
...@@ -176,7 +191,10 @@ export default { ...@@ -176,7 +191,10 @@ export default {
saveAssignees() { saveAssignees() {
if (this.isDirty) { if (this.isDirty) {
this.isDirty = false; this.isDirty = false;
this.updateAssignees(this.selected.map(({ username }) => username)); const usernames = this.oldSelected || this.selected;
this.updateAssignees(usernames.map(({ username }) => username));
this.oldIid = null;
this.oldSelected = null;
} }
this.$el.dispatchEvent(hideDropdownEvent); this.$el.dispatchEvent(hideDropdownEvent);
}, },
......
...@@ -1111,16 +1111,13 @@ describe('updateIssueOrder', () => { ...@@ -1111,16 +1111,13 @@ describe('updateIssueOrder', () => {
describe('setAssignees', () => { describe('setAssignees', () => {
const node = { username: 'name' }; const node = { username: 'name' };
const projectPath = 'h/h';
const refPath = `${projectPath}#3`;
const iid = '1';
describe('when succeeds', () => { describe('when succeeds', () => {
it('calls the correct mutation with the correct values', (done) => { it('calls the correct mutation with the correct values', (done) => {
testAction( testAction(
actions.setAssignees, actions.setAssignees,
[node], { assignees: [node], iid: '1' },
{ activeBoardItem: { iid, referencePath: refPath }, commit: () => {} }, { commit: () => {} },
[ [
{ {
type: 'UPDATE_BOARD_ITEM_BY_ID', type: 'UPDATE_BOARD_ITEM_BY_ID',
......
...@@ -176,7 +176,7 @@ describe('Sidebar assignees widget', () => { ...@@ -176,7 +176,7 @@ describe('Sidebar assignees widget', () => {
).toBe(true); ).toBe(true);
}); });
it('emits an event with assignees list on successful mutation', async () => { it('emits an event with assignees list and issuable id on successful mutation', async () => {
createComponent(); createComponent();
await waitForPromises(); await waitForPromises();
...@@ -193,18 +193,21 @@ describe('Sidebar assignees widget', () => { ...@@ -193,18 +193,21 @@ describe('Sidebar assignees widget', () => {
expect(wrapper.emitted('assignees-updated')).toEqual([ expect(wrapper.emitted('assignees-updated')).toEqual([
[ [
[ {
{ assignees: [
__typename: 'User', {
avatarUrl: __typename: 'User',
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', avatarUrl:
id: 'gid://gitlab/User/1', 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
name: 'Administrator', id: 'gid://gitlab/User/1',
username: 'root', name: 'Administrator',
webUrl: '/root', username: 'root',
status: null, webUrl: '/root',
}, status: null,
], },
],
id: 1,
},
], ],
]); ]);
}); });
...@@ -285,6 +288,21 @@ describe('Sidebar assignees widget', () => { ...@@ -285,6 +288,21 @@ describe('Sidebar assignees widget', () => {
expect(updateIssueAssigneesMutationSuccess).not.toHaveBeenCalled(); expect(updateIssueAssigneesMutationSuccess).not.toHaveBeenCalled();
expect(findUserSelect().isVisible()).toBe(true); expect(findUserSelect().isVisible()).toBe(true);
}); });
it('calls the mutation old issuable id if `iid` prop was changed', async () => {
findUserSelect().vm.$emit('input', [{ username: 'francina.skiles' }]);
wrapper.setProps({
iid: '2',
});
await nextTick();
findEditableItem().vm.$emit('close');
expect(updateIssueAssigneesMutationSuccess).toHaveBeenCalledWith({
assigneeUsernames: ['francina.skiles'],
fullPath: '/mygroup/myProject',
iid: '1',
});
});
}); });
it('shows an error if update assignees mutation is rejected', async () => { it('shows an error if update assignees mutation is rejected', async () => {
......
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