Skip to content

Commit

Permalink
Merge pull request #1447 from jpuzz0/MTV-1967-fix-provider-reselection
Browse files Browse the repository at this point in the history
[MTV-1967] Create plan wizard state is not set correctly when re-selecting a source provider
  • Loading branch information
metalice authored Feb 10, 2025
2 parents 56f1b60 + 5e4afde commit b93fcb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export const useProviderInventory = <T>({
handleError(null);
} catch (e) {
handleError(e);
} finally {
setLoading(false);
}
};

Expand All @@ -126,8 +128,6 @@ export const useProviderInventory = <T>({
function handleError(e: Error): void {
if (e?.toString() !== oldErrorRef.current?.error) {
setError(e);
setLoading(false);

oldErrorRef.current = { error: e?.toString() };
}
}
Expand Down Expand Up @@ -156,8 +156,6 @@ export const useProviderInventory = <T>({

if (needReRender) {
setInventory(newInventory);
setLoading(false);

oldDataRef.current = { inventory: newInventory };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const useFetchEffects = (
workArea: { targetProvider },
flow: { editingDone },
} = state;
const targetProviderName = targetProvider?.metadata?.name;

const dispatchWithFallback = (
action: PageAction<CreateVmMigration, unknown>,
Expand All @@ -81,7 +82,7 @@ export const useFetchEffects = (
() =>
!editingDone &&
dispatch(initState(namespace, planName, projectName, sourceProvider, selectedVms)),
[selectedVms],
[],
);

const [providers, providersLoaded, providerError] = useK8sWatchResource<V1beta1Provider[]>({
Expand All @@ -94,7 +95,7 @@ export const useFetchEffects = (
() =>
!editingDone &&
dispatchWithFallback(setAvailableProviders(providers), !providersLoaded, providerError),
[providers, providersLoaded, providerError, selectedVms],
[editingDone, providersLoaded, providerError?.message],
);

const [plans, plansLoaded, plansError] = useK8sWatchResource<V1beta1Plan[]>({
Expand All @@ -105,7 +106,7 @@ export const useFetchEffects = (
});
useEffect(
() => !editingDone && dispatchWithFallback(setExistingPlans(plans), !plansLoaded, plansError),
[plans, plansLoaded, plansError, selectedVms],
[editingDone, plansLoaded, plansError?.message],
);

const [netMaps, netMapsLoaded, netMapsError] = useK8sWatchResource<V1beta1NetworkMap[]>({
Expand All @@ -118,7 +119,7 @@ export const useFetchEffects = (
() =>
!editingDone &&
dispatchWithFallback(setExistingNetMaps(netMaps), !netMapsLoaded, netMapsError),
[netMaps, netMapsLoaded, netMapsError, selectedVms],
[editingDone, netMapsLoaded, netMapsError?.message],
);

const [stMaps, stMapsLoaded, stMapsError] = useK8sWatchResource<V1beta1StorageMap[]>({
Expand All @@ -131,30 +132,30 @@ export const useFetchEffects = (
() =>
!editingDone &&
dispatchWithFallback(setExistingStorageMaps(stMaps), !stMapsLoaded, stMapsError),
[stMaps, stMapsLoaded, stMapsError, selectedVms],
[editingDone, stMapsLoaded, stMapsError?.message],
);

const [namespaces, nsLoading, nsError] = useNamespaces(targetProvider);
useEffect(
() =>
targetProvider &&
targetProviderName &&
!editingDone &&
dispatchWithFallback(setAvailableTargetNamespaces(namespaces), nsLoading, nsError),
[namespaces, nsLoading, nsError, targetProvider, selectedVms],
[editingDone, nsLoading, nsError?.message, targetProviderName],
);

const [targetNetworks, targetNetworksLoading, targetNetworksError] =
useOpenShiftNetworks(targetProvider);
useEffect(
() =>
targetProvider &&
targetProviderName &&
!editingDone &&
dispatchWithFallback(
setAvailableTargetNetworks(targetNetworks),
targetNetworksLoading,
targetNetworksError,
),
[targetNetworks, targetNetworksLoading, targetNetworksError, targetProvider, selectedVms],
[editingDone, targetNetworksLoading, targetNetworksError?.message, targetProviderName],
);

const [sourceStorages, sourceStoragesLoading, sourceStoragesError] =
Expand All @@ -167,21 +168,21 @@ export const useFetchEffects = (
sourceStoragesLoading,
sourceStoragesError,
),
[sourceStorages, sourceStoragesLoading, sourceStoragesError, selectedVms],
[editingDone, sourceStoragesLoading, sourceStoragesError?.message],
);

const [targetStorages, targetStoragesLoading, targetStoragesError] =
useOpenShiftStorages(targetProvider);
useEffect(
() =>
targetProvider &&
targetProviderName &&
!editingDone &&
dispatchWithFallback(
setAvailableTargetStorages(targetStorages),
targetStoragesLoading,
targetStoragesError,
),
[targetStorages, targetStoragesLoading, targetStoragesError, targetProvider, selectedVms],
[editingDone, targetStoragesLoading, targetProviderName],
);

const [sourceNetworks, sourceNetworksLoading, sourceNetworksError] =
Expand All @@ -194,21 +195,21 @@ export const useFetchEffects = (
sourceNetworksLoading,
sourceNetworksError,
),
[sourceNetworks, sourceNetworksLoading, sourceNetworksError, selectedVms],
[editingDone, sourceNetworksLoading, sourceNetworksError?.message],
);

const [nicProfiles, nicProfilesLoading, nicProfilesError] = useNicProfiles(sourceProvider);
useEffect(
() =>
!editingDone &&
dispatchWithFallback(setNicProfiles(nicProfiles), nicProfilesLoading, nicProfilesError),
[nicProfiles, nicProfilesLoading, nicProfilesError, selectedVms],
[editingDone, nicProfilesLoading, nicProfilesError?.message],
);

const [disks, disksLoading, disksError] = useDisks(sourceProvider);
useEffect(
() => !editingDone && dispatchWithFallback(setDisks(disks), disksLoading, disksError),
[disks, disksLoading, disksError, selectedVms],
[editingDone, disksLoading, disksError?.message],
);

return [state, dispatch, emptyContext];
Expand Down

0 comments on commit b93fcb8

Please sign in to comment.