Merge pull request #1346 from strapi/fix-filters

Remove unappropriate filters according to field type
This commit is contained in:
Jim LAURIE 2018-06-11 19:30:11 +02:00 committed by GitHub
commit 414cb9dc4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 87 additions and 37 deletions

View File

@ -1,36 +1,86 @@
const FILTER_TYPES = [
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES.=',
value: '=',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._ne',
value: '_ne',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._lt',
value: '_lt',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._lte',
value: '_lte',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._gt',
value: '_gt',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._gte',
value: '_gte',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._contains',
value: '_contains',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._containss',
value: '_containss',
},
];
const getFilters = (type) => {
switch(type) {
case 'string':
case 'text':
case 'password':
case 'email':
return [
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES.=',
value: '=',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._ne',
value: '_ne',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._lt',
value: '_lt',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._lte',
value: '_lte',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._gt',
value: '_gt',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._gte',
value: '_gte',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._contains',
value: '_contains',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._containss',
value: '_containss',
},
];
case 'integer':
case 'float':
case 'decimal':
case 'date':
return [
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES.=',
value: '=',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._ne',
value: '_ne',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._lt',
value: '_lt',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._lte',
value: '_lte',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._gt',
value: '_gt',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._gte',
value: '_gte',
},
];
default:
return [
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES.=',
value: '=',
},
{
id: 'content-manager.components.FilterOptions.FILTER_TYPES._ne',
value: '_ne',
},
];
}
};
export default FILTER_TYPES;
export default getFilters;

View File

@ -17,7 +17,7 @@ import InputWithAutoFocus from './InputWithAutoFocus';
import Remove from './Remove';
import styles from './styles.scss';
import FILTER_TYPES from './filterTypes';
import getFilters from './filterTypes';
const defaultInputStyle = { width: '210px', marginRight: '10px', paddingTop: '4px' };
const midSelectStyle = { minWidth: '130px', maxWidth: '200px', marginLeft: '10px', marginRight: '10px' };
@ -51,7 +51,7 @@ function FilterOptions({ filter, filterToFocus, index, onChange, onClickAdd, onC
onChange={onChange}
name={`${index}.filter`}
value={get(filter, 'filter', '=')}
selectOptions={FILTER_TYPES}
selectOptions={getFilters(attrType)}
style={midSelectStyle}
/>
<div className={cn(isDate ? styles.filterOptionsInputWrapper : '')}>