Skip to content

Commit

Permalink
Avoid duplicate or empty dataset requests
Browse files Browse the repository at this point in the history
  • Loading branch information
weltenwort committed Apr 29, 2020
1 parent 1e2112f commit 545bdcb
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const useAnalysisSetupState = <JobType extends string>({
{
cancelPreviousOn: 'resolution',
createPromise: async () => {
if (validIndexNames.length === 0) {
return { data: { datasets: [] } };
}

return await validateSetupDatasets(
validIndexNames,
sourceConfiguration.timestampField,
Expand All @@ -113,11 +117,6 @@ export const useAnalysisSetupState = <JobType extends string>({
[validIndexNames, sourceConfiguration.timestampField, startTime, endTime]
);

const validateIndicesAndDatasets = useCallback(async () => {
await validateIndices();
await validateDatasets();
}, [validateDatasets, validateIndices]);

const setUp = useCallback(() => {
return setUpModule(selectedIndexNames, startTime, endTime);
}, [setUpModule, selectedIndexNames, startTime, endTime]);
Expand All @@ -127,11 +126,7 @@ export const useAnalysisSetupState = <JobType extends string>({
}, [cleanUpAndSetUpModule, selectedIndexNames, startTime, endTime]);

const isValidating = useMemo(
() =>
validateIndicesRequest.state === 'pending' ||
validateIndicesRequest.state === 'uninitialized' ||
validateDatasetsRequest.state === 'pending' ||
validateDatasetsRequest.state === 'uninitialized',
() => validateIndicesRequest.state === 'pending' || validateDatasetsRequest.state === 'pending',
[validateDatasetsRequest.state, validateIndicesRequest.state]
);

Expand Down Expand Up @@ -159,13 +154,17 @@ export const useAnalysisSetupState = <JobType extends string>({
const prevEndTime = usePrevious(endTime);
const prevValidIndexNames = usePrevious(validIndexNames);

useEffect(() => {
validateIndices();
}, [validateIndices]);

useEffect(() => {
if (
startTime !== prevStartTime ||
endTime !== prevEndTime ||
!isEqual(validIndexNames, prevValidIndexNames)
) {
validateIndicesAndDatasets();
validateDatasets();
}
}, [
endTime,
Expand All @@ -174,7 +173,7 @@ export const useAnalysisSetupState = <JobType extends string>({
prevValidIndexNames,
startTime,
validIndexNames,
validateIndicesAndDatasets,
validateDatasets,
]);

return {
Expand Down

0 comments on commit 545bdcb

Please sign in to comment.