-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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 deployed it locally and all existing trend charts still work.
|
||
echartsJenkinsApi.renderConfigurableTrendChart(`${chartId}`, `${enableLinks}`, `${configurationId}`, trendProxy); | ||
echartsJenkinsApi.renderConfigurableTrendChart(`${chartId}`, `${enableLinks}`, `${configurationId}`, window[`trendProxy${generatedId}`]); |
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.
Can you explain what the window[...]
does? It works but I do not understand the semantics.
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.
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.
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 thanks! So this trick is to get the actual value while using the key trendProxy${generatedId}
.
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
Link to relevant pull requests, esp. upstream and downstream changes