Skip to content
Snippets Groups Projects
Unverified Commit c33245e9 authored by Filipa Lacerda's avatar Filipa Lacerda
Browse files

Reuse getter

Add loading button for better UX
parent ab734240
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,10 +9,11 @@
import * as constants from '../constants';
import eventHub from '../event_hub';
import issueWarning from '../../vue_shared/components/issue/issue_warning.vue';
import noteSignedOutWidget from './note_signed_out_widget.vue';
import discussionLockedWidget from './discussion_locked_widget.vue';
import markdownField from '../../vue_shared/components/markdown/field.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 discussionLockedWidget from './discussion_locked_widget.vue';
import issuableStateMixin from '../mixins/issuable_state';
 
export default {
Loading
Loading
@@ -23,6 +24,7 @@
discussionLockedWidget,
markdownField,
userAvatarLink,
loadingButton,
},
mixins: [
issuableStateMixin,
Loading
Loading
@@ -41,11 +43,8 @@
'getUserData',
'getNoteableData',
'getNotesData',
'getIssueState',
'issueState',
]),
issueState() {
return this.getIssueState;
},
isLoggedIn() {
return this.getUserData.id;
},
Loading
Loading
@@ -131,6 +130,8 @@
}
},
handleSave(withIssueAction) {
this.isSubmitting = true;
if (this.note.length) {
const noteData = {
endpoint: this.endpoint,
Loading
Loading
@@ -147,7 +148,6 @@
if (this.noteType === constants.DISCUSSION) {
noteData.data.note.type = constants.DISCUSSION_NOTE;
}
this.isSubmitting = true;
this.note = ''; // Empty textarea while being requested. Repopulate in catch
this.resizeTextarea();
this.stopPolling();
Loading
Loading
@@ -189,13 +189,24 @@ Please check your network connection and try again.`;
this.toggleIssueState();
}
},
enableButton() {
this.isSubmitting = false;
},
toggleIssueState() {
if (this.isIssueOpen) {
this.closeIssue()
.catch(() => Flash(__('Something went wrong while closing the issue. Please try again later')));
.then(() => this.enableButton())
.catch(() => {
this.enableButton();
Flash(__('Something went wrong while closing the issue. Please try again later'));
});
} else {
this.reopenIssue()
.catch(() => Flash(__('Something went wrong while reopening the issue. Please try again later')));
.then(() => this.enableButton())
.catch(() => {
this.enableButton();
Flash(__('Something went wrong while reopening the issue. Please try again later'));
});
}
},
discard(shouldClear = true) {
Loading
Loading
@@ -373,15 +384,19 @@ append-right-10 comment-type-dropdown js-comment-type-dropdown droplab-dropdown"
</li>
</ul>
</div>
<button
type="button"
@click="handleSave(true)"
<loading-button
v-if="canUpdateIssue"
:class="actionButtonClassNames"
:loading="isSubmitting"
@click="handleSave(true)"
:container-class="[
actionButtonClassNames,
'btn btn-comment btn-comment-and-close js-action-button'
]"
:disabled="isSubmitting"
class="btn btn-comment btn-comment-and-close js-action-button">
{{ issueActionButtonTitle }}
</button>
:label="issueActionButtonTitle"
/>
<button
type="button"
v-if="note.length"
Loading
Loading
Loading
Loading
@@ -77,10 +77,10 @@ export const reopenIssue = ({ commit, dispatch, state }) => service
dispatch('emitStateChangedEvent', data);
});
 
export const emitStateChangedEvent = ({ commit }, data) => {
export const emitStateChangedEvent = ({ commit, getters }, data) => {
const event = new CustomEvent('issuable_vue_app:change', { detail: {
data,
isClosed: data.state === constants.CLOSED,
isClosed: getters.issueState === constants.CLOSED,
} });
 
document.dispatchEvent(event);
Loading
Loading
Loading
Loading
@@ -8,7 +8,7 @@ export const getNotesDataByProp = state => prop => state.notesData[prop];
 
export const getNoteableData = state => state.noteableData;
export const getNoteableDataByProp = state => prop => state.noteableData[prop];
export const getIssueState = state => state.noteableData.state;
export const issueState = state => state.noteableData.state;
 
export const getUserData = state => state.userData || {};
export const getUserDataByProp = state => prop => state.userData && state.userData[prop];
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@
required: false,
},
containerClass: {
type: String,
type: [String, Array, Object],
required: false,
default: 'btn btn-align-content',
},
Loading
Loading
Loading
Loading
@@ -109,7 +109,7 @@ describe('Actions Notes Store', () => {
it('emits an event on the document', () => {
document.addEventListener('issuable_vue_app:change', (event) => {
expect(event.detail.data).toEqual({ id: '1', state: 'closed' });
expect(event.detail.isClosed).toEqual(true);
expect(event.detail.isClosed).toEqual(false);
});
 
store.dispatch('emitStateChangedEvent', { id: '1', state: 'closed' });
Loading
Loading
Loading
Loading
@@ -55,4 +55,10 @@ describe('Getters Notes Store', () => {
expect(getters.getCurrentUserLastNote(state)).toEqual(individualNote.notes[0]);
});
});
describe('issueState', () => {
it('should return the issue state', () => {
expect(getters.issueState(state)).toEqual(noteableDataMock.state);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment