marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.91k stars 5.24k forks source link

Cannot filter List by array property #4886

Closed sulcad14 closed 4 years ago

sulcad14 commented 4 years ago

What you were expecting: I was expecting to filter the List component by my tag property, that is an array (index: value).

What happened instead: Basically nothing. The filter returns an empty List.

Steps to reproduce: Check out related code.

Related code:

const tags = [
    { id: 'testTag1', name: 'testTag1' },
    { id: 'testTag1', name: 'testTag1' }
];

const VideoFilter = (props) => (
    <Filter {...props}>
        <TextInput source="_id" alwaysOn />
        <TextInput source="name" alwaysOn />
        <ReferenceInput source="quizmaster" reference="qm" filterToQuery={searchText => ({ caption: searchText })} alwaysOn>
            <SelectInput optionText="caption" translateChoice={false} />
        </ReferenceInput>
        <SelectArrayInput source="tags" choices={tags} alwaysOn />
    </Filter>
);

Environment React-admin version: 3.2.2

fzaninotto commented 4 years ago

Hi, and thanks for this issue.

I cannot reproduce any problem when adding a similar filter in the simple example:

const tags = [
    { id: 'testTag1', name: 'testTag1' },
    { id: 'testTag2', name: 'testTag2' },
];

const PostFilter = props => (
    <Filter {...props}>
        <SearchInput source="q" alwaysOn />
        <SelectArrayInput source="tags" choices={tags} alwaysOn />
    </Filter>
);

Selecting one of more tags properly changes the URL and sends a request to the dataProvider:

getList posts {"pagination":{"page":1,"perPage":10},"sort":{"field":"published_at","order":"DESC"},"filter":{"tags":["testTag1","testTag2"]}}

If if doesn't return anything, it's probably because you've not handled the case where the value of a filter is an array in your dataProvider.

As it's not a bug in react-admin, I'm closing this issue.