-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Doc] Improve ListActions override #6218
Conversation
👍 Maybe we should do the same for the other action components as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patch. However, I'm not comfortable with this change, and for 2 reasons:
- it creates 2 ways to do one simple thing. This is confusing, which way should a developer use and why?
- your API "hides" that some other buttons are included. I think that will lead to WTF moments for developers.
Overall, I don't think we should implement that.
Ok, how about moving the logic of the Example: import Button from '@material-ui/core/Button';
import { TopToolbar, Edit, useEditActions } from 'react-admin';
const PostEditActions = (props) => {
const DefaultActions = useEditActions(props);
return (
<TopToolbar>
<DefaultActions/>
{/* Add your custom actions */}
<Button
color="primary"
onClick={() => { alert('Your custom action'); }}
>
Custom Action
</Button>
</TopToolbar>
);
};
export const PostEdit = (props) => (
<Edit actions={<PostEditActions />} {...props}>
...
</Edit>
); |
@fzaninotto, |
Why a hook here? We could just have a component rendering a fragment with the default actions right? |
You are right. |
When I think about it, only the First, the documentation could be simplified since we now use the various context: const ListActions = (props) => {
const {
className,
- exporter,
- filters,
- maxResults,
...rest
} = props;
const {
- currentSort,
- resource,
- displayedFilters,
- filterValues,
- hasCreate,
- basePath,
- selectedIds,
- showFilter,
total,
} = useListContext();
return (
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
- {filters && cloneElement(filters, {
- resource,
- showFilter,
- displayedFilters,
- filterValues,
- context: 'button',
- })}
+ {cloneElement(filters, { context: 'button' })}
- <CreateButton basePath={basePath} />
+ <CreateButton />
- <ExportButton
- disabled={total === 0}
- resource={resource}
- sort={currentSort}
- filterValues={filterValues}
- maxResults={maxResults}
- />
+ <ExportButton disabled={total === 0} maxResults={maxResults} />
{/* Add your custom actions */}
<Button
onClick={() => { alert('Your custom action'); }}
label="Show calendar"
>
<IconEvent />
</Button>
</TopToolbar>
);
}; For a simpler use case, the doc is even simpler: const ListActions = () => (
<TopToolbar >
{cloneElement(filters, { context: 'button' })}
<CreateButton />
<ExportButton />
{/* Add your custom actions */}
<Button
onClick={() => { alert('Your custom action'); }}
label="Show calendar"
>
<IconEvent />
</Button>
</TopToolbar>
); I think this is simple enough that we don't have to introduce a new component for that. |
So, I should revert everything and only update the documentation? |
e767c03
to
23373e6
Compare
6e1cd6c
to
dd8f78a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Co-authored-by: Gildas Garcia <[email protected]>
Co-authored-by: Gildas Garcia <[email protected]>
Thanks! |
Implements #6212