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

UIP-2529 Add validateProps method to UiComponent #88

Merged

Conversation

jacehensley-wf
Copy link
Contributor

Ultimate problem:

  • Consumers need an easy way to validate props without having to override componentWillReceiveProps and componentWillMount.

How it was fixed:

  • Add validateProps method that is called automatically during those lifecycle methods.

Testing suggestions:

  • Verify tests pass

Potential areas of regression:

  • Required prop validation

FYA: @greglittlefield-wf @aaronlademann-wf @clairesarsam-wf @joelleibow-wf

@aviary-wf
Copy link

aviary-wf commented Jun 24, 2017

Raven

Number of Findings: 0

@codecov-io
Copy link

codecov-io commented Jun 24, 2017

Codecov Report

Merging #88 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master      #88      +/-   ##
==========================================
+ Coverage   94.86%   94.87%   +0.01%     
==========================================
  Files          31       31              
  Lines        1536     1537       +1     
==========================================
+ Hits         1457     1458       +1     
  Misses         79       79

@aaronlademann-wf
Copy link
Contributor

+1

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

Nice! It'll be awesome to have this.

///
/// Use this as an opportunity validate props during the correct lifecycle of the component.
@mustCallSuper
void validateProps([Map appliedProps]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a required positional parameter, so that consumers don't have to null-coalesce the argument in overrides.

@@ -124,6 +124,16 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component {
);
}

/// Validation method called during [componentWillReceiveProps], and [componentWillMount].
///
/// Use this as an opportunity validate props during the correct lifecycle of the component.
Copy link
Contributor

Choose a reason for hiding this comment

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

#nit I think this comment could be a little more descriptive.

/// Throws a [PropError] if [appliedProps] are invalid.
/// 
/// This is called automatically with during [componentWillReceiveProps] and [componentWillMount],
/// and can also be called manually for custom validation.
/// 
/// Override with a custom implementation to easily add validation (and don't forget to call super!)
///
///     @mustCallSuper
///     void validateProps(Map appliedProps) {
///       super.validateProps(appliedProps);
///       
///       var tProps = typedPropsFactory(appliedProps);
///       if (tProps.items.length.isOdd) {
///         throw new PropError.value(tProps.items, 'items', 'must have an even number of items, because reasons');
///       }
///     }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea 👍

component.componentWillReceiveProps({});

expect(calls, ['onValidateProps']);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

These should also test that the correct props maps are passed into them

@@ -124,6 +124,27 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component {
);
}

/// Throws a [PropError] if [appliedProps] are invalid.
///
/// This is called automatically with during [componentWillReceiveProps] and [componentWillMount],
Copy link
Contributor

Choose a reason for hiding this comment

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

This is called automatically with during

Sorry, my typo here.

What about:

This is called automatically with the latest props available during

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:stare:

@aaronlademann-wf
Copy link
Contributor

Still +1

@greglittlefield-wf
Copy link
Contributor

+1

@rmconsole-wf
Copy link

@jacehensley-wf This pull request has merge conflicts, please resolve.

…s_method/dev

# Conflicts:
#	test/over_react/component_declaration/component_base_test.dart
@greglittlefield-wf
Copy link
Contributor

+1

@aaronlademann-wf aaronlademann-wf changed the title Add validateProps method to UiComponent UIP-2529 Add validateProps method to UiComponent Jul 20, 2017
@aaronlademann-wf
Copy link
Contributor

QA +10

  • Testing instruction
  • Dev +1's
  • Dev/QA +10
  • Unit tests created/updated
  • All unit tests pass
  • Rosie ran/Rosie comment displays expected info
  • Dependency Scan Clean

Merging.

@aaronlademann-wf aaronlademann-wf merged commit 52acf28 into Workiva:master Jul 20, 2017
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.

6 participants