Skip to content

Commit 1144b1d

Browse files
Add goto issue id function (#24479)
for #4109 (comment) Supports format: `#1234` `Org/Repo#1234` --------- Co-authored-by: techknowlogick <[email protected]>
1 parent 0bb5288 commit 1144b1d

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ repos = Repositories
308308
users = Users
309309
organizations = Organizations
310310
search = Search
311+
go_to = Go to
311312
code = Code
312313
search.type.tooltip = Search type
313314
search.fuzzy = Fuzzy

templates/repo/issue/search.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<input type="hidden" name="assignee" value="{{$.AssigneeID}}">
99
<input type="hidden" name="poster" value="{{$.PosterID}}">
1010
<input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}...">
11-
<button class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">
11+
<button id="hashtag-button" class="ui small icon button gt-hidden" data-tooltip-content="{{.locale.Tr "explore.go_to"}}">{{svg "octicon-hash"}}</button>
12+
<button id="search-button" class="ui small icon button" aria-label="{{.locale.Tr "explore.search"}}">
1213
{{svg "octicon-search"}}
1314
</button>
1415
</div>

templates/user/dashboard/issues.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
<input type="hidden" name="sort" value="{{$.SortType}}">
7979
<input type="hidden" name="state" value="{{$.State}}">
8080
<input name="q" value="{{$.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}...">
81-
<button class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">{{svg "octicon-search"}}</button>
81+
<button id="hashtag-button" class="ui small icon button gt-hidden" data-tooltip-content="{{.locale.Tr "explore.go_to"}}">{{svg "octicon-hash"}}</button>
82+
<button id="search-button" class="ui small icon button" aria-label="{{.locale.Tr "explore.search"}}">{{svg "octicon-search"}}</button>
8283
</div>
8384
</form>
8485
<!-- Sort -->

web_src/js/features/repo-issue.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {showTemporaryTooltip, createTippy} from '../modules/tippy.js';
44
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
55
import {setFileFolding} from './file-fold.js';
66
import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
7+
import {parseIssueHref} from '../utils.js';
78

89
const {appSubUrl, csrfToken} = window.config;
910

@@ -636,3 +637,31 @@ export function initRepoIssueBranchSelect() {
636637
};
637638
$('#branch-select > .item').on('click', changeBranchSelect);
638639
}
640+
641+
export function initRepoIssueGotoID() {
642+
const issueidre = /^(?:\w+\/\w+#\d+|#\d+|\d+)$/;
643+
const isGlobalIssuesArea = $('.repo.name.item').length > 0; // for global issues area or repository issues area
644+
$('form.list-header-search').on('submit', (e) => {
645+
const qval = e.target.q.value;
646+
const aElm = document.activeElement;
647+
if (!$('#hashtag-button').length || aElm.id === 'search-button' || (aElm.name === 'q' && !qval.includes('#')) || (isGlobalIssuesArea && !qval.includes('/')) || !issueidre.test(qval)) return;
648+
const pathname = window.location.pathname;
649+
let gotoUrl = qval.includes('/') ? `${qval.replace('#', '/issues/')}` : `${pathname}/${qval.replace('#', '')}`;
650+
if (appSubUrl.length) {
651+
gotoUrl = qval.includes('/') ? `/${appSubUrl}/${qval.replace('#', '/issues/')}` : `/${appSubUrl}/${pathname}/${qval.replace('#', '')}`;
652+
}
653+
const {owner, repo, type, index} = parseIssueHref(gotoUrl);
654+
if (owner && repo && type && index) {
655+
e.preventDefault();
656+
window.location.href = gotoUrl;
657+
}
658+
});
659+
$('form.list-header-search input[name=q]').on('input', (e) => {
660+
const qval = e.target.value;
661+
if (isGlobalIssuesArea && qval.includes('/') && issueidre.test(qval) || !isGlobalIssuesArea && issueidre.test(qval)) {
662+
showElem($('#hashtag-button'));
663+
} else {
664+
hideElem($('#hashtag-button'));
665+
}
666+
});
667+
}

web_src/js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
initRepoIssueWipTitle,
3131
initRepoPullRequestMergeInstruction,
3232
initRepoPullRequestAllowMaintainerEdit,
33-
initRepoPullRequestReview, initRepoIssueSidebarList,
33+
initRepoPullRequestReview, initRepoIssueSidebarList, initRepoIssueGotoID
3434
} from './features/repo-issue.js';
3535
import {
3636
initRepoEllipsisButton,
@@ -175,4 +175,5 @@ onDomReady(() => {
175175
initUserAuthWebAuthnRegister();
176176
initUserSettings();
177177
initRepoDiffView();
178+
initRepoIssueGotoID();
178179
});

0 commit comments

Comments
 (0)