From d997fcbd8614d2cb6418e1419549b5ac11041be6 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Mon, 31 Mar 2025 01:24:01 +0000 Subject: [PATCH 1/4] Fix: The issue that the commit_statuses at the top - right were not loaded when switching files from the left - hand file tree on the file viewing page. --- templates/repo/commit_statuses.tmpl | 4 ++-- tests/integration/repo_commits_test.go | 4 ++-- web_src/js/features/repo-commit.ts | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index a6f75584a31f4..9b2ee36004acd 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,10 +1,10 @@ {{if .Statuses}} {{if and (eq (len .Statuses) 1) .Status.TargetURL}} - + {{template "repo/commit_status" .Status}} {{else}} - + {{template "repo/commit_status" .Status}} {{end}} diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index fbe215eb859d0..9e1f4875e8ab1 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -240,7 +240,7 @@ func TestRepoCommitsStatusMultiple(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) doc = NewHTMLParser(t, resp.Body) - // Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present - sel := doc.doc.Find("#commits-table .message [data-tippy=\"commit-statuses\"] .commit-status") + // Check that the data-global-init="commit-statuses" (for trigger) and commit-status (svg) are present + sel := doc.doc.Find("#commits-table .message [data-global-init=\"commit-statuses\"] .commit-status") assert.Equal(t, 1, sel.Length()) } diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts index e6d1112778120..e252c022704be 100644 --- a/web_src/js/features/repo-commit.ts +++ b/web_src/js/features/repo-commit.ts @@ -1,6 +1,6 @@ import {createTippy} from '../modules/tippy.ts'; import {toggleElem} from '../utils/dom.ts'; -import {registerGlobalEventFunc} from '../modules/observer.ts'; +import {registerGlobalEventFunc, registerGlobalInitFunc} from '../modules/observer.ts'; export function initRepoEllipsisButton() { registerGlobalEventFunc('click', 'onRepoEllipsisButtonClick', async (el: HTMLInputElement, e: Event) => { @@ -12,15 +12,15 @@ export function initRepoEllipsisButton() { } export function initCommitStatuses() { - for (const element of document.querySelectorAll('[data-tippy="commit-statuses"]')) { + registerGlobalInitFunc('commit-statuses', async (el: HTMLElement) => { const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff'); - createTippy(element, { - content: element.nextElementSibling, + createTippy(el, { + content: el.nextElementSibling, placement: top ? 'top-start' : 'bottom-start', interactive: true, role: 'dialog', theme: 'box-with-header', }); - } + }); } From cf9f18bacaf11a0efbbadd820a1e6d4f193e0e0b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 31 Mar 2025 19:12:13 +0800 Subject: [PATCH 2/4] optimize --- templates/repo/commit_statuses.tmpl | 4 ++-- tests/integration/repo_commits_test.go | 4 ++-- web_src/js/features/repo-commit.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/repo/commit_statuses.tmpl b/templates/repo/commit_statuses.tmpl index 9b2ee36004acd..1bbfb331051c8 100644 --- a/templates/repo/commit_statuses.tmpl +++ b/templates/repo/commit_statuses.tmpl @@ -1,10 +1,10 @@ {{if .Statuses}} {{if and (eq (len .Statuses) 1) .Status.TargetURL}} - + {{template "repo/commit_status" .Status}} {{else}} - + {{template "repo/commit_status" .Status}} {{end}} diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index 9e1f4875e8ab1..9efeb1a9ee696 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -240,7 +240,7 @@ func TestRepoCommitsStatusMultiple(t *testing.T) { resp = session.MakeRequest(t, req, http.StatusOK) doc = NewHTMLParser(t, resp.Body) - // Check that the data-global-init="commit-statuses" (for trigger) and commit-status (svg) are present - sel := doc.doc.Find("#commits-table .message [data-global-init=\"commit-statuses\"] .commit-status") + // Check that the data-global-init="initCommitStatuses" (for trigger) and commit-status (svg) are present + sel := doc.doc.Find(`#commits-table .message [data-global-init="initCommitStatuses"] .commit-status`) assert.Equal(t, 1, sel.Length()) } diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts index e252c022704be..89e3555c823a6 100644 --- a/web_src/js/features/repo-commit.ts +++ b/web_src/js/features/repo-commit.ts @@ -12,12 +12,12 @@ export function initRepoEllipsisButton() { } export function initCommitStatuses() { - registerGlobalInitFunc('commit-statuses', async (el: HTMLElement) => { - const top = document.querySelector('.repository.file.list') || document.querySelector('.repository.diff'); - + registerGlobalInitFunc('initCommitStatuses', async (el: HTMLElement) => { + const nextEl = el.nextElementSibling; + if (!nextEl.matches('.tippy-target')) throw new Error('Expected next element to be a tippy target'); createTippy(el, { content: el.nextElementSibling, - placement: top ? 'top-start' : 'bottom-start', + placement: 'bottom-start', interactive: true, role: 'dialog', theme: 'box-with-header', From 99eec5b68c68a407ec5a0f6631ff47d28abe08fd Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 31 Mar 2025 19:14:07 +0800 Subject: [PATCH 3/4] fix var usage --- web_src/js/features/repo-commit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts index 89e3555c823a6..51126cc3e48f6 100644 --- a/web_src/js/features/repo-commit.ts +++ b/web_src/js/features/repo-commit.ts @@ -16,7 +16,7 @@ export function initCommitStatuses() { const nextEl = el.nextElementSibling; if (!nextEl.matches('.tippy-target')) throw new Error('Expected next element to be a tippy target'); createTippy(el, { - content: el.nextElementSibling, + content: nextEl, placement: 'bottom-start', interactive: true, role: 'dialog', From e6df1081088faa1140510452b3a8d86a388c22b9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 31 Mar 2025 19:14:30 +0800 Subject: [PATCH 4/4] remove async --- web_src/js/features/repo-commit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/repo-commit.ts b/web_src/js/features/repo-commit.ts index 51126cc3e48f6..98ec2328ec5f4 100644 --- a/web_src/js/features/repo-commit.ts +++ b/web_src/js/features/repo-commit.ts @@ -12,7 +12,7 @@ export function initRepoEllipsisButton() { } export function initCommitStatuses() { - registerGlobalInitFunc('initCommitStatuses', async (el: HTMLElement) => { + registerGlobalInitFunc('initCommitStatuses', (el: HTMLElement) => { const nextEl = el.nextElementSibling; if (!nextEl.matches('.tippy-target')) throw new Error('Expected next element to be a tippy target'); createTippy(el, {