Commit b2f03880 authored by Scott Stern's avatar Scott Stern Committed by Nicolò Maria Mezzopera

Add assign self to group boards sidebar

parent a42447df
<script> <script>
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import { cloneDeep } from 'lodash';
import { import {
GlDropdownItem, GlDropdownItem,
GlDropdownDivider, GlDropdownDivider,
...@@ -37,7 +38,7 @@ export default { ...@@ -37,7 +38,7 @@ export default {
return { return {
search: '', search: '',
participants: [], participants: [],
selected: this.$store.getters.activeIssue.assignees, selected: [],
}; };
}, },
apollo: { apollo: {
...@@ -89,9 +90,20 @@ export default { ...@@ -89,9 +90,20 @@ export default {
isSearchEmpty() { isSearchEmpty() {
return this.search === ''; return this.search === '';
}, },
currentUser() {
return gon?.current_username;
},
},
created() {
this.selected = cloneDeep(this.activeIssue.assignees);
}, },
methods: { methods: {
...mapActions(['setAssignees']), ...mapActions(['setAssignees']),
async assignSelf() {
const [currentUserObject] = await this.setAssignees(this.currentUser);
this.selectAssignee(currentUserObject);
},
clearSelected() { clearSelected() {
this.selected = []; this.selected = [];
}, },
...@@ -119,7 +131,7 @@ export default { ...@@ -119,7 +131,7 @@ export default {
<template> <template>
<board-editable-item :title="assigneeText" @close="saveAssignees"> <board-editable-item :title="assigneeText" @close="saveAssignees">
<template #collapsed> <template #collapsed>
<issuable-assignees :users="activeIssue.assignees" /> <issuable-assignees :users="selected" @assign-self="assignSelf" />
</template> </template>
<template #default> <template #default>
......
...@@ -325,11 +325,15 @@ export default { ...@@ -325,11 +325,15 @@ export default {
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
const { nodes } = data.issueSetAssignees?.issue?.assignees || [];
commit('UPDATE_ISSUE_BY_ID', { commit('UPDATE_ISSUE_BY_ID', {
issueId: getters.activeIssue.id, issueId: getters.activeIssue.id,
prop: 'assignees', prop: 'assignees',
value: data.issueSetAssignees.issue.assignees.nodes, value: nodes,
}); });
return nodes;
}); });
}, },
......
<script> <script>
import { GlButton } from '@gitlab/ui';
import { n__ } from '~/locale'; import { n__ } from '~/locale';
import UncollapsedAssigneeList from '~/sidebar/components/assignees/uncollapsed_assignee_list.vue'; import UncollapsedAssigneeList from '~/sidebar/components/assignees/uncollapsed_assignee_list.vue';
export default { export default {
components: { components: {
GlButton,
UncollapsedAssigneeList, UncollapsedAssigneeList,
}, },
inject: ['rootPath'], inject: ['rootPath'],
...@@ -27,9 +29,15 @@ export default { ...@@ -27,9 +29,15 @@ export default {
<template> <template>
<div class="gl-display-flex gl-flex-direction-column"> <div class="gl-display-flex gl-flex-direction-column">
<div v-if="emptyUsers" data-testid="none"> <div v-if="emptyUsers" data-testid="none">
<span> <span> {{ __('None') }} -</span>
{{ __('None') }} <gl-button
</span> data-testid="assign-yourself"
category="tertiary"
variant="link"
@click="$emit('assign-self')"
>
<span class="gl-text-gray-400">{{ __('assign yourself') }}</span>
</gl-button>
</div> </div>
<uncollapsed-assignee-list v-else :users="users" :root-path="rootPath" /> <uncollapsed-assignee-list v-else :users="users" :root-path="rootPath" />
</div> </div>
......
---
title: Add assign self to group boards sidebar
merge_request: 47705
author:
type: added
...@@ -20,6 +20,7 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -20,6 +20,7 @@ describe('BoardCardAssigneeDropdown', () => {
let fakeApollo; let fakeApollo;
let getIssueParticipantsSpy; let getIssueParticipantsSpy;
let getSearchUsersSpy; let getSearchUsersSpy;
let dispatchSpy;
const iid = '111'; const iid = '111';
const activeIssueName = 'test'; const activeIssueName = 'test';
...@@ -91,10 +92,11 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -91,10 +92,11 @@ describe('BoardCardAssigneeDropdown', () => {
}, },
}; };
jest.spyOn(store, 'dispatch').mockResolvedValue(); dispatchSpy = jest.spyOn(store, 'dispatch').mockResolvedValue();
}); });
afterEach(() => { afterEach(() => {
window.gon = {};
jest.restoreAllMocks(); jest.restoreAllMocks();
}); });
...@@ -305,4 +307,25 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -305,4 +307,25 @@ describe('BoardCardAssigneeDropdown', () => {
expect(wrapper.find(GlSearchBoxByType).exists()).toBe(true); expect(wrapper.find(GlSearchBoxByType).exists()).toBe(true);
}); });
describe('when assign-self is emitted from IssuableAssignees', () => {
const currentUser = { username: 'self', name: '', id: '' };
beforeEach(() => {
window.gon = { current_username: currentUser.username };
dispatchSpy.mockResolvedValue([currentUser]);
createComponent();
wrapper.find(IssuableAssignees).vm.$emit('assign-self');
});
it('calls setAssignees with currentUser', () => {
expect(store.dispatch).toHaveBeenCalledWith('setAssignees', currentUser.username);
});
it('adds the user to the selected list', async () => {
expect(findByText(currentUser.username).exists()).toBe(true);
});
});
}); });
...@@ -26,8 +26,8 @@ describe('IssuableAssignees', () => { ...@@ -26,8 +26,8 @@ describe('IssuableAssignees', () => {
createComponent(); createComponent();
}); });
it('renders "None"', () => { it('renders "None - assign yourself"', () => {
expect(findEmptyAssignee().text()).toBe('None'); expect(findEmptyAssignee().text()).toBe('None - assign yourself');
}); });
}); });
...@@ -38,4 +38,12 @@ describe('IssuableAssignees', () => { ...@@ -38,4 +38,12 @@ describe('IssuableAssignees', () => {
expect(findUncollapsedAssigneeList().exists()).toBe(true); expect(findUncollapsedAssigneeList().exists()).toBe(true);
}); });
}); });
describe('when clicking "assign yourself"', () => {
it('emits "assign-self"', () => {
createComponent();
wrapper.find('[data-testid="assign-yourself"]').vm.$emit('click');
expect(wrapper.emitted('assign-self')).toHaveLength(1);
});
});
}); });
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