mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 18:20:38 +08:00
copy to clipboard is updated (#1065)
This commit is contained in:
parent
6c5a48082b
commit
fe53aa412b
@ -1,7 +1,8 @@
|
|||||||
import { Button, Modal, notification, Typography } from 'antd';
|
import { Button, Modal, notification, Typography } from 'antd';
|
||||||
import Editor from 'components/Editor';
|
import Editor from 'components/Editor';
|
||||||
import React, { useCallback, useMemo, useState } from 'react';
|
import React, { useEffect, useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useCopyToClipboard } from 'react-use';
|
||||||
import { DashboardData } from 'types/api/dashboard/getAll';
|
import { DashboardData } from 'types/api/dashboard/getAll';
|
||||||
|
|
||||||
import { downloadObjectAsJson } from './util';
|
import { downloadObjectAsJson } from './util';
|
||||||
@ -16,23 +17,25 @@ function ShareModal({
|
|||||||
);
|
);
|
||||||
const [isViewJSON, setIsViewJSON] = useState<boolean>(false);
|
const [isViewJSON, setIsViewJSON] = useState<boolean>(false);
|
||||||
const { t } = useTranslation(['dashboard', 'common']);
|
const { t } = useTranslation(['dashboard', 'common']);
|
||||||
|
const [state, setCopy] = useCopyToClipboard();
|
||||||
|
|
||||||
const onClickCopyClipBoardHandler = useCallback(async () => {
|
useEffect(() => {
|
||||||
try {
|
if (state.error) {
|
||||||
await navigator.clipboard.writeText(jsonValue);
|
|
||||||
notification.success({
|
|
||||||
message: t('success', {
|
|
||||||
ns: 'common',
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
notification.error({
|
notification.error({
|
||||||
message: t('something_went_wrong', {
|
message: t('something_went_wrong', {
|
||||||
ns: 'common',
|
ns: 'common',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [jsonValue, t]);
|
|
||||||
|
if (state.value) {
|
||||||
|
notification.success({
|
||||||
|
message: t('success', {
|
||||||
|
ns: 'common',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [state.error, state.value, t]);
|
||||||
|
|
||||||
const GetFooterComponent = useMemo(() => {
|
const GetFooterComponent = useMemo(() => {
|
||||||
if (!isViewJSON) {
|
if (!isViewJSON) {
|
||||||
@ -58,11 +61,11 @@ function ShareModal({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Button onClick={onClickCopyClipBoardHandler} type="primary">
|
<Button onClick={(): void => setCopy(jsonValue)} type="primary">
|
||||||
{t('copy_to_clipboard')}
|
{t('copy_to_clipboard')}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}, [isViewJSON, onClickCopyClipBoardHandler, selectedData, t]);
|
}, [isViewJSON, jsonValue, selectedData, setCopy, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user