Commit d0173af1 authored by Phil Hughes's avatar Phil Hughes

Fixes loading icons when re-requesting a review

This also adds a spec file for the uncollapsed reviewers list
component.
parent 62fd4967
<script> <script>
// NOTE! For the first iteration, we are simply copying the implementation of Assignees
// It will soon be overhauled in Issue https://gitlab.com/gitlab-org/gitlab/-/issues/233736
import { GlButton, GlTooltipDirective, GlIcon } from '@gitlab/ui'; import { GlButton, GlTooltipDirective, GlIcon } from '@gitlab/ui';
import { __, sprintf } from '~/locale';
import ReviewerAvatarLink from './reviewer_avatar_link.vue'; import ReviewerAvatarLink from './reviewer_avatar_link.vue';
const DEFAULT_RENDER_COUNT = 5; const LOADING_STATE = 'loading';
const SUCCESS_STATE = 'success';
export default { export default {
components: { components: {
...@@ -34,35 +32,21 @@ export default { ...@@ -34,35 +32,21 @@ export default {
data() { data() {
return { return {
showLess: true, showLess: true,
loading: false, loadingStates: {},
requestedReviewSuccess: false,
}; };
}, },
computed: { watch: {
firstUser() { users: {
return this.users[0]; handler(users) {
}, this.loadingStates = users.reduce(
hasOneUser() { (acc, user) => ({
return this.users.length === 1; ...acc,
}, [user.id]: acc[user.id] || null,
hiddenReviewersLabel() { }),
const { numberOfHiddenReviewers } = this; this.loadingStates,
return sprintf(__('+ %{numberOfHiddenReviewers} more'), { numberOfHiddenReviewers }); );
}, },
renderShowMoreSection() { immediate: true,
return this.users.length > DEFAULT_RENDER_COUNT;
},
numberOfHiddenReviewers() {
return this.users.length - DEFAULT_RENDER_COUNT;
},
uncollapsedUsers() {
const uncollapsedLength = this.showLess
? Math.min(this.users.length, DEFAULT_RENDER_COUNT)
: this.users.length;
return this.showLess ? this.users.slice(0, uncollapsedLength) : this.users;
},
username() {
return `@${this.firstUser.username}`;
}, },
}, },
methods: { methods: {
...@@ -70,21 +54,23 @@ export default { ...@@ -70,21 +54,23 @@ export default {
this.showLess = !this.showLess; this.showLess = !this.showLess;
}, },
reRequestReview(userId) { reRequestReview(userId) {
this.loading = true; this.loadingStates[userId] = LOADING_STATE;
this.$emit('request-review', { userId, callback: this.requestReviewComplete }); this.$emit('request-review', { userId, callback: this.requestReviewComplete });
}, },
requestReviewComplete(success) { requestReviewComplete(userId, success) {
if (success) { if (success) {
this.requestedReviewSuccess = true; this.loadingStates[userId] = SUCCESS_STATE;
setTimeout(() => { setTimeout(() => {
this.requestedReviewSuccess = false; this.loadingStates[userId] = null;
}, 1500); }, 1500);
} else {
this.loadingStates[userId] = null;
} }
this.loading = false;
}, },
}, },
LOADING_STATE,
SUCCESS_STATE,
}; };
</script> </script>
...@@ -100,20 +86,22 @@ export default { ...@@ -100,20 +86,22 @@ export default {
<div class="gl-ml-3">@{{ user.username }}</div> <div class="gl-ml-3">@{{ user.username }}</div>
</reviewer-avatar-link> </reviewer-avatar-link>
<gl-icon <gl-icon
v-if="requestedReviewSuccess" v-if="loadingStates[user.id] === $options.SUCCESS_STATE"
:size="24" :size="24"
name="check" name="check"
class="float-right gl-text-green-500" class="float-right gl-text-green-500"
data-testid="re-request-success"
/> />
<gl-button <gl-button
v-else-if="user.can_update_merge_request && user.reviewed" v-else-if="user.can_update_merge_request && user.reviewed"
v-gl-tooltip.left v-gl-tooltip.left
:title="__('Re-request review')" :title="__('Re-request review')"
:loading="loading" :loading="loadingStates[user.id] === $options.LOADING_STATE"
class="float-right gl-text-gray-500!" class="float-right gl-text-gray-500!"
size="small" size="small"
icon="redo" icon="redo"
variant="link" variant="link"
data-testid="re-request-button"
@click="reRequestReview(user.id)" @click="reRequestReview(user.id)"
/> />
</div> </div>
......
...@@ -58,9 +58,9 @@ export default class SidebarMediator { ...@@ -58,9 +58,9 @@ export default class SidebarMediator {
.then(() => { .then(() => {
this.store.updateReviewer(userId); this.store.updateReviewer(userId);
toast(__('Requested review')); toast(__('Requested review'));
callback(true); callback(userId, true);
}) })
.catch(() => callback(false)); .catch(() => callback(userId, false));
} }
setMoveToProjectId(projectId) { setMoveToProjectId(projectId) {
......
...@@ -1027,9 +1027,6 @@ msgstr "" ...@@ -1027,9 +1027,6 @@ msgstr ""
msgid "+ %{numberOfHiddenAssignees} more" msgid "+ %{numberOfHiddenAssignees} more"
msgstr "" msgstr ""
msgid "+ %{numberOfHiddenReviewers} more"
msgstr ""
msgid "+%d more" msgid "+%d more"
msgid_plural "+%d more" msgid_plural "+%d more"
msgstr[0] "" msgstr[0] ""
......
import { shallowMount } from '@vue/test-utils';
import { TEST_HOST } from 'helpers/test_constants';
import UncollapsedReviewerList from '~/sidebar/components/reviewers/uncollapsed_reviewer_list.vue';
import ReviewerAvatarLink from '~/sidebar/components/reviewers/reviewer_avatar_link.vue';
import userDataMock from '../../user_data_mock';
describe('UncollapsedReviewerList component', () => {
let wrapper;
function createComponent(props = {}) {
const propsData = {
users: [],
rootPath: TEST_HOST,
...props,
};
wrapper = shallowMount(UncollapsedReviewerList, {
propsData,
});
}
afterEach(() => {
wrapper.destroy();
});
describe('single reviewer', () => {
beforeEach(() => {
const user = userDataMock();
createComponent({
users: [user],
});
});
it('only has one user', () => {
expect(wrapper.findAll(ReviewerAvatarLink).length).toBe(1);
});
it('shows one user with avatar, username and author name', () => {
expect(wrapper.text()).toContain(`@root`);
});
it('renders re-request loading icon', async () => {
await wrapper.setData({ loadingStates: { 1: 'loading' } });
expect(wrapper.find('[data-testid="re-request-button"]').props('loading')).toBe(true);
});
it('renders re-request success icon', async () => {
await wrapper.setData({ loadingStates: { 1: 'success' } });
expect(wrapper.find('[data-testid="re-request-success"]').exists()).toBe(true);
});
});
describe('multiple reviewers', () => {
beforeEach(() => {
const user = userDataMock();
createComponent({
users: [user, { ...user, id: 2, username: 'hello-world' }],
});
});
it('only has one user', () => {
expect(wrapper.findAll(ReviewerAvatarLink).length).toBe(2);
});
it('shows one user with avatar, username and author name', () => {
expect(wrapper.text()).toContain(`@root`);
expect(wrapper.text()).toContain(`@hello-world`);
});
it('renders re-request loading icon', async () => {
await wrapper.setData({ loadingStates: { 2: 'loading' } });
expect(wrapper.findAll('[data-testid="re-request-button"]').length).toBe(2);
expect(wrapper.findAll('[data-testid="re-request-button"]').at(1).props('loading')).toBe(
true,
);
});
it('renders re-request success icon', async () => {
await wrapper.setData({ loadingStates: { 2: 'success' } });
expect(wrapper.findAll('[data-testid="re-request-button"]').length).toBe(1);
expect(wrapper.findAll('[data-testid="re-request-success"]').length).toBe(1);
expect(wrapper.find('[data-testid="re-request-success"]').exists()).toBe(true);
});
});
});
...@@ -8,4 +8,6 @@ export default () => ({ ...@@ -8,4 +8,6 @@ export default () => ({
username: 'root', username: 'root',
web_url: `${TEST_HOST}/root`, web_url: `${TEST_HOST}/root`,
can_merge: true, can_merge: true,
can_update_merge_request: true,
reviewed: true,
}); });
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