-
Notifications
You must be signed in to change notification settings - Fork 328
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
Check component item arrays are not empty before outputting markup #1638
Check component item arrays are not empty before outputting markup #1638
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.
This PR addresses the issue raised here #1618
Spoke to Nat and they've said that they're going to be away for a week but @silasl (hi 👋 ) can help out in that time. We'll review this as a team tomorrow in our weekly triage session. |
It'd be good to remove the change to package-lock.json, which I believe is unrelated and just down to different versions of npm being used. (I've not had a chance to review the rest of the PR yet) |
28a2cb0
to
1d443c1
Compare
Thanks @natcarey! |
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.
This looks great to me! Thanks a lot.
I tried to help out and add a CHANGELOG entry myself but I don't have permission to push to your branch.
- [Pull request #1638: Check component item arrays are not empty before outputting markup](https://github.com/alphagov/govuk-frontend/pull/1638).
I think if we update the CHANGELOG and get another approval from someone else on the team we can get this merged and released in v3.4.0
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.
This is a useful change, thanks for all your work @natcarey.
Please note that we shouldn't be committing any package
files in this PR. They will get generated as part of the release process. So those need to be removed before this can be merged.
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.
We had a small review internally, two things I missed:
- some changes have been made in the
package
directory instead of thesrc
directory - we are wondering if there are more places we need to do this: for instance accordion, breadcrumbs, select also have an array of items
Oops sorry for the double feedback 😇
We're going to release 3.4.0 then do a small patch release with this once you've had time to look at this :) |
1d443c1
to
edbc952
Compare
I've updated with that feedback and I'm working as usual this week. Thanks all. |
I just spotted this comment "we are wondering if there are more places we need to do this: for instance accordion, breadcrumbs, select also have an array of items", I haven't addressed that yet. I'll look at that this morning. |
@NickColley said:
I don't think these are affected by the same problem. These examples are going to behave strangely when an empty array or no array is provided but the behaviour of an empty array matches the behaviour of no array. In the components I've updated there is a difference between the handling of "nothing" and an empty array. Adding conditions around the template would help avoid a nonsense output but it isn't needed for consistency between these two behaviours. For example |
CHANGELOG.md
Outdated
@@ -49,6 +49,7 @@ You can now add attributes to the `<body>` element of a page, by using the [`bod | |||
- [Pull request #1609: Update hex value for secondary text to improve contrast](https://github.com/alphagov/govuk-frontend/pull/1609). | |||
- [Pull request #1620: Only add underline to back link when href exists ](https://github.com/alphagov/govuk-frontend/pull/1620). | |||
- [Pull request #1631: Fix classes on character count when in error state](https://github.com/alphagov/govuk-frontend/pull/1631). | |||
- [Pull request #1638: Check component item arrays are not empty before outputting markup](https://github.com/alphagov/govuk-frontend/pull/1638). |
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.
Something I missed, this changelog entry needs to be in an 'unreleased section' instead of being in the previous release
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.
Morning. Just to check I've got this right - I'm putting it on Line 6 so the start of the file reads:
# Changelog
## Unreleased
### New features
- [Pull request #1638: Check component item arrays are not empty before outputting markup](https://github.com/alphagov/govuk-frontend/pull/1638).
Is that right?
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.
Yeah that looks great but 'New features' should be 'Fixes'
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.
Sorry, this probably needs updating again as v3.4.0 has now been released.
edbc952
to
1a6b768
Compare
1a6b768
to
501c199
Compare
501c199
to
8b2cbef
Compare
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.
This is looking great 🙌 Just need @NickColley to give a second team thumbs up.
I don't think these are affected by the same problem. These examples are going to behave strangely when an empty array or no array is provided but the behaviour of an empty array matches the behaviour of no array. In the components I've updated there is a difference between the handling of "nothing" and an empty array.
I think @natcarey is correct here. The other components that utilise the items
array are accordion, checkboxes, radios and select. With these ones there is no redundant markup output if items
is empty, like there is with the ones fixed in this PR. I guess we could decide to make it so that whenever you use arrays in templates you should check the length, regardless of whether anything is output if the array is empty but I think that's separate from this work as the scope of this PR was to "Check component item arrays are not empty before outputting markup".
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 work thanks Nat! Also thanks @hannalaakso for the sharp eye on the review 😅
Overview
When using the Nunjucks components there are a number of optional arrays, there's one behaviour when you provide something and another when you provide nothing. At HMRC we've found some confusion over the difference between providing nothing and providing an empty array.
This change standardises that behaviour so that an empty array is treated as nothing being provided.
Scope
This only affects the Nunjucks interface in its handling of empty arrays, users who aren't providing empty arrays will not be affected by this change.
There are no CSS or JS changes
Tests
We have added tests for the new behaviour.