fix: copy button do not work
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { CheckCircleFilled, CopyOutlined } from '@ant-design/icons';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Button, Tooltip, message } from 'antd';
|
||||
import ClipboardJS from 'clipboard';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Typography } from 'antd';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
type CopyButtonProps = {
|
||||
children?: React.ReactNode;
|
||||
@@ -40,65 +39,32 @@ const CopyButton: React.FC<CopyButtonProps> = ({
|
||||
size = 'middle'
|
||||
}) => {
|
||||
const intl = useIntl();
|
||||
const [copied, setCopied] = useState(false);
|
||||
const buttonRef = useRef(null);
|
||||
const clipboardRef = useRef<any>(null);
|
||||
|
||||
const initClipboard = () => {
|
||||
if (buttonRef.current) {
|
||||
clipboardRef.current = new ClipboardJS(buttonRef.current);
|
||||
clipboardRef.current.on('success', () => {
|
||||
setCopied(true);
|
||||
setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
clipboardRef.current.on('error', (e: any) => {
|
||||
message.error(intl.formatMessage({ id: 'common.copy.fail' }) as string);
|
||||
e.clearSelection();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const tipTitle = useMemo(() => {
|
||||
if (copied) {
|
||||
return intl.formatMessage({ id: 'common.button.copied' });
|
||||
}
|
||||
return tips ?? intl.formatMessage({ id: 'common.button.copy' });
|
||||
}, [copied, intl, tips]);
|
||||
|
||||
useEffect(() => {
|
||||
initClipboard();
|
||||
return () => {
|
||||
clipboardRef.current?.destroy();
|
||||
};
|
||||
}, [buttonRef]);
|
||||
const tooltips = useMemo(() => {
|
||||
return [
|
||||
intl.formatMessage({ id: 'common.button.copy' }),
|
||||
intl.formatMessage({ id: 'common.button.copied' })
|
||||
];
|
||||
}, [intl]);
|
||||
|
||||
return (
|
||||
<Tooltip title={tipTitle} placement={placement}>
|
||||
<Button
|
||||
className="copy-button"
|
||||
ref={buttonRef}
|
||||
type={type}
|
||||
shape={shape}
|
||||
size={size}
|
||||
disabled={!!disabled}
|
||||
data-clipboard-text={text}
|
||||
style={{ ...btnStyle }}
|
||||
icon={
|
||||
copied ? (
|
||||
<CheckCircleFilled
|
||||
style={{ color: 'var(--ant-color-success)', fontSize: fontSize }}
|
||||
/>
|
||||
) : (
|
||||
<CopyOutlined style={{ fontSize: fontSize, ...style }} />
|
||||
)
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Typography.Text
|
||||
style={{ ...btnStyle }}
|
||||
disabled={!!disabled}
|
||||
copyable={{
|
||||
text: text,
|
||||
tooltips: tooltips,
|
||||
icon: [
|
||||
<CopyOutlined style={{ fontSize: fontSize, ...style }} key="copy" />,
|
||||
<CheckCircleFilled
|
||||
style={{ color: 'var(--ant-color-success)', fontSize: fontSize }}
|
||||
key="check"
|
||||
/>
|
||||
]
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Typography.Text>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,12 @@ export function useQueryDataList<ListItem, Params = any>(option: {
|
||||
getLabel?: (item: ListItem) => string;
|
||||
getValue?: (item: ListItem) => any;
|
||||
errorMsg?: string;
|
||||
}) {
|
||||
}): {
|
||||
loading: boolean;
|
||||
dataList: Array<ListItem & { label: string; value: any }>;
|
||||
cancelRequest: () => void;
|
||||
fetchData: (params: Params, extra?: any) => Promise<ListItem[]>;
|
||||
} {
|
||||
const { key, fetchList, getLabel, getValue, errorMsg } = option;
|
||||
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
|
||||
const [dataList, setDataList] = useState<
|
||||
@@ -89,7 +94,12 @@ export function useQueryData<Detail, Params = any>(option: {
|
||||
fetchDetail: (params: Params, options?: any) => Promise<Detail>;
|
||||
getData?: (response: Detail) => any;
|
||||
errorMsg?: string;
|
||||
}) {
|
||||
}): {
|
||||
loading: boolean;
|
||||
detailData: Detail;
|
||||
cancelRequest: () => void;
|
||||
fetchData: (params: Params, extra?: any) => Promise<Detail>;
|
||||
} {
|
||||
const { key, fetchDetail, getData, errorMsg, delay } = option;
|
||||
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
|
||||
const [detailData, setDetailData] = useState<Detail>({} as Detail);
|
||||
|
||||
@@ -66,6 +66,11 @@ const options: BackendParameter[] = [
|
||||
value: '--ssl-certfile',
|
||||
options: []
|
||||
},
|
||||
{
|
||||
label: '--data-parallel-size-local',
|
||||
value: '--data-parallel-size-local',
|
||||
options: []
|
||||
},
|
||||
{
|
||||
label: '--enable-ssl-refresh',
|
||||
value: '--enable-ssl-refresh',
|
||||
|
||||
@@ -194,24 +194,3 @@ export const hotkeyConfigs = [
|
||||
},
|
||||
{ keys: HotKeys.NEW4, width: 600, source: modelSourceMap.local_path_value }
|
||||
];
|
||||
|
||||
/**
|
||||
* hotkeyConfigs.map(({ keys, width, source }) =>
|
||||
useHotkeys(
|
||||
keys.join(','),
|
||||
() => {
|
||||
setOpenDeployModal({
|
||||
show: true,
|
||||
width,
|
||||
source,
|
||||
gpuOptions: gpuDeviceList.current
|
||||
});
|
||||
},
|
||||
{
|
||||
preventDefault: true,
|
||||
enabled: !openAddModal && !openDeployModal.show && !openLogModal
|
||||
}
|
||||
)
|
||||
);
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useQueryData } from '@/hooks/use-query-data-list';
|
||||
import { SystemConfig } from '@/pages/cluster-management/config/types';
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
export const SYSTEM_CONFIG_API = '/config';
|
||||
|
||||
const useQuerySystemConfig = () => {
|
||||
async function querySystemConfig() {
|
||||
return request<SystemConfig>(`${SYSTEM_CONFIG_API}`, {
|
||||
method: 'GET'
|
||||
});
|
||||
}
|
||||
const { detailData, loading, cancelRequest, fetchData } =
|
||||
useQueryData<SystemConfig>({
|
||||
key: 'system-config',
|
||||
fetchDetail: querySystemConfig
|
||||
});
|
||||
|
||||
return {
|
||||
systemConfig: detailData,
|
||||
loading,
|
||||
cancelRequest,
|
||||
fetchSystemConfig: fetchData
|
||||
};
|
||||
};
|
||||
|
||||
export default useQuerySystemConfig;
|
||||
Reference in New Issue
Block a user