Commit 71675489 authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '229207-migrate-comment-close' into 'master'

Migrate comment and close to gl button

Closes #229207

See merge request gitlab-org/gitlab!39484
parents 55fd08f8 f549e5a6
...@@ -3,7 +3,7 @@ import $ from 'jquery'; ...@@ -3,7 +3,7 @@ import $ from 'jquery';
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import Autosize from 'autosize'; import Autosize from 'autosize';
import { GlAlert, GlIntersperse, GlLink, GlSprintf } from '@gitlab/ui'; import { GlAlert, GlIntersperse, GlLink, GlSprintf, GlButton } from '@gitlab/ui';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue'; import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue';
import { deprecatedCreateFlash as Flash } from '../../flash'; import { deprecatedCreateFlash as Flash } from '../../flash';
...@@ -20,7 +20,6 @@ import eventHub from '../event_hub'; ...@@ -20,7 +20,6 @@ import eventHub from '../event_hub';
import NoteableWarning from '../../vue_shared/components/notes/noteable_warning.vue'; import NoteableWarning from '../../vue_shared/components/notes/noteable_warning.vue';
import markdownField from '../../vue_shared/components/markdown/field.vue'; import markdownField from '../../vue_shared/components/markdown/field.vue';
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import loadingButton from '../../vue_shared/components/loading_button.vue';
import noteSignedOutWidget from './note_signed_out_widget.vue'; import noteSignedOutWidget from './note_signed_out_widget.vue';
import discussionLockedWidget from './discussion_locked_widget.vue'; import discussionLockedWidget from './discussion_locked_widget.vue';
import issuableStateMixin from '../mixins/issuable_state'; import issuableStateMixin from '../mixins/issuable_state';
...@@ -33,7 +32,7 @@ export default { ...@@ -33,7 +32,7 @@ export default {
discussionLockedWidget, discussionLockedWidget,
markdownField, markdownField,
userAvatarLink, userAvatarLink,
loadingButton, GlButton,
TimelineEntryItem, TimelineEntryItem,
GlAlert, GlAlert,
GlIntersperse, GlIntersperse,
...@@ -102,6 +101,9 @@ export default { ...@@ -102,6 +101,9 @@ export default {
noteable: this.noteableDisplayName, noteable: this.noteableDisplayName,
}); });
}, },
buttonVariant() {
return this.isOpen ? 'warning' : 'default';
},
actionButtonClassNames() { actionButtonClassNames() {
return { return {
'btn-reopen': !this.isOpen, 'btn-reopen': !this.isOpen,
...@@ -480,17 +482,19 @@ export default { ...@@ -480,17 +482,19 @@ export default {
</ul> </ul>
</div> </div>
<loading-button <gl-button
v-if="canToggleIssueState && !isToggleBlockedIssueWarning" v-if="canToggleIssueState && !isToggleBlockedIssueWarning"
:loading="isToggleStateButtonLoading" :loading="isToggleStateButtonLoading"
:container-class="[ category="secondary"
:variant="buttonVariant"
:class="[
actionButtonClassNames, actionButtonClassNames,
'btn btn-comment btn-comment-and-close js-action-button', 'btn-comment btn-comment-and-close js-action-button',
]" ]"
:disabled="isToggleStateButtonLoading || isSubmitting" :disabled="isToggleStateButtonLoading || isSubmitting"
:label="issueActionButtonTitle"
@click="handleSave(true)" @click="handleSave(true)"
/> >{{ issueActionButtonTitle }}</gl-button
>
</div> </div>
</form> </form>
</div> </div>
......
...@@ -267,15 +267,14 @@ describe('issue_comment_form component', () => { ...@@ -267,15 +267,14 @@ describe('issue_comment_form component', () => {
}); });
describe('when clicking close/reopen button', () => { describe('when clicking close/reopen button', () => {
it('should disable button and show a loading spinner', done => { it('should disable button and show a loading spinner', () => {
const toggleStateButton = wrapper.find('.js-action-button'); const toggleStateButton = wrapper.find('.js-action-button');
toggleStateButton.trigger('click'); toggleStateButton.trigger('click');
wrapper.vm.$nextTick(() => {
expect(toggleStateButton.element.disabled).toEqual(true);
expect(toggleStateButton.find('.js-loading-button-icon').exists()).toBe(true);
done(); return wrapper.vm.$nextTick().then(() => {
expect(toggleStateButton.element.disabled).toEqual(true);
expect(toggleStateButton.props('loading')).toBe(true);
}); });
}); });
}); });
...@@ -321,4 +320,33 @@ describe('issue_comment_form component', () => { ...@@ -321,4 +320,33 @@ describe('issue_comment_form component', () => {
expect(wrapper.find('textarea').exists()).toBe(false); expect(wrapper.find('textarea').exists()).toBe(false);
}); });
}); });
describe('when issuable is open', () => {
beforeEach(() => {
setupStore(userDataMock, noteableDataMock);
});
it.each([['opened', 'warning'], ['reopened', 'warning']])(
'when %i, it changes the variant of the btn to %i',
(a, expected) => {
store.state.noteableData.state = a;
mountComponent();
expect(wrapper.find('.js-action-button').props('variant')).toBe(expected);
},
);
});
describe('when issuable is not open', () => {
beforeEach(() => {
setupStore(userDataMock, noteableDataMock);
mountComponent();
});
it('should render the "default" variant of the button', () => {
expect(wrapper.find('.js-action-button').props('variant')).toBe('warning');
});
});
}); });
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