refine
refine copied to clipboard
[FEAT] - filters in useCustomMutation
Is your feature request related to a problem? Please describe.
I want to send custom mutation queries based on specific fields (not on id)
DELETE FROM your_table WHERE last_updated < 'some_date';
Describe alternatives you've considered
No idea how to send custom mutation queries (apart form hard-coding it on the data provider)
Additional context
No response
Describe the thing to improve
I'd like to have filters on useCustomMutation (the same way as in useCustom) to be able to specify conditions for UPDATEs and DELETEs
Hey @rodbs you can send extra params to your data provider through meta
field, and utilize these fields there.
I think it would still be nice to accept filter params to hooks such as useUpdateMany
and useDeleteMany
. cc @aliemir
We are open to contributions for this issue!
Basically, we need to accept optional filter
parameter to useUpdateMany
, useDeleteMany
hooks and pass them to the data providers.
After this, data providers can be revised to include filters in their requests.
I am up for this
Hi I am interested as well! Would like to attempt this if there is no PR in one week 🙏🙏
@BatuhanW Can I work on this?
Hey @beg1c, sure. Assigned this issue to you 🙌
@BatuhanW I looked into this a bit but I am a little bit confused. If we extend DeleteManyParams
with filters
, we end up with:
export interface DeleteManyParams<TVariables = {}> {
resource: string;
ids: BaseKey[];
filters?: CrudFilters;
variables?: TVariables;
meta?: MetaQuery;
metaData?: MetaQuery;
}
Since ids
can't be undefined, we would still have to select all known ids
and send them with filters to back-end. That could be handled on back-end as ids
could be ignored and deletion would be performed by filters.
Problem arises if deleteMany
method is not implemented in our dataProvider
, useDeleteMany
will execute a lot of requests with deleteOne
and that could cause problems.
const mutationFn = () => {
if (selectedDataProvider.deleteMany) {
return selectedDataProvider.deleteMany<TData, TVariables>({
resource: resource.name,
ids,
filters: filters,
meta: combinedMeta,
metaData: combinedMeta,
variables: values,
});
}
return handleMultiple(
ids.map((id) =>
selectedDataProvider.deleteOne<TData, TVariables>({
resource: resource.name,
id,
filters: filters,
meta: combinedMeta,
metaData: combinedMeta,
variables: values,
}),
),
);
};
Should we force deleteMany
if filters
are present so that user can, for example, delete every inactive product?
Hey @beg1c, you are right. Initially, we thought that it should makes sense, but we've discussed again, and since users are explicitly passing ids, filters would be redundant.