Skip to content

Commit 5b7851f

Browse files
fix: call color mapping code after the render cycle in Vis.tsx (#4233)
1 parent 17a4f49 commit 5b7851f

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/timeMachine/components/Vis.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {FC, memo} from 'react'
2+
import React, {FC, memo, useEffect} from 'react'
33
import {connect, ConnectedProps, useDispatch} from 'react-redux'
44
import classnames from 'classnames'
55
import {createGroupIDColumn, fromFlux} from '@influxdata/giraffe'
@@ -95,26 +95,31 @@ const TimeMachineVis: FC<Props> = ({
9595
giraffeResult.table.getColumnType('_value') !== 'number' &&
9696
!!giraffeResult.table.length)
9797

98-
if (
99-
isFlagEnabled('graphColorMapping') &&
100-
viewProperties.hasOwnProperty('colors')
101-
) {
102-
const groupKey = [...giraffeResult.fluxGroupKeyUnion, 'result']
103-
const [, fillColumnMap] = createGroupIDColumn(giraffeResult.table, groupKey)
104-
const {colorMappingForIDPE, needsToSaveToIDPE} = getColorMappingObjects(
105-
fillColumnMap,
106-
viewProperties as XYViewProperties
107-
)
108-
109-
if (loading === RemoteDataState.Done && needsToSaveToIDPE) {
110-
dispatch(
111-
setViewProperties({
112-
...viewProperties,
113-
colorMapping: colorMappingForIDPE,
114-
} as XYViewProperties)
98+
useEffect(() => {
99+
if (
100+
isFlagEnabled('graphColorMapping') &&
101+
viewProperties.hasOwnProperty('colors')
102+
) {
103+
const groupKey = [...giraffeResult.fluxGroupKeyUnion, 'result']
104+
const [, fillColumnMap] = createGroupIDColumn(
105+
giraffeResult.table,
106+
groupKey
107+
)
108+
const {colorMappingForIDPE, needsToSaveToIDPE} = getColorMappingObjects(
109+
fillColumnMap,
110+
viewProperties as XYViewProperties
115111
)
112+
113+
if (loading === RemoteDataState.Done && needsToSaveToIDPE) {
114+
dispatch(
115+
setViewProperties({
116+
...viewProperties,
117+
colorMapping: colorMappingForIDPE,
118+
} as XYViewProperties)
119+
)
120+
}
116121
}
117-
}
122+
})
118123

119124
// Handles deadman check edge case to allow non-numeric values
120125
if (viewRawData && files && files?.length) {

0 commit comments

Comments
 (0)