Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-grid): use a column filter operation as a filter selector value #1479

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/dx-react-grid/src/plugins/table-filter-row.jsx
Expand Up @@ -34,6 +34,15 @@ const defaultMessages = {
lessThanOrEqual: 'Less than or equal to',
};

const getSelectedFilterOperation = (
filterOperations, columnName, filter, columnFilterOperations,
) => {
if (filterOperations[columnName]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract getSelectedFilterOperation function to helpers file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite specific and used only here. I'm not sure it's necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in all packages, we extract specific methods to clear plugins code. If we want to support other frameworks we should extract all functionality to common package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

return filterOperations[columnName];
}
return filter && filter.operation ? filter.operation : columnFilterOperations[0];
};

export class TableFilterRow extends React.PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -85,8 +94,9 @@ export class TableFilterRow extends React.PureComponent {
const columnFilterOperations = getColumnFilterOperations(
getAvailableFilterOperations, columnName,
);
const selectedFilterOperation = filterOperations[columnName]
|| columnFilterOperations[0];
const selectedFilterOperation = getSelectedFilterOperation(
filterOperations, columnName, filter, columnFilterOperations,
);
const handleFilterOperationChange = (value) => {
this.setState({
filterOperations: {
Expand Down
16 changes: 16 additions & 0 deletions packages/dx-react-grid/src/plugins/table-filter-row.test.jsx
Expand Up @@ -311,4 +311,20 @@ describe('TableFilterRow', () => {
expect(tree.find(defaultProps.filterSelectorComponent).prop('value'))
.toBe('a');
});

it('should use a column filter operation as the FilterSelector value', () => {
getColumnFilterConfig.mockImplementation(() => ({ columnName: 'a', value: 'b', operation: 'startsWith' }));
const filterSelectorValue = mount((
<PluginHost>
{pluginDepsToComponents(defaultDeps)}
<TableFilterRow
{...defaultProps}
showFilterSelector
/>
</PluginHost>
)).find(defaultProps.filterSelectorComponent).prop('value');

expect(filterSelectorValue)
.toBe('startsWith');
});
});