Skip to content

Commit

Permalink
[JENKINS-71983] allow symbols in MenuItem#withIconClass (#8471)
Browse files Browse the repository at this point in the history
[JENKINS-71983] fix symbols in MenuItem#withIconClass

when a symbol is passed to MenuItem#withIconClass the symbol is now
properly displayed
  • Loading branch information
mawinter69 committed Sep 10, 2023
1 parent 6b00394 commit d41b0f5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.apache.commons.jelly.XMLOutput;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.symbol.Symbol;
import org.jenkins.ui.symbol.SymbolRequest;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.HttpResponse;
Expand Down Expand Up @@ -436,8 +438,18 @@ public MenuItem withStockIcon(String icon) {
}

public MenuItem withIconClass(String iconClass) {
Icon iconByClass = IconSet.icons.getIconByClassSpec(iconClass + " icon-md");
this.icon = iconByClass == null ? null : iconByClass.getQualifiedUrl(getResourceUrl());
if (iconClass != null && iconClass.startsWith("symbol-")) {

Check warning on line 441 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 441 is only partially covered, 4 branches are missing
this.icon = iconClass;

Check warning on line 442 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 442 is not covered by tests
this.iconXml = Symbol.get(new SymbolRequest.Builder()

Check warning on line 443 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 443 is not covered by tests
.withName(iconClass.split(" ")[0].substring(7))

Check warning on line 444 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 444 is not covered by tests
.withPluginName(Functions.extractPluginNameFromIconSrc(iconClass))

Check warning on line 445 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 445 is not covered by tests
.withClasses("icon-md")

Check warning on line 446 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 446 is not covered by tests
.build()

Check warning on line 447 in core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 447 is not covered by tests
);
} else {
Icon iconByClass = IconSet.icons.getIconByClassSpec(iconClass + " icon-md");
this.icon = iconByClass == null ? null : iconByClass.getQualifiedUrl(getResourceUrl());
}
return this;
}

Expand Down

0 comments on commit d41b0f5

Please sign in to comment.