Skip to content

Commit

Permalink
Drive isArchetype off of location in case of hard nav
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Sep 15, 2023
1 parent 725e53d commit fa5d61a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ interface QuestionnaireSummaryProps {
fetchError?: AxiosError | null;
summaryData: Assessment | Questionnaire | undefined;
summaryType: SummaryType;
isArchetype?: boolean;
}

const QuestionnaireSummary: React.FC<QuestionnaireSummaryProps> = ({
summaryData,
summaryType,
isFetching = false,
fetchError = null,
isArchetype,
}) => {
const { t } = useTranslation();

const isArchetype = location.pathname.includes("/archetypes/");
const [activeSectionIndex, setActiveSectionIndex] = useState<"all" | number>(
"all"
);
Expand Down Expand Up @@ -90,13 +88,23 @@ const QuestionnaireSummary: React.FC<QuestionnaireSummaryProps> = ({
summaryType === SummaryType.Assessment ? (
<Breadcrumb>
<BreadcrumbItem>
<Link
to={formatPath(Paths.applicationAssessmentActions, {
applicationId: (summaryData as Assessment)?.application?.id,
})}
>
Assessment
</Link>
{isArchetype ? (
<Link
to={formatPath(Paths.archetypeAssessmentActions, {
archetypeId: (summaryData as Assessment)?.archetype?.id,
})}
>
Assessment
</Link>
) : (
<Link
to={formatPath(Paths.applicationAssessmentActions, {
applicationId: (summaryData as Assessment)?.application?.id,
})}
>
Assessment
</Link>
)}
</BreadcrumbItem>
<BreadcrumbItem to="#" isActive>
{summaryData?.name}
Expand Down
12 changes: 2 additions & 10 deletions client/src/app/pages/assessment/assessment-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { AssessmentWizard } from "./components/assessment-wizard/assessment-wiza

const AssessmentPage: React.FC = () => {
const { t } = useTranslation();
const isArchetype = location.pathname.includes("/archetypes/");

const { assessmentId } = useParams<AssessmentRoute>();

Expand All @@ -34,10 +33,7 @@ const AssessmentPage: React.FC = () => {
return (
<>
<PageSection variant="light">
<AssessmentPageHeader
assessment={assessment}
isArchetype={isArchetype}
/>
<AssessmentPageHeader assessment={assessment} />
</PageSection>
<PageSection variant="light" type={PageSectionTypes.wizard}>
<Bullseye>
Expand Down Expand Up @@ -68,11 +64,7 @@ const AssessmentPage: React.FC = () => {
/>
)}
<ConditionalRender when={isFetching} then={<AppPlaceholder />}>
<AssessmentWizard
assessment={assessment}
isOpen
isArchetype={isArchetype}
/>
<AssessmentWizard assessment={assessment} isOpen />
</ConditionalRender>
</PageSection>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ enum AssessmentAction {

interface DynamicAssessmentActionsRowProps {
questionnaire: Questionnaire;
isArchetype: boolean;
application?: Application;
archetype?: Archetype;
assessment?: Assessment;
}

const DynamicAssessmentActionsRow: FunctionComponent<
DynamicAssessmentActionsRowProps
> = ({ questionnaire, application, archetype, assessment, isArchetype }) => {
> = ({ questionnaire, application, archetype, assessment }) => {
const isArchetype = location.pathname.includes("/archetypes/");
const history = useHistory();
const { t } = useTranslation();
const queryClient = useQueryClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const QuestionnairesTable: React.FC<QuestionnairesTableProps> = ({
<DynamicAssessmentActionsRow
assessment={matchingAssessment}
questionnaire={questionnaire}
isArchetype={!!archetype}
application={application}
archetype={archetype}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import { useFetchArchetypeOrApplicationByAssessment } from "@app/hooks/useFetchA

export interface AssessmentPageHeaderProps {
assessment?: Assessment;
isArchetype?: boolean;
}

export const AssessmentPageHeader: React.FC<AssessmentPageHeaderProps> = ({
assessment,
isArchetype,
}) => {
const { t } = useTranslation();
const history = useHistory();

const isArchetype = location.pathname.includes("/archetypes/");
const { data } = useFetchArchetypeOrApplicationByAssessment(
isArchetype,
isArchetype ? assessment?.archetype?.id : assessment?.archetype?.id
Expand Down Expand Up @@ -93,7 +91,9 @@ export const AssessmentPageHeader: React.FC<AssessmentPageHeaderProps> = ({
cancelBtnLabel={t("actions.cancel")}
onCancel={() => setIsConfirmDialogOpen(false)}
onClose={() => setIsConfirmDialogOpen(false)}
onConfirm={() => history.push(Paths.applications)}
onConfirm={() =>
history.push(isArchetype ? Paths.archetypes : Paths.applications)
}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ export interface AssessmentWizardValues {
export interface AssessmentWizardProps {
assessment?: Assessment;
isOpen: boolean;
isArchetype?: boolean;
}

export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
assessment,
isOpen,
isArchetype,
}) => {
const isArchetype = location.pathname.includes("/archetypes/");
const queryClient = useQueryClient();
const { questionnaires } = useFetchQuestionnaires();
const onHandleUpdateAssessmentSuccess = () => {
Expand Down

0 comments on commit fa5d61a

Please sign in to comment.