-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Fix unnecessary re-renders on the Overview page #56587
Changes from 9 commits
59ddb37
112a64b
fbcf91b
7999e0e
1b40bf4
1044ea6
d9f5dd5
68a57e9
cadabd6
3544d45
abe7967
a681c58
876805e
839f609
aa2dca1
3ee3dd8
99c62f9
f041e65
92f292e
90ab4dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/* | ||
TODO: Remove after https://github.com/epoberezkin/fast-deep-equal/pull/48 | ||
is merged and fast-deep-equal version is bumped | ||
*/ | ||
|
||
declare const equal: (a: any, b: any) => boolean; | ||
export = equal; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import React from 'react'; | |
import { Chart, BarSeries, Axis, Position, ScaleType, Settings } from '@elastic/charts'; | ||
import { getOr, get, isNumber } from 'lodash/fp'; | ||
import deepmerge from 'deepmerge'; | ||
import deepEqual from 'fast-deep-equal/react'; | ||
|
||
import { useTimeZone } from '../../hooks'; | ||
import { AutoSizer } from '../auto_sizer'; | ||
|
@@ -23,6 +24,15 @@ import { | |
useTheme, | ||
} from './common'; | ||
|
||
const MemoChart = React.memo(Chart, deepEqual); | ||
MemoChart.displayName = 'MemoChart'; | ||
const MemoSettings = React.memo(Settings, deepEqual); | ||
MemoSettings.displayName = 'MemoSettings'; | ||
const MemoBarSeries = React.memo(BarSeries, deepEqual); | ||
MemoBarSeries.displayName = 'MemoBarSeries'; | ||
const MemoAxis = React.memo(Axis, deepEqual); | ||
MemoAxis.displayName = 'MemoAxis'; | ||
|
||
const checkIfAllTheDataInTheSeriesAreValid = (series: ChartSeriesData): series is ChartSeriesData => | ||
series != null && | ||
!!get('value.length', series) && | ||
|
@@ -58,12 +68,12 @@ export const BarChartBaseComponent = ({ | |
}; | ||
|
||
return chartConfigs.width && chartConfigs.height ? ( | ||
<Chart> | ||
<Settings {...settings} /> | ||
<MemoChart> | ||
<MemoSettings {...settings} /> | ||
{data.map(series => { | ||
const barSeriesKey = series.key; | ||
return checkIfAllTheDataInTheSeriesAreValid ? ( | ||
<BarSeries | ||
<MemoBarSeries | ||
id={barSeriesKey} | ||
key={barSeriesKey} | ||
name={series.key} | ||
|
@@ -80,22 +90,27 @@ export const BarChartBaseComponent = ({ | |
) : null; | ||
})} | ||
|
||
<Axis | ||
<MemoAxis | ||
id={xAxisId} | ||
position={Position.Bottom} | ||
showOverlappingTicks={false} | ||
tickSize={tickSize} | ||
tickFormat={xTickFormatter} | ||
/> | ||
|
||
<Axis id={yAxisId} position={Position.Left} tickSize={tickSize} tickFormat={yTickFormatter} /> | ||
</Chart> | ||
<MemoAxis | ||
id={yAxisId} | ||
position={Position.Left} | ||
tickSize={tickSize} | ||
tickFormat={yTickFormatter} | ||
/> | ||
</MemoChart> | ||
) : null; | ||
}; | ||
|
||
BarChartBaseComponent.displayName = 'BarChartBaseComponent'; | ||
|
||
export const BarChartBase = React.memo(BarChartBaseComponent); | ||
export const BarChartBase = React.memo(BarChartBaseComponent, deepEqual); | ||
|
||
BarChartBase.displayName = 'BarChartBase'; | ||
|
||
|
@@ -131,8 +146,6 @@ export const BarChartComponent = ({ | |
); | ||
}; | ||
|
||
BarChartComponent.displayName = 'BarChartComponent'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do the recent tooling changes make explicitly setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes with @patrykkopycinski npm library There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the library wasn't added @XavierM :( but the good news is that if we declare component as |
||
|
||
export const BarChart = React.memo(BarChartComponent); | ||
|
||
BarChart.displayName = 'BarChart'; | ||
export const BarChart = React.memo(BarChartComponent, (prevProps, nextProps) => | ||
deepEqual(nextProps.barChart, prevProps.barChart) | ||
); |
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.
I would add a comment where this came from.Looks like it is from one of these files?epoberezkin/fast-deep-equal@f0e3dc1and why we have to have it here and cannot use regular TypeScript without additional "cruft" and duplication for the next maintainer.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.
Ok, I see this above:
I think you are good!