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

✨ Add assessment/review status to archetype table #1755

Merged
merged 2 commits into from
Mar 15, 2024
Merged
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
125 changes: 85 additions & 40 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
useLocalTableControls,
} from "@app/hooks/table-controls";
import {
ARCHETYPES_QUERY_KEY,
ARCHETYPE_QUERY_KEY,
useDeleteArchetypeMutation,
useFetchArchetypes,
} from "@app/queries/archetypes";
Expand All @@ -69,11 +71,14 @@ import {
} from "@app/rbac";
import { checkAccess } from "@app/utils/rbac-utils";
import keycloak from "@app/keycloak";
import { IconedStatus } from "@app/components/IconedStatus";
import { useQueryClient } from "@tanstack/react-query";

const Archetypes: React.FC = () => {
const { t } = useTranslation();
const history = useHistory();
const { pushNotification } = React.useContext(NotificationsContext);
const queryClient = useQueryClient();

const [openCreateArchetype, setOpenCreateArchetype] =
useState<boolean>(false);
Expand Down Expand Up @@ -115,34 +120,37 @@ const Archetypes: React.FC = () => {
onError
);

const { mutate: deleteAssessment } = useDeleteAssessmentMutation();

const discardAssessment = async (archetype: Archetype) => {
try {
if (archetype.assessments) {
await Promise.all(
archetype.assessments.map(async (assessment) => {
await deleteAssessment({
assessmentId: assessment.id,
archetypeId: archetype.id,
});
})
).then(() => {
pushNotification({
title: t("toastr.success.assessmentDiscarded", {
application: archetype.name,
}),
variant: "success",
});
const { mutateAsync: deleteAssessment } = useDeleteAssessmentMutation();

const discardAssessment = (archetype: Archetype) => {
if (!archetype.assessments) {
return;
}
Promise.all(
archetype.assessments.map((assessment) =>
deleteAssessment({
assessmentId: assessment.id,
archetypeId: archetype.id,
})
)
)
.then(() => {
sjd78 marked this conversation as resolved.
Show resolved Hide resolved
pushNotification({
title: t("toastr.success.assessmentDiscarded", {
application: archetype.name,
}),
variant: "success",
});
queryClient.invalidateQueries([ARCHETYPES_QUERY_KEY]);
queryClient.invalidateQueries([ARCHETYPE_QUERY_KEY, archetype.id]);
})
.catch((error) => {
console.error("Error while deleting assessments:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
} catch (error) {
console.error("Error while deleting assessments:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
};

const onDeleteReviewSuccess = (name: string) => {
Expand All @@ -154,25 +162,29 @@ const Archetypes: React.FC = () => {
});
};

const { mutate: deleteReview } = useDeleteReviewMutation(
const { mutateAsync: deleteReview } = useDeleteReviewMutation(
onDeleteReviewSuccess
);

const discardReview = async (archetype: Archetype) => {
try {
if (archetype.review?.id) {
await deleteReview({
id: archetype.review.id,
name: archetype.name,
const discardReview = (archetype: Archetype) => {
if (!archetype.review?.id) {
return;
}
deleteReview({
id: archetype.review.id,
name: archetype.name,
})
.then(() => {
sjd78 marked this conversation as resolved.
Show resolved Hide resolved
queryClient.invalidateQueries([ARCHETYPES_QUERY_KEY]);
queryClient.invalidateQueries([ARCHETYPE_QUERY_KEY, archetype.id]);
})
.catch((error) => {
console.error("Error while deleting review:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
} catch (error) {
console.error("Error while deleting review:", error);
pushNotification({
title: getAxiosErrorMessage(error as AxiosError),
variant: "danger",
});
}
};
const urlParams = new URLSearchParams(window.location.search);
const filters = urlParams.get("filters");
Expand All @@ -193,6 +205,8 @@ const Archetypes: React.FC = () => {
tags: t("terms.tags"),
maintainers: t("terms.maintainers"),
applications: t("terms.applications"),
assessment: t("terms.assessment"),
review: t("terms.review"),
},

isFilterEnabled: true,
Expand Down Expand Up @@ -380,6 +394,11 @@ const Archetypes: React.FC = () => {
<Th {...getThProps({ columnKey: "tags" })} />
<Th {...getThProps({ columnKey: "maintainers" })} />
<Th {...getThProps({ columnKey: "applications" })} />
<Th
{...getThProps({ columnKey: "assessment" })}
width={10}
/>
<Th {...getThProps({ columnKey: "review" })} width={10} />
</TableHeaderContentWithControls>
</Tr>
</Thead>
Expand Down Expand Up @@ -427,6 +446,32 @@ const Archetypes: React.FC = () => {
<Td {...getTdProps({ columnKey: "applications" })}>
<ArchetypeApplicationsColumn archetype={archetype} />
</Td>
<Td
width={15}
modifier="truncate"
{...getTdProps({ columnKey: "assessment" })}
>
<IconedStatus
preset={
archetype.assessed
? "Completed"
: archetype?.assessments?.length
? "InProgress"
: "NotStarted"
}
/>
</Td>
<Td
width={15}
modifier="truncate"
{...getTdProps({ columnKey: "review" })}
>
<IconedStatus
preset={
archetype.review ? "Completed" : "NotStarted"
}
/>
</Td>
<Td isActionCell>
{(archetypeWriteAccess ||
assessmentWriteAccess ||
Expand Down
Loading