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

[APM] Add react-hooks lint rules for APM folder, fix dependencies #42129

Merged
merged 3 commits into from
Jul 29, 2019

Conversation

dgieselaar
Copy link
Member

Closes #42128.

@dgieselaar dgieselaar requested a review from a team as a code owner July 29, 2019 11:46
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@@ -120,15 +120,19 @@ export function KueryBar() {
let didCancel = false;

async function loadIndexPattern() {
setState({ ...state, isLoadingIndexPattern: true });
setState(value => ({ ...value, isLoadingIndexPattern: true }));
Copy link
Member

Choose a reason for hiding this comment

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

Better 👍

Copy link
Member

Choose a reason for hiding this comment

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

... again: did the linter catch this? If so, that's great!

Copy link
Member Author

Choose a reason for hiding this comment

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

yep!

preservePreviousResponse,
dispatchStatus,
...effectKey
/* eslint-enable react-hooks/exhaustive-deps */
Copy link
Member

Choose a reason for hiding this comment

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

Is it complaining about counter not being used?

Copy link
Member

Choose a reason for hiding this comment

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

I guess that's fine. Although would be better if we could avoid disabling the lint rule somehow...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, and we can't add fn because it's usually recreated every render. Passing fn as a dependency would be more correct, but it would mean that we require the consumer to wrap the function that is passed to useFetcher in useCallback(). Adding result.data breaks stuff as well. I figure we have to do a significant rewrite of this hook to have correct dependencies.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, let's just leave it at this, then

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

Nice work! This is gonna catch some bugs - I can feel it! :)

@dgieselaar dgieselaar requested a review from a team July 29, 2019 13:24
@sorenlouv
Copy link
Member

sorenlouv commented Jul 29, 2019

Would the lint rule catch this issue (missing uiFilters in the dependency list):

  const { data } = useFetcher(() => {
    if (start && end) {
      return loadServiceList({ start, end, uiFilters });
    }
  }, [start, end]);

I'd be surprised if it did, since it's a custom hook.

@dgieselaar
Copy link
Member Author

@sqren There's seemingly an additionalHooks option, we can probably use that:
https://github.com/facebook/react/blob/master/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js#L20

I'll give it a shot, and update the PR if it works.

@@ -0,0 +1,7 @@
module.exports = {
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep the behaviour we are already doing for other overrides of keep everything from eslint in a global configuration other than have nested config files? Like for example https://github.com/elastic/kibana/blob/master/.eslintrc.js#L390,

You can just add other object with those rules on that line,

Copy link
Member Author

Choose a reason for hiding this comment

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

@mistic added another item to the array that only applies to .ts(x) files (it was already applied to .js files).

@dgieselaar
Copy link
Member Author

@sqren the exhaustive-deps rule is now applied to the useFetcher hook as well 👍

@sorenlouv
Copy link
Member

@dgieselaar Wow! That's super cool!

@@ -30,7 +30,7 @@ export function useTransactionBreakdown() {
uiFilters
});
}
}, [serviceName, start, end, uiFilters]);
}, [serviceName, start, end, transactionType, transactionName, uiFilters]);
Copy link
Member

Choose a reason for hiding this comment

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

Did you almost forget to fix what brought you here in the first place :p

Copy link
Member

Choose a reason for hiding this comment

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

Super nice with this custom hooks linter 👍 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I actually left it open because I wanted to test it until I found out that the transaction type select was broken. And then I forgot about it 😅

Copy link
Member

Choose a reason for hiding this comment

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

But the linter saved us! Already proving its worth! :D

Copy link
Member

@mistic mistic left a comment

Choose a reason for hiding this comment

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

The changes to the ESLINT rules looks good to me know 👍

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@dgieselaar dgieselaar merged commit b6258b2 into elastic:master Jul 29, 2019
@dgieselaar dgieselaar deleted the apm-eslint-hooks branch July 29, 2019 18:36
dgieselaar added a commit to dgieselaar/kibana that referenced this pull request Jul 29, 2019
…astic#42129)

* [APM] Add react-hooks lint rules for APM folder, fix dependencies

Closes elastic#42128.

* Validate useFetcher dependencies as well

* Add useFetcher hook; move eslint config to kibana eslint config
dgieselaar added a commit to dgieselaar/kibana that referenced this pull request Aug 2, 2019
…astic#42129)

* [APM] Add react-hooks lint rules for APM folder, fix dependencies

Closes elastic#42128.

* Validate useFetcher dependencies as well

* Add useFetcher hook; move eslint config to kibana eslint config
dgieselaar added a commit that referenced this pull request Aug 2, 2019
* [APM] Add react-hooks lint rules for APM folder, fix dependencies (#42129)

* [APM] Add react-hooks lint rules for APM folder, fix dependencies

Closes #42128.

* Validate useFetcher dependencies as well

* Add useFetcher hook; move eslint config to kibana eslint config

* Fix type errors
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.

[APM] Breakdown graph is not refreshed when transaction type is changed
4 participants