11// Libraries
22import React , { FC , memo } from 'react'
3- import { connect , ConnectedProps } from 'react-redux'
3+ import { connect , ConnectedProps , useDispatch } from 'react-redux'
44import classnames from 'classnames'
5- import { fromFlux } from '@influxdata/giraffe'
5+ import { createGroupIDColumn , fromFlux } from '@influxdata/giraffe'
66import { isEqual } from 'lodash'
77
88// Components
99import { View } from 'src/visualization'
10- import { SimpleTableViewProperties } from 'src/types'
10+ import { SimpleTableViewProperties , XYViewProperties } from 'src/types'
1111import ErrorBoundary from 'src/shared/components/ErrorBoundary'
1212import EmptyQueryView , { ErrorFormat } from 'src/shared/components/EmptyQueryView'
1313import SimpleTable from 'src/visualization/types/SimpleTable/view'
@@ -25,12 +25,15 @@ import {
2525 getYSeriesColumns ,
2626} from 'src/timeMachine/selectors'
2727import { getTimeRangeWithTimezone } from 'src/dashboards/selectors'
28+ import { isFlagEnabled } from 'src/shared/utils/featureFlag'
29+ import { getColorMappingObjects } from 'src/visualization/utils/colorMappingUtils'
2830
2931// Types
3032import { RemoteDataState , AppState , ViewProperties } from 'src/types'
3133
3234// Selectors
3335import { getActiveTimeRange } from 'src/timeMachine/selectors/index'
36+ import { setViewProperties } from 'src/timeMachine/actions'
3437
3538type ReduxProps = ConnectedProps < typeof connector >
3639type Props = ReduxProps
@@ -53,6 +56,8 @@ const TimeMachineVis: FC<Props> = ({
5356 cellID,
5457} ) => {
5558 const { type} = viewProperties
59+ const dispatch = useDispatch ( )
60+
5661 // If the current selections for `xColumn`/`yColumn`/ etc. are invalid given
5762 // the current Flux response, attempt to make a valid selection instead. This
5863 // fallback logic is contained within the selectors that supply each of these
@@ -90,6 +95,24 @@ const TimeMachineVis: FC<Props> = ({
9095 giraffeResult . table . getColumnType ( '_value' ) !== 'number' &&
9196 ! ! giraffeResult . table . length )
9297
98+ if ( isFlagEnabled ( 'graphColorMapping' ) ) {
99+ const groupKey = [ ...giraffeResult . fluxGroupKeyUnion , 'result' ]
100+ const [ , fillColumnMap ] = createGroupIDColumn ( giraffeResult . table , groupKey )
101+ const { colorMappingForIDPE, needsToSaveToIDPE} = getColorMappingObjects (
102+ fillColumnMap ,
103+ viewProperties as XYViewProperties
104+ )
105+
106+ if ( loading === RemoteDataState . Done && needsToSaveToIDPE ) {
107+ dispatch (
108+ setViewProperties ( {
109+ ...viewProperties ,
110+ colorMapping : colorMappingForIDPE ,
111+ } as XYViewProperties )
112+ )
113+ }
114+ }
115+
93116 // Handles deadman check edge case to allow non-numeric values
94117 if ( viewRawData && files && files ?. length ) {
95118 const [ parsedResults ] = files . flatMap ( fromFlux )
0 commit comments