Skip to content

Commit

Permalink
fix(ui): ensure map type variables can get selected key
Browse files Browse the repository at this point in the history
  • Loading branch information
ischolten committed May 6, 2019
1 parent 6b2562c commit 20dcbaf
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Bug Fixes
1. [13753](https://github.com/influxdata/influxdb/pull/13753): Removed hardcoded bucket for Getting Started with Flux dashboard
1. [13783](https://github.com/influxdata/influxdb/pull/13783): Ensure map type variables allow for selecting values

### UI Improvements

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Libraries
import React from 'react'
import {fireEvent} from 'react-testing-library'

// Components
import VariableDropdown from 'src/dashboards/components/variablesControlBar/VariableDropdown'

// Utils
import {renderWithRedux} from 'src/mockState'
import {AppState} from 'src/types'

const values = {
def: 'defbuck',
def2: 'defbuck',
foo: 'foobuck',
goo: 'goobuck',
new: 'newBuck',
}

const setInitialState = (state: AppState) => {
return {
...state,
orgs: [
{
id: '03cbdc8a53a63000',
},
],
variables: {
status: 'Done',
variables: {
'03cbdc8a53a63000': {
variable: {
id: '03cbdc8a53a63000',
orgID: '03c02466515c1000',
name: 'map_buckets',
description: '',
selected: null,
arguments: {
type: 'map',
values,
},
labels: [],
},
status: 'Done',
},
},
values: {
'03c8070355fbd000': {
status: 'Done',
values: {
'03cbdc8a53a63000': {
valueType: 'string',
values: Object.values(values),
selectedValue: 'defbuck',
},
},
order: ['03cbdc8a53a63000'],
},
},
},
}
}

describe('Dashboards.Components.VariablesControlBar.VariableDropdown', () => {
describe('if map type', () => {
it('renders dropdown with keys as dropdown items', () => {
const {getByTestId, getAllByTestId} = renderWithRedux(
<VariableDropdown
variableID="03cbdc8a53a63000"
dashboardID="03c8070355fbd000"
/>,
setInitialState
)

const dropdownClosed = getByTestId('variable-dropdown')
fireEvent.click(dropdownClosed)
const dropdownItems = getAllByTestId(/dropdown--item/)

expect(dropdownItems.length).toBe(Object.keys(values).length)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class VariableDropdown extends PureComponent<Props> {
selectedID={selectedKey}
onChange={this.handleSelect}
widthPixels={140}
titleText="No Values"
titleText={selectedKey || 'No Values'}
customClass="variable-dropdown--dropdown"
menuColor={DropdownMenuColors.Amethyst}
buttonTestID="variable-dropdown"
>
{dropdownValues.map(({name}) => (
/*
Expand Down
2 changes: 1 addition & 1 deletion ui/src/dashboards/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getVariableValuesForDropdown = (
const selection = list.find(({value}) => value === selectedValue)

return {
selectedKey: selection[0],
selectedKey: get(selection, 'name', ''),
list,
}
}
Expand Down

0 comments on commit 20dcbaf

Please sign in to comment.