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

[SIEM] Add react/display-name eslint rule #53107

Conversation

patrykkopycinski
Copy link
Contributor

Summary

Add eslint rule to make sure we always add displayName to the components

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@patrykkopycinski patrykkopycinski self-assigned this Dec 16, 2019
@patrykkopycinski patrykkopycinski added release_note:skip Skip the PR/issue when compiling release notes v7.6.0 v8.0.0 Team:SIEM labels Dec 16, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

…lint-display-name

# Conflicts:
#	x-pack/legacy/plugins/siem/public/apps/start_app.tsx
#	x-pack/legacy/plugins/siem/public/components/page/hosts/uncommon_process_table/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/components/activity_monitor/columns.tsx
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/rule_details/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/columns.tsx
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/signals/components/closed_signals/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/signals/components/open_signals/index.tsx
#	x-pack/legacy/plugins/siem/public/pages/detection_engine/signals/index.tsx
@spong
Copy link
Member

spong commented Jan 6, 2020

@elasticmachine merge upstream

@@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

/* eslint-disable react/display-name */
Copy link
Member

Choose a reason for hiding this comment

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

May want to add a comment here as to why this is being disabled -- when I added displayName's for the below three components (AppPluginRoot, StartApp, and SiemApp) they were not being shown in the react dev tools Component tree, so I assume this is the reason?

pageFilters?: esFilters.Filter[];
}

const AlertsTableComponent: React.FC<Props> = ({ endDate, startDate, pageFilters = [] }) => {
Copy link
Member

Choose a reason for hiding this comment

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

What is the intent of creating this intermediary AlertsTableComponent using React.FC and then wrapping as AlertsTable using React.memo vs the previous implementation of just using React.memo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

React.memo propagates name of the wrapped component, but as we were passing an inline function to the memo we end up with Anonymus (Memo)

Copy link
Member

Choose a reason for hiding this comment

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

Ahhh, perfect, that's what I was wondering! 🙂

For anyone passing through, @patrykkopycinski outlines this behavior in https://github.com/elastic/siem-team/issues/485.

Comment on lines +7 to +8
/* eslint-disable react/display-name */

Copy link
Member

Choose a reason for hiding this comment

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

Just noting the consistency of naming our connected components. Seems it's hit or miss on if we set the displayName after calling connect(). Here in AuthenticationTable we do not set displayName after connecting, but we do for UncommonProcessTable. The linter rule does not enforce it for connected components, so we'll need to keep an eye out in reviews (or perhaps see if the updated react-redux can handle setting the displayName?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

with react-redux@7 we will be able to migrate from connect to hooks, so the linter will be able to properly enforce the rule 💪

onFilterGroupChanged: (filterGroup: SignalFilterOption) => void;
}

const SignalsTableFilterGroupComponent: React.FC<Props> = ({ onFilterGroupChanged }) => {
Copy link
Member

Choose a reason for hiding this comment

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

As above, why the change to React.FC and then wrapping in React.memo below?

Also, in this instance, there is no displayName set for either SignalsTableFilterGroupComponent or SignalsTableFilterGroup and I'm seeing no linter error. If I move SignalsTableFilterGroupComponent back to React.memo I then see the "Component definition is missing displayName" linter error. Any idea why we're not seeing errors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for components defined with const the variable name is propagated automatically as a component name, so we don't have to do it manually

sendSignalsToTimeline,
}) => {
const [defaultNumberFormat] = useUiSetting$<string>(DEFAULT_NUMBER_FORMAT);
const SignalsUtilityBarComponent: React.FC<SignalsUtilityBarProps> = ({
Copy link
Member

Choose a reason for hiding this comment

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

Same clarification as above -- why React.FC then wrapped with React.memo? Also, both SignalsUtilityBarComponent and SignalsUtilityBar are missing displayName and no linter error is shown.


export const StepPanel = memo(StepPanelComponent);

StepPanel.displayName = 'StepPanel';
Copy link
Member

Choose a reason for hiding this comment

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

Seems react-dev-tools will detect the memo and use the displayName of the component being wrapped (adding a Memo tag), so we don't need to add a display name for subsequent memo's (unlike the behavior when wrapping components with connect()).


SignalsChartsComponent.displayName = 'SignalsChartsComponent';

export const SignalsCharts = memo(SignalsChartsComponent);
Copy link
Member

Choose a reason for hiding this comment

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

Same question here for why we're abstracting the memo to a parent component? (This component has no props either fwiw)

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Tested locally and performed code review. These changes look good to me, but I left a few comments around our methods of adding displayName to connected and memoized components. Approving now, but we may want to standardize on these methods/add additional comments so any inconsistencies don't propagate through the codebase.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@patrykkopycinski
Copy link
Contributor Author

@spong Thank you for your comments, I did another round and now I believe it was fixed properly. Would you mind to take a look again?

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Reviewed latest changes and LGTM! Thanks for the additional details and fixes @patrykkopycinski!

For anyone passing through, please be sure to check out the following two links for details on setting dispayName (and why creating a FC and wrapping via memo is necessary):

@patrykkopycinski patrykkopycinski merged commit 23a0513 into elastic:master Jan 7, 2020
@patrykkopycinski patrykkopycinski deleted the chore/siem-eslint-display-name branch January 7, 2020 17:05
patrykkopycinski added a commit to patrykkopycinski/kibana that referenced this pull request Jan 7, 2020
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 7, 2020
…le-saved-objects

* 'master' of github.com:elastic/kibana: (86 commits)
  [Uptime] Added date range filter into expanded list query (elastic#52609)
  [SIEM] Add react/display-name eslint rule (elastic#53107)
  [SIEM] Enable eslint prefer-template rule (elastic#53983)
  Elasticsearch snapshots automation (elastic#53706)
  [SIEM] Enable eslint react/no-children-prop (elastic#53985)
  [DOCS][Reporting] Adds info about using a custom reporting index (elastic#54052)
  Changing background color to align with EUI color (elastic#54060)
  Fix linting issues (elastic#54068)
  NP Migration: Move doc views registry and existing doc views into discover plugin (elastic#53465)
  [ML] DF Analytics job creation: Add 'excludes' input field to form (elastic#53856)
  EMT-issue-65: add endpoint list api (elastic#53861)
  [SIEM] Fix doubled drag handles in Timeline (elastic#52679)
  Functional tests: refactor visualize_page (elastic#53845)
  [Dashboard] Redesign empty screen in readonly mode (elastic#54073)
  [ML] Support search for partitions on Single Metric Viewer (elastic#53879)
  update apm index pattern (elastic#54095)
  Add data ui for envoyproxy Metricbeat Module (elastic#53476)
  [ML] persist the brush when expanded to full width (elastic#54020)
  Skip failing test (elastic#54100)
  [APM] Show errors on the timeline instead of under the transaction (elastic#53756)
  ...

# Conflicts:
#	src/legacy/core_plugins/console/public/np_ready/application/contexts/services_context.tsx
#	src/legacy/core_plugins/console/public/np_ready/application/index.tsx
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 7, 2020
…/kibana into feature/console-saved-objects

* 'feature/console-saved-objects' of github.com:jloleysens/kibana: (86 commits)
  [Uptime] Added date range filter into expanded list query (elastic#52609)
  [SIEM] Add react/display-name eslint rule (elastic#53107)
  [SIEM] Enable eslint prefer-template rule (elastic#53983)
  Elasticsearch snapshots automation (elastic#53706)
  [SIEM] Enable eslint react/no-children-prop (elastic#53985)
  [DOCS][Reporting] Adds info about using a custom reporting index (elastic#54052)
  Changing background color to align with EUI color (elastic#54060)
  Fix linting issues (elastic#54068)
  NP Migration: Move doc views registry and existing doc views into discover plugin (elastic#53465)
  [ML] DF Analytics job creation: Add 'excludes' input field to form (elastic#53856)
  EMT-issue-65: add endpoint list api (elastic#53861)
  [SIEM] Fix doubled drag handles in Timeline (elastic#52679)
  Functional tests: refactor visualize_page (elastic#53845)
  [Dashboard] Redesign empty screen in readonly mode (elastic#54073)
  [ML] Support search for partitions on Single Metric Viewer (elastic#53879)
  update apm index pattern (elastic#54095)
  Add data ui for envoyproxy Metricbeat Module (elastic#53476)
  [ML] persist the brush when expanded to full width (elastic#54020)
  Skip failing test (elastic#54100)
  [APM] Show errors on the timeline instead of under the transaction (elastic#53756)
  ...
rylnd pushed a commit that referenced this pull request Jan 7, 2020
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 8, 2020
* master: (55 commits)
  [ui/public/utils] Copy rarely used items to where they are consumed (elastic#53819)
  set AppArch team as an owner of the search endpoints (elastic#54131)
  Don't expose Elasticsearch client as Observable (elastic#53824)
  [SIEM] Cleanup unnecessary use of enzyme-to-json (elastic#53980)
  fix ui exports doc (elastic#54138)
  change markdown element title (elastic#54194)
  [Logs UI] Refactor log position to hooks (elastic#53540)
  [SIEM] Implement NP Plugin Setup (elastic#54030)
  [DOCS] Updates ML links (elastic#53613)
  sort renovate packages in config
  Spaces - fix flakey api tests (elastic#54154)
  Remove dependency that was causing effect to re-execute infinitely. (elastic#54160)
  [dev/run] expose unexpected flags as more than just names (elastic#54080)
  [DOCS] Moves index pattern doc to Discover (elastic#53347)
  [SIEM] Cleanup React imports (elastic#53981)
  Update eslint related packages (elastic#54107)
  [Uptime] Added date range filter into expanded list query (elastic#52609)
  [SIEM] Add react/display-name eslint rule (elastic#53107)
  [SIEM] Enable eslint prefer-template rule (elastic#53983)
  Elasticsearch snapshots automation (elastic#53706)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:SIEM v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants