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

Add ability to define filters as an array of Inputs #6368

Merged
merged 6 commits into from Jun 28, 2021
Merged

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Jun 17, 2021

Problem

<ListActions> is hard to override, partly because of the filter button/form combo. The <Filter> element renders twice, which isn't a common practice, and creates a few problems.

Refs #6212

Solution

Allow <List filters> to be an array of inputs instead of a React element.

-const PostFilter = props => (
-    <Filter {...props}>
-        <SearchInput source="q" alwaysOn />
-        <TextInput
-            source="title"
-            defaultValue="Qui tempore rerum et voluptates"
-        />
-        <QuickFilter
-            label="resources.posts.fields.commentable"
-            source="commentable"
-            defaultValue
-        />
-    </Filter>
-);
+const postFilters = [
+    <SearchInput source="q" alwaysOn />,
+    <TextInput source="title" defaultValue="Qui tempore rerum et voluptates" />,
+    <QuickFilter
+        label="resources.posts.fields.commentable"
+        source="commentable"
+        defaultValue
+    />,
+];

const PostList = props => {
         <List
             {...props}
             bulkActionButtons={<PostListBulkActions />}
-            filters={<PostFilter />}
+            filters={postFilters}
             sort={{ field: 'published_at', order: 'DESC' }}
             exporter={exporter}
         >

This allows to put the filters in a context, and to use <FilterForm> and <FilterButton> directly:

const  ListActions = () => (
    <TopToolbar>
        <FilterButton />
        <CreateButton />
        <ExportButton />
    </TopToolbar>
);
  • Add support for array filters in <List>
  • Write tests
  • Update documentation

The change is backwards compatible: <Filter> continues to exist and still works as before.

@fzaninotto fzaninotto added the WIP Work In Progress label Jun 17, 2021
@fzaninotto fzaninotto changed the title Add ability to define filters as array of Inputs Add ability to define filters as an array of Inputs Jun 17, 2021
@fzaninotto fzaninotto added RFR Ready For Review and removed WIP Work In Progress labels Jun 22, 2021
@fzaninotto
Copy link
Member Author

Switching to RFR

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Awesome! I remember having eslint issues about missing keys with the array syntax for the <Resource> though.

docs/Inputs.md Outdated Show resolved Hide resolved
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
@fzaninotto
Copy link
Member Author

@djhi I have had no eslint warning, and GitHub doesn't show any... Would you have a reproducible case?

@djhi
Copy link
Contributor

djhi commented Jun 28, 2021

Nope, it was just something I remembered while working with the <Resource> in a render function. All good then!

@djhi djhi merged commit 392c146 into next Jun 28, 2021
@djhi djhi deleted the filter_arrays branch June 28, 2021 15:26
@fzaninotto fzaninotto added this to the 3.17.0 milestone Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants