Skip to content

Conversation

@Vlatombe
Copy link
Member

@Vlatombe Vlatombe commented Jun 14, 2022

In some cases, plugins need to generate markup with symbols (for example when generating FormValidation with html markup). This is adding a way for them to build such markup.

This also improves coverage for this method.

  • Exposes the existing IconSet#getSymbol for plugins by adding a builder
    pattern, 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

See JENKINS-XXXXX.

Proposed changelog entries

  • Developer: allow plugins to generate symbol markup from Java code.
  • ...

Proposed upgrade guidelines

N/A

Submitter checklist

  • (If applicable) Jira issue is well described
  • Changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developer, depending on the change) and are in the imperative mood. Examples
    • Fill-in the Proposed changelog entries section only if there are breaking changes or other changes which may require extra steps from users during the upgrade
  • Appropriate autotests or explanation to why this change has no tests
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadoc, as appropriate.
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@mention

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

* 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
@Vlatombe Vlatombe requested review from a team and janfaracik June 14, 2022 11:32
@timja timja requested a review from a team June 14, 2022 14:33
@timja timja added the rfe For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Jun 14, 2022
Copy link
Member

@timja timja left a 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

Copy link
Member

@NotMyFault NotMyFault left a comment

Choose a reason for hiding this comment

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

Nice one

@daniel-beck
Copy link
Member

To minimize problems integrating next week's core security fixes into jenkinsci/master, I'm on-holding this PR.

@daniel-beck daniel-beck added the on-hold This pull request depends on another event/release, and it cannot be merged right now label Jun 14, 2022
@daniel-beck daniel-beck removed the on-hold This pull request depends on another event/release, and it cannot be merged right now label Jun 22, 2022
@daniel-beck
Copy link
Member

Un-on-holding since the release is now out.

.replaceAll("(class=\").*?(\")", "")
.replaceAll("(tooltip=\").*?(\")", "")
.replaceAll("(id=\").*?(\")", "")
.replace("stroke:#000", "stroke:currentColor");
Copy link
Member

@timja timja Jun 23, 2022

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?

Copy link
Member

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.

Copy link
Member

@daniel-beck daniel-beck Jun 23, 2022

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?)

Copy link
Member Author

@Vlatombe Vlatombe Jun 23, 2022

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.

Copy link
Member

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

Copy link
Member Author

@Vlatombe Vlatombe Jun 23, 2022

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 path has at least one of fill,stroke defined and set to either none or currentColor. Could be defined either through attribute or through style.

@timja timja added the needs-security-review Awaiting review by a security team member label Jun 23, 2022
@timja timja requested a review from a team June 23, 2022 21:29
@NotMyFault NotMyFault added the web-ui The PR includes WebUI changes which may need special expertise label Jun 26, 2022
@github-actions
Copy link
Contributor

Please take a moment and address the merge conflicts of your pull request. Thanks!

@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Jul 15, 2022
@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label Jul 20, 2022
@Vlatombe
Copy link
Member Author

Could I get a review from @jenkinsci/core-security-review ? This has been hanging for a while now.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2022

Please take a moment and address the merge conflicts of your pull request. Thanks!

@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label Sep 2, 2022
@basil
Copy link
Member

basil commented Sep 2, 2022

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.

@timja
Copy link
Member

timja commented Sep 5, 2022

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.

@basil
Copy link
Member

basil commented Sep 13, 2022

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.

@timja
Copy link
Member

timja commented Sep 13, 2022

Is that a use case that we would expect this API to work with

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.

@basil
Copy link
Member

basil commented Sep 13, 2022

Unsure

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.

Comment on lines +25 to +26
.withName("science")
.withPluginName("missing-plugin")
Copy link
Member

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?

Copy link
Member

@uhafner uhafner Sep 23, 2022

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.

Copy link
Member

@uhafner uhafner Sep 23, 2022

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.

@uhafner
Copy link
Member

uhafner commented Nov 22, 2022

@Vlatombe are you planning to finish this PR in the near future?

@Vlatombe
Copy link
Member Author

@uhafner I pushed a new method based on what you commented earlier. Let me know if it satisfies your use case.

@github-actions github-actions bot added the unresolved-merge-conflict There is a merge conflict with the target branch. label Nov 25, 2022
@github-actions
Copy link
Contributor

Please take a moment and address the merge conflicts of your pull request. Thanks!

@uhafner
Copy link
Member

uhafner commented Nov 26, 2022

@uhafner I pushed a new method based on what you commented earlier. Let me know if it satisfies your use case.

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!

@uhafner
Copy link
Member

uhafner commented Nov 29, 2022

@github-actions github-actions bot removed the unresolved-merge-conflict There is a merge conflict with the target branch. label Dec 14, 2022
@timja
Copy link
Member

timja commented Dec 14, 2022

/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!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Dec 14, 2022
@NotMyFault NotMyFault merged commit 53e59bb into jenkinsci:master Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback rfe For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted security-approved @jenkinsci/core-security-review reviewed this PR for security issues web-ui The PR includes WebUI changes which may need special expertise

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants