Research if we can scan features and automatically add views to view registry #607

Open
opened 2026-04-28 08:41:06 +00:00 by a24vinla · 5 comments
Collaborator

We currently have to manually add views to the views/viewRegistry constants. Although this isn't too big of a hassle, it would be nice if we only have too add the view to the features folder.

This should not be merged, but please create a branch where we can test this approach.

We currently have to manually add views to the views/viewRegistry constants. Although this isn't too big of a hassle, it would be nice if we only have too add the view to the features folder. This should not be merged, but please create a branch where we can test this approach.
Collaborator

Webpack has a built in feature called require.context that can scan a folder and import all files matching a pattern at build time.
The idea is to create a new file features/viewRegistry.js that scans features/ for all *View.js files, checks if they export a viewMeta object and if they do, adds them to views and viewRegister automatically. Dashboard.js then just imports from the registry instead of listing everything manually.
Each view needs one new export so the registry knows to pick it up, javascriptexport const viewMeta = { name: 'TemperatureView' };

Positives

No external dependencies
Only one place to maintain
Removes a lot of manual imports from Dashboard.js
The viewMeta check filters out hooks and other non-view files automatically

Negatives

require.context only works in Webpack. If the project switches to something else this would need to be rewritten
The dropdown order becomes alphabetical by file path instead of the current order
Special cases still have to stay in Dashboard

### Recommended approach is Webpack require.context Webpack has a built in feature called require.context that can scan a folder and import all files matching a pattern at build time. The idea is to create a new file features/viewRegistry.js that scans features/ for all *View.js files, checks if they export a viewMeta object and if they do, adds them to views and viewRegister automatically. Dashboard.js then just imports from the registry instead of listing everything manually. Each view needs one new export so the registry knows to pick it up, javascriptexport const viewMeta = { name: 'TemperatureView' }; **Positives** No external dependencies Only one place to maintain Removes a lot of manual imports from Dashboard.js The viewMeta check filters out hooks and other non-view files automatically **Negatives** require.context only works in Webpack. If the project switches to something else this would need to be rewritten The dropdown order becomes alphabetical by file path instead of the current order Special cases still have to stay in Dashboard
Owner

Does this require a new dependency?

Changing an existing dependency?

Give me a TLDR compliant explanation.

Does this require a new dependency? Changing an existing dependency? Give me a TLDR compliant explanation.
Collaborator

No new or changed dependencies, Webpack is already included as a dependency in react-scripts.

No new or changed dependencies, Webpack is already included as a dependency in react-scripts.
Collaborator

@c24carso have you created a branch that we can test?

@c24carso have you created a branch that we can test?
Collaborator

Will redo it on the current branch since it's old now.

Will redo it on the current branch since it's old now.
Sign in to join this conversation.
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K#607
No description provided.