Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Inform the user on the Review step if a new target namespace is being…
Browse files Browse the repository at this point in the history
… created (#511)

* Pause polling while namespace select is open, to prevent clobbering search filter

* Inform the user on the Review step if a new target namespace is being created

Co-authored-by: Fabien Dupont <fdupont@redhat.com>
  • Loading branch information
mturley and fabiendupont committed Apr 7, 2021
1 parent 2027a07 commit 11d37e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/app/Plans/components/Wizard/GeneralForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ProviderType } from '@app/common/constants';
import SelectOpenShiftNetworkModal from '@app/common/components/SelectOpenShiftNetworkModal';
import { HelpIcon } from '@patternfly/react-icons';
import { useOpenShiftNetworksQuery } from '@app/queries/networks';
import { usePausedPollingEffect } from '@app/common/context';

interface IGeneralFormProps {
form: PlanWizardFormState['general'];
Expand All @@ -40,6 +41,7 @@ const GeneralForm: React.FunctionComponent<IGeneralFormProps> = ({
const namespacesQuery = useNamespacesQuery(form.values.targetProvider);

const [isNamespaceSelectOpen, setIsNamespaceSelectOpen] = React.useState(false);
usePausedPollingEffect(isNamespaceSelectOpen);

const getFilteredOptions = (searchText?: string) => {
const namespaceOptions = namespacesQuery.data?.map((namespace) => namespace.name) || [];
Expand Down
19 changes: 18 additions & 1 deletion src/app/Plans/components/Wizard/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IKubeResponse, KubeClientError } from '@app/client/types';
import { QuerySpinnerMode, ResolvedQueries } from '@app/common/components/ResolvedQuery';
import { generateMappings } from './helpers';
import { usePausedPollingEffect } from '@app/common/context';
import { useNamespacesQuery } from '@app/queries/namespaces';

interface IReviewProps {
forms: PlanWizardFormState;
Expand All @@ -40,6 +41,13 @@ const Review: React.FunctionComponent<IReviewProps> = ({
usePausedPollingEffect();

const { networkMapping, storageMapping } = generateMappings({ forms });

const namespacesQuery = useNamespacesQuery(forms.general.values.targetProvider);
const namespaceOptions = namespacesQuery.data?.map((namespace) => namespace.name) || [];
const isNewNamespace = !namespaceOptions.find(
(namespace) => namespace === forms.general.values.targetNamespace
);

return (
<Form>
<TextContent>
Expand All @@ -63,7 +71,16 @@ const Review: React.FunctionComponent<IReviewProps> = ({
<GridItem md={3}>Target provider</GridItem>
<GridItem md={9}>{forms.general.values.targetProvider?.name}</GridItem>
<GridItem md={3}>Target namespace</GridItem>
<GridItem md={9}>{forms.general.values.targetNamespace}</GridItem>
<GridItem md={9}>
{forms.general.values.targetNamespace}
{isNewNamespace ? (
<TextContent>
<Text component="small">
This is a new namespace that will be created when the plan is started.
</Text>
</TextContent>
) : null}
</GridItem>
<GridItem md={3}>Migration transfer network</GridItem>
<GridItem md={9}>{forms.general.values.migrationNetwork || POD_NETWORK.name}</GridItem>
<GridItem md={3}>Selected VMs</GridItem>
Expand Down
12 changes: 8 additions & 4 deletions src/app/common/context/PollingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ export const PollingContextProvider: React.FunctionComponent<IPollingContextProv

export const usePollingContext = (): IPollingContext => React.useContext(PollingContext);

export const usePausedPollingEffect = (): void => {
// Pauses polling when a component mounts, resumes when it unmounts
export const usePausedPollingEffect = (shouldPause = true): void => {
// Pauses polling when a component mounts, resumes when it unmounts. If shouldPause changes while mounted, polling pauses/resumes to match.
const { pausePolling, resumePolling } = usePollingContext();
React.useEffect(() => {
pausePolling();
if (shouldPause) {
pausePolling();
} else {
resumePolling();
}
return resumePolling;
}, [pausePolling, resumePolling]);
}, [pausePolling, resumePolling, shouldPause]);
};

0 comments on commit 11d37e9

Please sign in to comment.