-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul search with a Command Palette (#7569)
Co-authored-by: Wadeck Follonier <[email protected]> Co-authored-by: Tim Jacomb <[email protected]> Co-authored-by: Alexander Brandes <[email protected]> Co-authored-by: Tim Jacomb <[email protected]>
- Loading branch information
1 parent
f6802dd
commit 930c7ff
Showing
28 changed files
with
600 additions
and
163 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
6 changes: 0 additions & 6 deletions
6
core/src/main/resources/jenkins/views/JenkinsHeader/search-box.js
This file was deleted.
Oops, something went wrong.
This file contains 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,47 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2024, Jenkins contributors | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:s="jelly:stapler" xmlns:l="/lib/layout"> | ||
<s:documentation> | ||
The command palette overlay | ||
</s:documentation> | ||
|
||
<div id="command-palette-i18n" class="i18n" | ||
data-no-results-for="${%No results for}" | ||
data-help="${%Help}" | ||
data-get-help="${%Get help using Jenkins search}" | ||
/> | ||
|
||
<dialog id="command-palette" class="jenkins-command-palette__dialog"> | ||
<div class="jenkins-command-palette__wrapper"> | ||
<div class="jenkins-command-palette"> | ||
<l:search-bar id="command-bar" clazz="jenkins-command-palette__search" hasKeyboardShortcut="false" /> | ||
<div id="search-results-container" class="jenkins-command-palette__results-container"> | ||
<div id="search-results" class="jenkins-command-palette__results" /> | ||
</div> | ||
</div> | ||
</div> | ||
</dialog> | ||
</j:jelly> |
38 changes: 20 additions & 18 deletions
38
core/src/main/resources/lib/layout/header/searchbox.jelly
This file contains 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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout"> | ||
<div class="searchbox hidden-xs"> | ||
<!-- search box --> | ||
<j:set var="searchURL" value="${h.searchURL}"/> | ||
<form action="${searchURL}" method="get" style="position:relative;" class="no-json" name="search" role="search"> | ||
<!-- this div is used to calculate the width of the text box --> | ||
<div id="search-box-sizer"/> | ||
<div id="searchform"> | ||
<input name="q" placeholder="${searchPlaceholder}" id="search-box" class="main-search__input" value="${request.getParameter('q')}" role="searchbox" /> | ||
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler"> | ||
<div class="page-header__hyperlinks"> | ||
<j:forEach var="factory" items="${h.searchFactories}"> | ||
<st:include it="${factory}" page="search.jelly" optional="true" /> | ||
</j:forEach> | ||
|
||
<span class="main-search__icon-leading"> | ||
<l:icon src="symbol-search"/> | ||
<j:set var="commandPaletteTooltip"> | ||
<div class="jenkins-keyboard-shortcut__tooltip"> | ||
<span class="jenkins-!-margin-right-1"> | ||
${%Search} | ||
</span> | ||
<a href="${searchHelpUrl}" class="main-search__icon-trailing"> | ||
<l:icon src="symbol-help-circle"/> | ||
</a> | ||
|
||
<div id="search-box-completion" data-search-url="${searchURL}" /> | ||
<st:adjunct includes="jenkins.views.JenkinsHeader.search-box" /> | ||
<l:keyboard-shortcut shortcut="CMD+K" /> | ||
</div> | ||
</form> | ||
</j:set> | ||
|
||
<button id="button-open-command-palette" | ||
data-html-tooltip="${commandPaletteTooltip}" | ||
data-keyboard-shortcut="CMD+K" | ||
data-search-url="${rootURL + '/search/suggest'}" | ||
data-search-help-url="${searchHelpUrl}" | ||
> | ||
<l:icon src="symbol-search" /> | ||
</button> | ||
</div> | ||
<script src="${resURL}/jsbundles/keyboard-shortcuts.js" type="text/javascript"/> | ||
</j:jelly> |
This file contains 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 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 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,10 @@ | ||
/** | ||
* @param {string} searchTerm | ||
*/ | ||
function search(searchTerm) { | ||
const address = document.getElementById("button-open-command-palette").dataset | ||
.searchUrl; | ||
return fetch(`${address}?query=${encodeURIComponent(searchTerm)}`); | ||
} | ||
|
||
export default { search: search }; |
This file contains 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 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,29 @@ | ||
import { LinkResult } from "./models"; | ||
import Search from "@/api/search"; | ||
import * as Symbols from "./symbols"; | ||
|
||
export const JenkinsSearchSource = { | ||
execute(query) { | ||
const rootUrl = document.head.dataset.rooturl; | ||
|
||
function correctAddress(url) { | ||
if (url.startsWith("/")) { | ||
url = url.substring(1); | ||
} | ||
|
||
return rootUrl + "/" + url; | ||
} | ||
|
||
return Search.search(query).then((rsp) => | ||
rsp.json().then((data) => { | ||
return data["suggestions"].slice().map((e) => | ||
LinkResult({ | ||
icon: Symbols.SEARCH, | ||
label: e.name, | ||
url: correctAddress(e.url), | ||
}), | ||
); | ||
}), | ||
); | ||
}, | ||
}; |
Oops, something went wrong.