Skip to content
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

Add goto issue id function #24479

Merged
merged 19 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ repos = Repositories
users = Users
organizations = Organizations
search = Search
goto = Goto
tyroneyeh marked this conversation as resolved.
Show resolved Hide resolved
code = Code
search.type.tooltip = Search type
search.fuzzy = Fuzzy
Expand Down
3 changes: 2 additions & 1 deletion templates/repo/issue/search.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<input type="hidden" name="assignee" value="{{$.AssigneeID}}">
<input type="hidden" name="poster" value="{{$.PosterID}}">
<input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}...">
<button class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">
<button id="hashtag-button" class="ui small icon button gt-hidden" type="submit" aria-label="{{.locale.Tr "explore.goto"}}">{{svg "octicon-hash"}}</button>
tyroneyeh marked this conversation as resolved.
Show resolved Hide resolved
<button id="search-button" class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">
{{svg "octicon-search"}}
</button>
</div>
Expand Down
3 changes: 2 additions & 1 deletion templates/user/dashboard/issues.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
<input type="hidden" name="sort" value="{{$.SortType}}">
<input type="hidden" name="state" value="{{$.State}}">
<input name="q" value="{{$.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}...">
<button class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">{{svg "octicon-search"}}</button>
<button id="hashtag-button" class="ui small icon button gt-hidden" type="submit" aria-label="{{.locale.Tr "explore.goto"}}">{{svg "octicon-hash"}}</button>
<button id="search-button" class="ui small icon button" type="submit" aria-label="{{.locale.Tr "explore.search"}}">{{svg "octicon-search"}}</button>
</div>
</form>
<!-- Sort -->
Expand Down
20 changes: 20 additions & 0 deletions web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,23 @@ export function initRepoIssueBranchSelect() {
};
$('#branch-select > .item').on('click', changeBranchSelect);
}

export function initRepoIssueGotoID() {
const issueidre = /^(?:\w+\/\w+#\d+|#\d+|\d+)$/;
$('form.list-header-search').on('submit', (e) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class list-header-search has also been used on milestone search but only issues search are expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This on milestones no effect

const qval = e.target.q.value;
const aElm = document.activeElement;
if (aElm.id === 'search-button' || (aElm.name === 'q' && !qval.includes('#')) || (window.location.pathname.split('/').length === 2 && !qval.includes('/')) || !issueidre.test(qval) || !$('#hashtag-button').length) return;
e.preventDefault();
window.location.href = !qval.includes('/') ? `${window.location.pathname}/${qval.replace('#', '')}` : `/${qval.replace('#', '/issues/')}`;
});
$('form.list-header-search input[name=q]').on('keyup', (e) => {
tyroneyeh marked this conversation as resolved.
Show resolved Hide resolved
const qval = e.target.value;
const pathSlashCount = window.location.pathname.split('/'); // for global issues area or repository issue area
if ((pathSlashCount.length === 2 && qval.includes('/') || pathSlashCount.length === 4) && issueidre.test(qval)) {
showElem($('#hashtag-button'));
} else {
hideElem($('#hashtag-button'));
}
});
}
3 changes: 2 additions & 1 deletion web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
initRepoIssueWipTitle,
initRepoPullRequestMergeInstruction,
initRepoPullRequestAllowMaintainerEdit,
initRepoPullRequestReview, initRepoIssueSidebarList,
initRepoPullRequestReview, initRepoIssueSidebarList, initRepoIssueGotoID
} from './features/repo-issue.js';
import {
initRepoEllipsisButton,
Expand Down Expand Up @@ -175,4 +175,5 @@ onDomReady(() => {
initUserAuthWebAuthnRegister();
initUserSettings();
initRepoDiffView();
initRepoIssueGotoID();
});