[ML] Transforms: Reduce rerenders and multiple fetches of source index on transform wizard load. (#160979)

Adds checks to avoid unnecessary initial rerenders and refetches of data
when loading the transform wizard. This reduces rerenders from 14 to 11
and more importantly the request to fetch index data is triggered only
once instead of three times. One of the requests even triggered an error
which could briefly trigger a callout on slower connections.
This commit is contained in:
Walter Rafelsberger 2023-07-10 12:37:19 +02:00 committed by GitHub
parent ea53763028
commit fc4edd68a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -86,6 +86,9 @@ export const useIndexData = (
};
useEffect(() => {
if (dataView.timeFieldName !== undefined && timeRangeMs === undefined) {
return;
}
const abortController = new AbortController();
// Fetch 500 random documents to determine populated fields.
@ -197,6 +200,9 @@ export const useIndexData = (
}, [JSON.stringify([query, timeRangeMs])]);
useEffect(() => {
if (typeof dataViewFields === 'undefined') {
return;
}
const abortController = new AbortController();
const fetchDataGridData = async function () {