Skip to content

Commit

Permalink
cleanup duplicates
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Sep 20, 2023
1 parent 8cbc247 commit 10007b5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import {
Assessment,
InitialAssessment,
Questionnaire,
Ref,
} from "@app/api/models";
import {
assessmentsByItemIdQueryKey,
useCreateAssessmentMutation,
useDeleteAssessmentMutation,
} from "@app/queries/assessments";
import { Button, ButtonVariant } from "@patternfly/react-core";
import { Button } from "@patternfly/react-core";
import React, { FunctionComponent } from "react";
import { useHistory } from "react-router-dom";
import "./dynamic-assessment-actions-row.css";
Expand All @@ -23,8 +22,6 @@ import { NotificationsContext } from "@app/components/NotificationsContext";
import { useTranslation } from "react-i18next";
import { useQueryClient } from "@tanstack/react-query";
import { TrashIcon } from "@patternfly/react-icons";
import { ConfirmDialog } from "@app/components/ConfirmDialog";
import { getAssessmentsByItemId } from "@app/api/rest";
import useIsArchetype from "@app/hooks/useIsArchetype";

enum AssessmentAction {
Expand All @@ -38,21 +35,19 @@ interface DynamicAssessmentActionsRowProps {
application?: Application;
archetype?: Archetype;
assessment?: Assessment;
isReadonly?: boolean;
}

const DynamicAssessmentActionsRow: FunctionComponent<
DynamicAssessmentActionsRowProps
> = ({ questionnaire, application, archetype, assessment }) => {
> = ({ questionnaire, application, archetype, assessment, isReadonly }) => {
const isArchetype = useIsArchetype();
const history = useHistory();
const { t } = useTranslation();
const queryClient = useQueryClient();

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

const [archetypeRefToOverride, setArchetypeRefToOverride] =
React.useState<Ref | null>(null);

const onSuccessHandler = () => {};
const onErrorHandler = () => {};

Expand Down Expand Up @@ -148,17 +143,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
if (!isArchetype && application?.archetypes?.length) {
for (const archetypeRef of application.archetypes) {
try {
const assessments = await getAssessmentsByItemId(
true,
archetypeRef.id
);

if (assessments && assessments.length > 0) {
setArchetypeRefToOverride(archetypeRef);
break;
} else {
createAssessment();
}
createAssessment();
} catch (error) {
console.error(
`Error fetching archetype with ID ${archetypeRef.id}:`,
Expand Down Expand Up @@ -227,16 +212,18 @@ const DynamicAssessmentActionsRow: FunctionComponent<
<>
<Td>
<div>
<Button
type="button"
variant="primary"
className={determineButtonClassName()}
onClick={() => {
onHandleAssessmentAction();
}}
>
{determineAction()}
</Button>
{!isReadonly ? (
<Button
type="button"
variant="primary"
className={determineButtonClassName()}
onClick={() => {
onHandleAssessmentAction();
}}
>
{determineAction()}
</Button>
) : null}
{assessment?.status === "complete" ? (
<Button
type="button"
Expand All @@ -256,6 +243,10 @@ const DynamicAssessmentActionsRow: FunctionComponent<
>
{viewButtonLabel}
</Button>
) : isReadonly ? (
<Button type="button" variant="secondary" isDisabled={true}>
{viewButtonLabel}
</Button>
) : null}
</div>
</Td>
Expand All @@ -275,37 +266,6 @@ const DynamicAssessmentActionsRow: FunctionComponent<
</Button>
</Td>
) : null}
<ConfirmDialog
title={t("composed.editQuestion", {
what: t("terms.assessment").toLowerCase(),
})}
alertMessage={t("message.overrideAssessmentDescription", {
what: archetypeRefToOverride?.name || "Archetype name",
})}
message={t("message.overrideAssessmentConfirmation")}
titleIconVariant={"warning"}
isOpen={archetypeRefToOverride !== null}
confirmBtnVariant={ButtonVariant.primary}
confirmBtnLabel={t("actions.override")}
cancelBtnLabel={t("actions.cancel")}
customActionLabel={t("actions.viewArchetypes")}
onCancel={() => setArchetypeRefToOverride(null)}
onClose={() => setArchetypeRefToOverride(null)}
//TODO
// onCustomAction={() => {
// //nav to view archetypes
// console.log("nav to view archetypes");
// }}
onConfirm={() => {
history.push(
formatPath(Paths.applicationsAssessment, {
assessmentId: archetypeRefToOverride?.id,
})
);
setArchetypeRefToOverride(null);
createAssessment();
}}
/>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import DynamicAssessmentActionsRow from "./dynamic-assessment-actions-row";
interface QuestionnairesTableProps {
tableName: string;
isFetching: boolean;
isReadonly?: boolean;
application?: Application;
archetype?: Archetype;
assessments?: Assessment[];
Expand All @@ -28,7 +29,7 @@ interface QuestionnairesTableProps {
const QuestionnairesTable: React.FC<QuestionnairesTableProps> = ({
assessments,
questionnaires,
isFetching,
isReadonly,
application,
archetype,
tableName,
Expand Down Expand Up @@ -109,6 +110,7 @@ const QuestionnairesTable: React.FC<QuestionnairesTableProps> = ({
questionnaire={questionnaire}
application={application}
archetype={archetype}
isReadonly={isReadonly}
/>
) : null}
</TableRowContentWithControls>
Expand Down

This file was deleted.

Loading

0 comments on commit 10007b5

Please sign in to comment.