From 02946a48a21de4177e61b942f90f31d5bed6876b Mon Sep 17 00:00:00 2001 From: Bucky Schwarz Date: Tue, 31 Mar 2020 15:23:39 -0700 Subject: [PATCH] fix: view editor overlay should respect table view options --- CHANGELOG.md | 1 + ui/src/timeMachine/reducers/index.test.ts | 35 +++++++++++++++++++++++ ui/src/timeMachine/reducers/index.ts | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e6f1d89f..26027a1250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ 1. [17391](https://github.com/influxdata/influxdb/pull/17391): Fixed threshold check bug where checks could not be created when a field had a space in the name 1. [17384](https://github.com/influxdata/influxdb/pull/17384): Reuse slices built by iterator to reduce allocations 1. [17404](https://github.com/influxdata/influxdb/pull/17404): Updated duplicate check error message to be more explicit and actionable +1. [17515](https://github.com/influxdata/influxdb/pull/17515): Editing a table cell shows the proper values and respects changes ### UI Improvements diff --git a/ui/src/timeMachine/reducers/index.test.ts b/ui/src/timeMachine/reducers/index.test.ts index 7eb054754f..5f279989f5 100644 --- a/ui/src/timeMachine/reducers/index.test.ts +++ b/ui/src/timeMachine/reducers/index.test.ts @@ -7,6 +7,8 @@ import { timeMachinesReducer, } from 'src/timeMachine/reducers' +import {RemoteDataState, TableViewProperties} from 'src/types' + describe('the Time Machine reducer', () => { describe('setting the default aggregateFunctionType', () => { const store = createStore(timeMachinesReducer, initialState()) @@ -189,4 +191,37 @@ describe('the Time Machine reducer', () => { expect(activeTimeMachine.activeQueryIndex).toBe(originalActiveQueryIndex) }) }) + + // Fix for: https://github.com/influxdata/influxdb/issues/17364 + describe('editing a table view', () => { + it('does not overwrite internal TableViewProperites when files is an empty array', () => { + const initial = initialState() + + const store = createStore(timeMachinesReducer, initial) + store.dispatch({type: 'SET_VIEW_TYPE', payload: {type: 'table'}}) + + const midState = store.getState() + const tableViewProperties = midState.timeMachines[ + midState.activeTimeMachineID + ].view.properties as TableViewProperties + tableViewProperties.fieldOptions = [ + {internalName: '_foo', displayName: 'foo'}, + ] + + store.dispatch({ + type: 'SET_QUERY_RESULTS', + payload: { + status: RemoteDataState.Done, + files: [], + fetchDuration: 234, + }, + }) + + const endState = store.getState() + expect( + (endState.timeMachines[endState.activeTimeMachineID].view + .properties as TableViewProperties).fieldOptions[0].displayName + ).toBe(tableViewProperties.fieldOptions[0].displayName) + }) + }) }) diff --git a/ui/src/timeMachine/reducers/index.ts b/ui/src/timeMachine/reducers/index.ts index bc6208bcc6..ea15d955df 100644 --- a/ui/src/timeMachine/reducers/index.ts +++ b/ui/src/timeMachine/reducers/index.ts @@ -274,7 +274,7 @@ export const timeMachineReducer = ( draftState.queryResults.status = status draftState.queryResults.errorMessage = errorMessage - if (files) { + if (files && files.length) { if ( state.view && state.view.properties &&