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

refactor templated JS #46

Merged
merged 1 commit into from
Apr 5, 2019
Merged

refactor templated JS #46

merged 1 commit into from
Apr 5, 2019

Conversation

rbren
Copy link
Contributor

@rbren rbren commented Apr 4, 2019

This takes the audit data and creates a single variable using JSON, rather than using templating to create JavaScript on the fly.

Copy link
Contributor

@robscott robscott left a 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 }};
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

labels: Object.keys(AUDIT.NamespacedResults),
datasets: [{
label: 'Passing',
data: Object.values(AUDIT.NamespacedResults).map(r => r.Summary.Successes),
Copy link
Contributor

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

Copy link
Contributor Author

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.

labels: Object.keys(fairwindsAuditData.NamespacedResults),
datasets: [{
label: 'Passing',
data: Object.values(fairwindsAuditData.NamespacedResults)
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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

@robscott robscott merged commit 5c69b99 into master Apr 5, 2019
@robscott robscott deleted the bb/refactor-template-js branch April 5, 2019 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants