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

[JENKINS-73911] Un-inline JavaScript in trend-chart.jelly #357

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

yaroslavafenkin
Copy link
Contributor

@yaroslavafenkin yaroslavafenkin commented Oct 11, 2024

https://issues.jenkins.io/browse/JENKINS-73911

Testing done

Tested with warnings-ng and forensics-api being API consumers. Below are the scenarios I've had in mind.

https://www.loom.com/share/2b4acc3c16b34477b337f829077e550b?sid=9a6559cc-a3e9-4edd-a0c4-04957e5df077

https://www.loom.com/share/5a48e07ae13740fdaf00837d2154ec0d?sid=9a32b2c2-f848-4c55-9293-321dfde05c8b

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.42%. Comparing base (52e861b) to head (d542ca5).
Report is 83 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #357   +/-   ##
=========================================
  Coverage     51.42%   51.42%           
  Complexity       17       17           
=========================================
  Files             7        7           
  Lines           105      105           
  Branches          3        3           
=========================================
  Hits             54       54           
  Misses           51       51           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yaroslavafenkin yaroslavafenkin marked this pull request as ready for review October 14, 2024 16:54
@yaroslavafenkin yaroslavafenkin changed the title [JENKINS-73911][WIP] Un-inline JavaScript in trend-chart.jelly [JENKINS-73911] Un-inline JavaScript in trend-chart.jelly Oct 14, 2024
yaroslavafenkin added a commit to yaroslavafenkin/acceptance-test-harness that referenced this pull request Oct 15, 2024
yaroslavafenkin added a commit to yaroslavafenkin/bom that referenced this pull request Oct 15, 2024
@uhafner uhafner added the internal Internal changes without user or API impact label Oct 15, 2024
Copy link
Member

@uhafner uhafner left a comment

Choose a reason for hiding this comment

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

I deployed it locally and all existing trend charts still work.

@uhafner uhafner merged commit 9aa496d into jenkinsci:main Oct 15, 2024
30 of 31 checks passed

echartsJenkinsApi.renderConfigurableTrendChart(`${chartId}`, `${enableLinks}`, `${configurationId}`, trendProxy);
echartsJenkinsApi.renderConfigurableTrendChart(`${chartId}`, `${enableLinks}`, `${configurationId}`, window[`trendProxy${generatedId}`]);
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain what the window[...] does? It works but I do not understand the semantics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a way of accessing a global variable.
The variable is declared by the internals of <st:bind value="${it}" var="trendProxy${generatedId}" /> and it's in the global scope. I do not know upfront what the name of the variable will be because generatedId is generated in runtime. I'm passing the generatedId as a data attribute to the script so that I can access the object the name of which I can only know in runtime.

I could alternatively pass the name of the variable to the script instead of generatedId as I did in jenkinsci/warnings-ng-plugin#1862. Though the window[...] syntax still stays.

If the name was static we would simply access the variable by its name (like e.g. echartsJenkinsApi is accessed on this exact line).

Let me know if it's more clear now.

Copy link
Member

Choose a reason for hiding this comment

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

I see thanks! So this trick is to get the actual value while using the key trendProxy${generatedId}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Internal changes without user or API impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants