Skip to content

Commit 25cacaf

Browse files
Fixed Issue of Review Menu Shown Behind (#32631)
Fixed #31144 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 703be6b commit 25cacaf

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

templates/repo/diff/box.tmpl

+14-16
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,22 @@
164164
<input type="checkbox" name="{{$file.GetDiffFileName}}" autocomplete="off"{{if $file.IsViewed}} checked{{end}}> {{ctx.Locale.Tr "repo.pulls.has_viewed_file"}}
165165
</label>
166166
{{end}}
167-
<div class="ui dropdown basic">
168-
{{svg "octicon-kebab-horizontal" 18 "icon tw-mx-2"}}
169-
<div class="ui menu">
170-
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
171-
<button class="unescape-button item">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
172-
<button class="escape-button tw-hidden item">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
173-
{{end}}
174-
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
175-
{{if $file.IsDeleted}}
176-
<a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
177-
{{else}}
178-
<a class="item" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
179-
{{if and $.Repository.CanEnableEditor $.CanEditFile (not $file.IsLFSFile) (not $file.IsBin)}}
180-
<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>
181-
{{end}}
167+
<button class="btn diff-header-popup-btn tw-p-1">{{svg "octicon-kebab-horizontal" 18}}</button>
168+
<div class="tippy-target">
169+
{{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}}
170+
<button class="unescape-button item" data-file-content-elem-id="diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
171+
<button class="escape-button tw-hidden item" data-file-content-elem-id="diff-{{$file.NameHash}}">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
172+
{{end}}
173+
{{if and (not $file.IsSubmodule) (not $.PageIsWiki)}}
174+
{{if $file.IsDeleted}}
175+
<a class="item" rel="nofollow" href="{{$.BeforeSourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
176+
{{else}}
177+
<a class="item" rel="nofollow" href="{{$.SourcePath}}/{{PathEscapeSegments .Name}}">{{ctx.Locale.Tr "repo.diff.view_file"}}</a>
178+
{{if and $.Repository.CanEnableEditor $.CanEditFile (not $file.IsLFSFile) (not $file.IsBin)}}
179+
<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>
182180
{{end}}
183181
{{end}}
184-
</div>
182+
{{end}}
185183
</div>
186184
</div>
187185
</h4>

tests/integration/pull_compare_test.go

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

web_src/css/modules/tippy.css

+2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@
7777
align-items: center;
7878
padding: 9px 18px;
7979
color: inherit;
80+
background: inherit;
8081
text-decoration: none;
8182
gap: 10px;
83+
width: 100%;
8284
}
8385

8486
.tippy-box[data-theme="menu"] .item:hover {

web_src/js/features/repo-diff.ts

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from '../utils/dom.ts';
1919
import {POST, GET} from '../modules/fetch.ts';
2020
import {fomanticQuery} from '../modules/fomantic/base.ts';
21+
import {createTippy} from '../modules/tippy.ts';
2122

2223
const {pageData, i18n} = window.config;
2324

@@ -140,12 +141,22 @@ export function initRepoDiffConversationNav() {
140141
});
141142
}
142143

144+
function initDiffHeaderPopup() {
145+
for (const btn of document.querySelectorAll('.diff-header-popup-btn:not([data-header-popup-initialized])')) {
146+
btn.setAttribute('data-header-popup-initialized', '');
147+
const popup = btn.nextElementSibling;
148+
if (!popup?.matches('.tippy-target')) throw new Error('Popup element not found');
149+
createTippy(btn, {content: popup, theme: 'menu', placement: 'bottom', trigger: 'click', interactive: true, hideOnClick: true});
150+
}
151+
}
152+
143153
// Will be called when the show more (files) button has been pressed
144154
function onShowMoreFiles() {
145155
initRepoIssueContentHistory();
146156
initViewedCheckboxListenerFor();
147157
countAndUpdateViewedFiles();
148158
initImageDiff();
159+
initDiffHeaderPopup();
149160
}
150161

151162
export async function loadMoreFiles(url) {
@@ -221,6 +232,7 @@ export function initRepoDiffView() {
221232
initDiffFileList();
222233
initDiffCommitSelect();
223234
initRepoDiffShowMore();
235+
initDiffHeaderPopup();
224236
initRepoDiffFileViewToggle();
225237
initViewedCheckboxListenerFor();
226238
initExpandAndCollapseFilesButton();

web_src/js/features/repo-unicode-escape.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts';
1+
import {addDelegatedEventListener, hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.ts';
22

33
export function initUnicodeEscapeButton() {
4-
document.addEventListener('click', (e) => {
5-
const btn = e.target.closest('.escape-button, .unescape-button, .toggle-escape-button');
6-
if (!btn) return;
7-
4+
addDelegatedEventListener(document, 'click', '.escape-button, .unescape-button, .toggle-escape-button', (btn, e) => {
85
e.preventDefault();
96

10-
const fileContent = btn.closest('.file-content, .non-diff-file-content');
7+
const fileContentElemId = btn.getAttribute('data-file-content-elem-id');
8+
const fileContent = fileContentElemId ?
9+
document.querySelector(`#${fileContentElemId}`) :
10+
btn.closest('.file-content, .non-diff-file-content');
1111
const fileView = fileContent?.querySelectorAll('.file-code, .file-view');
1212
if (btn.matches('.escape-button')) {
1313
for (const el of fileView) el.classList.add('unicode-escaped');

web_src/js/utils/dom.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {debounce} from 'throttle-debounce';
22
import type {Promisable} from 'type-fest';
33
import type $ from 'jquery';
44

5-
type ElementArg = Element | string | NodeListOf<Element> | Array<Element> | ReturnType<typeof $>;
5+
type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array
6+
type ElementArg = Element | string | ArrayLikeIterable<Element> | ReturnType<typeof $>;
67
type ElementsCallback<T extends Element> = (el: T) => Promisable<any>;
78
type ElementsCallbackWithArgs = (el: Element, ...args: any[]) => Promisable<any>;
8-
type ArrayLikeIterable<T> = ArrayLike<T> & Iterable<T>; // for NodeListOf and Array
99

1010
function elementsCall(el: ElementArg, func: ElementsCallbackWithArgs, ...args: any[]) {
1111
if (typeof el === 'string' || el instanceof String) {

0 commit comments

Comments
 (0)