2024-02-12 00:23:19 +05:30
|
|
|
import './AddToQueryHOC.styles.scss';
|
|
|
|
|
|
2023-05-18 12:36:02 +05:30
|
|
|
import { Popover } from 'antd';
|
2023-07-13 15:55:43 +03:00
|
|
|
import { OPERATORS } from 'constants/queryBuilder';
|
2024-06-21 11:46:04 +05:30
|
|
|
import { memo, MouseEvent, ReactNode, useMemo } from 'react';
|
2022-08-11 11:45:28 +05:30
|
|
|
|
|
|
|
|
function AddToQueryHOC({
|
|
|
|
|
fieldKey,
|
|
|
|
|
fieldValue,
|
2023-07-11 16:53:15 +03:00
|
|
|
onAddToQuery,
|
2022-08-11 11:45:28 +05:30
|
|
|
children,
|
2022-08-19 17:16:04 +05:30
|
|
|
}: AddToQueryHOCProps): JSX.Element {
|
2024-06-21 11:46:04 +05:30
|
|
|
const handleQueryAdd = (event: MouseEvent<HTMLDivElement>): void => {
|
|
|
|
|
event.stopPropagation();
|
2023-07-13 15:55:43 +03:00
|
|
|
onAddToQuery(fieldKey, fieldValue, OPERATORS.IN);
|
2024-06-21 11:46:04 +05:30
|
|
|
};
|
2022-12-26 16:20:34 +05:30
|
|
|
|
|
|
|
|
const popOverContent = useMemo(() => <span>Add to query: {fieldKey}</span>, [
|
|
|
|
|
fieldKey,
|
2022-08-11 11:45:28 +05:30
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-02-12 00:23:19 +05:30
|
|
|
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
|
|
|
|
|
<div className="addToQueryContainer" onClick={handleQueryAdd}>
|
2022-08-11 11:45:28 +05:30
|
|
|
<Popover placement="top" content={popOverContent}>
|
|
|
|
|
{children}
|
|
|
|
|
</Popover>
|
2024-02-12 00:23:19 +05:30
|
|
|
</div>
|
2022-08-11 11:45:28 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-11 16:53:15 +03:00
|
|
|
export interface AddToQueryHOCProps {
|
2022-12-26 16:20:34 +05:30
|
|
|
fieldKey: string;
|
|
|
|
|
fieldValue: string;
|
2023-07-13 15:55:43 +03:00
|
|
|
onAddToQuery: (fieldKey: string, fieldValue: string, operator: string) => void;
|
2023-05-19 13:14:32 +05:30
|
|
|
children: ReactNode;
|
2022-08-11 11:45:28 +05:30
|
|
|
}
|
|
|
|
|
|
2022-12-26 16:20:34 +05:30
|
|
|
export default memo(AddToQueryHOC);
|