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-1164 (OR): Provide easy access to DOM node in ValidationUtil.warn messages #60

Merged

Conversation

kaanaksoy-wk
Copy link
Contributor

@kaanaksoy-wk kaanaksoy-wk commented Apr 3, 2017

This pull request is connected with UIP-1164 (WSD)

Ultimate problem:

ValidationUtil.warn should take an optional Element parameter which will be console.log/.warn'd to the browser console, allowing consumers to navigate to the offending DOM node in the inspector.

All usages of ValidationUtil.warn should be updated to pass in the corresponding DOM node, where applicable.

How it was fixed:

  • Because ValidationUtil.warn is often used in components' render methods, it cannot use the findDomNode method, since it causes the following error message:

render() should be a pure function of props and state. It should never access something that requires stale data from the previous render, such as refs. Move this logic to componentDidMount and componentDidUpdate instead.

  • To get around this issue, findDomNode will no longer be called within the ValidationUtil.warn method. As a result, the component will be logged to the console rather than the DOM node itself.

  • Make the ValidationUtil.warn method accept an optional second parameter for a component.

  • Following the standard warning message, log the component itself as well as its props in a collapsed group.

Testing suggestions:

  • Verify that all current tests continue to pass.

Potential areas of regression:

  • N/A

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

@aviary2-wf
Copy link

aviary2-wf commented Apr 3, 2017

Raven

Number of Findings: 0

@kaanaksoy-wk kaanaksoy-wk changed the base branch from master to 1.3.0 April 3, 2017 16:54
@kaanaksoy-wk kaanaksoy-wk changed the base branch from 1.3.0 to master April 3, 2017 16:54
@codecov-io
Copy link

codecov-io commented Apr 3, 2017

Codecov Report

Merging #60 into master will decrease coverage by 0.07%.
The diff coverage is 90%.

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
- Coverage   97.73%   97.67%   -0.06%     
==========================================
  Files          28       28              
  Lines        1365     1372       +7     
==========================================
+ Hits         1334     1340       +6     
- Misses         31       32       +1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1986adf...8e3aca2. Read the comment docs.

window.console.groupCollapsed('(Warning info)');

window.console.log(component);
window.console.log('props: ${component.props}');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we "pretty print" these props?

Copy link
Contributor

Choose a reason for hiding this comment

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

UiProps.toString has pretty-printing built in, so this will pretty-print them.

/// assert(ValidationUtil.warn('Some warning message', component));
///
/// The message will be printed out to the console.
static bool warn(String message, [dynamic component]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're expecting a component, we can type this to be react.Component.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, or I wonder if we should accept ReactElements as well (would we ever want to print just the child?)...

Could do something like:

static bool warn(String message, [dynamic data]) {
  ...

  if (data != null) {
    window.console.groupCollapsed('(Warning info)');
    window.console.log(data);

    if (isValidElement(data)) {
      window.console.log('props: ${prettyPrintMap(getProps(data))}');
    } else if (data is react.Component) {
      window.console.log('props: ${prettyPrintMap(data.props)}');
    }
  }

 ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Not trying to move the goalposts of this PR, just putting it out there as an idea 😃.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@greglittlefield-wf Do I need to use prettyPrintMap in both cases? I thought that the toString method on UiProps already handled that for us.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, you're right. The only case it'd be needed is if they're using plain react-dart component, but we don't really have to worry about that.

@greglittlefield-wf
Copy link
Contributor

+1

@aaronlademann-wf
Copy link
Contributor

QA +1

  • 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 d2cd86a into Workiva:master Apr 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.

None yet

7 participants