2022-08-11 11:45:28 +05:30
|
|
|
import { MinusCircleOutlined, PlusCircleOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Button, Col, Popover } from 'antd';
|
2023-07-13 15:55:43 +03:00
|
|
|
import { OPERATORS } from 'constants/queryBuilder';
|
|
|
|
|
import { removeJSONStringifyQuotes } from 'lib/removeJSONStringifyQuotes';
|
|
|
|
|
import { memo, useCallback, useMemo } from 'react';
|
2025-06-22 16:28:43 +05:30
|
|
|
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
|
2022-08-11 11:45:28 +05:30
|
|
|
|
2022-08-19 17:16:04 +05:30
|
|
|
function ActionItem({
|
|
|
|
|
fieldKey,
|
|
|
|
|
fieldValue,
|
2023-07-13 15:55:43 +03:00
|
|
|
onClickActionItem,
|
|
|
|
|
}: ActionItemProps): JSX.Element {
|
|
|
|
|
const handleClick = useCallback(
|
|
|
|
|
(operator: string) => {
|
|
|
|
|
const validatedFieldValue = removeJSONStringifyQuotes(fieldValue);
|
|
|
|
|
|
|
|
|
|
onClickActionItem(fieldKey, validatedFieldValue, operator);
|
|
|
|
|
},
|
|
|
|
|
[onClickActionItem, fieldKey, fieldValue],
|
2022-08-11 11:45:28 +05:30
|
|
|
);
|
|
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
const onClickHandler = useCallback(
|
|
|
|
|
(operator: string) => (): void => {
|
|
|
|
|
handleClick(operator);
|
|
|
|
|
},
|
|
|
|
|
[handleClick],
|
|
|
|
|
);
|
2022-08-11 11:45:28 +05:30
|
|
|
|
|
|
|
|
const PopOverMenuContent = useMemo(
|
|
|
|
|
() => (
|
|
|
|
|
<Col>
|
2023-07-13 15:55:43 +03:00
|
|
|
<Button type="text" size="small" onClick={onClickHandler(OPERATORS.IN)}>
|
2024-02-12 00:23:19 +05:30
|
|
|
<PlusCircleOutlined size={12} /> Filter for value
|
2022-08-11 11:45:28 +05:30
|
|
|
</Button>
|
|
|
|
|
<br />
|
2023-07-13 15:55:43 +03:00
|
|
|
<Button type="text" size="small" onClick={onClickHandler(OPERATORS.NIN)}>
|
2024-02-12 00:23:19 +05:30
|
|
|
<MinusCircleOutlined size={12} /> Filter out value
|
2022-08-11 11:45:28 +05:30
|
|
|
</Button>
|
|
|
|
|
</Col>
|
|
|
|
|
),
|
2023-07-13 15:55:43 +03:00
|
|
|
[onClickHandler],
|
2022-08-11 11:45:28 +05:30
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<Popover placement="bottomLeft" content={PopOverMenuContent} trigger="click">
|
|
|
|
|
<Button type="text" size="small">
|
|
|
|
|
...
|
|
|
|
|
</Button>
|
|
|
|
|
</Popover>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
export interface ActionItemProps {
|
|
|
|
|
fieldKey: string;
|
|
|
|
|
fieldValue: string;
|
|
|
|
|
onClickActionItem: (
|
|
|
|
|
fieldKey: string,
|
|
|
|
|
fieldValue: string,
|
|
|
|
|
operator: string,
|
2025-06-22 16:28:43 +05:30
|
|
|
isJSON?: boolean,
|
|
|
|
|
dataType?: DataTypes,
|
2025-07-22 14:51:07 +05:30
|
|
|
fieldType?: string,
|
2023-07-13 15:55:43 +03:00
|
|
|
) => void;
|
|
|
|
|
}
|
2022-08-11 11:45:28 +05:30
|
|
|
|
2023-07-13 15:55:43 +03:00
|
|
|
export default memo(ActionItem);
|