fix: add worker button do not work
This commit is contained in:
@@ -95,7 +95,7 @@ const LogsViewer: React.FC<LogsViewerProps> = forwardRef((props, ref) => {
|
||||
|
||||
const createChunkConnection = async () => {
|
||||
chunkRequedtRef.current?.current?.cancel?.();
|
||||
chunkRequedtRef.current = setChunkRequest({
|
||||
chunkRequedtRef.current = await setChunkRequest({
|
||||
url,
|
||||
params: {
|
||||
...props.params,
|
||||
|
||||
@@ -166,11 +166,11 @@ const useSetChunkRequest = () => {
|
||||
return axiosToken.current;
|
||||
};
|
||||
|
||||
const setChunkRequest = (config: RequestConfig) => {
|
||||
const setChunkRequest = async (config: RequestConfig) => {
|
||||
requestConfig.current = { ...particalConfig, ...config };
|
||||
retryCount.current = totalCount;
|
||||
clearTimeout(timer.current);
|
||||
axiosChunkRequest(requestConfig.current);
|
||||
await axiosChunkRequest(requestConfig.current);
|
||||
return axiosToken;
|
||||
};
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ export default function useTableFetch<T>(
|
||||
try {
|
||||
const query = _.omit(params || queryParams, ['page', 'perPage']);
|
||||
|
||||
chunkRequedtRef.current = setChunkRequest({
|
||||
chunkRequedtRef.current = await setChunkRequest({
|
||||
url: `${API}?${qs.stringify(_.pickBy(query, (val: any) => !!val))}`,
|
||||
handler: updateHandler
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
|
||||
const createWatchChunkRequest = useMemoizedFn(async () => {
|
||||
chunkRequestRef.current?.current?.cancel?.();
|
||||
try {
|
||||
chunkRequestRef.current = setChunkRequest({
|
||||
chunkRequestRef.current = await setChunkRequest({
|
||||
url: `${watchAPI}`,
|
||||
params: {},
|
||||
handler: updateWatchDataListHandler
|
||||
|
||||
@@ -64,17 +64,11 @@ const AddWorkerSteps: React.FC<AddWorkerProps> = (props) => {
|
||||
const [collapseKey, setCollapseKey] = React.useState<Set<string>>(
|
||||
new Set([stepList[0]])
|
||||
);
|
||||
const startWatchRef = React.useRef(false);
|
||||
const { update, summary, register } = useSummaryStatus();
|
||||
const { addedCount, createModelsChunkRequest } = useAddWorkerMessage({
|
||||
startWatch: startWatchRef
|
||||
});
|
||||
const { addedCount, createModelsChunkRequest } = useAddWorkerMessage();
|
||||
|
||||
const onToggle = (open: boolean, key: string) => {
|
||||
setCollapseKey(open ? new Set([key]) : new Set());
|
||||
if (key === StepNamesMap.RunCommand && open) {
|
||||
startWatchRef.current = true;
|
||||
}
|
||||
};
|
||||
|
||||
const handleOnClusterChange = (value: number, row?: any) => {
|
||||
|
||||
@@ -58,10 +58,7 @@ const AddWorker: React.FC<AddWorkerProps> = (props) => {
|
||||
stepList = []
|
||||
} = props || {};
|
||||
const intl = useIntl();
|
||||
const startWatchRef = React.useRef(false);
|
||||
const { addedCount, createModelsChunkRequest } = useAddWorkerMessage({
|
||||
startWatch: startWatchRef
|
||||
});
|
||||
const { addedCount, createModelsChunkRequest } = useAddWorkerMessage();
|
||||
const firstLoad = React.useRef(true);
|
||||
const [registrationInfo, setRegistrationInfo] = React.useState<{
|
||||
token: string;
|
||||
@@ -83,7 +80,6 @@ const AddWorker: React.FC<AddWorkerProps> = (props) => {
|
||||
...data,
|
||||
cluster_id: value
|
||||
});
|
||||
startWatchRef.current = true;
|
||||
} catch (error) {
|
||||
firstLoad.current = false;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import useSetChunkRequest from '@/hooks/use-chunk-request';
|
||||
import useUpdateChunkedList from '@/hooks/use-update-chunk-list';
|
||||
import _ from 'lodash';
|
||||
import { useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { WORKERS_API } from '../../resources/apis';
|
||||
|
||||
export default function useAddWorkerMessage(params: {
|
||||
startWatch?: React.RefObject<boolean>;
|
||||
}) {
|
||||
export default function useAddWorkerMessage() {
|
||||
const chunkRequestRef = useRef<any>(null);
|
||||
const newItemsRef = useRef<any[]>([]);
|
||||
const [addedCount, setAddedCount] = useState(0);
|
||||
const startWatchRef = useRef(false);
|
||||
const timerRef = useRef<any>(null);
|
||||
|
||||
const showAddWorkerMessage = () => {
|
||||
if (newItemsRef.current.length > 0) {
|
||||
@@ -23,7 +23,7 @@ export default function useAddWorkerMessage(params: {
|
||||
events: ['CREATE', 'INSERT'],
|
||||
dataList: [],
|
||||
onCreate: (newItems: any) => {
|
||||
if (params.startWatch?.current) {
|
||||
if (startWatchRef.current) {
|
||||
newItemsRef.current = newItemsRef.current.concat(newItems);
|
||||
console.log('newItemsRef.current:', newItemsRef.current);
|
||||
showAddWorkerMessage();
|
||||
@@ -37,18 +37,38 @@ export default function useAddWorkerMessage(params: {
|
||||
});
|
||||
};
|
||||
|
||||
const resetAddedCount = () => {
|
||||
setAddedCount(0);
|
||||
newItemsRef.current = [];
|
||||
startWatchRef.current = false;
|
||||
clearTimeout(timerRef.current);
|
||||
};
|
||||
|
||||
const createModelsChunkRequest = async () => {
|
||||
chunkRequestRef.current?.current?.cancel?.();
|
||||
resetAddedCount();
|
||||
try {
|
||||
chunkRequestRef.current = setChunkRequest({
|
||||
chunkRequestRef.current = await setChunkRequest({
|
||||
url: WORKERS_API,
|
||||
handler: updateHandler
|
||||
});
|
||||
timerRef.current = setTimeout(() => {
|
||||
startWatchRef.current = true;
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
chunkRequestRef.current?.current?.cancel?.();
|
||||
startWatchRef.current = false;
|
||||
newItemsRef.current = [];
|
||||
clearTimeout(timerRef.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return {
|
||||
addedCount,
|
||||
createModelsChunkRequest
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { clusterSessionAtom } from '@/atoms/clusters';
|
||||
import IconFont from '@/components/icon-font';
|
||||
import ScrollerModal from '@/components/scroller-modal/index';
|
||||
import { PageAction } from '@/config';
|
||||
import useClusterList from '@/pages/cluster-management/hooks/use-cluster-list';
|
||||
import { useIntl, useNavigate } from '@umijs/max';
|
||||
import { Button } from 'antd';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useMemo, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
@@ -53,6 +56,7 @@ const Content = styled.div`
|
||||
export default function useAddResource() {
|
||||
const intl = useIntl();
|
||||
const navigate = useNavigate();
|
||||
const [, setClusterSession] = useAtom(clusterSessionAtom);
|
||||
|
||||
const { fetchAll, clusterList, workerList, clustersAtom, workersAtom } =
|
||||
useClusterList();
|
||||
@@ -87,7 +91,27 @@ export default function useAddResource() {
|
||||
return isNoResource && !hiddenModal;
|
||||
}, [isNoResource, hiddenModal]);
|
||||
|
||||
const handleCreate = () => {};
|
||||
const handleCreate = () => {
|
||||
if (clusterList.length === 0) {
|
||||
setClusterSession({
|
||||
firstAddWorker: false,
|
||||
firstAddCluster: true
|
||||
});
|
||||
|
||||
navigate(
|
||||
`/cluster-management/clusters/create?action=${PageAction.CREATE}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (workerList.length === 0) {
|
||||
setClusterSession({
|
||||
firstAddWorker: true,
|
||||
firstAddCluster: false
|
||||
});
|
||||
navigate(`/cluster-management/clusters/list`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
setHiddenModal(true);
|
||||
|
||||
@@ -72,9 +72,11 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
||||
if (!props.id) return;
|
||||
if (open) {
|
||||
requestRef.current?.current?.cancel?.();
|
||||
requestRef.current = setChunkRequest({
|
||||
setChunkRequest({
|
||||
url: `${MODELS_API}/${props.modelId}/instances`,
|
||||
handler: updateHandler
|
||||
}).then((res) => {
|
||||
requestRef.current = res;
|
||||
});
|
||||
} else {
|
||||
logsViewerRef.current?.abort();
|
||||
|
||||
@@ -201,7 +201,7 @@ const Models: React.FC = () => {
|
||||
search: search,
|
||||
categories: categories
|
||||
};
|
||||
chunkRequedtRef.current = setChunkRequest({
|
||||
chunkRequedtRef.current = await setChunkRequest({
|
||||
url: `${MODELS_API}?${qs.stringify(_.pickBy(query, (val: any) => !!val))}`,
|
||||
handler: updateHandler
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user