Add component wrapper to more components #7048
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
result_card
,result-item
andresult-sections
components.result-sections
Why
Standardising our components to use the component wrapper helper will reduce code, increase standardisation, and improve future feature implementation speed.
Bug discovered
When making this change I realised that the component guide for these component is not rendering any of the CSS. For example: http://127.0.0.1:3010/component-guide/result_card.
I was going to just add
add_app_component_stylesheet("result-card")
etc. to the components but first I looked further into why the CSS wasn't rendering on the component guide. It seems to be because the code which determines whether to include the stylesheet or not is tied up in Ruby in theoutcome_presenter.rb
file, which means the CSS stylesheet is only added on outcome pages, and therefore the component guide previews have no stylesheet to use.smart-answers/app/presenters/outcome_presenter.rb
Lines 41 to 45 in d58494f
https://github.com/alphagov/smart-answers/blob/main/app/views/smart_answers/custom_result_full_width.erb#L5-L9
I couldn't think of a simple way of fixing this - do you have any suggestions? I think the way it currently is breaks our component isolation principle, since Ruby logic is deciding whether the CSS stylesheet is added or not - so the component can't just be placed wherever needed?
I spoke to the developers who introduced the change - they did suggest as it's a small amount of CSS we could just go back to having
add_app_component_stylesheet("result-card")
etc. directly on the components, but I'm guessing that would mean the individual CSS loading might break.I did look into just passing a boolean to the component previews which would then force them include the stylesheet, but I thought that might look confusing on the component guide previews, as we would have to tell devs not to include this extra boolean when they use the component in production.