Skip to content

Commit

Permalink
normal commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng Kaifan committed Aug 23, 2020
1 parent f370034 commit eeaf277
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
reviewCommentsExtraData: () => this.reviewCommentsExtraData.data,
pendingReviewComments: () => this.pendingReview.reviewComments.data,
pendingReview: () => this.pendingReview,
reviewCommentsGetter: () => this.network_getReviewComments,
commentReviewCreatedHook: () => this.network_getReviewComments,
reviewCommentDeletedHook: () => this.network_getReviewComments,
pendingReviewGetter: () => this.network_getPendingReview,
replyCreatedHook: () => this.replyCreatedHook
reviewCommentCreatedHook: () => this.reviewCommentCreatedHook
}
},
data() {
Expand All @@ -92,6 +93,7 @@
},
pendingReview: {
data: {},
emptyFlag: false,
loading: false,
reviewComments: {
data: [],
Expand All @@ -101,7 +103,8 @@
changedFiles: {
data: [],
loading: false
}
},
dirty: false
}
},
computed: {
Expand Down Expand Up @@ -231,8 +234,10 @@
)
try{
this.pendingReview.data = res.data.data.repository.pullRequest.reviews.nodes[0]
if(this.pendingReview.data) {
this.pendingReview.data = res.data.data.repository.pullRequest.reviews.nodes[0] || {}
this.pendingReview.emptyFlag = false
if(!res.data.data.repository.pullRequest.reviews.nodes[0]) this.pendingReview.emptyFlag = true
if(this.pendingReview.data.databaseId) {
await this.network_getPendingReviewComments(this.pendingReview.data)
}else {
this.pendingReview.reviewComments.data = []
Expand Down Expand Up @@ -362,7 +367,7 @@
return ['deletion','neutral']
}
},
async replyCreatedHook(comment) {
async reviewCommentCreatedHook(comment) {
let newCreatedComment
if(comment.state == 'PENDING') {
newCreatedComment = await this.network_getNewCreatedPendingReviewComment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
import * as graphql from '../../graphql.js'
import * as api from '@/network/api'
export default {
inject: ['reviewCommentsExtraData','repoOwnerType','triggerReplyButtonDisabled','reviewCommentsGetter','pendingReviewGetter'],
inject: ['reviewCommentsExtraData','repoOwnerType','triggerReplyButtonDisabled','reviewCommentDeletedHook','pendingReviewGetter'],
data() {
return {
showMinimized: false,
Expand Down Expand Up @@ -188,7 +188,7 @@
await this.pendingReviewGetter()()
console.log('pendingReviewGetter finish!!')
}else{
await this.reviewCommentsGetter()()
await this.reviewCommentDeletedHook()()
}
} catch (e) {
this.handleError(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

<script>
import styled from 'vue-styled-components'
import {authRequiredPost,authRequiredGitHubGraphqlApiQuery} from '@/network'
import {authRequiredPost,authRequiredGet,authRequiredGitHubGraphqlApiQuery} from '@/network'
import * as api from '@/network/api'
import * as graphql from '../../graphql.js'
import { authRequiredGet } from '../../../../../../store/modules/network.js'
export default {
inject: ['pendingReview','pendingReviewGetter','replyCreatedHook'],
inject: ['pendingReview','pendingReviewGetter','reviewCommentCreatedHook'],
props: {
comment: Object,
path: String,
Expand Down Expand Up @@ -91,7 +90,9 @@ import { authRequiredGet } from '../../../../../../store/modules/network.js'
try {
let comment = res.data.data.addPullRequestReviewComment.comment
this.replyCreatedHook()(comment)
await this.reviewCommentCreatedHook()(comment)
this.content = ''
this.$emit('cancel')
} catch (e) {
this.handleGraphqlError(res)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<Container class="the-container">
<textarea :disabled="loadingStartReview || loadingAddSingleComment" ref="textarea" v-model="content" class="form-control" placeholder="Leave a comment" rows="5" style="width: 100%"></textarea>
<textarea :disabled="loadingStartReview || loadingAddComment" ref="textarea" v-model="content" class="form-control" placeholder="Leave a comment" rows="5" style="width: 100%"></textarea>
<div class="text-right position-relative no-wrap d-flex flex-justify-end">
<button class="btn mt-2 flex-shrink-0 d-block" @click.stop="() => $emit('cancel')" :disabled="loadingStartReview || loadingAddSingleComment">Cancel</button>
<button class="btn mt-2 ml-1 btn-primary flex-shrink-1 truncate d-block" @click.stop="network_addSingleComment" :disabled="loadingStartReview || loadingAddSingleComment || !content">
{{loadingAddSingleComment ? 'Trying...' : 'Add comment'}}
<button class="btn mt-2 flex-shrink-0 d-block" @click.stop="() => $emit('cancel')" :disabled="loadingStartReview || loadingAddComment">Cancel</button>
<button class="btn mt-2 ml-1 btn-primary flex-shrink-1 truncate d-block" @click.stop="network_addSingleComment" :disabled="loadingStartReview || loadingAddComment || !content || pendingReview().loading">
{{loadingAddComment ? 'Trying...' : 'Add comment'}}
</button>
<button class="btn mt-2 ml-1 btn-primary flex-shrink-0 d-block" v-if="!(pendingReview().data && pendingReview().data.databaseId)" @click.stop="network_startAReview" :disabled="loadingStartReview || loadingAddSingleComment || !content">
<button class="btn mt-2 ml-1 btn-primary flex-shrink-0 d-block" v-if="!(pendingReview().data && pendingReview().data.databaseId)" @click.stop="network_startAReview" :disabled="loadingStartReview || loadingAddComment || !content">
{{loadingStartReview ? 'Trying...' : 'Start a review'}}
</button>
</div>
Expand All @@ -16,30 +16,75 @@
<script>
import ReviewCommentReplyCreator from './ReviewCommentReplyCreator'
import {Popover} from '@/components'
import {authRequiredGitHubGraphqlApiQuery} from '@/network'
import * as graphql from '../../graphql.js'
export default {
mixins: [ReviewCommentReplyCreator],
inject: ['reviewCommentsGetter'],
inject: ['commentReviewCreatedHook','pendingReview'],
data() {
return {
loadingAddSingleComment: false
loadingAddComment: false
}
},
methods: {
async network_addSingleComment() {
network_addSingleComment() {
if(this.pendingReview().emptyFlag) {
this.network_createCommentReview()
} else {
this.network_addReviewCommentToPendingReview()
}
},
async network_createCommentReview() {
try {
this.loadingAddSingleComment = true
this.loadingAddComment = true
let reviewCreated = await this.network_createReview('COMMENT')
await this.reviewCommentsGetter()()
await this.commentReviewCreatedHook()()
this.content = ''
this.$emit('cancel')
} catch (e) {
this.handleError(e)
} finally {
this.loadingAddSingleComment = false
this.loadingAddComment = false
}
},
async network_addReviewCommentToPendingReview() {
try{
this.loadingAddComment = true
let res = await authRequiredGitHubGraphqlApiQuery(
graphql.GRAPHQL_ADD_PULL_REQUEST_REVIEW_COMMENT,
{
variables: {
input: {
body: this.content,
pullRequestReviewId: this.pendingReview().data.id,
path: this.path,
position: this.position,
}
}
}
)
try {
let comment = res.data.data.addPullRequestReviewComment.comment
await this.reviewCommentCreatedHook()(comment)
this.content = ''
this.$emit('cancel')
} catch (e) {
this.handleGraphqlError(res)
}
} catch (e) {
if(e.response && e.response.status == 422) {
this.$toast(this.$t("pullRequestDetailFileChangesPage.pendingReviewExistNotice"),'error')
}else{
this.handleError(e)
}
} finally {
this.loadingAddComment = false
}
}
},
components: {
Popover
Expand Down

0 comments on commit eeaf277

Please sign in to comment.