-
Notifications
You must be signed in to change notification settings - Fork 0
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
Include text directly in components (removing verbiage files) #100
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.
Awesome work here, I fully support this effort. Going through this PR and seeing less abstraction, less complexity and less obscurity was a true pleasure!
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.
41c0d63
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.
Errors page and Not Found page
Code Climate has analyzed commit f58776b and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 96.9% (90% is the threshold). This pull request will bring the total coverage in the repository to 93.8% (0.0% change). View more on Code Climate. |
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.
Awesome work, Ben!
Existing Pattern
The pattern in our other apps is to create verbiage objects, with text properties. Many components have a required verbiage prop, which provides the text of that component.
In theory, this approach allows us to
What does this PR change
This PR embeds most of our app's text directly in the component code.
The big win here is simplicity - by removing the layer of indirection between component and text, our app becomes easier to understand and (hopefully) easier to change as needs arise.
We lose the advantages outlined above, but
The final disadvantage I can think of is a minor one: our repo becomes slightly less greppable. Whereas we ignore our line-length prettification rules in verbiage files, they do affect formatting in component files. Therefore, searching our repo for a phrase copied from the site may no longer find that text - because it may include line breaks in the component file. Again, I believe this is more than offset by the simplicity win (especially given the other ways to find pages in our codebase, such as by consulting AppRoutes.tsx)
Change Details
components/report/Element.tsx:accordionElement()
- it was using a TemplateCardAccordion, specifically for its ability to parseCustomHtml. This is an instance of Point 1 mentioned earlier: we do version report verbiage. Therefore this function now calls parseCustomHtml directly (and does so within a direct use of Accordion and AccordionItem).[key: string]: any
escape hatch in its Props type. The only prop we ever pass here (other thanlabel
andchildren
, which were already listed explicitly) issx
, which gets passed through to the underlying Chakra component. This was (potentially) overriding the sx included in the component itself. I removed the escape hatch and made this override behavior more explicit.borderStyle: none
, and everywhere we pass in an override, that override includes its ownborderStyle: none
. This is a potentially precarious situation - if we decide to add a property to the default style, or if we override it from a new location without passing in a borderStyle, there's an unfortunate potential for time spent trying to figure out why things look wrong. But I don't want to add anything more to this PR, so we will have to solve for that later (if ever).children
prop, rather than a CustomHtmlElementdescription
prop. This is a more natural way for us to declare alerts in general: as<Alert>my alert content</Alert>
rather than<Alert description="my alert content" />
Alert
component. I may still attempt to refactor this further; perhaps we could skip the description step, and map directly from error code toAlert
component. But for now I am happy that theCustomHtmlElement[]
has been removed from verbiage/error.ts.<Alert>
from<Banner>
and<ErrorAlert>
. Both of those have been changed to passchildren
instead ofdescription
, as well as everything that uses those.[key: string]: any
escape hatch from its props as well. As with the AccordionItem props, this currently causes no unexpected behavior - except in the case of any error alerts from LoginCognito.tsx. Since that is not a customer-facing page, I don't solve for it in this PR.meta subject
on the ExportedReportPage.Related ticket(s)
N/A
How to test
Log in to the site and poke around! There should be no visual or behavioral changes. I'm 90% sure I didn't screw anything up.
Important updates
Uh... see above. If you're adding a new component, and it feels like adding a verbiage file would be a natural solution, let's talk! We may be able to come up with an alternative approach. Or, we may not! My goal isn't to eradicate all verbiage everywhere - my goal is to make the app as simple as possible.
Author checklist