Skip to content

Commit fe11ddf

Browse files
feat: color mapping for when the cell is edited through the time machine (#3561)
1 parent 78e03e2 commit fe11ddf

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/timeMachine/components/Vis.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Libraries
22
import React, {FC, memo} from 'react'
3-
import {connect, ConnectedProps} from 'react-redux'
3+
import {connect, ConnectedProps, useDispatch} from 'react-redux'
44
import classnames from 'classnames'
5-
import {fromFlux} from '@influxdata/giraffe'
5+
import {createGroupIDColumn, fromFlux} from '@influxdata/giraffe'
66
import {isEqual} from 'lodash'
77

88
// Components
99
import {View} from 'src/visualization'
10-
import {SimpleTableViewProperties} from 'src/types'
10+
import {SimpleTableViewProperties, XYViewProperties} from 'src/types'
1111
import ErrorBoundary from 'src/shared/components/ErrorBoundary'
1212
import EmptyQueryView, {ErrorFormat} from 'src/shared/components/EmptyQueryView'
1313
import SimpleTable from 'src/visualization/types/SimpleTable/view'
@@ -25,12 +25,15 @@ import {
2525
getYSeriesColumns,
2626
} from 'src/timeMachine/selectors'
2727
import {getTimeRangeWithTimezone} from 'src/dashboards/selectors'
28+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
29+
import {getColorMappingObjects} from 'src/visualization/utils/colorMappingUtils'
2830

2931
// Types
3032
import {RemoteDataState, AppState, ViewProperties} from 'src/types'
3133

3234
// Selectors
3335
import {getActiveTimeRange} from 'src/timeMachine/selectors/index'
36+
import {setViewProperties} from 'src/timeMachine/actions'
3437

3538
type ReduxProps = ConnectedProps<typeof connector>
3639
type 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

Comments
 (0)