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

Modularized components #798

Merged
merged 10 commits into from
Jan 3, 2023
Merged

Modularized components #798

merged 10 commits into from
Jan 3, 2023

Conversation

olemartinorg
Copy link
Contributor

@olemartinorg olemartinorg commented Dec 29, 2022

Description

Started modularizing layout components. In other words, a new LayoutComponent class has been added (which every layout component now has to implement). It is the common 'tool box' used by GenericComponent.tsx and serves as a place where every peculiarity of each layout component implementation should be implemented.

This is the start, and builds a framework we can extend further. As discussed in the comments under, getDisplayFormData is probably the next thing to start working on moving into this class.

As this change is only about moving code around, I'm relying on our automatic tests to catch any bugs introduced, and so I haven't really tested this change myself. It turned out that not all components expected all the same properties as they get from GenericComponent.tsx, so I had to clean some of them up for this to work. For example, CheckboxContainerComponent could render validation messages if given validationMessages, but that doesn't ever seem to happen (so I removed that part).

Related Issue(s)

Verification

  • Manual testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added
    • Cypress E2E test(s) have been added
    • No automatic tests are needed here
    • I want someone to help me make some tests
  • User documentation @ altinn-studio-docs
    • Has been updated
    • No changes/updates needed
  • 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

Ole Martin Handeland added 4 commits December 29, 2022 15:00
…with PropsFromGenericComponent, and making sure typescript knows that:

- Summary components cannot be inside Group components (now using ComponentInGroup for this type)
- Summary components cannot be rendered directly using GenericComponent.tsx (now using RenderableGenericComponent for this)
- Lots more various cleanup to make typings work
…pecific logic to where the code should belong (in the layout component folder)
@olemartinorg olemartinorg added the kind/other Pull requests containing chores/repo structure/other changes label Dec 29, 2022
Ole Martin Handeland added 3 commits December 30, 2022 11:25
…r not. Cleaning up some splat-properties and passing componentValidations to everyone (each component can decide on their own if they want to use the validations).
@olemartinorg
Copy link
Contributor Author

What do you think, @bjosttveit? I know you had thoughts about how to solve this. Did you imagine it differently, or were we on the same track?

@bjosttveit
Copy link
Member

What do you think, @bjosttveit? I know you had thoughts about how to solve this. Did you imagine it differently, or were we on the same track?

I guess my thoughts were mostly idealistic and more relevant to a major release by having component classes do much more than having a render function (like validation logic, having some sort of renderSummary(), and also replacing getDisplayFormData by using a function defined in the class for getting a string-representation of its data, etc.). I also thought about having different types of groups be different classes, and kind of inplicitly included #345 in my thoughts. That would be a very large refactor though 😅. But this is definitely on the same track and a good step in the right direction!

@olemartinorg
Copy link
Contributor Author

Ah, yup, sounds like we think much in the same way, then.. 😅 I think smaller steps at each point in time will be easier to implement (and test), so I also think this is just the beginning. I thought about starting the refactor to include getDisplayFormData last week, but I think that's next (and then moving on to Summary).

I'm also having (admittedly half-baked) thoughts about running nodesInLayout first, then passing each LayoutNode to GenericComponent instead - and in that process making (repeating) groups something more similar to a normal component (just rendering a table, but also making sure it can render child components). There's a lot of code in src/utils/formLayout.ts that does much of the same as the node hierarchy, so it would be nice to get rid of the duplication. That may be a practical route to complete #345, but that issue is spinning out in a direction where replacing Redux/Sagas seems to be on the table (at least in my head, and with my current understanding of the issue).

I'll open up this one for review, so that we can tackle each puzzle piece at a time (so not closing #377 quite yet).

@bjosttveit
Copy link
Member

Sounds good! So I guess we are on the same page, except you actually have a plan to get there, I had no idea where to begin 😅

Ole Martin Handeland added 2 commits January 2, 2023 14:17
# Conflicts:
#	src/layout/GenericComponent.tsx
…that change arrived now when merging from main)
@olemartinorg olemartinorg marked this pull request as ready for review January 2, 2023 13:20
…(that was also read in checkboxes, but no longer used there either). It's not passed by GenericComponent, so I suspected this not to be in use - and validation messages never arrives here in any way I can figure out how to test either.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 2, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

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

74.9% 74.9% Coverage
0.0% 0.0% Duplication

Copy link
Member

@bjosttveit bjosttveit left a comment

Choose a reason for hiding this comment

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

🎖️

@olemartinorg olemartinorg merged commit c68c1a6 into main Jan 3, 2023
@olemartinorg olemartinorg deleted the feat/component-class branch January 3, 2023 10:38
@olemartinorg olemartinorg added the ignore-for-release Pull requests to be ignored in release notes label Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-for-release Pull requests to be ignored in release notes kind/other Pull requests containing chores/repo structure/other changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants