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

feat: implement a very basic MVP form element #206

Merged
merged 6 commits into from
Jan 17, 2025
Merged

Conversation

DukeFerdinand
Copy link

@DukeFerdinand DukeFerdinand commented Jan 14, 2025

Not feature complete, but ready to start implementing real work.

Alaska Airlines Pull Request

Closes #185

Before Submitting this pull request:

  • Link all tickets in this repository related to this PR in the Development section
    note: all pull requests require at least one linked ticket
  • If this PR is Ready For Review, all ticket's linked under Development must have their status changed to Ready For Review as well

By submitting this Pull Request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I have performed a self-review of my own update.

Summary by Sourcery

Implement a basic MVP form element.

New Features:

  • Add a new auro-form element to provide a basic form structure. Include form submission and validation capabilities.

Tests:

  • Add tests for the new form element.

Copy link

sourcery-ai bot commented Jan 14, 2025

Reviewer's Guide by Sourcery

This pull request introduces a basic implementation of the auro-form component, which is designed to manage and track the state of form elements within its scope. It includes features for identifying form and submit elements, managing form data, and tracking validity. The component is not feature complete, but it provides a foundation for further development.

Sequence diagram for form submission flow

sequenceDiagram
    participant User
    participant Form as AuroForm
    participant FormElements as Form Elements
    participant Event as Event System

    User->>FormElements: Inputs data
    FormElements->>Form: input event
    Form->>Form: Update _formState
    FormElements->>Form: auroFormElement-validated event
    Form->>Form: Update validity state
    User->>Form: Clicks submit
    Form->>Event: Dispatch submit event with form value
Loading

Class diagram for AuroForm component

classDiagram
    class AuroForm {
        -_formState: FormState
        +static formElementTags: string[]
        +static submitElementTags: string[]
        +value: Record~string, any~
        +validity: string
        +isInitialState: boolean
        +isFormElement(element: HTMLElement): boolean
        +isSubmitElement(element: HTMLElement): boolean
        +getSubmitFunction(): function
        +queryAuroElements(): NodeList
        +onSlotChange(): void
    }
    note for AuroForm "New form component that manages form state and validation"
Loading

State diagram for form validation

stateDiagram-v2
    [*] --> Initial: Form Created
    Initial --> Valid: All required fields valid
    Initial --> Invalid: Required fields missing/invalid
    Valid --> Invalid: Field becomes invalid
    Invalid --> Valid: All validations pass
    Valid --> [*]: Submit form
    note right of Invalid: Form tracks validity
of all child elements
Loading

File-Level Changes

Change Details Files
Initial implementation of the auro-form component.
  • Added a constructor to initialize the form state.
  • Added static properties to define form and submit elements.
  • Added methods to check if an element is a form or submit element.
  • Added a getter to retrieve the form value as a key-value pair.
  • Added a getter to determine the form's validity.
  • Added a getter to determine if the form is in its initial state.
  • Added a method to get the submit function.
  • Added a method to query all relevant auro elements.
  • Added a firstUpdated lifecycle hook to add event listeners for input and validation events.
  • Added a onSlotChange method to update the form state when the slot changes.
  • Added a render method to render the form and display the form value and validity.
components/form/src/auro-form.js
Updated documentation to reflect the new component and its properties.
  • Added documentation for the cssClass attribute.
  • Added documentation for the formElements, formState, and value properties.
  • Added documentation for the getSubmitFunction, isFormElement, isSubmitElement, and onSlotChange methods.
components/form/docs/api.md
Updated the README to include the new component.
  • Updated the README to include the new component and its basic usage.
components/form/README.md
Added basic styling for the form element.
  • Added basic styling for the form element.
components/form/src/styles/style.scss
Updated the basic example to include the new component.
  • Updated the basic example to include the new component.
components/form/apiExamples/basic.html
Updated package.json to include new dependencies.
  • Added @aurodesignsystem/auro-datepicker and @aurodesignsystem/auro-input as dependencies.
components/form/package.json
Added a demo page for the form component.
  • Added a demo page for the form component.
  • Added a script to register demo dependencies.
components/form/demo/working.html
components/form/demo/registerDemoDeps.js

Assessment against linked issues

Issue Objective Addressed Explanation
#185 Extend LitElement class -> AuroFormElement class
#185 Include code to link elements to the form
#185 Validate form element linking and capabilities

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Not feature complete, but ready to start implementing real work.
This listens to, and attaches event listeners for, the following:

- input
- auroFormElement-validated
- button[type=submit] clicks

It also adds a datepicker to the example form.
1. Uses one root querySelector instead of looping through elements.

2. Add more explicit validity state handling.

3. Add handling for renamed auro components.

4. Revert import in datepicker html example file.
Remove console logs, fix elementCollection tag name casing, dispatch
submit event on submit, add renamed formElement `name` condition.
Formkit prefixes were causing issues with installation after rebasing.
@DukeFerdinand DukeFerdinand marked this pull request as ready for review January 17, 2025 21:16
@DukeFerdinand DukeFerdinand requested a review from a team as a code owner January 17, 2025 21:16
Copy link

@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 @DukeFerdinand - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Remove the debug output (<p>Value: ${JSON.stringify(this.value)}</p> and <p>Validity: ${this.validity}</p>) from the render method as this shouldn't be in production code. Consider adding a debug mode if this visibility is needed for development.
  • The validation logic could be simplified and improved. Consider adding proper error states and messages rather than just returning 'valid'/'invalid'. This would provide better UX for form validation.
Here's what I looked at during the review
  • 🟡 General issues: 6 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 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 and I'll use the feedback to improve your reviews.

Comment on lines +192 to +194
if (this.isFormElement(eventTarget)) {
this._formState[eventTarget.getAttribute("name")].value = eventTarget.value;
}
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Add a guard clause to check for name attribute before accessing formState

The current code assumes the name attribute exists on form elements. Add a check like if (this.isFormElement(eventTarget) && eventTarget.hasAttribute('name')) to prevent potential errors.

Suggested change
if (this.isFormElement(eventTarget)) {
this._formState[eventTarget.getAttribute("name")].value = eventTarget.value;
}
if (this.isFormElement(eventTarget) && eventTarget.hasAttribute('name')) {
this._formState[eventTarget.getAttribute("name")].value = eventTarget.value;
}

Copy link
Author

Choose a reason for hiding this comment

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

will handle this in subsequent work (in the next couple of hours)


// this property is DEMO ONLY! Please delete.
cssClass: { type: String }
_formState: { attribute: false },
};
}
Copy link

Choose a reason for hiding this comment

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

issue (performance): Store submit handler as instance property to prevent memory leaks

Create a class property _submitHandler in constructor and assign getSubmitFunction() result to it. This ensures proper event listener cleanup.

components/form/docs/api.md Show resolved Hide resolved
components/form/docs/api.md Show resolved Hide resolved
components/form/docs/api.md Show resolved Hide resolved
components/form/docs/api.md Show resolved Hide resolved
@DukeFerdinand DukeFerdinand merged commit 4a0e53c into beta Jan 17, 2025
4 checks passed
@DukeFerdinand DukeFerdinand deleted the dhook/auro-form branch January 17, 2025 21:20
@jason-capsule42
Copy link
Member

🎉 This PR is included in version 2.0.0-beta.16 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants