Skip to content

Commit 741b53e

Browse files
[Fix] Resolve the problem of commit_statuses not being loaded at the top - right when switching files from the file tree (#34079)
Co-authored-by: wxiaoguang <[email protected]>
1 parent 0fde8ec commit 741b53e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

templates/repo/commit_statuses.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{{if .Statuses}}
22
{{if and (eq (len .Statuses) 1) .Status.TargetURL}}
3-
<a class="flex-text-inline tw-no-underline {{.AdditionalClasses}}" data-tippy="commit-statuses" href="{{.Status.TargetURL}}">
3+
<a class="flex-text-inline tw-no-underline {{.AdditionalClasses}}" data-global-init="initCommitStatuses" href="{{.Status.TargetURL}}">
44
{{template "repo/commit_status" .Status}}
55
</a>
66
{{else}}
7-
<span class="flex-text-inline {{.AdditionalClasses}}" data-tippy="commit-statuses" tabindex="0">
7+
<span class="flex-text-inline {{.AdditionalClasses}}" data-global-init="initCommitStatuses" tabindex="0">
88
{{template "repo/commit_status" .Status}}
99
</span>
1010
{{end}}

tests/integration/repo_commits_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestRepoCommitsStatusMultiple(t *testing.T) {
240240
resp = session.MakeRequest(t, req, http.StatusOK)
241241

242242
doc = NewHTMLParser(t, resp.Body)
243-
// Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present
244-
sel := doc.doc.Find("#commits-table .message [data-tippy=\"commit-statuses\"] .commit-status")
243+
// Check that the data-global-init="initCommitStatuses" (for trigger) and commit-status (svg) are present
244+
sel := doc.doc.Find(`#commits-table .message [data-global-init="initCommitStatuses"] .commit-status`)
245245
assert.Equal(t, 1, sel.Length())
246246
}

web_src/js/features/repo-commit.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createTippy} from '../modules/tippy.ts';
22
import {toggleElem} from '../utils/dom.ts';
3-
import {registerGlobalEventFunc} from '../modules/observer.ts';
3+
import {registerGlobalEventFunc, registerGlobalInitFunc} from '../modules/observer.ts';
44

55
export function initRepoEllipsisButton() {
66
registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => {
@@ -12,15 +12,15 @@ export function initRepoEllipsisButton() {
1212
}
1313

1414
export function initCommitStatuses() {
15-
for (const element of document.querySelectorAll('[data-tippy="commit-statuses"]')) {
16-
const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff');
17-
18-
createTippy(element, {
19-
content: element.nextElementSibling,
20-
placement: top ? 'top-start' : 'bottom-start',
15+
registerGlobalInitFunc('initCommitStatuses', (el: HTMLElement) => {
16+
const nextEl = el.nextElementSibling;
17+
if (!nextEl.matches('.tippy-target')) throw new Error('Expected next element to be a tippy target');
18+
createTippy(el, {
19+
content: nextEl,
20+
placement: 'bottom-start',
2121
interactive: true,
2222
role: 'dialog',
2323
theme: 'box-with-header',
2424
});
25-
}
25+
});
2626
}

0 commit comments

Comments
 (0)