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

✨ Review archetypes #1376

Merged
merged 2 commits into from
Sep 21, 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
1 change: 1 addition & 0 deletions client/src/app/Paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum Paths {
applicationAssessmentSummary = "/applications/assessment-summary/:assessmentId",
archetypeAssessmentSummary = "/archetypes/assessment-summary/:assessmentId",
applicationsReview = "/applications/:applicationId/review",
archetypeReview = "/archetypes/:archetypeId/review",
applicationsAnalysis = "/applications/analysis",
archetypes = "/archetypes",
controls = "/controls",
Expand Down
5 changes: 5 additions & 0 deletions client/src/app/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const devRoutes: IRoute[] = [
comp: Assessment,
exact: false,
},
{
path: Paths.archetypeReview,
comp: Review,
exact: false,
},
{
path: Paths.applicationsReview,
comp: Review,
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface Review {
workPriority: number;
comments?: string;
application?: Ref;
archetype?: Ref;
}

export interface ApplicationDependency {
Expand Down Expand Up @@ -753,4 +754,5 @@ export interface Archetype {
stakeholderGroups?: Ref[];
applications?: Ref[];
assessments?: Ref[];
review?: Ref;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
ApplicationDetailDrawer,
IApplicationDetailDrawerProps,
} from "./application-detail-drawer";
import { useGetReviewByAppId } from "@app/queries/reviews";
import { useFetchReviewById } from "@app/queries/reviews";

export interface IApplicationDetailDrawerAssessmentProps
extends Pick<IApplicationDetailDrawerProps, "application" | "onCloseClick"> {
Expand All @@ -32,7 +32,7 @@ export const ApplicationDetailDrawerAssessment: React.FC<
> = ({ application, onCloseClick, task }) => {
const { t } = useTranslation();

const { review: appReview } = useGetReviewByAppId(application?.id || "");
const { review: appReview } = useFetchReviewById(application?.review?.id);
const notYetReviewed = (
<EmptyTextMessage message={t("terms.notYetReviewed")} />
);
Expand Down
22 changes: 9 additions & 13 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,6 @@ const Archetypes: React.FC = () => {
setArchetypeToAssess(null);
}
};
const reviewSelectedArchetype = (archetype: Archetype) => {
//TODO: Review archetype
// if (application.review) {
// setReviewToEdit(application.id);
// } else {
// history.push(
// formatPath(Paths.applicationsReview, {
// applicationId: application.id,
// })
// );
// }
};

return (
<>
<PageSection variant={PageSectionVariants.light}>
Expand Down Expand Up @@ -309,6 +296,15 @@ const Archetypes: React.FC = () => {
onClick: () =>
assessSelectedArchetype(archetype),
},
{
title: t("actions.review"),
onClick: () =>
history.push(
formatPath(Paths.archetypeReview, {
archetypeId: archetype.id,
})
),
},
{
title: t("actions.edit"),
onClick: () => setArchetypeToEdit(archetype),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
import { ApplicationSelectionContext } from "../../application-selection-context";
import { CartesianSquare } from "./cartesian-square";
import { Arrow } from "./arrow";
import { useGetReviewByAppId } from "@app/queries/reviews";
import useFetchApplicationDependencies from "@app/hooks/useFetchApplicationDependencies/useFetchApplicationDependencies";
import { useFetchReviewById } from "@app/queries/reviews";

interface Line {
from: LinePoint;
Expand Down Expand Up @@ -165,7 +165,7 @@ export const AdoptionCandidateGraph: React.FC = () => {
const appConfidence = confidences.find(
(elem) => elem.applicationId === current.id
);
const { review: appReview } = useGetReviewByAppId(current?.id || "");
const { review: appReview } = useFetchReviewById(current?.review?.id);

if (appConfidence && appReview) {
const key = appReview.proposedAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "@app/api/models";

import { ApplicationSelectionContext } from "../../application-selection-context";
import { useGetReviewByAppId } from "@app/queries/reviews";
import { useFetchReviewById } from "@app/queries/reviews";
import { useQuery } from "@tanstack/react-query";
import { useFetchRisks } from "@app/queries/risks";
import { AppTableWithControls } from "@app/components/AppTableWithControls";
Expand Down Expand Up @@ -110,7 +110,7 @@ export const AdoptionCandidateTable: React.FC<IAdoptionCandidateTable> = () => {
const confidenceData = confidence?.find(
(e) => e.applicationId === app.id
);
const { review: reviewData } = useGetReviewByAppId(app?.id || "");
const { review: reviewData } = useFetchReviewById(app?.review?.id);

const riskData = assessmentRisks?.find((e) => e.applicationId === app.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Application, Assessment } from "@app/api/models";
import { useFetchQuestionnaires } from "@app/queries/questionnaires";

export interface IApplicationDetailsProps {
application: Application;
application?: Application;
assessment?: Assessment;
}

Expand All @@ -27,7 +27,7 @@ export const ApplicationDetails: React.FC<IApplicationDetailsProps> = ({
(questionnaire) => questionnaire.id === assessment?.questionnaire?.id
);
const { t } = useTranslation();
if (!matchingQuestionnaire) {
if (!matchingQuestionnaire || !application) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PROPOSED_ACTION_LIST, EFFORT_ESTIMATE_LIST } from "@app/Constants";
import { number } from "yup";
import {
Application,
Archetype,
EffortEstimate,
New,
ProposedAction,
Expand All @@ -27,14 +28,13 @@ import {
} from "@app/components/HookFormPFFields";
import { OptionWithValue, SimpleSelect } from "@app/components/SimpleSelect";
import {
reviewsByItemIdQueryKey,
useCreateReviewMutation,
useUpdateReviewMutation,
} from "@app/queries/reviews";
import { useQueryClient } from "@tanstack/react-query";
import { useHistory } from "react-router-dom";
import { Paths } from "@app/Paths";
import { NotificationsContext } from "@app/components/NotificationsContext";
import useIsArchetype from "@app/hooks/useIsArchetype";

export interface FormValues {
action: ProposedAction;
Expand All @@ -45,17 +45,21 @@ export interface FormValues {
}

export interface IReviewFormProps {
application: Application;
application?: Application;
archetype?: Archetype;
review?: Review | null;
}

export const ReviewForm: React.FC<IReviewFormProps> = ({
archetype,
application,
review,
}) => {
console.log("existing review", review);
const { t } = useTranslation();
const history = useHistory();
const { pushNotification } = React.useContext(NotificationsContext);
const isArchetype = useIsArchetype();

const actionOptions: OptionWithValue<ProposedAction>[] = useMemo(() => {
return Object.entries(PROPOSED_ACTION_LIST).map(([key, value]) => ({
Expand Down Expand Up @@ -107,45 +111,8 @@ export const ReviewForm: React.FC<IReviewFormProps> = ({
console.log("Invalid form", errors);
};

// const onSubmit = (formValues: FormValues) => {
// const payload: Review = {
// ...review,
// proposedAction: formValues.action,
// effortEstimate: formValues.effort,
// businessCriticality: formValues.criticality || 0,
// workPriority: formValues.priority || 0,
// comments: formValues.comments.trim(),
// // application: { ...application, review: undefined },
// application: { id: application.id, name: application.name },
// };

// let promise: Promise<Review>;
// if (review) {
// promise = updateReview({
// ...review,
// ...payload,
// });
// } else {
// promise = createReview(payload);
// }

// promise
// .then((response) => {
// onSaved(response);
// })
// .catch((error) => {});
// };
const queryClient = useQueryClient();
const onHandleUpdateReviewSuccess = () => {
queryClient.invalidateQueries([
reviewsByItemIdQueryKey,
application.review?.id,
]);
};
const createReviewMutation = useCreateReviewMutation();
const updateReviewMutation = useUpdateReviewMutation(
onHandleUpdateReviewSuccess
);
const updateReviewMutation = useUpdateReviewMutation();

const onSubmit = async (formValues: FormValues) => {
const payload: New<Review> = {
Expand All @@ -155,7 +122,15 @@ export const ReviewForm: React.FC<IReviewFormProps> = ({
businessCriticality: formValues.criticality || 0,
workPriority: formValues.priority || 0,
comments: formValues.comments.trim(),
application: { id: application.id, name: application.name },
...(isArchetype && archetype
? {
archetype: { id: archetype.id, name: archetype.name },
}
: application
? {
application: { id: application.id, name: application.name },
}
: undefined),
};

try {
Expand All @@ -178,7 +153,7 @@ export const ReviewForm: React.FC<IReviewFormProps> = ({
});
}

history.push(Paths.applications);
history.push(isArchetype ? Paths.archetypes : Paths.applications);
} catch (error) {
console.error("Error:", error);
pushNotification({
Expand Down Expand Up @@ -266,7 +241,7 @@ export const ReviewForm: React.FC<IReviewFormProps> = ({
label={t("composed.workPriority")}
fieldId="priority"
isRequired
renderInput={({ field: { value, name, onChange } }) => (
renderInput={({ field: { value, onChange } }) => (
<NumberInput
inputName="priority"
inputAriaLabel="priority"
Expand Down Expand Up @@ -309,7 +284,7 @@ export const ReviewForm: React.FC<IReviewFormProps> = ({
aria-label="cancel"
variant={ButtonVariant.link}
onClick={() => {
history.push(Paths.applications);
history.push(isArchetype ? Paths.archetypes : Paths.applications);
}}
>
{t("actions.cancel")}
Expand Down
Loading