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

🐛 Update archetype tags labels to use category color #1551

Merged
merged 3 commits into from
Nov 20, 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const getTagCategoryFallbackColor = (category?: TagCategory) => {
return colorValues[category?.id % colorValues.length];
};

export interface ApplicationTagLabelProps {
export interface ItemTagLabelProps {
tag: Tag;
category?: TagCategory;
className?: string;
}

export const ApplicationTagLabel: React.FC<ApplicationTagLabelProps> = ({
export const ItemTagLabel: React.FC<ItemTagLabelProps> = ({
tag,
category,
className,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import { Label, LabelGroup } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";

export function LabelsFromItems<T extends { name: string }>({
items,
noneMessage,
}: {
items?: T[];
noneMessage?: string;
}): JSX.Element {
const { t } = useTranslation();

if (items && items.length > 0) {
return (
<LabelGroup>
{items.map((item, index) => (
<Label key={index}>{item.name}</Label>
))}
</LabelGroup>
);
}
return <div>{noneMessage || t("terms.none")}</div>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { LabelGroup } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { ItemTagLabel } from "../item-tag-label/item-tag-label";
import { Tag } from "@app/api/models";
import { useFetchTagCategories } from "@app/queries/tags";

export function LabelsFromTags({
tags,
noneMessage,
}: {
tags?: Tag[];
noneMessage?: string;
}): JSX.Element {
const { t } = useTranslation();
const { tagCategories } = useFetchTagCategories();

const findCategoryForTag = (tagId: number) => {
return tagCategories.find(
(category) =>
category.tags?.some((categoryTag) => categoryTag.id === tagId)
);
};

if (tags && tags.length > 0) {
return (
<LabelGroup>
{tags.map((tag) => {
const tagCategory = findCategoryForTag(tag.id);

if (!tagCategory) return null;

return <ItemTagLabel key={tag.id} tag={tag} category={tagCategory} />;
})}
</LabelGroup>
);
}

return <div>{noneMessage || t("terms.none")}</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import CheckCircleIcon from "@patternfly/react-icons/dist/esm/icons/check-circle
import ExclamationCircleIcon from "@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon";
import { ApplicationFacts } from "./application-facts";
import { ReviewFields } from "./review-fields";
import { LabelsFromItems } from "@app/components/labels-from-items/labels-from-items";
import { LabelsFromItems } from "@app/components/labels/labels-from-items/labels-from-items";
import { ReviewedArchetypeItem } from "./reviewed-archetype-item";
import { RiskLabel } from "@app/components/RiskLabel";
import { ApplicationDetailFields } from "./application-detail-fields";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from "@app/components/FilterToolbar";
import { useLegacyFilterState } from "@app/hooks/useLegacyFilterState";
import { useHistory } from "react-router-dom";
import { ApplicationTagLabel } from "./application-tag-label";
import { ItemTagLabel } from "../../../../components/labels/item-tag-label/item-tag-label";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the "@app/ style

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I missed this.


interface TagWithSource extends Tag {
source?: string;
Expand Down Expand Up @@ -237,7 +237,7 @@ export const ApplicationTags: React.FC<ApplicationTagsProps> = ({
</TextContent>
<Flex>
{tagsInThisCategoryInThisSource.map((tag) => (
<ApplicationTagLabel
<ItemTagLabel
key={tag.id}
tag={tag}
category={tagCategoriesById.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
import { PageDrawerContent } from "@app/components/PageDrawerContext";

import { dedupeArrayOfObjects } from "@app/utils/utils";
import { LabelsFromItems } from "@app/components/labels-from-items/labels-from-items";
import { LabelsFromItems } from "@app/components/labels/labels-from-items/labels-from-items";
import { ReviewFields } from "@app/pages/applications/components/application-detail-drawer/review-fields";
import { RiskLabel } from "@app/components/RiskLabel";
import { LabelsFromTags } from "@app/components/labels/labels-from-tags/labels-from-tags";

export interface IArchetypeDetailDrawerProps {
onCloseClick: () => void;
Expand Down Expand Up @@ -227,7 +228,7 @@ const ApplicationLabels: React.FC<{ applicationRefs?: Ref[] }> = ({
}) => <LabelsFromItems items={applicationRefs as Ref[]} />;

const TagLabels: React.FC<{ tags?: Tag[] }> = ({ tags }) => (
<LabelsFromItems items={tags} />
<LabelsFromTags tags={tags} />
);

const StakeholderLabels: React.FC<{ archetype: Archetype }> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { Color } from "@app/components/Color";
import { OptionWithValue, SimpleSelect } from "@app/components/SimpleSelect";
import { NotificationsContext } from "@app/components/NotificationsContext";
import { getTagCategoryFallbackColor } from "@app/pages/applications/components/application-tags/application-tag-label";
import { getTagCategoryFallbackColor } from "@app/components/labels/item-tag-label/item-tag-label";
export interface FormValues {
name: string;
rank?: number;
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/pages/controls/tags/tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { NotificationsContext } from "@app/components/NotificationsContext";
import { COLOR_NAMES_BY_HEX_VALUE } from "@app/Constants";
import { TagForm } from "./components/tag-form";
import { TagCategoryForm } from "./components/tag-category-form";
import { getTagCategoryFallbackColor } from "@app/pages/applications/components/application-tags/application-tag-label";
import { getTagCategoryFallbackColor } from "@app/components/labels/item-tag-label/item-tag-label";
import { AppTableActionButtons } from "@app/components/AppTableActionButtons";
import { Color } from "@app/components/Color";
import { ConditionalRender } from "@app/components/ConditionalRender";
Expand Down
Loading