forked from marmelab/react-admin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FilterButtonMenuItem.tsx
47 lines (43 loc) · 1.5 KB
/
FilterButtonMenuItem.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
import * as React from 'react';
import { forwardRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import MenuItem from '@material-ui/core/MenuItem';
import { FieldTitle, useResourceContext } from 'ra-core';
export const FilterButtonMenuItem = forwardRef<any, FilterButtonMenuItemProps>(
(props, ref) => {
const { filter, onShow } = props;
const resource = useResourceContext(props);
const handleShow = useCallback(() => {
onShow({
source: filter.props.source,
defaultValue: filter.props.defaultValue,
});
}, [filter.props.defaultValue, filter.props.source, onShow]);
return (
<MenuItem
className="new-filter-item"
data-key={filter.props.source}
data-default-value={filter.props.defaultValue}
key={filter.props.source}
onClick={handleShow}
ref={ref}
>
<FieldTitle
label={filter.props.label}
source={filter.props.source}
resource={resource}
/>
</MenuItem>
);
}
);
FilterButtonMenuItem.propTypes = {
filter: PropTypes.element.isRequired,
onShow: PropTypes.func.isRequired,
resource: PropTypes.string,
};
export interface FilterButtonMenuItemProps {
filter: JSX.Element;
onShow: (params: { source: string; defaultValue: any }) => void;
resource: string;
}