-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
ResetViewsButton.tsx
56 lines (52 loc) · 1.48 KB
/
ResetViewsButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as React from 'react';
import PropTypes from 'prop-types';
import VisibilityOff from '@material-ui/icons/VisibilityOff';
import {
useUpdateMany,
useNotify,
useUnselectAll,
Button,
CRUD_UPDATE_MANY,
} from 'react-admin';
const ResetViewsButton = ({ resource, selectedIds }) => {
const notify = useNotify();
const unselectAll = useUnselectAll();
const [updateMany, { loading }] = useUpdateMany(
resource,
selectedIds,
{ views: 0 },
{
action: CRUD_UPDATE_MANY,
onSuccess: () => {
notify('ra.notification.updated', 'info', {
smart_count: selectedIds.length,
});
unselectAll(resource);
},
onFailure: error =>
notify(
typeof error === 'string'
? error
: error.message || 'ra.notification.http_error',
'warning'
),
mutationMode: 'optimistic',
}
);
return (
<Button
label="simple.action.resetViews"
disabled={loading}
onClick={updateMany}
>
<VisibilityOff />
</Button>
);
};
ResetViewsButton.propTypes = {
basePath: PropTypes.string,
label: PropTypes.string,
resource: PropTypes.string.isRequired,
selectedIds: PropTypes.arrayOf(PropTypes.any).isRequired,
};
export default ResetViewsButton;