1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-22 17:34:03 +03:00

Fixed Issue of Review Menu Shown Behind (#32631)

Fixed #31144 

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Kerwin Bryant 2024-11-26 09:24:56 +08:00 committed by GitHub
parent 703be6bf30
commit 25cacaf0aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 38 additions and 26 deletions

View File

@ -164,24 +164,22 @@
<input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}} <input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
</label> </label>
{{end}} {{end}}
<div class="ui dropdown basic"> <button class="btn diff-header-popup-btn tw-p-1">{{svg "octicon-kebab-horizontal" 18}}</button>
{{svg "octicon-kebab-horizontal" 18 "icon tw-mx-2"}} <div class="tippy-target">
<div class="ui menu"> {{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}} <button class="unescape-button item" data-file-content-elem-id="diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
<button class="unescape-button item">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button> <button class="escape-button tw-hidden item" data-file-content-elem-id="diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
<button class="escape-button tw-hidden item">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button> {{end}}
{{end}} {{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}} {{if $file.IsDeleted}}
{{if $file.IsDeleted}} <a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
<a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a> {{else}}
{{else}} <a class="item" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
<a class="item" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a> {{if and $.Repository.CanEnableEditor $.CanEditFile (not $file.IsLFSFile) (not $file.IsBin)}}
{{if and $.Repository.CanEnableEditor $.CanEditFile (not $file.IsLFSFile) (not $file.IsBin)}} <a class="item" rel="nofollow" href="{{$.HeadRepoLink}}/_edit/{{PathEscapeSegments $.HeadBranchName}}/{{PathEscapeSegments $file.Name}}?return_uri={{print $.BackToLink "#diff-" $file.NameHash | QueryEscape}}">{{ctx.Locale.Tr "repo.editor.edit_this_file"}}</a>
<a class="item" rel="nofollow" href="{{$.HeadRepoLink}}/_edit/{{PathEscapeSegments $.HeadBranchName}}/{{PathEscapeSegments $file.Name}}?return_uri={{print $.BackToLink "#diff-" $file.NameHash | QueryEscape}}">{{ctx.Locale.Tr "repo.editor.edit_this_file"}}</a>
{{end}}
{{end}} {{end}}
{{end}} {{end}}
</div> {{end}}
</div> </div>
</div> </div>
</h4> </h4>

View File

@ -97,7 +97,7 @@ func TestPullCompare_EnableAllowEditsFromMaintainer(t *testing.T) {
user2Session := loginUser(t, "user2") user2Session := loginUser(t, "user2")
resp = user2Session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("%s/files", prURL)), http.StatusOK) resp = user2Session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("%s/files", prURL)), http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body) htmlDoc := NewHTMLParser(t, resp.Body)
nodes := htmlDoc.doc.Find(".diff-file-box[data-new-filename=\"README.md\"] .diff-file-header-actions .dropdown .menu a") nodes := htmlDoc.doc.Find(".diff-file-box[data-new-filename=\"README.md\"] .diff-file-header-actions .tippy-target a")
if assert.Equal(t, 1, nodes.Length()) { if assert.Equal(t, 1, nodes.Length()) {
// there is only "View File" button, no "Edit File" button // there is only "View File" button, no "Edit File" button
assert.Equal(t, "View File", nodes.First().Text()) assert.Equal(t, "View File", nodes.First().Text())
@ -121,7 +121,7 @@ func TestPullCompare_EnableAllowEditsFromMaintainer(t *testing.T) {
// user2 (admin of repo3) goes to the PR files page again // user2 (admin of repo3) goes to the PR files page again
resp = user2Session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("%s/files", prURL)), http.StatusOK) resp = user2Session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("%s/files", prURL)), http.StatusOK)
htmlDoc = NewHTMLParser(t, resp.Body) htmlDoc = NewHTMLParser(t, resp.Body)
nodes = htmlDoc.doc.Find(".diff-file-box[data-new-filename=\"README.md\"] .diff-file-header-actions .dropdown .menu a") nodes = htmlDoc.doc.Find(".diff-file-box[data-new-filename=\"README.md\"] .diff-file-header-actions .tippy-target a")
if assert.Equal(t, 2, nodes.Length()) { if assert.Equal(t, 2, nodes.Length()) {
// there are "View File" button and "Edit File" button // there are "View File" button and "Edit File" button
assert.Equal(t, "View File", nodes.First().Text()) assert.Equal(t, "View File", nodes.First().Text())

View File

@ -77,8 +77,10 @@
align-items: center; align-items: center;
padding: 9px 18px; padding: 9px 18px;
color: inherit; color: inherit;
background: inherit;
text-decoration: none; text-decoration: none;
gap: 10px; gap: 10px;
width: 100%;
} }
.tippy-box[data-theme="menu"] .item:hover { .tippy-box[data-theme="menu"] .item:hover {

View File

@ -18,6 +18,7 @@ import {
} from '../utils/dom.ts'; } from '../utils/dom.ts';
import {POST, GET} from '../modules/fetch.ts'; import {POST, GET} from '../modules/fetch.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts'; import {fomanticQuery} from '../modules/fomantic/base.ts';
import {createTippy} from '../modules/tippy.ts';
const {pageData, i18n} = window.config; const {pageData, i18n} = window.config;
@ -140,12 +141,22 @@ export function initRepoDiffConversationNav() {
}); });
} }
function initDiffHeaderPopup() {
for (const btn of document.querySelectorAll('.diff-header-popup-btn:not([data-header-popup-initialized])')) {
btn.setAttribute('data-header-popup-initialized', '');
const popup = btn.nextElementSibling;
if (!popup?.matches('.tippy-target')) throw new Error('Popup element not found');
createTippy(btn, {content: popup, theme: 'menu', placement: 'bottom', trigger: 'click', interactive: true, hideOnClick: true});
}
}
// Will be called when the show more (files) button has been pressed // Will be called when the show more (files) button has been pressed
function onShowMoreFiles() { function onShowMoreFiles() {
initRepoIssueContentHistory(); initRepoIssueContentHistory();
initViewedCheckboxListenerFor(); initViewedCheckboxListenerFor();
countAndUpdateViewedFiles(); countAndUpdateViewedFiles();
initImageDiff(); initImageDiff();
initDiffHeaderPopup();
} }
export async function loadMoreFiles(url) { export async function loadMoreFiles(url) {
@ -221,6 +232,7 @@ export function initRepoDiffView() {
initDiffFileList(); initDiffFileList();
initDiffCommitSelect(); initDiffCommitSelect();
initRepoDiffShowMore(); initRepoDiffShowMore();
initDiffHeaderPopup();
initRepoDiffFileViewToggle(); initRepoDiffFileViewToggle();
initViewedCheckboxListenerFor(); initViewedCheckboxListenerFor();
initExpandAndCollapseFilesButton(); initExpandAndCollapseFilesButton();

View File

@ -1,13 +1,13 @@
import {hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts'; import {addDelegatedEventListener, hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts';
export function initUnicodeEscapeButton() { export function initUnicodeEscapeButton() {
document.addEventListener('click', (e) => { addDelegatedEventListener(document, 'click', '.escape-button, .unescape-button, .toggle-escape-button', (btn, e) => {
const btn = e.target.closest('.escape-button, .unescape-button, .toggle-escape-button');
if (!btn) return;
e.preventDefault(); e.preventDefault();
const fileContent = btn.closest('.file-content, .non-diff-file-content'); const fileContentElemId = btn.getAttribute('data-file-content-elem-id');
const fileContent = fileContentElemId ?
document.querySelector(`#${fileContentElemId}`) :
btn.closest('.file-content, .non-diff-file-content');
const fileView = fileContent?.querySelectorAll('.file-code, .file-view'); const fileView = fileContent?.querySelectorAll('.file-code, .file-view');
if (btn.matches('.escape-button')) { if (btn.matches('.escape-button')) {
for (const el of fileView) el.classList.add('unicode-escaped'); for (const el of fileView) el.classList.add('unicode-escaped');

View File

@ -2,10 +2,10 @@ import {debounce} from 'throttle-debounce';
import type {Promisable} from 'type-fest'; import type {Promisable} from 'type-fest';
import type $ from 'jquery'; import type $ from 'jquery';
type ElementArg = Element | string | NodeListOf<Element> | Array<Element> | ReturnType<typeof $>; type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array
type ElementArg = Element | string | ArrayLikeIterable<Element> | ReturnType<typeof $>;
type ElementsCallback<T extends Element> = (el: T) => Promisable<any>; type ElementsCallback<T extends Element> = (el: T) => Promisable<any>;
type ElementsCallbackWithArgs = (el: Element, ...args: any[]) => Promisable<any>; type ElementsCallbackWithArgs = (el: Element, ...args: any[]) => Promisable<any>;
type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array
function elementsCall(el: ElementArg, func: ElementsCallbackWithArgs, ...args: any[]) { function elementsCall(el: ElementArg, func: ElementsCallbackWithArgs, ...args: any[]) {
if (typeof el === 'string' || el instanceof String) { if (typeof el === 'string' || el instanceof String) {