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

Making Group and Summary regular components, only node passed to components #987

Merged
merged 13 commits into from
Mar 10, 2023

Conversation

olemartinorg
Copy link
Contributor

@olemartinorg olemartinorg commented Mar 9, 2023

Description

Yet another installment after #976 made GenericComponent possible render with just the node object as input. This time:

  • All component classes now only receive node from GenericComponent, meaning this PR takes this concept one step further. Components no longer should require every component property as input when rendering themselves. A lot of tests had to be rewritten to make this work.
  • Group and Summary has been promoted (or demoted?) to regular components, which render via GenericComponent. No more need for a super-function that decides if a component can be rendered using GenericComponent or directly rendered (any component can now ask to be directly rendered).
  • No need for SummaryComponentSwitch anymore, as every component type can now implement how it is to be rendered in a Summary instead of the Summary component having to know about different component types.

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Changes/additions to component properties
    • Changes are reflected in both src/layout/layout.d.ts and layout.schema.v1.json, and these are all backwards-compatible
    • No changes made
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Ole Martin Handeland added 8 commits March 9, 2023 16:44
… means overrides might disappear, which might break Likert)
…w that the node is passed into a component from GenericComponent (and overridden props are not passed along)
… to the component so they can be handled there instead of using a Context (a context did not affect the directRender() check, so GenericComponent also rendered errors, and the <tbody> got children that were not <tr> elements, because GenericComponent wrapped them).
…need for renderLayoutNode(), which was just a component-switcher _outside_ of GenericComponent, so there was no reason a Summary or Group could not just be rendered in the same way as other components.
…irly safely assume that the function will always return an object (otherwise GenericComponent will still refuse to render anything, which we also have unit tests for).
@olemartinorg olemartinorg added the kind/other Pull requests containing chores/repo structure/other changes label Mar 9, 2023
@olemartinorg olemartinorg self-assigned this Mar 9, 2023
Ole Martin Handeland added 3 commits March 10, 2023 10:53
…y. It doesn't have to be this complex, as you can't really click a button that does not exist (and is visible), so cypress would fail the click anyway. Focussing it first is also pointless. Simplifying the code, hoping that will avoid sporadic failures where the elements disappear before actions can be performed.
…borked it, but the cypress tests caught that nicely. Passing each prop on its own is cleaner and works better.
…DOM changed at some point here, so the wrapped items were updated and confuses cypress when the button is clicked. This fixes the problem.
Copy link
Contributor

@framitdavid framitdavid left a comment

Choose a reason for hiding this comment

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

As always a lot of great work! 🚀

label={label}
overrides={overrides}
/>
{RenderSummary && component instanceof FormComponent ? (
Copy link
Contributor

@framitdavid framitdavid Mar 10, 2023

Choose a reason for hiding this comment

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

I think we can just check if RenderSummary is not null. Because RenderSummary is set to null if the component is not an instance of FormComponent at line 116. :D

Suggested change
{RenderSummary && component instanceof FormComponent ? (
{RenderSummary ? (

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, but typescript doesn't agree with that.. 🤷 It complains because it didn't infer that component must be a FormComponent if RenderSummary is set, so the call to component.renderSummaryBoilerplate() below fails without that check.

src/components/summary/SummaryComponent.tsx Outdated Show resolved Hide resolved
src/components/summary/SummaryComponent.tsx Show resolved Hide resolved
src/features/form/containers/Form.tsx Show resolved Hide resolved
src/layout/AttachmentList/AttachmentListComponent.tsx Outdated Show resolved Hide resolved
src/layout/FileUploadWithTag/EditWindowComponent.tsx Outdated Show resolved Hide resolved
src/layout/GenericComponent.tsx Show resolved Hide resolved
src/layout/Group/index.tsx Show resolved Hide resolved
olemartinorg and others added 2 commits March 10, 2023 15:09
Co-authored-by: David Øvrelid <46874830+framitdavid@users.noreply.github.com>
Co-authored-by: David Øvrelid <46874830+framitdavid@users.noreply.github.com>
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

73.5% 73.5% Coverage
0.0% 0.0% Duplication

@olemartinorg olemartinorg merged commit 9281519 into main Mar 10, 2023
@olemartinorg olemartinorg deleted the chore/all-are-generic-components branch March 10, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/other Pull requests containing chores/repo structure/other changes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants