Skip to content

Commit dd08798

Browse files
authored
fix(Bug): remove unnecesary state setting to stop multiple re-renderings (#4467)
1 parent cc65cf9 commit dd08798

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

src/visualization/utils/useStaticLegend.ts

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import {useMemo, useContext, useCallback} from 'react'
3-
import {useDispatch, useSelector} from 'react-redux'
3+
import {useDispatch} from 'react-redux'
44

55
// Context
66
import {PipeContext} from 'src/flows/context/pipe'
@@ -12,15 +12,10 @@ import {setStaticLegend} from 'src/timeMachine/actions'
1212
import {StaticLegend as StaticLegendConfig} from '@influxdata/giraffe'
1313
import {StaticLegend as StaticLegendAPI} from 'src/types'
1414

15-
// Utils
16-
import {getActiveTimeMachine} from 'src/timeMachine/selectors'
17-
1815
// Constants
1916
import {
2017
LEGEND_COLORIZE_ROWS_DEFAULT,
2118
LEGEND_OPACITY_DEFAULT,
22-
LEGEND_OPACITY_MINIMUM,
23-
LEGEND_OPACITY_MAXIMUM,
2419
LEGEND_ORIENTATION_THRESHOLD_DEFAULT,
2520
LEGEND_ORIENTATION_THRESHOLD_HORIZONTAL,
2621
LEGEND_ORIENTATION_THRESHOLD_VERTICAL,
@@ -71,7 +66,6 @@ const eventPrefix = 'visualization.customize.staticlegend'
7166
export const useStaticLegend = (properties): StaticLegendConfig => {
7267
const {id, data, update} = useContext(PipeContext)
7368

74-
const {isViewingVisOptions} = useSelector(getActiveTimeMachine)
7569
const dispatch = useDispatch()
7670
const timeMachineUpdate = useCallback(
7771
(staticLegend: StaticLegendAPI) => {
@@ -102,8 +96,6 @@ export const useStaticLegend = (properties): StaticLegendConfig => {
10296

10397
return useMemo(() => {
10498
const {
105-
legendColorizeRows = LEGEND_COLORIZE_ROWS_DEFAULT,
106-
legendOpacity = LEGEND_OPACITY_DEFAULT,
10799
legendOrientationThreshold = LEGEND_ORIENTATION_THRESHOLD_DEFAULT,
108100
} = properties
109101

@@ -119,47 +111,14 @@ export const useStaticLegend = (properties): StaticLegendConfig => {
119111
} = properties
120112

121113
const {
122-
colorizeRows = false, // undefined is false because of omitempty
114+
colorizeRows = false,
123115
heightRatio = STATIC_LEGEND_HEIGHT_RATIO_NOT_SET,
124116
opacity = LEGEND_OPACITY_DEFAULT,
125117
orientationThreshold = legendOrientationThreshold,
126118
show = STATIC_LEGEND_SHOW_DEFAULT,
127119
...config
128120
} = staticLegend
129121

130-
if (
131-
isViewingVisOptions &&
132-
!show &&
133-
heightRatio === STATIC_LEGEND_HEIGHT_RATIO_NOT_SET
134-
) {
135-
let validOpacity = LEGEND_OPACITY_DEFAULT
136-
if (
137-
typeof legendOpacity === 'number' &&
138-
legendOpacity === legendOpacity &&
139-
legendOpacity >= LEGEND_OPACITY_MINIMUM &&
140-
legendOpacity <= LEGEND_OPACITY_MAXIMUM
141-
) {
142-
validOpacity = legendOpacity
143-
}
144-
145-
let validThreshold: number
146-
if (
147-
typeof legendOrientationThreshold !== 'number' ||
148-
legendOrientationThreshold !== legendOrientationThreshold ||
149-
legendOrientationThreshold > 0
150-
) {
151-
validThreshold = LEGEND_ORIENTATION_THRESHOLD_HORIZONTAL
152-
} else {
153-
validThreshold = LEGEND_ORIENTATION_THRESHOLD_VERTICAL
154-
}
155-
156-
updateStaticLegendProperties({
157-
colorizeRows: legendColorizeRows,
158-
opacity: validOpacity,
159-
orientationThreshold: validThreshold,
160-
})
161-
}
162-
163122
return {
164123
...config,
165124
colorizeRows,
@@ -226,5 +185,5 @@ export const useStaticLegend = (properties): StaticLegendConfig => {
226185
}
227186
},
228187
}
229-
}, [properties, isViewingVisOptions, updateStaticLegendProperties])
188+
}, [properties, updateStaticLegendProperties])
230189
}

0 commit comments

Comments
 (0)