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

🐛 Missing assessment tags #1459

Merged
merged 2 commits into from
Oct 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const ApplicationForm: React.FC<ApplicationFormProps> = ({

const manualTags: TagRef[] = useMemo(() => {
const rawManualTags: TagRef[] =
application?.tags?.filter((t) => t?.source ?? "" === "") ?? [];
application?.tags?.filter((t) => !t?.source) ?? [];
return dedupeArrayOfObjects<TagRef>(rawManualTags, "name");
}, [application?.tags]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import {
} from "@patternfly/react-core";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";

import { Archetype, Tag } from "@app/api/models";
import { Archetype, Tag, TagRef } from "@app/api/models";
import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
import { PageDrawerContent } from "@app/components/PageDrawerContext";
import { useFetchTagCategories } from "@app/queries/tags";

import "./archetype-detail-drawer.css";
import { dedupeArrayOfObjects } from "@app/utils/utils";

export interface IArchetypeDetailDrawerProps {
onCloseClick: () => void;
Expand All @@ -40,17 +41,17 @@ const ArchetypeDetailDrawer: React.FC<IArchetypeDetailDrawerProps> = ({
[tagCategories]
);

const archetypeTags =
archetype?.tags
?.filter((t) => t?.source ?? "" === "")
.map((ref) => tags.find((tag) => ref.id === tag.id))
.filter(Boolean) ?? [];
const manualTags: TagRef[] = useMemo(() => {
const rawManualTags: TagRef[] =
archetype?.tags?.filter((t) => !t?.source) ?? [];
return dedupeArrayOfObjects<TagRef>(rawManualTags, "name");
}, [archetype?.tags]);

const assessmentTags =
archetype?.tags
?.filter((t) => t?.source ?? "" !== "")
.map((ref) => tags.find((tag) => ref.id === tag.id))
.filter(Boolean) ?? [];
const assessmentTags: TagRef[] = useMemo(() => {
const rawAssessmentTags: TagRef[] =
archetype?.tags?.filter((t) => t?.source === "assessment") ?? [];
return dedupeArrayOfObjects<TagRef>(rawAssessmentTags, "name");
}, [archetype?.tags]);

return (
<PageDrawerContent
Expand Down Expand Up @@ -93,8 +94,8 @@ const ArchetypeDetailDrawer: React.FC<IArchetypeDetailDrawerProps> = ({
<DescriptionListGroup>
<DescriptionListTerm>{t("terms.tagsArchetype")}</DescriptionListTerm>
<DescriptionListDescription>
{archetypeTags.length > 0 ? (
<TagLabels tags={archetypeTags} />
{manualTags.length > 0 ? (
<TagLabels tags={manualTags} />
) : (
<EmptyTextMessage message={t("terms.none")} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
Stakeholder,
StakeholderGroup,
Tag,
TagRef,
} from "@app/api/models";
import {
HookFormPFTextArea,
Expand All @@ -30,7 +31,11 @@ import {
useCreateArchetypeMutation,
useUpdateArchetypeMutation,
} from "@app/queries/archetypes";
import { duplicateNameCheck, getAxiosErrorMessage } from "@app/utils/utils";
import {
dedupeArrayOfObjects,
duplicateNameCheck,
getAxiosErrorMessage,
} from "@app/utils/utils";
import { useFetchTagCategories } from "@app/queries/tags";

import { useFetchStakeholderGroups } from "@app/queries/stakeholdergoups";
Expand Down Expand Up @@ -78,11 +83,17 @@ export const ArchetypeForm: React.FC<ArchetypeFormProps> = ({
onActionSuccess: onClose,
});

const archetypeTags =
archetype?.tags?.filter((t) => t?.source ?? "" === "") ?? [];
const manualTags: TagRef[] = useMemo(() => {
const rawManualTags: TagRef[] =
archetype?.tags?.filter((t) => !t?.source) ?? [];
return dedupeArrayOfObjects<TagRef>(rawManualTags, "name");
}, [archetype?.tags]);

const assessmentTags =
archetype?.tags?.filter((t) => t?.source ?? "" !== "") ?? [];
const assessmentTags: TagRef[] = useMemo(() => {
const rawAssessmentTags: TagRef[] =
archetype?.tags?.filter((t) => t?.source === "assessment") ?? [];
return dedupeArrayOfObjects<TagRef>(rawAssessmentTags, "name");
}, [archetype?.tags]);

const validationSchema = yup.object().shape({
name: yup
Expand Down Expand Up @@ -154,7 +165,7 @@ export const ArchetypeForm: React.FC<ArchetypeFormProps> = ({
comments: archetype?.comments || "",

criteria: archetype?.criteria?.map((tag) => tag.name).sort() ?? [],
tags: archetypeTags.map((tag) => tag.name).sort() ?? [],
tags: manualTags.map((tag) => tag.name).sort() ?? [],

stakeholders: archetype?.stakeholders?.map((sh) => sh.name).sort() ?? [],
stakeholderGroups:
Expand All @@ -167,14 +178,14 @@ export const ArchetypeForm: React.FC<ArchetypeFormProps> = ({
const onValidSubmit = (values: ArchetypeFormValues) => {
// Note: We need to manually retain the tags with source != "" in the payload
const tags = [...(tagsToRefs(values.tags) ?? []), ...assessmentTags];
const criteriaTags = tagsToRefs(values.criteria) ?? [];

const payload: New<Archetype> = {
name: values.name.trim(),
description: values.description?.trim() ?? "",
comments: values.comments?.trim() ?? "",

criteria: values.criteria
.map((tagName) => tags.find((tag) => tag.name === tagName))
.map((tagName) => criteriaTags.find((tag) => tag.name === tagName))
.filter(Boolean),

tags: values.tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,15 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
);

useEffect(() => {
return () => {
if (assessment) {
const unlisten = history.listen((newLocation, action) => {
if (action === "PUSH" && assessment) {
handleCancelAssessment();
}
});
return () => {
unlisten();
};
}, [assessment]);
}, [history, assessment]);

const handleCancelAssessment = () => {
if (assessment) {
Expand Down
Loading