Skip to content

Commit

Permalink
🐛 Missing assessment tags (#1459)
Browse files Browse the repository at this point in the history
https://issues.redhat.com/browse/MTA-1381

- Shows criteria tags in edit form
- Fixes hard nav cleanup oversight. Only cancel assessment when not
actively saving.

Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 authored Oct 11, 2023
1 parent f5a315d commit cedcd28
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
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

0 comments on commit cedcd28

Please sign in to comment.