-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Improve "goto issue by number" button #24577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c008592
fix
wxiaoguang c5c3386
Update web_src/js/utils/dom.js
wxiaoguang 16777fd
Update web_src/js/features/common-issue-list.js
wxiaoguang d72af39
Merge branch 'main' into improve-goto-issue
wxiaoguang cb20419
Merge branch 'main' into improve-goto-issue
wxiaoguang b5371f8
Update web_src/js/features/common-issue-list.js
silverwind 30f00ff
debounce
wxiaoguang 6b69dc5
Update web_src/js/features/common-issue-list.js
silverwind 21416dd
Merge branch 'main' into improve-goto-issue
GiteaBot 239bf8c
Merge branch 'main' into improve-goto-issue
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import $ from 'jquery'; | ||
import {isElemHidden, onInputDebounce, toggleElem} from '../utils/dom.js'; | ||
const {appSubUrl} = window.config; | ||
|
||
const reIssueIndex = /^(\d+)$/; // eg: "123" | ||
const reIssueSharpIndex = /^#(\d+)$/; // eg: "#123" | ||
const reIssueOwnerRepoIndex = /^([-.\w]+)\/([-.\w]+)#(\d+)$/; // eg: "{owner}/{repo}#{index}" | ||
|
||
// if the searchText can be parsed to an "issue goto link", return the link, otherwise return empty string | ||
export function parseIssueListQuickGotoLink(repoLink, searchText) { | ||
searchText = searchText.trim(); | ||
let targetUrl = ''; | ||
if (repoLink) { | ||
// try to parse it in current repo | ||
if (reIssueIndex.test(searchText)) { | ||
targetUrl = `${repoLink}/issues/${searchText}`; | ||
} else if (reIssueSharpIndex.test(searchText)) { | ||
targetUrl = `${repoLink}/issues/${searchText.substr(1)}`; | ||
} | ||
} else { | ||
// try to parse it for a global search (eg: "owner/repo#123") | ||
const matchIssueOwnerRepoIndex = searchText.match(reIssueOwnerRepoIndex); | ||
if (matchIssueOwnerRepoIndex) { | ||
const [_, owner, repo, index] = matchIssueOwnerRepoIndex; | ||
targetUrl = `${appSubUrl}/${owner}/${repo}/issues/${index}`; | ||
} | ||
} | ||
return targetUrl; | ||
} | ||
|
||
export function initCommonIssueListQuickGoto() { | ||
const $goto = $('#issue-list-quick-goto'); | ||
if (!$goto.length) return; | ||
|
||
const $form = $goto.closest('form'); | ||
const $input = $form.find('input[name=q]'); | ||
const repoLink = $goto.attr('data-repo-link'); | ||
|
||
$form.on('submit', (e) => { | ||
// if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly | ||
let doQuickGoto = !isElemHidden($goto); | ||
const submitter = e.originalEvent.submitter; | ||
if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false; | ||
if (!doQuickGoto) return; | ||
|
||
// if there is a goto button, use its link | ||
e.preventDefault(); | ||
window.location.href = $goto.attr('data-issue-goto-link'); | ||
}); | ||
|
||
const onInput = async () => { | ||
const searchText = $input.val(); | ||
|
||
// try to check whether the parsed goto link is valid | ||
let targetUrl = parseIssueListQuickGotoLink(repoLink, searchText); | ||
if (targetUrl) { | ||
const res = await fetch(`${targetUrl}/info`); | ||
if (res.status !== 200) targetUrl = ''; | ||
} | ||
|
||
// if the input value has changed, then ignore the result | ||
if ($input.val() !== searchText) return; | ||
|
||
toggleElem($goto, Boolean(targetUrl)); | ||
$goto.attr('data-issue-goto-link', targetUrl); | ||
}; | ||
|
||
$input.on('input', onInputDebounce(onInput)); | ||
const _ = onInput(); | ||
silverwind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {test, expect} from 'vitest'; | ||
import {parseIssueListQuickGotoLink} from './common-issue-list.js'; | ||
|
||
test('parseIssueListQuickGotoLink', () => { | ||
expect(parseIssueListQuickGotoLink('/link', '')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('/link', 'abc')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('/link', '123')).toEqual('/link/issues/123'); | ||
expect(parseIssueListQuickGotoLink('/link', '#123')).toEqual('/link/issues/123'); | ||
expect(parseIssueListQuickGotoLink('/link', 'owner/repo#123')).toEqual(''); | ||
|
||
expect(parseIssueListQuickGotoLink('', '')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('', 'abc')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('', '123')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('', '#123')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('', 'owner/repo#')).toEqual(''); | ||
expect(parseIssueListQuickGotoLink('', 'owner/repo#123')).toEqual('/owner/repo/issues/123'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.