Skip to content

Commit

Permalink
Merge pull request #800 from mbland/filterable-#725
Browse files Browse the repository at this point in the history
Stop filter from matching invisible properties
  • Loading branch information
dahlbyk authored Mar 5, 2018
2 parents e038440 + 920d90b commit eab0dff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
36 changes: 35 additions & 1 deletion src/plugins/local/selectors/__tests__/localSelectorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,34 @@ test('filteredDataSelector filters data respecting filterable', test => {
name: {
filterable: false,
},
weapon: {
filterable: true,
}
}
},
filter: 'H',
data: [
{ id: '1', name: 'luke skywalker', weapon: 'light saber' },
{ id: '2', name: 'han solo', weapon: 'blaster' },
]
});

test.deepEqual(selectors.filteredDataSelector(state).toJSON(), [
{ id: '1', name: 'luke skywalker', weapon: 'light saber' }
]);
});

test('filteredDataSelector matches ColumnDefinition fields only', test => {
const state = new Immutable.fromJS({
renderProperties: {
columnProperties: {
weapon: null,
}
},
filter: 'H',
data: [
{ id: '1', name: 'luke skywalker', weapon: 'light saber' },
{ id: '2', name: 'han solo', weapon: 'blaster' }
{ id: '2', name: 'han solo', weapon: 'blaster' },
]
});

Expand All @@ -263,6 +285,18 @@ test('filteredDataSelector filters data respecting filterable', test => {
]);
});

test('filteredDataSelector ignores griddleKey matches', test => {
const state = new Immutable.fromJS({
filter: '1',
data: [
{ griddleKey: '11', name: 'luke skywalker' },
{ griddleKey: '12', name: 'han solo' }
]
});

test.deepEqual(selectors.filteredDataSelector(state).toJSON(), []);
});

test('sortedDataSelector uses default sort if no sort method specifed for column', test => {
const state = new Immutable.fromJS({
data: [
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/local/selectors/localSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ export const filteredDataSelector = createSelector(
return data.filter(row =>
row.keySeq()
.some((key) => {
const filterable = columnProperties && columnProperties.getIn([key, 'filterable']);
if (filterable === false) {
if (key === 'griddleKey') {
return false;
} else if (columnProperties) {
if (columnProperties.get(key) === undefined ||
columnProperties.getIn([key, 'filterable']) === false) {
return false;
}
}
const value = row.get(key);
return value &&
Expand Down

0 comments on commit eab0dff

Please sign in to comment.