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

🐛 Archetype table, applications column is now a link #2024

Merged
merged 1 commit into from
Jul 23, 2024
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
4 changes: 2 additions & 2 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
useFetchArchetypes,
} from "@app/queries/archetypes";

import ArchetypeApplicationsColumn from "./components/archetype-applications-column";
import LinkToArchetypeApplications from "./components/link-to-archetype-applications";
import ArchetypeDescriptionColumn from "./components/archetype-description-column";
import ArchetypeDetailDrawer from "./components/archetype-detail-drawer";
import ArchetypeForm from "./components/archetype-form";
Expand Down Expand Up @@ -446,7 +446,7 @@ const Archetypes: React.FC = () => {
<ArchetypeMaintainersColumn archetype={archetype} />
</Td>
<Td {...getTdProps({ columnKey: "applications" })}>
<ArchetypeApplicationsColumn archetype={archetype} />
<LinkToArchetypeApplications archetype={archetype} />
</Td>
<Td
width={15}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "./archetype-detail-drawer.css";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";

import {
TextContent,
Expand All @@ -19,8 +18,6 @@ import {
} from "@patternfly/react-core";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import { dedupeArrayOfObjects } from "@app/utils/utils";
import { Paths } from "@app/Paths";
import { serializeFilterUrlParams } from "@app/hooks/table-controls";
import { Archetype, Ref, Review, Tag, TagRef } from "@app/api/models";

import { EmptyTextMessage } from "@app/components/EmptyTextMessage";
Expand All @@ -29,6 +26,7 @@ import { ReviewFields } from "@app/components/detail-drawer/review-fields";
import { RiskLabel } from "@app/components/RiskLabel";
import { LabelsFromItems } from "@app/components/labels/labels-from-items/labels-from-items";
import { LabelsFromTags } from "@app/components/labels/labels-from-tags/labels-from-tags";
import LinkToArchetypeApplications from "./link-to-archetype-applications";

export interface IArchetypeDetailDrawerProps {
onCloseClick: () => void;
Expand Down Expand Up @@ -107,22 +105,12 @@ const ArchetypeDetailDrawer: React.FC<IArchetypeDetailDrawerProps> = ({
{t("terms.applications")}
</DescriptionListTerm>
<DescriptionListDescription>
{archetype?.applications?.length ? (
<>
<Link to={getApplicationsUrl(archetype?.name)}>
{archetype.applications.length}{" "}
{t("terms.application", {
count: archetype.applications.length,
context:
archetype.applications.length > 1
? "plural"
: "singular",
}).toLocaleLowerCase()}{" "}
</Link>
</>
) : (
<EmptyTextMessage message={t("terms.none")} />
)}
<LinkToArchetypeApplications
archetype={archetype}
noApplicationsMessage={
<EmptyTextMessage message={t("terms.none")} />
}
/>
</DescriptionListDescription>
</DescriptionListGroup>

Expand Down Expand Up @@ -249,16 +237,3 @@ const StakeholderGroupsLabels: React.FC<{ archetype: Archetype }> = ({
}) => <LabelsFromItems items={archetype.stakeholderGroups as Ref[]} />;

export default ArchetypeDetailDrawer;

const getApplicationsUrl = (archetypeName: string) => {
const filterValues = {
archetypes: [archetypeName],
};

const serializedParams = serializeFilterUrlParams(filterValues);

const queryString = serializedParams.filters
? `filters=${serializedParams.filters}`
: "";
return `${Paths.applications}?${queryString}`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import { Text } from "@patternfly/react-core";

import type { Archetype } from "@app/api/models";
import { serializeFilterUrlParams } from "@app/hooks/table-controls";
import { Paths } from "@app/Paths";

const getApplicationsUrl = (archetypeName?: string) => {
if (!archetypeName) return "";

const filterValues = {
archetypes: [archetypeName],
};

const serializedParams = serializeFilterUrlParams(filterValues);

const queryString = serializedParams.filters
? `filters=${serializedParams.filters}`
: "";
return `${Paths.applications}?${queryString}`;
};

const LinkToArchetypeApplications: React.FC<{
archetype: Archetype | null | undefined;
noApplicationsMessage?: React.ReactNode;
}> = ({ archetype, noApplicationsMessage }) => {
const { t } = useTranslation();

const hasApplications = (archetype?.applications?.length ?? 0) > 0;

return !hasApplications && noApplicationsMessage ? (
<>{noApplicationsMessage}</>
) : !hasApplications && !noApplicationsMessage ? (
<Text>{t("message.archetypeNoApplications")}</Text>
) : (
<Link to={getApplicationsUrl(archetype?.name)}>
{t("message.archetypeApplicationCount", {
count: archetype?.applications?.length ?? 0,
})}
</Link>
);
};

export default LinkToArchetypeApplications;
Loading