Add test from display value of selected
parent
68151dd92e
commit
9d4162c60b
|
@ -1,24 +1,31 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Dropdown from 'src/shared/components/Dropdown'
|
import Dropdown from 'src/shared/components/Dropdown'
|
||||||
|
|
||||||
|
interface TableColumn {
|
||||||
|
internalName: string
|
||||||
|
displayName: string
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
sortByOptions: any[]
|
sortByOptions: any[]
|
||||||
onChooseSortBy: (any) => void
|
onChooseSortBy: (any) => void
|
||||||
selected: string
|
selected: TableColumn
|
||||||
}
|
}
|
||||||
|
|
||||||
const GraphOptionsSortBy = ({sortByOptions, onChooseSortBy, selected} : Props) => (
|
const GraphOptionsSortBy = ({sortByOptions, onChooseSortBy, selected} : Props) => {
|
||||||
<div className="form-group col-xs-6">
|
const selectedValue = selected.displayName || selected.internalName
|
||||||
|
|
||||||
|
return <div className="form-group col-xs-6">
|
||||||
<label>Sort By</label>
|
<label>Sort By</label>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
items={sortByOptions}
|
items={sortByOptions}
|
||||||
selected={selected}
|
selected={selectedValue}
|
||||||
buttonColor="btn-default"
|
buttonColor="btn-default"
|
||||||
buttonSize="btn-sm"
|
buttonSize="btn-sm"
|
||||||
className="dropdown-stretch"
|
className="dropdown-stretch"
|
||||||
onChoose={onChooseSortBy}
|
onChoose={onChooseSortBy}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
}
|
||||||
|
|
||||||
export default GraphOptionsSortBy
|
export default GraphOptionsSortBy
|
||||||
|
|
|
@ -145,7 +145,7 @@ export class TableOptions extends PureComponent<Props, {}> {
|
||||||
onToggleTimeAxis={this.handleToggleTimeAxis}
|
onToggleTimeAxis={this.handleToggleTimeAxis}
|
||||||
/>
|
/>
|
||||||
<GraphOptionsSortBy
|
<GraphOptionsSortBy
|
||||||
selected={tableOptions.sortBy.internalName || TIME_COLUMN_DEFAULT.internalName}
|
selected={tableOptions.sortBy || TIME_COLUMN_DEFAULT}
|
||||||
sortByOptions={tableSortByOptions}
|
sortByOptions={tableSortByOptions}
|
||||||
onChooseSortBy={this.handleChooseSortBy}
|
onChooseSortBy={this.handleChooseSortBy}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TableGraph extends Component {
|
||||||
data: [[]],
|
data: [[]],
|
||||||
hoveredColumnIndex: NULL_COLUMN_INDEX,
|
hoveredColumnIndex: NULL_COLUMN_INDEX,
|
||||||
hoveredRowIndex: NULL_ROW_INDEX,
|
hoveredRowIndex: NULL_ROW_INDEX,
|
||||||
columnIndex: -1,
|
sortByColumnIndex: -1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ class TableGraph extends Component {
|
||||||
const {data} = timeSeriesToTableGraph(nextProps.data)
|
const {data} = timeSeriesToTableGraph(nextProps.data)
|
||||||
|
|
||||||
const {tableOptions: {sortBy: {internalName}}} = nextProps
|
const {tableOptions: {sortBy: {internalName}}} = nextProps
|
||||||
const columnIndex = _.indexOf(data[0], internalName)
|
const sortByColumnIndex = _.indexOf(data[0], internalName)
|
||||||
|
|
||||||
const sortedData = _.sortBy(_.drop(data, 1), columnIndex)
|
const sortedData = _.sortBy(_.drop(data, 1), sortByColumnIndex)
|
||||||
this.setState({data: [data[0], ...sortedData], columnIndex})
|
this.setState({data: [data[0], ...sortedData], sortByColumnIndex})
|
||||||
}
|
}
|
||||||
|
|
||||||
calcHoverTimeRow = (data, hoverTime) =>
|
calcHoverTimeRow = (data, hoverTime) =>
|
||||||
|
@ -137,7 +137,7 @@ class TableGraph extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {hoveredColumnIndex, hoveredRowIndex} = this.state
|
const {sortByColumnIndex, hoveredColumnIndex, hoveredRowIndex} = this.state
|
||||||
const {hoverTime, tableOptions, colors} = this.props
|
const {hoverTime, tableOptions, colors} = this.props
|
||||||
const {data} = this.state
|
const {data} = this.state
|
||||||
const columnCount = _.get(data, ['0', 'length'], 0)
|
const columnCount = _.get(data, ['0', 'length'], 0)
|
||||||
|
@ -175,7 +175,7 @@ class TableGraph extends Component {
|
||||||
columnNames={
|
columnNames={
|
||||||
tableOptions ? tableOptions.columnNames : [TIME_COLUMN_DEFAULT]
|
tableOptions ? tableOptions.columnNames : [TIME_COLUMN_DEFAULT]
|
||||||
}
|
}
|
||||||
columnIndex={columnIndex}
|
sortByColumnIndex={sortByColumnIndex}
|
||||||
scrollToRow={hoverTimeRow}
|
scrollToRow={hoverTimeRow}
|
||||||
cellRenderer={this.cellRenderer}
|
cellRenderer={this.cellRenderer}
|
||||||
hoveredColumnIndex={hoveredColumnIndex}
|
hoveredColumnIndex={hoveredColumnIndex}
|
||||||
|
|
|
@ -7,7 +7,10 @@ import Dropdown from 'src/shared/components/Dropdown'
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
sortByOptions: [],
|
sortByOptions: [],
|
||||||
onChooseSortBy: () => {},
|
onChooseSortBy: () => {},
|
||||||
selected: ''
|
selected: {
|
||||||
|
internalName: 'boom',
|
||||||
|
displayName: 'here',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setup = (override = {}) => {
|
const setup = (override = {}) => {
|
||||||
|
@ -25,8 +28,19 @@ describe('Dashboards.Components.GraphOptionsSortBy', () => {
|
||||||
const dropdown = wrapper.find(Dropdown)
|
const dropdown = wrapper.find(Dropdown)
|
||||||
const label = wrapper.find('label')
|
const label = wrapper.find('label')
|
||||||
|
|
||||||
|
expect(dropdown.props().selected).toEqual('here')
|
||||||
expect(dropdown.exists()).toBe(true)
|
expect(dropdown.exists()).toBe(true)
|
||||||
expect(label.exists()).toBe(true)
|
expect(label.exists()).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('when selected display name is not available', () => {
|
||||||
|
it('render internal name as selected', () => {
|
||||||
|
const {wrapper} = setup({selected: {internalName: 'boom'}})
|
||||||
|
|
||||||
|
const dropdown = wrapper.find(Dropdown)
|
||||||
|
|
||||||
|
expect(dropdown.props().selected).toEqual('boom')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue