-
Notifications
You must be signed in to change notification settings - Fork 215
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
refactor templated JS #46
Conversation
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.
Great improvements here, thanks! Just one comment around a variable name but otherwise lgtm.
@@ -15,6 +15,9 @@ | |||
|
|||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script> | |||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/cash/3.0.0-beta.3/cash.min.js"></script> | |||
<script> | |||
window.AUDIT = {{ .JSON }}; |
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 think it would be good to use a Fairwinds prefixed name for a global variable like this, maybe even just FairwindsAuditData
or something?
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.
Done!
public/js/charts.js
Outdated
labels: Object.keys(AUDIT.NamespacedResults), | ||
datasets: [{ | ||
label: 'Passing', | ||
data: Object.values(AUDIT.NamespacedResults).map(r => r.Summary.Successes), |
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 sure is nice to not have to target any legacy browsers
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.
Probably worth being safe though. I think Safari still struggles with arrow functions.
I'm so used to working with transpilers that I often forget about browser support.
6c46ddd
to
0c6b644
Compare
labels: Object.keys(fairwindsAuditData.NamespacedResults), | ||
datasets: [{ | ||
label: 'Passing', | ||
data: Object.values(fairwindsAuditData.NamespacedResults) |
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.
Even Object.values
is a bit of a stretch for older browsers unfortunately: https://caniuse.com/#feat=object-values. I don't feel too strongly on this, there's probably not a ton of overlap between people using this tool and people using old browsers, but it certainly could be an issue.
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.
If it's a pain to reimplement that, you could also include all or part of lodash: https://www.jsdelivr.com/package/npm/lodash
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.
Good call - wrote a quick polyfill
0c6b644
to
dab34b9
Compare
This takes the audit data and creates a single variable using JSON, rather than using templating to create JavaScript on the fly.