Skip to content

Commit

Permalink
Merge branch 'master' into command-palette
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Dec 8, 2024
1 parent 8c6024c commit 57d5411
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 183 deletions.
22 changes: 22 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -2582,4 +2583,25 @@ public static String generateItemId() {
public static ExtensionList<SearchFactory> getSearchFactories() {
return SearchFactory.all();
}

/**
* @param keyboardShortcut the shortcut to be translated
* @return the translated shortcut, e.g. CMD+K to ⌘+K for macOS, CTRL+K for Windows
*/
@Restricted(NoExternalUse.class)
public static String translateModifierKeysForUsersPlatform(String keyboardShortcut) {
StaplerRequest2 currentRequest = Stapler.getCurrentRequest2();
currentRequest.getWebApp().getDispatchValidator().allowDispatch(currentRequest, Stapler.getCurrentResponse2());
String userAgent = currentRequest.getHeader("User-Agent");

List<String> platformsThatUseCommand = List.of("MAC", "IPHONE", "IPAD");
boolean useCmdKey = platformsThatUseCommand.stream().anyMatch(e -> userAgent.toUpperCase().contains(e));

return keyboardShortcut.replace("CMD", useCmdKey ? "⌘" : "CTRL");
}

@Restricted(NoExternalUse.class)
public static String formatMessage(String format, Object args) {
return MessageFormat.format(format, args);
}
}
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ public void calcAutoCompleteSettings(String field, Map<String, Object> attribute
if (method == null)
return; // no auto-completion

// build query parameter line by figuring out what should be submitted
List<String> depends = buildFillDependencies(method, new ArrayList<>());
if (!depends.isEmpty()) {
attributes.put("fillDependsOn", String.join(" ", depends));
}

attributes.put("autoCompleteUrl", String.format("%s/%s/autoComplete%s", getCurrentDescriptorByNameUrl(), getDescriptorUrl(), capitalizedFieldName));
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public long getDataTimestamp() {
return updateData(DownloadService.loadJSON(new URL(getUrl() + "?id=" + URLEncoder.encode(getId(), StandardCharsets.UTF_8) + "&version=" + URLEncoder.encode(Jenkins.VERSION, StandardCharsets.UTF_8))), signatureCheck);
}

private FormValidation updateData(String json, boolean signatureCheck)
protected FormValidation updateData(String json, boolean signatureCheck)
throws IOException {

dataTimestamp = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ public Details newInstance(StaplerRequest2 req, JSONObject formData) throws Form
throw new FormException("Please confirm the password by typing it twice", "user.password2");
}

if (FIPS140.useCompliantAlgorithms() && pwd.length() < FIPS_PASSWORD_LENGTH) {
throw new FormException(Messages.HudsonPrivateSecurityRealm_CreateAccount_FIPS_PasswordLengthInvalid(), "user.password");
}

// will be null if it wasn't encrypted
String data = Protector.unprotect(pwd);
String data2 = Protector.unprotect(pwd2);
Expand Down
13 changes: 12 additions & 1 deletion core/src/main/resources/lib/layout/header/searchbox.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
<st:include it="${factory}" page="search.jelly" optional="true" />
</j:forEach>

<button id="button-open-command-palette" tooltip="${%Search}" data-keyboard-shortcut="CMD+K"
<j:set var="commandPaletteTooltip">
<div class="jenkins-keyboard-shortcut__tooltip">
<span class="jenkins-!-margin-right-1">
${%Search}
</span>
<l:keyboard-shortcut shortcut="CMD+K" />
</div>
</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}"
>
Expand Down
70 changes: 70 additions & 0 deletions core/src/main/resources/lib/layout/keyboard-shortcut.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!--
The MIT License
Copyright (c) 2023, 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:st="jelly:stapler" xmlns:l="/lib/layout">
<st:documentation>
<st:attribute name="shortcut" use="required">
The shortcut to display

CMD will automatically be translated to the user's operating system's appropriate variant

This attribute also supports Jenkins Symbols, values prefixed with 'symbol-' will be displayed as expected
</st:attribute>
<st:attribute name="message">
Optional tooltip message for the shortcut. Use the placeholder {0} escaped (wrapped in '). A minimal message consisting of
only the shortcut would be '{0}'
</st:attribute>
Displays a keyboard shortcut chip
</st:documentation>

<j:set var="tooltip">
<div class="jenkins-keyboard-shortcut__tooltip">
<j:set var="body">
<div class="jenkins-keyboard-shortcut jenkins-keyboard-shortcut--tooltip">
<j:choose>
<j:when test="${attrs.shortcut.startsWith('symbol-')}">
<l:icon src="${attrs.shortcut}" />
</j:when>
<j:otherwise>
${attrs.shortcut}
</j:otherwise>
</j:choose>
</div>
</j:set>
<j:out value="${h.formatMessage(message, h.translateModifierKeysForUsersPlatform(body))}"/>
</div>
</j:set>

<div class="jenkins-keyboard-shortcut" data-html-tooltip="${attrs.message != null ? tooltip : null}">
<j:choose>
<j:when test="${attrs.shortcut.startsWith('symbol-')}">
<l:icon src="${attrs.shortcut}" />
</j:when>
<j:otherwise>
${h.translateModifierKeysForUsersPlatform(attrs.shortcut)}
</j:otherwise>
</j:choose>
</div>
</j:jelly>
4 changes: 1 addition & 3 deletions core/src/main/resources/lib/layout/search-bar.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ THE SOFTWARE.
spellcheck="false"
disabled="${attrs.enabled == false ? true : null}" />
<j:if test="${attrs.hasKeyboardShortcut != 'false'}">
<div class="jenkins-search__shortcut" tooltip="${%Press / on your keyboard to focus}">
<l:icon src="symbol-search-shortcut" />
</div>
<l:keyboard-shortcut shortcut="symbol-search-shortcut" message="${%shortcut}" />
</j:if>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/resources/lib/layout/search-bar.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The MIT License
#
# Copyright (c) 2023, Damian Szczepanik
#
# 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.

shortcut=Press '{0}' on your keyboard to focus
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Press\ /\ on\ your\ keyboard\ to\ focus=Naciśnij / na klawiaturze, aby przesunąć tutaj kursor
shortcut=Naciśnij '{0}' na klawiaturze, aby przesunąć tutaj kursor
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# THE SOFTWARE.

Search=Busca
Press\ /\ on\ your\ keyboard\ to\ focus=Digite /\ no seu teclado para realçar
shortcut=Digite '{0}' no seu teclado para realçar
2 changes: 2 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module.exports = [
object: "readonly",
objectToUrlFormEncoded: "readonly",
onSetupWizardInitialized: "readonly",
qs: "readonly",
refillOnChange: "readonly",
refreshPart: "readonly",
registerSortableDragDrop: "readonly",
Expand All @@ -71,6 +72,7 @@ module.exports = [
shortenName: "readonly",
Sortable: "readonly",
toQueryString: "readonly",
TryEach: "readonly",
ts_refresh: "readonly",
updateOptionalBlock: "readonly",
Utilities: "readonly",
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@
"@babel/cli": "7.25.9",
"@babel/core": "7.26.0",
"@babel/preset-env": "7.26.0",
"@eslint/js": "9.15.0",
"@eslint/js": "9.16.0",
"babel-loader": "9.2.1",
"clean-webpack-plugin": "4.0.0",
"css-loader": "7.1.2",
"css-minimizer-webpack-plugin": "7.0.0",
"eslint": "9.15.0",
"eslint": "9.16.0",
"eslint-config-prettier": "9.1.0",
"eslint-formatter-checkstyle": "8.40.0",
"globals": "15.12.0",
"globals": "15.13.0",
"handlebars-loader": "1.7.3",
"mini-css-extract-plugin": "2.9.2",
"postcss": "8.4.49",
"postcss-loader": "8.1.1",
"postcss-preset-env": "10.1.1",
"postcss-scss": "4.0.9",
"prettier": "3.4.1",
"sass": "1.81.0",
"sass-loader": "16.0.3",
"prettier": "3.4.2",
"sass": "1.82.0",
"sass-loader": "16.0.4",
"style-loader": "4.0.0",
"stylelint": "16.11.0",
"stylelint-checkstyle-reporter": "1.0.0",
"stylelint-config-standard": "36.0.1",
"webpack": "5.96.1",
"webpack": "5.97.0",
"webpack-cli": "5.1.4",
"webpack-remove-empty-scripts": "1.0.4"
},
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ THE SOFTWARE.
</issueManagement>

<properties>
<revision>2.488</revision>
<revision>2.489</revision>
<changelist>-SNAPSHOT</changelist>
<project.build.outputTimestamp>2024-11-25T19:14:52Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-12-03T13:54:11Z</project.build.outputTimestamp>

<!-- configuration for patch tracker plugin -->
<project.patchManagement.system>github</project.patchManagement.system>
Expand Down Expand Up @@ -281,7 +281,7 @@ THE SOFTWARE.
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.20.1</version>
<version>10.20.2</version>
</dependency>
</dependencies>
<executions>
Expand Down
27 changes: 24 additions & 3 deletions src/main/js/components/dropdowns/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,30 @@ function init() {
}
return;
}
const url =
e.getAttribute("autoCompleteUrl") + "?value=" + encodeURIComponent(word);
fetch(url)

const url = e.getAttribute("autoCompleteUrl");

const depends = e.getAttribute("fillDependsOn");
const q = qs(e).addThis();
if (depends && depends.length > 0) {
depends.split(" ").forEach(
TryEach(function (n) {
q.nearBy(n);
}),
);
}

const queryString = q.toString();
const idx = queryString.indexOf("?");
const parameters = queryString.substring(idx + 1);

fetch(url, {
method: "post",
headers: crumb.wrap({
"Content-Type": "application/x-www-form-urlencoded",
}),
body: parameters,
})
.then((rsp) => (rsp.ok ? rsp.json() : {}))
.then((response) => createAndShowDropdown(e, response.suggestions || []));
}
Expand Down
67 changes: 67 additions & 0 deletions src/main/scss/components/_tooltips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@
margin: 0;
width: 450px;
}

.jenkins-keyboard-shortcut {
&::after {
content: "";
position: absolute;
inset: 0;
border-radius: 0.375rem;
border: 0.1rem solid var(--text-color-secondary);
opacity: 0.3;
mask-image: linear-gradient(
-45deg,
transparent 40%,
white,
transparent 60%
);
mask-size: 200% 200%;
animation: shortcut-glow-animation 1.25s forwards linear;
}

@keyframes shortcut-glow-animation {
0% {
opacity: 0;
mask-position: 100% 100%;
}

50% {
opacity: 1;
}

100% {
opacity: 0;
mask-position: 0;
}
}
}
}

.tippy-box[data-animation="tooltip"][data-state="hidden"] {
Expand All @@ -52,3 +87,35 @@
.jenkins-table .healthReportDetails {
display: none !important;
}

.jenkins-keyboard-shortcut {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 1.7em;
min-height: 1.7em;
padding-inline: 0.55ch;

&::before {
content: "";
position: absolute;
inset: 0;
border-radius: 0.375rem;
border: 0.1rem solid var(--text-color-secondary);
opacity: 0.3;
}

svg {
width: 1em;
height: 1em;
}
}

.jenkins-keyboard-shortcut__tooltip {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.6ch;
}
Loading

0 comments on commit 57d5411

Please sign in to comment.