-
Notifications
You must be signed in to change notification settings - Fork 31
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
Architecture: Modularize components using classes and inheritance #377
Comments
Closing this epic, as the concept has now been well-understood, and we're a long way from were we were when this was first created. With v4 we're going further with modularization than we've done before, and even though there are still things we could solve better, I think it's better to focus on that in code review and future discussions rather than leaving this Epic open without having any measurable and concrete things to do with it. |
Description
There are multiple code paths which branch off to do something different depending on the encountered component type. This has historically been needed to implement some custom functionality for "abnormal" components.
Solution
The idea in this issue is to refactor away some complexities in existing code such that we can have cleaner implementations of the generic frontend app, and at the same time concentrate custom overrides for each component in their respective folders. This should also make it easier to implement a new component, as potential overrides are centralized. One way to implement this is to define an abstract class (i.e.
BaseComponent
), have every component implement their own concrete class from this abstract base class, and then reference instances of these classes in thecomponents
map insrc/altinn-app-frontend/src/components/index.ts
.GenericComponent.tsx
can then fetch each react component viacomponents[props.type].getReactComponent()
or similar.Examples from
GenericComponent.tsx
This case should instead be handled using a function call, like
!component.shouldRenderValidationsGenerically()
(quite possibly an overly verbose method name).This case should instead be handled using a function call, like
component.shouldRenderLabel()
:Examples from
validation.ts
:In
validateEmptyFieldsForLayout
, this code should instead look up the function to see if it has implemented any custom 'empty field' validations. Quite possibly every component type should have its own method to figure out if the formData is "empty" or not.The whole function called
validateFormComponentsForLayout
is filled with custom validation rules for certain components. These should be implemented in the component definitions themselves.In
findLayoutIdsFromValidationIssue()
, there is a special case for some components:Examples in
formComponentUtils.ts
:The functions
componentValidationsHandledByGenericComponent
,getDisplayFormData
andgetFormDataForComponentInRepeatingGroup
include lots of code to make sure different components produce some valid results. These should look up some component definition/declaration instead, where components themselves can override implementations.The text was updated successfully, but these errors were encountered: