Skip to content

Commit

Permalink
[JENKINS-71326] - Support colored badges in breadcrumb dropdown (#8853)
Browse files Browse the repository at this point in the history
* [JENKINS-71326] - Support colored badges in breadcrumb dropdown

* [JENKINS-71326] - Support colored badges in breadcrumb dropdown - Creating a badge jelly view.

* [JENKINS-71326] - Support colored badges in breadcrumb dropdown - Adding class attribute to the badge jelly.

* Apply suggestions from code review

Co-authored-by: Alexander Brandes <brandes.alexander@web.de>

* [JENKINS-71326] - Support colored badges in breadcrumb dropdown - Lint and license Fix

---------

Co-authored-by: Alexander Brandes <brandes.alexander@web.de>
  • Loading branch information
eduardojandre and NotMyFault authored Feb 12, 2024
1 parent 510867a commit 8b94924
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 76 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/jenkins/management/Badge.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public String getTooltip() {
*
* @return severity as String
*/
@Exported(visibility = 999)
public String getSeverity() {
return severity.toString().toLowerCase(Locale.US);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@ THE SOFTWARE.
<a href="${m.urlName}">
<div class="jenkins-section__item__icon" aria-hidden="true">
<l:icon src="${m.iconFileName}" class="icon" />
<j:set var="badge" value="${m.badge}"/>
<j:if test="${badge != null}">
<div tooltip="${badge.tooltip}" class="jenkins-section__item__icon__badge alert-${badge.severity}">
${badge.text}
</div>
</j:if>
<l:badge badge="${m.badge}" class="jenkins-section__item__icon__badge"/>
</div>
<dl>
<dt>${m.displayName}</dt>
Expand Down
46 changes: 46 additions & 0 deletions core/src/main/resources/lib/layout/badge.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
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:st="jelly:stapler">
<st:documentation>
If a Badge is informed it will be displayed, otherwise nothing is done.

@since TODO
<st:attribute name="badge" type="jenkins.management.Badge">
Badge to be displayed, accepts null value.

@since TODO
</st:attribute>
<st:attribute name="class" use="optional">
Additional class to be applied.

@since TODO
</st:attribute>
</st:documentation>
<j:if test="${attrs.badge != null}">
<span class="jenkins-badge alert-${attrs.badge.severity} ${attrs.class?:''}" tooltip="${attrs.badge.tooltip}">
${attrs.badge.text}
</span>
</j:if>
</j:jelly>
18 changes: 3 additions & 15 deletions core/src/main/resources/lib/layout/task.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ THE SOFTWARE.
<l:icon src="${icon}" />
</span>
<span class="task-link-text">${title}</span>
<j:if test="${attrs.badge != null}">
<span class="task-icon-badge" tooltip="${attrs.badge.tooltip}">
${attrs.badge.text}
</span>
</j:if>
<l:badge badge="${attrs.badge}" class="task-icon-badge"/>
</span>
</span>
</div>
Expand All @@ -181,11 +177,7 @@ THE SOFTWARE.
<l:icon src="${icon}" />
</span>
<span>${title}</span>
<j:if test="${attrs.badge != null}">
<span class="task-icon-badge" tooltip="${attrs.badge.tooltip}">
${attrs.badge.text}
</span>
</j:if>
<l:badge badge="${attrs.badge}" class="task-icon-badge"/>
</l:confirmationLink>
</j:when>

Expand All @@ -202,11 +194,7 @@ THE SOFTWARE.
<l:icon src="${icon}" />
</span>
<span class="task-link-text">${title}</span>
<j:if test="${attrs.badge != null}">
<span class="task-icon-badge" tooltip="${attrs.badge.tooltip}">
${attrs.badge.text}
</span>
</j:if>
<l:badge badge="${attrs.badge}" class="task-icon-badge"/>
</m:a>
<st:adjunct includes="lib.layout.task.task" />
</j:otherwise>
Expand Down
4 changes: 3 additions & 1 deletion war/src/main/js/components/dropdowns/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ function menuItem(options) {
const label = xmlEscape(itemOptions.label);
let badgeText;
let badgeTooltip;
let badgeSeverity;
if (itemOptions.badge) {
badgeText = xmlEscape(itemOptions.badge.text);
badgeTooltip = xmlEscape(itemOptions.badge.tooltip);
badgeSeverity = xmlEscape(itemOptions.badge.severity);
}
const tag = itemOptions.type === "link" ? "a" : "button";

Expand All @@ -58,7 +60,7 @@ function menuItem(options) {
${label}
${
itemOptions.badge != null
? `<span class="jenkins-dropdown__item__badge" tooltip="${badgeTooltip}">${badgeText}</span>`
? `<span class="jenkins-dropdown__item__badge jenkins-badge alert-${badgeSeverity}" tooltip="${badgeTooltip}">${badgeText}</span>`
: ``
}
${
Expand Down
29 changes: 29 additions & 0 deletions war/src/main/scss/components/_badges.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,32 @@
.am-badge {
display: inline;
}

.jenkins-badge {
display: flex;
align-items: center;
justify-content: center;
border-radius: 100px;
font-size: 0.7rem;
min-height: 20px;
min-width: 20px;
padding: 0 0.4rem;
box-shadow: 0 1px 1px rgba(black, 0.1);
animation: animate-in-badge var(--elastic-transition) 0.1s both;

&::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(white, black);
border-radius: 100px;
mix-blend-mode: overlay;
opacity: 0.35;
}
}

@keyframes animate-in-badge {
from {
transform: scale(0);
}
}
10 changes: 0 additions & 10 deletions war/src/main/scss/components/_dropdowns.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,8 @@ $dropdown-padding: 0.4rem;
}

&__badge {
position: relative;
margin-left: auto;
margin-right: -0.85rem;

&::before {
content: "";
position: absolute;
inset: -0.0625rem -0.375rem;
background: var(--text-color-secondary);
opacity: 0.1;
border-radius: 100vmax;
}
}

&__chevron {
Expand Down
26 changes: 0 additions & 26 deletions war/src/main/scss/components/_section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,6 @@
position: absolute;
top: -4px;
right: -4px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 100px;
font-size: 0.7rem;
min-height: 20px;
min-width: 20px;
padding: 0 0.4rem;
box-shadow: 0 1px 1px rgba(black, 0.1);
animation: animate-in-badge var(--elastic-transition) 0.1s both;

&::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(white, black);
border-radius: 100px;
mix-blend-mode: overlay;
opacity: 0.35;
}
}
}

Expand All @@ -140,9 +120,3 @@
font-size: 0.925rem;
}
}

@keyframes animate-in-badge {
from {
transform: scale(0);
}
}
18 changes: 0 additions & 18 deletions war/src/main/scss/components/_side-panel-tasks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,7 @@ $background-outset: 0.7rem;
}

.task-icon-badge {
position: relative;
color: currentColor;
letter-spacing: 0;
z-index: 0;
margin-left: auto;
min-width: 24px;
text-align: center;
padding: 0 8px;
line-height: 0.75rem;
font-size: 0.75rem;

&::before {
content: "";
position: absolute;
inset: -6px 0;
background: var(--item-background--hover);
border-radius: 100px;
z-index: -1;
}
}

.task-link-text {
Expand Down

0 comments on commit 8b94924

Please sign in to comment.