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

Update appearance of keyboard shortcut tooltips #8435

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0d8e1a2
Init
janfaracik Aug 23, 2023
1783029
yarn lint:fix
timja Aug 25, 2023
ec58717
Merge branch 'master' into keyboard-shortcut-animation
janfaracik Nov 5, 2023
231631d
Merge branch 'master' into keyboard-shortcut-animation
janfaracik Nov 20, 2023
3996dc0
Address comments
janfaracik Nov 20, 2023
95be904
Merge branch 'master' into keyboard-shortcut-animation
janfaracik Nov 26, 2023
8c2ef1a
Update localisation
timja Dec 16, 2023
b5d4170
Merge branch 'master' into keyboard-shortcut-animation
timja Dec 16, 2023
ce09ad8
Update core/src/main/java/hudson/Functions.java
timja Dec 17, 2023
f0efb07
Merge branch 'master' into keyboard-shortcut-animation
timja Apr 3, 2024
5551fc9
Allow setting empty prefix or suffix
timja Apr 3, 2024
f925849
Combine into one format string with escaped format placeholder
daniel-beck Apr 20, 2024
cd1cd50
Merge branch 'master' into keyboard-shortcut-animation
timja May 19, 2024
dadcd51
Merge branch 'master' into keyboard-shortcut-animation
janfaracik May 26, 2024
b0d87b9
Add english default message
timja May 29, 2024
02a8466
More detailed wording for message attribute
timja Jun 3, 2024
ae0685a
Merge branch 'master' into keyboard-shortcut-animation
janfaracik Aug 4, 2024
08c24de
Update keyboard shortcut component
janfaracik Aug 4, 2024
f9fad99
Merge branch 'master' into keyboard-shortcut-animation
janfaracik Sep 13, 2024
08a248c
Merge branch 'master' into keyboard-shortcut-animation
janfaracik Sep 16, 2024
f3913dd
Update core/src/main/java/hudson/Functions.java
timja Sep 16, 2024
b893717
Adapt for Java EE upgrade
timja Sep 16, 2024
34f77dd
Merge branch 'master' into keyboard-shortcut-animation
timja Oct 12, 2024
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
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 @@ -117,6 +117,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 @@ -2489,4 +2490,25 @@
public static String generateItemId() {
return String.valueOf(Math.floor(Math.random() * 3000));
}

/**
* @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) {
daniel-beck marked this conversation as resolved.
Show resolved Hide resolved
StaplerRequest currentRequest = Stapler.getCurrentRequest();
timja marked this conversation as resolved.
Show resolved Hide resolved
currentRequest.getWebApp().getDispatchValidator().allowDispatch(currentRequest, Stapler.getCurrentResponse());
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");

Check warning on line 2507 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 2507 is only partially covered, one branch is missing
}

@Restricted(NoExternalUse.class)
public static String formatMessage(String format, Object args) {
return MessageFormat.format(format, args);
}
}
43 changes: 43 additions & 0 deletions core/src/main/resources/lib/layout/keyboard-shortcut.jelly
timja marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
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:d="jelly:define">
<st:documentation>
<st:attribute name="message">
Optional message for the shortcut
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Optional message for the shortcut
Tooltip message for the shortcut. Use the placeholder <code>{0}</code> escaped (wrapped in <code>&quot;</code>). A minimal message consisting of only the shortcut would be <code>&quot;{0}&quot;</code>.

(Assuming <code> works here.)

Copy link
Member

Choose a reason for hiding this comment

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

it renders the code and &quot literally with the intellij plugin, unsure about stapler-maven-plugin itself, searching the code I couldn't see any handling of it though.

</st:attribute>
Displays a keyboard shortcut chip based on the component's body.
CMD will automatically be translated to the user's operating system's appropriate variant.
</st:documentation>

<div class="jenkins-tooltip__keyboard-shortcut">
<j:set var="body">
<div class="jenkins-tooltip__keyboard-shortcut__symbol">
<d:invokeBody trim="true" />
</div>
</j:set>
<j:out value="${h.formatMessage(message, h.translateModifierKeysForUsersPlatform(body))}" />
</div>
</j:jelly>
7 changes: 6 additions & 1 deletion core/src/main/resources/lib/layout/search-bar.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ 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}">
<j:set var="tooltip">
<l:keyboard-shortcut message="${%shortcut}">
<l:icon src="symbol-search-shortcut" />
</l:keyboard-shortcut>
</j:set>
<div class="jenkins-search__shortcut" data-html-tooltip="${tooltip}">
<l:icon src="symbol-search-shortcut" />
</div>
</j:if>
Expand Down
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
59 changes: 59 additions & 0 deletions war/src/main/scss/components/_tooltips.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,62 @@
.jenkins-table .healthReportDetails {
display: none !important;
}

.jenkins-tooltip__keyboard-shortcut {
display: flex;
align-items: center;
justify-content: center;
gap: 0.6ch;

&__symbol {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 1.7em;
height: 1.7em;
padding-inline: 0.5ch;

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

&::after {
mask-image: linear-gradient(
-45deg,
transparent 40%,
white,
transparent 60%
);
mask-size: 200% 200%;
animation: shortcut-glow-animation 1.25s forwards linear;
}

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

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

50% {
opacity: 1;
}

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