-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Expose org.jenkins.ui.symbol.Symbol
#6659
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
Expose org.jenkins.ui.symbol.Symbol
#6659
Conversation
* Exposes the existing IconSet#getSymbol for plugins by adding a builder pattern and moving it to its own package and class to separate the symbol framework from the Icon one. * Added coverage to the existing method including symbol lookup from plugins
test/src/test/java/org/jenkins/ui/symbol/SymbolJenkinsTest.java
Outdated
Show resolved
Hide resolved
test/src/test/java/org/jenkins/ui/symbol/SymbolJenkinsTest.java
Outdated
Show resolved
Hide resolved
timja
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Needed something like this in credentials plugin.
There's a fork of IconSet basically. For the menu's, only way I got it working was calling the restricted code but I left it out of the change set in the end
NotMyFault
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one
|
To minimize problems integrating next week's core security fixes into jenkinsci/master, I'm on-holding this PR. |
|
Un-on-holding since the release is now out. |
| .replaceAll("(class=\").*?(\")", "") | ||
| .replaceAll("(tooltip=\").*?(\")", "") | ||
| .replaceAll("(id=\").*?(\")", "") | ||
| .replace("stroke:#000", "stroke:currentColor"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NotMyFault might this be the root cause of this PR instead? #6686
replace instead of replaceAll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dot of the price tag has no stroke defined, this replacement pattern wouldn't apply at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace replaces all, it's just not a regex. (Although the first arg seems to assume it's never #000000? Is that not a potential problem?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that 3 core symbols have stroke:#000 (lock-closed.svg, play.svg and power.svg)
And it appears twice in lock-closed.svg and power.svg so this could be updated. Not sure what is best between just fixing the svg files compared to changing this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dot of the price tag has no stroke defined, this replacement pattern wouldn't apply at all.
ah my bad.
it could be yes although I guess it's an assumption based on what ionicon's does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like everything is fine so far. However having some logic to validate symbols at build time would be interesting.
What comes to my mind:
- Check that each
pathhas at least one offill,strokedefined and set to eithernoneorcurrentColor. Could be defined either through attribute or throughstyle.
|
Please take a moment and address the merge conflicts of your pull request. Thanks! |
|
Could I get a review from @jenkinsci/core-security-review ? This has been hanging for a while now. |
|
Please take a moment and address the merge conflicts of your pull request. Thanks! |
|
As far as I can tell the only pending task left on this PR is a validation of the proposed new API with a consumer. We have identified one possible consumer, the Credentials plugin. Given Vincent's limited availability, we would welcome any community contributions to adapt the Credentials plugin to the new API proposed in this PR. |
|
I've had a look at the credentials plugin and I'm not sure if this API is useful for it. It's after an Icon not a symbol. and fixing the issue there with symbols in context menus not working will likely require more refactoring in core around context menus and symbols. I can't see a way with the current API to make it work right now. |
Is that a use case that we would expect this API to work with? If so, that would be an indication to me that the API needs further refinement to support this use case before this PR can be merged. |
Unsure, the credentials plugin context menu code is not easy to reason with. I or someone else will need more time in there to try unravel it. I think this API is a net positive, it would make that sort of thing easier to implement in the future. |
Fair enough. I don't think we should move forward with this PR until we become sure one way or another. Committing to an API that doesn't necessarily satisfy all use cases could be a liability in the future, since changing an API to accommodate new use cases while retaining compatibility once there are existing consumers is much harder (and in some cases impossible) compared to getting the design right at the outset. |
| .withName("science") | ||
| .withPluginName("missing-plugin") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would not work out of the box in my use case. I have a given symbol as full referenced string with plugin included, e.g. "symbol-solid/triangle-exclamation plugin-font-awesome-api". I can split this manually before and after the space but it would be simpler if another builder method would be available that takes the whole string. What do you think, does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to use the new API in jenkinsci/prism-api-plugin#60. However, it seems that I only get a cross as icon. It would be really helpful if we can add some logging why an icon is not found :-(
It seems I need to strip the plugin- and symbol- prefixes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I got it working now:
name = "symbol-solid/triangle-exclamation plugin-font-awesome-api";
String[] elements = StringUtils.split(name);
if (elements.length == 2) {
String symbol = Symbol.get(new SymbolRequest.Builder()
.withName(StringUtils.removeStart(elements[0], "symbol-"))
.withPluginName(StringUtils.removeStart(elements[1], "plugin-"))
.withClasses(ICON_MD)
.build());
return new UnescapedText(symbol);
}
From my perspective it would be helpful, if there would be another builder method (something like withId or withIdentifier), that takes the whole symbol identifier and splits it accordingly.
|
@Vlatombe are you planning to finish this PR in the near future? |
|
@uhafner I pushed a new method based on what you commented earlier. Let me know if it satisfies your use case. |
|
Please take a moment and address the merge conflicts of your pull request. Thanks! |
Yes, this is exactly what I need. It seems that the incremental has not been published so I cannot test, but from the code and test case it looks good! |
|
I tested the new implementation, it works as expected! (See https://github.com/jenkinsci/prism-api-plugin/blob/599a3307af0e4e6263db95cee1ed79f7ae541131/src/main/java/io/jenkins/plugins/prism/SourcePrinter.java#L105-L113) 🎉 |
|
/label ready-for-merge This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback. Thanks! |
In some cases, plugins need to generate markup with symbols (for example when generating
FormValidationwith html markup). This is adding a way for them to build such markup.This also improves coverage for this method.
IconSet#getSymbolfor plugins by adding a builderpattern, moving it to its own package and class to separate the
Symbol framework from the Icon one.
plugins
See JENKINS-XXXXX.
Proposed changelog entries
Proposed upgrade guidelines
N/A
Submitter checklist
Proposed changelog entriessection only if there are breaking changes or other changes which may require extra steps from users during the upgrade@Restrictedor have@since TODOJavadoc, as appropriate.Desired reviewers
@mention
Maintainer checklist
Before the changes are marked as
ready-for-merge:Proposed changelog entriesare accurate, human-readable, and in the imperative moodupgrade-guide-neededlabel is set and there is aProposed upgrade guidelinessection in the PR title. (example)lts-candidateto be considered (see query).