-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SIEM] Add react/display-name eslint rule #53107
Conversation
Pinging @elastic/siem (Team:SIEM) |
💚 Build SucceededTo update your PR or re-run it, just comment with: |
…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
@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 */ |
There was a problem hiding this comment.
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 = [] }) => { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
/* eslint-disable react/display-name */ | ||
|
There was a problem hiding this comment.
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?).
There was a problem hiding this comment.
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 }) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> = ({ |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
SignalsChartsComponent.displayName = 'SignalsChartsComponent'; | ||
|
||
export const SignalsCharts = memo(SignalsChartsComponent); |
There was a problem hiding this comment.
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)
There was a problem hiding this 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.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
@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? |
There was a problem hiding this 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):
…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
…/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) ...
Co-authored-by: Elastic Machine <[email protected]>
* 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) ...
Summary
Add eslint rule to make sure we always add
displayName
to the componentsChecklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.For maintainers