fix: add worker button do not work
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user