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

refactor: modularization #330

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

refactor: modularization #330

wants to merge 15 commits into from

Conversation

SalihuDickson
Copy link
Contributor

@SalihuDickson SalihuDickson commented Jul 12, 2024

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

  • My code follows the contributing guidelines of this project.
  • I am aware that all my commits will be squashed into a single commit, using the PR title as the commit message.
  • I have performed a self-review of my own code.
  • I have commented my code in hard-to-understand areas.
  • I have updated the user-facing documentation to describe any new or changed behavior.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have not reduced the existing code coverage.

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.

  • Enhancements:
    • Refactored form component to improve modularization, enhancing readability and manageability.
    • Replaced repeated logic in form component with reusable templates for input, switch, array, and group fields.
    • Updated styles to use new design tokens and variables for consistency across components.
    • Introduced new utility functions for rendering labels and tooltips in form fields.

Copy link

changeset-bot bot commented Jul 12, 2024

⚠️ No Changeset found

Latest commit: 87f2143

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jul 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
elixir-cloud-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2024 8:21pm

Copy link
Contributor

sourcery-ai bot commented Jul 12, 2024

Reviewer's Guide by Sourcery

This 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

Files Changes
packages/ecc-utils-design/src/styles/shoelace.styles.ts
packages/ecc-utils-design/src/components/form/form.styles.ts
packages/ecc-utils-design/src/components/collection/collection.styles.ts
packages/ecc-utils-design/src/components/code/code.styles.ts
packages/ecc-utils-design/src/components/details/details.styles.ts
Updated styles to use --ecc-* variables for consistent design system.
packages/ecc-utils-design/src/components/form/form.ts
packages/ecc-utils-design/src/components/form/templates/arrayTemplate.ts
packages/ecc-utils-design/src/components/form/templates/inputTemplate.ts
packages/ecc-utils-design/src/components/form/templates/switchTemplate.ts
packages/ecc-utils-design/src/components/form/templates/groupTemplate.ts
packages/ecc-utils-design/src/components/form/templates/successTemplate.ts
packages/ecc-utils-design/src/components/form/templates/errorTemplate.ts
packages/ecc-utils-design/src/components/form/utils.ts
Refactored form component to use modular templates for rendering different form elements.
packages/ecc-utils-design/src/components/code/code.ts
packages/ecc-utils-design/src/components/code/code.styles.ts
Replaced Shoelace components with Ace editor for code input and updated styles.
packages/ecc-utils-design/demo/form/index.html
packages/ecc-utils-design/demo/collection/index.html
packages/ecc-utils-design/demo/details/index.html
Updated demos to reflect new form fields and styles.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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";
Copy link
Contributor

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:

  1. Increased Number of Imports: The additional imports for templates and stylesheets increase dependencies and make the code harder to follow.
  2. Fragmented Logic: Moving the rendering logic for different templates to separate files can make understanding the flow of the component more difficult.
  3. Additional Abstraction Layers: The new abstraction layers spread the logic across multiple functions and files, increasing cognitive load.
  4. 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.
  5. 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);
Copy link
Contributor

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)

Suggested change
if (this.disabled) this.editor.setReadOnly(true);
if (this.disabled) {


ExplanationIt 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;
Copy link
Contributor

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)

Suggested change
if (!this.editor) return;
if (!this.editor) {


ExplanationIt 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).

Comment on lines +226 to +229
if (field.children?.length)
return html` ${field.children?.map((child) =>
this.renderTemplate(child, `${path}[${index}]`)
)}`;
Copy link
Contributor

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)

Suggested change
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}]`)
)}`;
}


ExplanationIt 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).

salihuDickson added 3 commits July 12, 2024 20:45
This reverts commit f95ec07.
This reverts commit f46ed88.
This reverts commit f2d2901.
salihuDickson added 5 commits July 12, 2024 20:57
This reverts commit f46ed88.
This reverts commit f2d2901.
This reverts commit f2d2901.
This reverts commit f2d2901.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants