-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3448 from marmelab/actions-without-side-effect
[RFR] Add useDeleteMany and useUpdateMany hooks
- Loading branch information
Showing
8 changed files
with
423 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CRUD_DELETE_MANY } from '../actions/dataActions/crudDeleteMany'; | ||
import { DELETE_MANY } from '../dataFetchActions'; | ||
import useMutation from './useMutation'; | ||
import { Identifier } from '../types'; | ||
|
||
/** | ||
* Get a callback to call the dataProvider with a DELETE_MANY verb, the result | ||
* of the call (the list of deleted record ids), and the loading state. | ||
* | ||
* The return value updates according to the request state: | ||
* | ||
* - start: [callback, { loading: true, loaded: false }] | ||
* - success: [callback, { data: [data from response], loading: false, loaded: true }] | ||
* - error: [callback, { error: [error from response], loading: false, loaded: true }] | ||
* | ||
* @param resource The resource name, e.g. 'posts' | ||
* @param ids The resource identifiers, e.g. [123, 456] | ||
* @param options Options object to pass to the dataProvider. May include side effects to be executed upon success of failure, e.g. { onSuccess: { refresh: true } } | ||
* | ||
* @returns The current request state. Destructure as [delete, { data, error, loading, loaded }]. | ||
* | ||
* @example | ||
* | ||
* import { useDeleteMany } from 'react-admin'; | ||
* | ||
* const BulkDeletePostsButton = ({ selectedIds }) => { | ||
* const [deleteMany, { loading, error }] = useDeleteMany('posts', selectedIds); | ||
* if (error) { return <p>ERROR</p>; } | ||
* return <button disabled={loading} onClick={deleteMany}>Delete selected posts</button>; | ||
* }; | ||
*/ | ||
const useDeleteMany = (resource: string, ids: [Identifier], options?: any) => | ||
useMutation( | ||
{ type: DELETE_MANY, resource, payload: { ids } }, | ||
{ ...options, action: CRUD_DELETE_MANY } | ||
); | ||
|
||
export default useDeleteMany; |
Oops, something went wrong.