Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change form actions to fetch for submit review box #25219

Merged
merged 33 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f774943
save
HesterG Jun 12, 2023
3c56833
change to fetch
HesterG Jun 12, 2023
984a30b
update
HesterG Jun 12, 2023
2b71734
change to post
HesterG Jun 12, 2023
7d3683b
Merge branch 'go-gitea:main' into change-actions-fetch
HesterG Jun 12, 2023
2318bb3
change redirect
HesterG Jun 12, 2023
183dc8e
update
HesterG Jun 12, 2023
ed54590
add loading
HesterG Jun 12, 2023
8f57fc1
add comments
HesterG Jun 12, 2023
0dc11e1
update js
HesterG Jun 12, 2023
4602642
update
HesterG Jun 12, 2023
7fa9e1e
Merge branch 'go-gitea:main' into change-actions-fetch
HesterG Jun 13, 2023
9db8855
comment
HesterG Jun 13, 2023
acdd3cd
comment
HesterG Jun 13, 2023
f029cfb
change to resirect
HesterG Jun 13, 2023
8f382f2
Merge branch 'main' into change-actions-fetch
HesterG Jun 13, 2023
cf540cd
Merge branch 'main' into change-actions-fetch
HesterG Jun 13, 2023
bfe1c6b
update to dataform
HesterG Jun 13, 2023
1a8472f
add method
HesterG Jun 13, 2023
c3d5bfb
Merge branch 'main' into change-actions-fetch
HesterG Jun 13, 2023
2d7d5d0
rename and append submitter value
HesterG Jun 13, 2023
f4da606
comment
HesterG Jun 13, 2023
b37a7db
comment
HesterG Jun 13, 2023
74e330d
fix lint
HesterG Jun 13, 2023
a5c5145
Merge branch 'main' into change-actions-fetch
HesterG Jun 13, 2023
c45a1e1
fine tune (wip)
wxiaoguang Jun 13, 2023
3b271d7
quick fix for submitterName and value
HesterG Jun 13, 2023
6023a45
Merge branch 'main' into change-actions-fetch
wxiaoguang Jun 13, 2023
b8f64ca
improve
wxiaoguang Jun 13, 2023
722d0ed
improve
wxiaoguang Jun 14, 2023
9f428a3
improve
wxiaoguang Jun 14, 2023
f43cdc6
Merge branch 'main' into change-actions-fetch
HesterG Jun 14, 2023
713feda
Merge branch 'main' into change-actions-fetch
GiteaBot Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions routers/web/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ func SubmitReview(ctx *context.Context) {
}
if ctx.HasError() {
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirectLink": fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index),
})
return
}

Expand All @@ -214,7 +216,9 @@ func SubmitReview(ctx *context.Context) {
}

ctx.Flash.Error(translated)
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirectLink": fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index),
})
return
}
}
Expand All @@ -228,14 +232,17 @@ func SubmitReview(ctx *context.Context) {
if err != nil {
if issues_model.IsContentEmptyErr(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.review.content.empty"))
ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirectLink": fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index),
})
} else {
ctx.ServerError("SubmitReview", err)
}
return
}

ctx.Redirect(fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirectLink": fmt.Sprintf("%s/pulls/%d#%s", ctx.Repo.RepoLink, issue.Index, comm.HashTag()),
HesterG marked this conversation as resolved.
Show resolved Hide resolved
})
}

// DismissReview dismissing stale review by repo admin
Expand Down
8 changes: 4 additions & 4 deletions services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) bindi

// SubmitReviewForm for submitting a finished code review
type SubmitReviewForm struct {
Content string
Type string
CommitID string
Files []string
Content string `json:"content"`
Type string `json:"type"`
CommitID string `json:"commitID"`
Files []string `json:"files"`
}

// Validate validates the fields
Expand Down
18 changes: 8 additions & 10 deletions templates/repo/diff/new_review.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
<span class="ui small label review-comments-counter" data-pending-comment-number="{{.PendingCodeCommentNumber}}">{{.PendingCodeCommentNumber}}</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</button>
<div class="review-box-panel tippy-target">
<div class="review-box-panel tippy-target" data-url="{{.Link}}/reviews/submit" data-commit-id="{{.AfterCommitID}}">
<div class="ui segment">
<form class="ui form" action="{{.Link}}/reviews/submit" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="commit_id" value="{{.AfterCommitID}}">
<div class="ui form">
<div class="field gt-df gt-ac">
<div class="gt-f1">{{$.locale.Tr "repo.diff.review.header"}}</div>
<a class="muted close">{{svg "octicon-x" 16}}</a>
Expand All @@ -32,20 +30,20 @@
{{$showSelfTooltip := (and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID))}}
{{if $showSelfTooltip}}
<span class="gt-dib" data-tooltip-content="{{$.locale.Tr "repo.diff.review.self_approve"}}">
<button type="submit" name="type" value="approve" disabled class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
<button data-type="approve" disabled class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
</span>
{{else}}
<button type="submit" name="type" value="approve" class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
<button data-type="approve" class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
{{end}}
<button type="submit" name="type" value="comment" class="ui submit tiny basic button btn-submit">{{$.locale.Tr "repo.diff.review.comment"}}</button>
<button data-type="comment" class="ui submit tiny basic button btn-submit">{{$.locale.Tr "repo.diff.review.comment"}}</button>
{{if $showSelfTooltip}}
<span class="gt-dib" data-tooltip-content="{{$.locale.Tr "repo.diff.review.self_reject"}}">
<button type="submit" name="type" value="reject" disabled class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
<button data-type="reject" disabled class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
</span>
{{else}}
<button type="submit" name="type" value="reject" class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
<button data-type="reject" class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
{{end}}
</form>
</div>
</div>
</div>
</div>
42 changes: 42 additions & 0 deletions web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,47 @@ export async function handleReply($el) {
return editor;
}

function prepareReviewBoxButtons ($reviewBox) {
for (const btn of $reviewBox.find('.btn-submit')) {
$(btn).on('click', async function () {
// Do not fetch repeatedly if post request has sent.
// Added to $reviewBox to avoid sending several requests when approve, comment,
// and request change buttons are clicked.
if ($reviewBox.hasClass('isFetching')) return;
$reviewBox.addClass('isFetching');
$(this).addClass('loading');
const fileIds = [];
for (const fileInput of $reviewBox.find('.dropzone .files input')) {
fileIds.push($(fileInput).attr('id'));
}
const $textEditor = $reviewBox.find('textarea.markdown-text-editor');
const data = {
'commitID': $reviewBox.attr('data-commit-id'),
'type': $(this).attr('data-type'),
'content': $textEditor.val(),
};
if (fileIds.length > 0) data['files'] = fileIds;
const response = await fetch($reviewBox.attr('data-url'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Csrf-Token': csrfToken,
},
body: JSON.stringify(data),
});
// if page is redirected, no need to remove loading status
if (response.status === 200) {
const {redirectLink} = await response.json();
window.location.href = redirectLink;
// error occurs, still on the same page, remove loading status
} else {
$reviewBox.removeClass('isFetching');
$(this).removeClass('loading');
}
});
}
}

export function initRepoPullRequestReview() {
if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) {
// set scrollRestoration to 'manual' when there is a hash in url, so that the scroll position will not be remembered after refreshing
Expand Down Expand Up @@ -453,6 +494,7 @@ export function initRepoPullRequestReview() {
const $reviewBox = $('.review-box-panel');
if ($reviewBox.length === 1) {
const _promise = initComboMarkdownEditor($reviewBox.find('.combo-markdown-editor'));
prepareReviewBoxButtons($reviewBox);
}

// The following part is only for diff views
Expand Down