Skip to content

Commit 90f96c3

Browse files
authored
Fix PR toggle WIP (#34920)
Fix #34919 --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 6596b92 commit 90f96c3

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

routers/web/repo/issue_view.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ func ViewPullMergeBox(ctx *context.Context) {
443443
preparePullViewPullInfo(ctx, issue)
444444
preparePullViewReviewAndMerge(ctx, issue)
445445
ctx.Data["PullMergeBoxReloading"] = issue.PullRequest.IsChecking()
446+
447+
// TODO: it should use a dedicated struct to render the pull merge box, to make sure all data is prepared correctly
448+
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.Doer.ID)
449+
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
446450
ctx.HTML(http.StatusOK, tplPullMergeBox)
447451
}
448452

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}}
2-
<a class="toggle-wip tw-block tw-mt-2" data-title="{{.Issue.Title}}" data-wip-prefix="{{index .PullRequestWorkInProgressPrefixes 0}}" data-update-url="{{.Issue.Link}}/title">
2+
<a data-global-init="initPullRequestWipToggle" data-title="{{.Issue.Title}}" data-wip-prefix="{{index .PullRequestWorkInProgressPrefixes 0}}" data-update-url="{{.Issue.Link}}/title">
33
{{ctx.Locale.Tr "repo.pulls.still_in_progress"}} {{ctx.Locale.Tr "repo.pulls.add_prefix" (index .PullRequestWorkInProgressPrefixes 0)}}
44
</a>
55
{{end}}

templates/repo/issue/view_content/pull_merge_box.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
{{ctx.Locale.Tr "repo.pulls.cannot_merge_work_in_progress"}}
9696
</div>
9797
{{if or .HasIssuesOrPullsWritePermission .IsIssuePoster}}
98-
<button class="ui compact button toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title">
98+
<button class="ui compact button" data-global-init="initPullRequestWipToggle" data-title="{{.Issue.Title}}" data-wip-prefix="{{.WorkInProgressPrefix}}" data-update-url="{{.Issue.Link}}/title">
9999
{{ctx.Locale.Tr "repo.pulls.remove_prefix" .WorkInProgressPrefix}}
100100
</button>
101101
{{end}}

web_src/js/features/repo-issue.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {showErrorToast} from '../modules/toast.ts';
1717
import {initRepoIssueSidebar} from './repo-issue-sidebar.ts';
1818
import {fomanticQuery} from '../modules/fomantic/base.ts';
1919
import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts';
20+
import {registerGlobalInitFunc} from '../modules/observer.ts';
2021

2122
const {appSubUrl} = window.config;
2223

@@ -416,25 +417,20 @@ export function initRepoIssueWipNewTitle() {
416417

417418
export function initRepoIssueWipToggle() {
418419
// Toggle WIP for existing PR
419-
queryElems(document, '.toggle-wip', (el) => el.addEventListener('click', async (e) => {
420+
registerGlobalInitFunc('initPullRequestWipToggle', (toggleWip) => toggleWip.addEventListener('click', async (e) => {
420421
e.preventDefault();
421-
const toggleWip = el;
422422
const title = toggleWip.getAttribute('data-title');
423423
const wipPrefix = toggleWip.getAttribute('data-wip-prefix');
424424
const updateUrl = toggleWip.getAttribute('data-update-url');
425425

426-
try {
427-
const params = new URLSearchParams();
428-
params.append('title', title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`);
429-
430-
const response = await POST(updateUrl, {data: params});
431-
if (!response.ok) {
432-
throw new Error('Failed to toggle WIP status');
433-
}
434-
window.location.reload();
435-
} catch (error) {
436-
console.error(error);
426+
const params = new URLSearchParams();
427+
params.append('title', title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`);
428+
const response = await POST(updateUrl, {data: params});
429+
if (!response.ok) {
430+
showErrorToast(`Failed to toggle 'work in progress' status`);
431+
return;
437432
}
433+
window.location.reload();
438434
}));
439435
}
440436

0 commit comments

Comments
 (0)