Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix stale wizard state when navigating between assessments #1484

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/app/pages/assessment/assessment-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const AssessmentPage: React.FC = () => {
)}
<AssessmentWizard
assessment={assessment}
isOpen
isLoadingAssessment={isFetching}
fetchError={fetchError}
/>
</PageSection>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,6 @@ const DynamicAssessmentActionsRow: FunctionComponent<
}).then(() => {
createAssessment();
});
history.push(
formatPath(
isArchetype
? Paths.archetypesAssessment
: Paths.applicationsAssessment,
{
assessmentId: assessment?.id,
}
)
);
} catch (error) {
pushNotification({
title: t("terms.error"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import React, { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { FieldErrors, FormProvider, useForm } from "react-hook-form";
import { ButtonVariant, Wizard, WizardStep } from "@patternfly/react-core";
import {
Alert,
ButtonVariant,
Spinner,
Wizard,
WizardStep,
} from "@patternfly/react-core";

import {
Assessment,
Expand Down Expand Up @@ -37,6 +43,7 @@ import useIsArchetype from "@app/hooks/useIsArchetype";
import { useFetchStakeholderGroups } from "@app/queries/stakeholdergoups";
import { useFetchStakeholders } from "@app/queries/stakeholders";
import { WizardStepNavDescription } from "../wizard-step-nav-description";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";

export const SAVE_ACTION_KEY = "saveAction";

Expand All @@ -60,14 +67,14 @@ export interface AssessmentWizardValues {

export interface AssessmentWizardProps {
assessment?: Assessment;
isOpen: boolean;
isLoadingAssessment: boolean;
fetchError?: AxiosError | null;
}

export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
assessment,
isOpen,
isLoadingAssessment,
fetchError,
}) => {
const isArchetype = useIsArchetype();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -97,8 +104,8 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({

const { pushNotification } = React.useContext(NotificationsContext);

const sortedSections = (!isLoadingAssessment && assessment ? assessment.sections : []).sort(
(a, b) => a.order - b.order
const sortedSections = (assessment ? assessment.sections : []).sort(
(a, b) => a.order - b.order
);

//TODO: Add comments to the sections when/if available from api
Expand Down Expand Up @@ -583,7 +590,17 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({

return (
<>
{isOpen && !!sortedSections.length && (
{fetchError && (
<Alert
className={`${spacing.mtMd} ${spacing.mbMd}`}
variant="danger"
isInline
title={getAxiosErrorMessage(fetchError)}
/>
)}
{isLoadingAssessment ? (
<Spinner />
) : (
<FormProvider {...methods}>
<Wizard
isVisitRequired
Expand Down
Loading