-
Notifications
You must be signed in to change notification settings - Fork 14
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
refactor: modularization #330
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Reviewer's Guide by SourceryThis pull request refactors the form component to improve modularization, making the code more readable and manageable. It introduces new templates for rendering different form elements and updates the styles to use a more consistent design system. File-Level Changes
Tips
|
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.
Hey @SalihuDickson - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
error?: string; | ||
children?: Array<Field>; | ||
} | ||
import { Field } from "./types.js"; |
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.
issue (complexity): Consider reducing the number of imports and abstraction layers.
The new code introduces several complexities that could be streamlined for better readability and maintainability:
- Increased Number of Imports: The additional imports for templates and stylesheets increase dependencies and make the code harder to follow.
- Fragmented Logic: Moving the rendering logic for different templates to separate files can make understanding the flow of the component more difficult.
- Additional Abstraction Layers: The new abstraction layers spread the logic across multiple functions and files, increasing cognitive load.
- Complexity in Template Rendering: The more complex logic for rendering templates, including passing multiple parameters and actions, adds to the difficulty of understanding data flow.
- Increased Boilerplate: The additional boilerplate code makes the code longer and more cumbersome to read and maintain.
A less complex approach could involve keeping the rendering logic within the main component while still modularizing some parts for reusability. This would make the code more concise and the flow more straightforward, reducing the complexity introduced by the additional abstraction layers and fragmented logic.
const opening = e.key; | ||
const closing = this.closing[this.opening.indexOf(opening)]; | ||
await this.setEditorLanguage(this.language); | ||
if (this.disabled) this.editor.setReadOnly(true); |
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.
suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces
)
if (this.disabled) this.editor.setReadOnly(true); | |
if (this.disabled) { |
Explanation
It is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).
e.preventDefault(); | ||
this._setCursor(selStart + 1); | ||
async setEditorLanguage(language: Language) { | ||
if (!this.editor) return; |
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.
suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces
)
if (!this.editor) return; | |
if (!this.editor) { |
Explanation
It is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).
if (field.children?.length) | ||
return html` ${field.children?.map((child) => | ||
this.renderTemplate(child, `${path}[${index}]`) | ||
)}`; |
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.
suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces
)
if (field.children?.length) | |
return html` ${field.children?.map((child) => | |
this.renderTemplate(child, `${path}[${index}]`) | |
)}`; | |
if (field.children?.length) { | |
return html` ${field.children?.map((child) => | |
this.renderTemplate(child, `${path}[${index}]`) | |
)}`; | |
} | |
Explanation
It is recommended to always use braces and create explicit statement blocks.Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).
1845262
to
1395942
Compare
Description
This PR aims to improve the modularization in the form component. This is important as it makes the code more readable and the form class more manageable, it also removes lines of logic that have been repeated while making it easier to implement new features.
Checklist
Comments
Summary by Sourcery
This pull request refactors the form component to improve modularization, making the code more readable and manageable. It introduces reusable templates for various form fields, updates styles to use new design tokens, and adds utility functions for rendering labels and tooltips.