Commit 4e81ad2a authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Add constants

parent cf5cc6a9
<script> <script>
/* global Flash */ /* global Flash */
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 markdownField from '../../vue_shared/components/markdown/field.vue'; import markdownField from '../../vue_shared/components/markdown/field.vue';
import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue'; import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import * as constants from '../constants';
export default { export default {
data() { data() {
const { create_note_path, state } = window.gl.issueData; const { create_note_path, state } = window.gl.issueData;
const { currentUserData } = window.gl; const { currentUserData } = window.gl;
...@@ -15,7 +16,7 @@ export default { ...@@ -15,7 +16,7 @@ export default {
note: '', note: '',
markdownDocsUrl: '', markdownDocsUrl: '',
markdownPreviewUrl: gl.issueData.preview_note_path, markdownPreviewUrl: gl.issueData.preview_note_path,
noteType: 'comment', noteType: constants.COMMENT,
issueState: state, issueState: state,
endpoint: create_note_path, endpoint: create_note_path,
author: currentUserData, author: currentUserData,
...@@ -31,16 +32,16 @@ export default { ...@@ -31,16 +32,16 @@ export default {
return window.gon.current_user_id; return window.gon.current_user_id;
}, },
commentButtonTitle() { commentButtonTitle() {
return this.noteType === 'comment' ? 'Comment' : 'Start discussion'; return this.noteType === constants.COMMENT ? 'Comment' : 'Start discussion';
}, },
isIssueOpen() { isIssueOpen() {
return this.issueState === 'opened' || this.issueState === 'reopened'; return this.issueState === constants.OPENED || this.issueState === constants.REOPENED;
}, },
issueActionButtonTitle() { issueActionButtonTitle() {
if (this.note.length) { if (this.note.length) {
const actionText = this.isIssueOpen ? 'close' : 'reopen'; const actionText = this.isIssueOpen ? 'close' : 'reopen';
return this.noteType === 'comment' ? `Comment & ${actionText} issue` : `Start discussion & ${actionText} issue`; return this.noteType === constants.COMMENT ? `Comment & ${actionText} issue` : `Start discussion & ${actionText} issue`;
} }
return this.isIssueOpen ? 'Close issue' : 'Reopen issue'; return this.isIssueOpen ? 'Close issue' : 'Reopen issue';
...@@ -74,8 +75,8 @@ export default { ...@@ -74,8 +75,8 @@ export default {
}, },
}; };
if (this.noteType === 'discussion') { if (this.noteType === constants.DISCUSSION) {
noteData.data.note.type = 'DiscussionNote'; noteData.data.note.type = constants.DISCUSSION_NOTE;
} }
this.$store.dispatch('saveNote', noteData) this.$store.dispatch('saveNote', noteData)
...@@ -97,11 +98,11 @@ export default { ...@@ -97,11 +98,11 @@ export default {
if (withIssueAction) { if (withIssueAction) {
if (this.isIssueOpen) { if (this.isIssueOpen) {
gl.issueData.state = 'closed'; gl.issueData.state = constants.CLOSED;
this.issueState = 'closed'; this.issueState = constants.CLOSED;
} else { } else {
gl.issueData.state = 'reopened'; gl.issueData.state = constants.REOPENED;
this.issueState = 'reopened'; this.issueState =constants.REOPENED;
} }
this.isIssueOpen = !this.isIssueOpen; this.isIssueOpen = !this.isIssueOpen;
...@@ -146,10 +147,14 @@ export default { ...@@ -146,10 +147,14 @@ export default {
this.markdownDocsUrl = issueData.markdownDocs; this.markdownDocsUrl = issueData.markdownDocs;
eventHub.$on('issueStateChanged', (isClosed) => { eventHub.$on('issueStateChanged', (isClosed) => {
this.issueState = isClosed ? 'closed' : 'reopened'; this.issueState = isClosed ? constants.CLOSED : constants.REOPENED;
}); });
}, },
};
destroyed() {
eventHub.$off('issueStateChanged');
}
};
</script> </script>
<template> <template>
...@@ -167,7 +172,8 @@ export default { ...@@ -167,7 +172,8 @@ export default {
:link-href="author.path" :link-href="author.path"
:img-src="author.avatar_url" :img-src="author.avatar_url"
:img-alt="author.name" :img-alt="author.name"
:img-size="40" /> :img-size="40"
/>
</div> </div>
<div class="js-main-target-form timeline-content timeline-content-form common-note-form"> <div class="js-main-target-form timeline-content timeline-content-form common-note-form">
<markdown-field <markdown-field
......
export const DISCUSSION_NOTE = 'DiscussionNote';
export const DISCUSSION = 'discussion';
export const NOTE = 'note';
export const SYSTEM_NOTE = 'systemNote';
export const COMMENT = 'comment';
export const OPENED = 'opened';
export const REOPENED = 'reopened';
export const CLOSED = 'closed';
\ No newline at end of file
/* global Flash */ /* global Flash */
import * as types from './mutation_types'; import * as types from './mutation_types';
import * as utils from './issue_notes_utils'; import * as utils from './utils';
import * as constants from '../constants';
import service from '../services/issue_notes_service'; import service from '../services/issue_notes_service';
import loadAwardsHandler from '../../awards_handler'; import loadAwardsHandler from '../../awards_handler';
import sidebarTimeTrackingEventHub from '../../sidebar/event_hub'; import sidebarTimeTrackingEventHub from '../../sidebar/event_hub';
...@@ -147,7 +148,7 @@ export const poll = ({ commit, state, getters }) => { ...@@ -147,7 +148,7 @@ export const poll = ({ commit, state, getters }) => {
res.notes.forEach((note) => { res.notes.forEach((note) => {
if (notesById[note.id]) { if (notesById[note.id]) {
commit(types.UPDATE_NOTE, note); commit(types.UPDATE_NOTE, note);
} else if (note.type === 'DiscussionNote') { } else if (note.type === constants.DISCUSSION_NOTE) {
const discussion = utils.findNoteObjectById(state.notes, note.discussion_id); const discussion = utils.findNoteObjectById(state.notes, note.discussion_id);
if (discussion) { if (discussion) {
......
import * as utils from './utils'; import * as utils from './utils';
import * as types from './mutation_types'; import * as types from './mutation_types';
import * as constants from '../constants';
export default { export default {
[types.ADD_NEW_NOTE](state, note) { [types.ADD_NEW_NOTE](state, note) {
...@@ -7,7 +8,7 @@ export default { ...@@ -7,7 +8,7 @@ export default {
const noteData = { const noteData = {
expanded: true, expanded: true,
id: discussion_id, id: discussion_id,
individual_note: !(type === 'DiscussionNote'), individual_note: !(type === constants.DISCUSSION_NOTE),
notes: [note], notes: [note],
reply_id: discussion_id, reply_id: discussion_id,
}; };
...@@ -78,7 +79,7 @@ export default { ...@@ -78,7 +79,7 @@ export default {
notesArr.push({ notesArr.push({
individual_note: true, individual_note: true,
isPlaceholderNote: true, isPlaceholderNote: true,
placeholderType: data.isSystemNote ? 'systemNote' : 'note', placeholderType: data.isSystemNote ? constants.SYSTEM_NOTE : constants.NOTE,
notes: [ notes: [
{ {
body: data.noteBody, body: data.noteBody,
......
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