mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 01:12:04 +08:00
102 lines
2.1 KiB
TypeScript
102 lines
2.1 KiB
TypeScript
import { Button, Dropdown, MenuProps, Modal } from 'antd';
|
|
import { COMPOSITE_QUERY } from 'constants/queryBuilderQueryNames';
|
|
import ROUTES from 'constants/routes';
|
|
import history from 'lib/history';
|
|
import { useCallback, useMemo, useState } from 'react';
|
|
import { Dashboard } from 'types/api/dashboard/getAll';
|
|
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
|
|
|
import { MENU_KEY, MENU_LABEL } from './config';
|
|
import ExportPanelContainer from './ExportPanel';
|
|
|
|
function ExportPanel({
|
|
isLoading,
|
|
onExport,
|
|
query,
|
|
}: ExportPanelProps): JSX.Element {
|
|
const [isExport, setIsExport] = useState<boolean>(false);
|
|
|
|
const onModalToggle = useCallback((value: boolean) => {
|
|
setIsExport(value);
|
|
}, []);
|
|
|
|
const onCreateAlertsHandler = useCallback(() => {
|
|
history.push(
|
|
`${ROUTES.ALERTS_NEW}?${COMPOSITE_QUERY}=${encodeURIComponent(
|
|
JSON.stringify(query),
|
|
)}`,
|
|
);
|
|
}, [query]);
|
|
|
|
const onMenuClickHandler: MenuProps['onClick'] = useCallback(
|
|
(e: OnClickProps) => {
|
|
if (e.key === MENU_KEY.EXPORT) {
|
|
onModalToggle(true);
|
|
}
|
|
|
|
if (e.key === MENU_KEY.CREATE_ALERTS) {
|
|
onCreateAlertsHandler();
|
|
}
|
|
},
|
|
[onModalToggle, onCreateAlertsHandler],
|
|
);
|
|
|
|
const menu: MenuProps = useMemo(
|
|
() => ({
|
|
items: [
|
|
{
|
|
key: MENU_KEY.EXPORT,
|
|
label: MENU_LABEL.EXPORT,
|
|
},
|
|
{
|
|
key: MENU_KEY.CREATE_ALERTS,
|
|
label: MENU_LABEL.CREATE_ALERTS,
|
|
},
|
|
],
|
|
onClick: onMenuClickHandler,
|
|
}),
|
|
[onMenuClickHandler],
|
|
);
|
|
|
|
const onCancel = (value: boolean) => (): void => {
|
|
onModalToggle(value);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Dropdown trigger={['click']} menu={menu}>
|
|
<Button>Actions</Button>
|
|
</Dropdown>
|
|
<Modal
|
|
footer={null}
|
|
onOk={onCancel(false)}
|
|
onCancel={onCancel(false)}
|
|
open={isExport}
|
|
centered
|
|
>
|
|
<ExportPanelContainer
|
|
query={query}
|
|
isLoading={isLoading}
|
|
onExport={onExport}
|
|
/>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
ExportPanel.defaultProps = {
|
|
isLoading: false,
|
|
};
|
|
|
|
interface OnClickProps {
|
|
key: string;
|
|
}
|
|
|
|
export interface ExportPanelProps {
|
|
isLoading?: boolean;
|
|
onExport: (dashboard: Dashboard | null) => void;
|
|
query: Query | null;
|
|
}
|
|
|
|
export default ExportPanel;
|