Skip to content

Migrate FormTextField to TS#22302

Merged
georgewrmarshall merged 13 commits intodevelopfrom
feat/formtextfield-to-ts
Dec 21, 2023
Merged

Migrate FormTextField to TS#22302
georgewrmarshall merged 13 commits intodevelopfrom
feat/formtextfield-to-ts

Conversation

@garrettbear
Copy link
Copy Markdown
Contributor

@garrettbear garrettbear commented Dec 15, 2023

Description

Move FormTextField js version into deprecated folder with deprecation notice
Update import of any production uses for FormTextField to the js version
Update/create TS version of FormTextField

Related issues

Fixes: #19120

Manual testing steps

  1. Run storybook
  2. Visit FormTextField
  3. Test inputs and props

Screenshots/Recordings

Before

After

Screen.Recording.2023-12-19.at.12.46.59.PM.mov

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@garrettbear garrettbear added the team-design-system All issues relating to design system in Extension label Dec 15, 2023
Comment on lines +63 to +75
// Validation function for 'id' prop
const validateIdProp = () => {
if (label && !id) {
throw new Error(
`If a label prop exists, you must provide an 'id' prop for the label's htmlFor attribute for accessibility. Warning coming from FormTextField component.`,
);
}
};

// Invoke the validation function
React.useEffect(() => {
validateIdProp();
}, [label, id]);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@georgewrmarshall this is another one of those proptypes throwing a curve ball at me

The original JS version:

/**
   * The id of the FormTextField
   * Required if label prop exists to ensure accessibility
   *
   * @param {object} props - The props passed to the component.
   * @param {string} propName - The prop name in this case 'id'.
   * @param {string} componentName - The name of the component.
   */
  id: (props, propName, componentName) => {
    if (props.label && !props[propName]) {
      return new Error(
        `If a label prop exists you must provide an ${propName} prop for the label's htmlFor attribute for accessibility. Warning coming from ${componentName} ui/components/component-library/form-text-field/form-text-field.js`,
      );
    }
    return null;
  },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we check if label is always used in the instances for this component and if so we could just make id a required prop? Otherwise I'll have to have a think about it when I get back tomorrow

Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

Looking good! Reviewed on my phone so will do a full review tomorrow

/**
* Props for the TextField component within the FormTextField
*/
textFieldProps?: TextFieldProps<'input'>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe the wrapper that receives the spread props is still a div

Suggested change
textFieldProps?: TextFieldProps<'input'>;
textFieldProps?: TextFieldProps<'div'>;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Then does TextField need to be changed as well?

Screenshot 2023-12-19 at 12 49 55 PM

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are treating the prop types as an input even though the wrapper is a div

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indeed, it should. Here, the input in ElementType refers to all props spread to the wrapper element, which is a div in this case. Therefore, we should be accepting valid div attributes. The attributes specific to the input element are defined in inputProps as seen here: https://github.com/MetaMask/metamask-extension/blob/develop/ui/components/component-library/text-field/text-field.types.ts#L61

Comment on lines +63 to +75
// Validation function for 'id' prop
const validateIdProp = () => {
if (label && !id) {
throw new Error(
`If a label prop exists, you must provide an 'id' prop for the label's htmlFor attribute for accessibility. Warning coming from FormTextField component.`,
);
}
};

// Invoke the validation function
React.useEffect(() => {
validateIdProp();
}, [label, id]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we check if label is always used in the instances for this component and if so we could just make id a required prop? Otherwise I'll have to have a think about it when I get back tomorrow

@garrettbear garrettbear marked this pull request as ready for review December 19, 2023 22:06
@garrettbear garrettbear requested a review from a team as a code owner December 19, 2023 22:06
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 19, 2023

Codecov Report

Attention: 68 lines in your changes are missing coverage. Please review.

Comparison is base (6f35864) 67.96% compared to head (15e4996) 67.91%.
Report is 38 commits behind head on develop.

❗ Current head 15e4996 differs from pull request most recent head e13f5e6. Consider uploading reports for the commit e13f5e6 to get more accurate results

Files Patch % Lines
ui/selectors/selectors.js 53.85% 18 Missing ⚠️
app/scripts/lib/account-tracker.js 77.42% 14 Missing ⚠️
...omponents/app/reveal-SRP-modal/reveal-SRP-modal.js 42.86% 8 Missing ⚠️
app/scripts/metamask-controller.js 80.77% 5 Missing ⚠️
ui/pages/onboarding-flow/onboarding-flow.js 42.86% 4 Missing ⚠️
ui/pages/asset/components/token-asset.js 0.00% 3 Missing ⚠️
ui/pages/confirmation/confirmation.js 66.67% 3 Missing ⚠️
app/scripts/controllers/mmi-controller.js 33.33% 2 Missing ⚠️
...ents/app/modals/qr-scanner/qr-scanner.component.js 0.00% 2 Missing ⚠️
.../components/app/qr-hardware-popover/base-reader.js 0.00% 2 Missing ⚠️
... and 6 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #22302      +/-   ##
===========================================
- Coverage    67.96%   67.91%   -0.05%     
===========================================
  Files         1067     1072       +5     
  Lines        41276    41393     +117     
  Branches     11084    11124      +40     
===========================================
+ Hits         28051    28111      +60     
- Misses       13225    13282      +57     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [15e4996]
Page Load Metrics (1150 ± 159 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint822601496330
domContentLoaded9167546230
load77222961150331159
domInteractive9167546230
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.42 KiB (0.10%)
  • common: 0 Bytes (0.00%)

@garrettbear garrettbear force-pushed the feat/formtextfield-to-ts branch from 15e4996 to d104594 Compare December 20, 2023 17:21
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

Looks good! Left one suggestion in the types regarding the wrapping html element otherwise LGTM!

  • Checked stories, docs and controls ✅
  • Checked all instances of <FormTextField> were pointing to deprecated version ✅
    Screenshot 2023-12-20 at 11 28 34 AM

…d.types.ts

Co-authored-by: George Marshall <george.marshall@consensys.net>
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

🔥🔥🔥🔥 🚀 🚀 🚀 🚀

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [37ba33f]
Page Load Metrics (1367 ± 127 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1013151685728
domContentLoaded10239576732
load101019281367264127
domInteractive10239576732
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 6.42 KiB (0.09%)
  • common: 0 Bytes (0.00%)

@georgewrmarshall georgewrmarshall merged commit 23d59a8 into develop Dec 21, 2023
@georgewrmarshall georgewrmarshall deleted the feat/formtextfield-to-ts branch December 21, 2023 16:45
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
@metamaskbot metamaskbot added the release-11.9.0 Issue or pull request that will be included in release 11.9.0 label Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-11.9.0 Issue or pull request that will be included in release 11.9.0 team-design-system All issues relating to design system in Extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate components to TS: FormTextField

4 participants