refactor: extract updateList into callback
This commit is contained in:
parent
fdf39a2970
commit
01a0024ce7
|
|
@ -93,6 +93,7 @@ export const UIModeView: React.FC<{}> = ({
|
||||||
const [isDisconnected, setIsDisconnected] = React.useState(false);
|
const [isDisconnected, setIsDisconnected] = React.useState(false);
|
||||||
const [hasBrowsers, setHasBrowsers] = React.useState(true);
|
const [hasBrowsers, setHasBrowsers] = React.useState(true);
|
||||||
const [testServerConnection, setTestServerConnection] = React.useState<TestServerConnection>();
|
const [testServerConnection, setTestServerConnection] = React.useState<TestServerConnection>();
|
||||||
|
const [teleSuiteUpdater, setTeleSuiteUpdater] = React.useState<TeleSuiteUpdater>();
|
||||||
|
|
||||||
const inputRef = React.useRef<HTMLInputElement>(null);
|
const inputRef = React.useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
|
@ -157,20 +158,7 @@ export const UIModeView: React.FC<{}> = ({
|
||||||
pathSeparator,
|
pathSeparator,
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateList = () => {
|
setTeleSuiteUpdater(teleSuiteUpdater);
|
||||||
commandQueue.current = commandQueue.current.then(async () => {
|
|
||||||
setIsLoading(true);
|
|
||||||
try {
|
|
||||||
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args });
|
|
||||||
teleSuiteUpdater.processListReport(result.report);
|
|
||||||
} catch (e) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(e);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
setTestModel(undefined);
|
setTestModel(undefined);
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
@ -189,7 +177,6 @@ export const UIModeView: React.FC<{}> = ({
|
||||||
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args });
|
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args });
|
||||||
teleSuiteUpdater.processListReport(result.report);
|
teleSuiteUpdater.processListReport(result.report);
|
||||||
|
|
||||||
testServerConnection.onListChanged(updateList);
|
|
||||||
testServerConnection.onReport(params => {
|
testServerConnection.onReport(params => {
|
||||||
teleSuiteUpdater.processTestReportEvent(params);
|
teleSuiteUpdater.processTestReportEvent(params);
|
||||||
});
|
});
|
||||||
|
|
@ -205,6 +192,29 @@ export const UIModeView: React.FC<{}> = ({
|
||||||
};
|
};
|
||||||
}, [testServerConnection]);
|
}, [testServerConnection]);
|
||||||
|
|
||||||
|
const updateList = React.useCallback(async () => {
|
||||||
|
if (!testServerConnection || !teleSuiteUpdater)
|
||||||
|
return;
|
||||||
|
|
||||||
|
commandQueue.current = commandQueue.current.then(async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const result = await testServerConnection.listTests({ projects: queryParams.projects, locations: queryParams.args });
|
||||||
|
teleSuiteUpdater.processListReport(result.report);
|
||||||
|
} catch (e) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(e);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await commandQueue.current;
|
||||||
|
}, [testServerConnection, teleSuiteUpdater]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
testServerConnection?.onListChanged(updateList);
|
||||||
|
}, [testServerConnection, updateList]);
|
||||||
|
|
||||||
// Update project filter default values.
|
// Update project filter default values.
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!testModel)
|
if (!testModel)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue