Skip to content

Commit 11faa0b

Browse files
author
rofrischmann
committed
#9 normalize data and only do ascending sort
1 parent f9c366d commit 11faa0b

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Diff for: containers/TableView.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ const defaultColumns = [
3535
'mechanism'
3636
]
3737

38+
// normalize data
39+
Object.keys(data).forEach(library => {
40+
Object.keys(columnNames).forEach(column => {
41+
if (!data[library].hasOwnProperty(column)) {
42+
data[library][column] = false
43+
}
44+
})
45+
})
46+
3847
export default class TableView extends Component {
3948
constructor(props, context) {
4049
super(props, context)
4150
this.state = {
4251
sortBy: undefined,
43-
sortAscending: true,
4452
allCollumns: true,
4553
filters: {
4654
vendorPrefixing: false,
@@ -97,8 +105,7 @@ export default class TableView extends Component {
97105

98106
sortBy(column) {
99107
this.setState({
100-
sortBy: this.state.sortBy === column && !this.state.sortAscending ? undefined : column,
101-
sortAscending: this.state.sortBy === column ? !this.state.sortAscending : true
108+
sortBy: this.state.sortBy === column ? undefined : column
102109
})
103110
}
104111

@@ -129,9 +136,9 @@ export default class TableView extends Component {
129136
</Cell>
130137
))
131138

132-
const sortData = Object.keys(data).sort(left => {
139+
const sortData = Object.keys(data).sort((left, right) => {
133140
if (this.state.sortBy) {
134-
if (data[left][this.state.sortBy] === this.state.sortAscending) {
141+
if (data[left][this.state.sortBy] > data[right][this.state.sortBy]) {
135142
return -1
136143
} else {
137144
return 1
@@ -146,11 +153,14 @@ export default class TableView extends Component {
146153
return fulfilled
147154
}, true)
148155

149-
if (this.state.filter) {
150-
return library.indexOf(this.state.filter) > -1 && fulfilled
151-
}
156+
if (fulfilled) {
157+
if (this.state.filter) {
158+
return library.indexOf(this.state.filter) > -1
159+
}
152160

153-
return fulfilled
161+
return true
162+
}
163+
return false
154164
})
155165

156166
const libraries = sortData.map(library => this.renderRow(library, columns))

0 commit comments

Comments
 (0)