Skip to content

Commit

Permalink
fix(patents): update patents with new index, change types also
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Apr 4, 2024
1 parent f46c200 commit b733eb9
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 130 deletions.
5 changes: 3 additions & 2 deletions client/src/api/patents/_utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export const FIELDS = [
export const LIGHT_SOURCE = [
"title",
"id",
"submissionDate",
"applicationDate",
"publicationDate",
"authors",
"inventors",
"patents",
"applicants",
];
10 changes: 7 additions & 3 deletions client/src/config/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { VITE_API_URL: API_URL, VITE_API_KEY: API_KEY, VITE_TOPICS_URL: TOPICS_URL } = import.meta.env;
const {
VITE_API_URL: API_URL,
VITE_API_KEY: API_KEY,
VITE_TOPICS_URL: TOPICS_URL,
} = import.meta.env;

// Headers
export const headers = API_KEY ? { Authorization: `Basic ${API_KEY}` } : {};
Expand All @@ -9,6 +13,6 @@ export const publicationsIndex = `${API_URL}/scanr-publications`;
export const authorsIndex = `${API_URL}/scanr-persons`;
export const organizationsIndex = `${API_URL}/scanr-organizations`;
export const projectsIndex = `${API_URL}/scanr-projects`;
export const patentsIndex = `${API_URL}/scanr-patents`;
export const patentsIndex = `${API_URL}/scanr-patents-20240403`;
export const localisationIndex = `${API_URL}/scanr-localisations`;
export const topicsURL = TOPICS_URL ? `${TOPICS_URL}/topics` : '/topics';
export const topicsURL = TOPICS_URL ? `${TOPICS_URL}/topics` : "/topics";
150 changes: 74 additions & 76 deletions client/src/pages/patents/[id]/components/actors/index.tsx
Original file line number Diff line number Diff line change
@@ -1,100 +1,98 @@
import { Row, Col, Text, Link } from "@dataesr/dsfr-plus";
import { Row, Col, Link, Text } from "@dataesr/dsfr-plus";
import LinkCard from "../../../../../components/link-card";
import { PatentActorsData } from "../../../../../types/patent";
import { useIntl } from "react-intl";
import { InventorData, ApplicantData } from "../../../../../types/patent";
import { useQueryClient } from "@tanstack/react-query";
import { getAuthorById } from "../../../../../api/authors/[id]";
import { getOrganizationById } from "../../../../../api/organizations/[id]";
import { getAuthorById } from "../../../../../api/authors/[id]";
import { useIntl } from "react-intl";

function ActorsCard({ actor }: { actor: PatentActorsData }) {
const intl = useIntl();
function PatentActors({
actors,
}: {
actors: (ApplicantData | InventorData)[];
}) {
const queryClient = useQueryClient();
const isPm = actor.typeParticipant === "pm";
const id = actor.affiliations?.[0];

// Waiting for the API to return the correct id
// ? actor.affiliations?.[0]?.siren
// : `idref${actor.affiliations?.[0]?.idref}`;
const prefetch = isPm ? prefetchOrganization : prefetchAuthor;
const intl = useIntl();

function prefetchAuthor(id: string) {
function prefetchOrganization(id: string) {
if (!id) return;
queryClient.prefetchQuery({
queryKey: ["author", id],
queryFn: () => getAuthorById(id),
queryKey: ["organization", id],
queryFn: () => getOrganizationById(id),
});
}

function prefetchOrganization(id: string) {
function prefetchAuthor(id: string) {
if (!id) return;
queryClient.prefetchQuery({
queryKey: ["organization", id],
queryFn: () => getOrganizationById(id),
queryKey: ["author", id],
queryFn: () => getAuthorById(id),
});
}

return (
<LinkCard
prefetch={id ? () => prefetch(id[0]) : undefined}
type={isPm ? "organization" : "author"}
icon={isPm ? "building-line" : "user-line"}
>
{actor.affiliations.length > 0 ? (
<Link
className="fr-text--bold"
href={`/${isPm ? "organizations" : "authors"}/${
actor.affiliations[0]
}`}
>
{actor.fullName}
</Link>
) : (
<Text bold className="fr-m-0">
{actor.fullName}
</Text>
)}
{actor.country && (
<Text className="fr-card__detail" size="sm">
<i>{intl.formatMessage({ id: `${actor.country}` })}</i>
</Text>
)}
</LinkCard>
);
}
const groupedActors = actors.reduce((acc, actor) => {
acc[actor.name] = (acc[actor.name] || []).concat(actor);
return acc;
}, {});

export default function PatentActors({
data: actors,
type,
}: {
data: PatentActorsData[];
type: "inv" | "dep";
}) {
const filteredActors = actors
.filter((actor) => actor.rolePatent.some((role) => role.role === type))
.map(({ typeParticipant, country, fullName, affiliations }) => {
return {
typeParticipant: typeParticipant,
country: country,
affiliations: affiliations,
fullName: fullName,
};
});
return (
<Row gutters>
{Object.values(groupedActors).map((group, index) => {
const actorToDisplay =
(group as (ApplicantData | InventorData)[]).find(
(actor) => actor.ids?.[0]?.type === "idref"
) || group[0];

const uniqueActors = [
...new Set(filteredActors.map((i) => JSON.stringify(i))),
].map((i) => JSON.parse(i));
if (!actorToDisplay) return null;

if (!uniqueActors.length) return null;
const organizationId = actorToDisplay.ids?.[0]?.id;
const isOrganization = actorToDisplay.type === "organisation";
const isUndefinedId =
`/authors/${actorToDisplay?.ids?.[0]?.id}` === "/authors/undefined";

return (
<div>
<Row gutters>
{uniqueActors.map((actor, index) => (
return (
<Col xs="12" md="6" key={index}>
<ActorsCard actor={actor} />
<LinkCard
prefetch={
organizationId && !isUndefinedId
? () => {
prefetchOrganization(organizationId);
prefetchAuthor(organizationId);
}
: undefined
}
type={isOrganization ? "organization" : "author"}
icon={isOrganization ? "building-line" : "user-line"}
>
{isUndefinedId ? (
<Text className="fr-text--bold fr-m-0">
{actorToDisplay.name}
</Text>
) : (
<Link
href={
isOrganization
? `/organizations/${organizationId}`
: `/authors/${actorToDisplay?.ids?.[0]?.id}`
}
className="fr-text--bold"
>
{actorToDisplay.name}
</Link>
)}
{actorToDisplay.country && (
<Text className="fr-card__detail" size="sm">
<i>
{intl.formatMessage({ id: `${actorToDisplay.country}` })}
</i>
</Text>
)}
</LinkCard>
</Col>
))}
</Row>
</div>
);
})}
</Row>
);
}

export default PatentActors;
17 changes: 8 additions & 9 deletions client/src/pages/patents/[id]/components/cpc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import { Patent } from "../../../../../types/patent";
import { Badge } from "@dataesr/dsfr-plus";

export default function PatentCPC({ domains }: { domains: Patent["domains"] }) {
if (!domains.length) return null;
export default function PatentCPC({ cpc }: { cpc: Patent["cpc"] }) {
if (!cpc.ss_classe) return null;

const ssClasseItems = domains.filter((el) => el.level === "ss_classe");
const ssClasseItems = cpc.ss_classe;

return (
<ul className="fr-badges-group">
{ssClasseItems.map((el, index) => (
<>
<li key={index}>
<Badge
color="purple-glycine"
aria-describedby={`tootip-${index}`}
aria-describedby={`tooltip-${index}`}
as="a"
href={`/search/patents?q=${el.code}`}
>
{el.code}
</Badge>
<span
className="fr-tooltip fr-placement"
id={`tootip-${index}`}
id={`tooltip-${index}`}
role="tooltip"
aria-hidden="true"
>
{el.label.default}
{el.label}
</span>
</>
</li>
))}
</ul>

);
}
20 changes: 10 additions & 10 deletions client/src/pages/patents/[id]/components/patents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useIntl } from "react-intl";
import { Patent } from "../../../../types/patent";
import useScreenSize from "../../../../hooks/useScreenSize";
import { PageContent, PageSection } from "../../../../components/page-content";
import PatentActors from "./actors";
import Share from "../../../../components/share";
import getLangFieldValue from "../../../../utils/lang";
import PatentCPC from "./cpc";
Expand All @@ -23,6 +22,7 @@ import Truncate from "../../../../components/truncate";
import PatentTimeline from "./timeline";
import Websites from "../../../../components/websites";
import MoreLikeThis from "../../../../components/more-like-this";
import PatentActors from "./actors";

export default function PatentPage({ data }: { data: Patent }) {
const { locale } = useDSFRConfig();
Expand Down Expand Up @@ -100,29 +100,29 @@ export default function PatentPage({ data }: { data: Patent }) {
<PageContent>
<PageSection
show={
!!data.authors.filter((author) =>
author.rolePatent.some((role) => role.role === "dep")
!!data.applicants.filter(
(app) =>
app.type === "organisation" || app.type === "person"
).length
}
size="lead"
title={intl.formatMessage({
id: "patents.section.dep",
})}
>
<PatentActors data={data.authors} type="dep" />
<PatentActors actors={data.applicants} />
</PageSection>
<PageSection
show={
!!data.authors.filter((author) =>
author.rolePatent.some((role) => role.role === "inv")
).length
!!data.inventors.filter((author) => author.type === "person")
.length
}
size="lead"
title={intl.formatMessage({
id: "patents.section.inv",
})}
>
<PatentActors data={data.authors} type="inv" />
<PatentActors actors={data.inventors} />
</PageSection>
<PageSection
show
Expand Down Expand Up @@ -161,15 +161,15 @@ export default function PatentPage({ data }: { data: Patent }) {
<Col xs="12" md="4" xl="3" offsetXl="1">
<PageContent>
<PageSection
show={!!data.domains.length}
show
title={intl.formatMessage({
id: "patents.section.cpc.title",
})}
description={intl.formatMessage({
id: "patents.section.cpc.description",
})}
>
<PatentCPC domains={data.domains} />
<PatentCPC cpc={data.cpc} />
</PageSection>
<PageSection
show={!!data.patents.length}
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/patents/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default function Patents() {
throwOnError: true,
});
const title = getLangFieldValue(locale)(data?.title);

return (
<RawIntlProvider value={intl}>
<Container>
Expand Down
12 changes: 3 additions & 9 deletions client/src/pages/search/components/patents/patent-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const messages = Object.keys(modules).reduce((acc, key) => {
}
return acc;
}, {});

export default function PatentItem({
data: patent,
highlight,
Expand All @@ -38,13 +37,8 @@ export default function PatentItem({
});
}

const numberOfDep = patent.authors.filter((author) =>
author.rolePatent.some((role) => role.role === "dep")
).length;

const numberOfInv = patent.authors.filter((author) =>
author.rolePatent.some((role) => role.role === "inv")
).length;
const numberOfDep = patent?.applicants?.length || 0;
const numberOfInv = patent?.inventors?.length || 0;

return (
<RawIntlProvider value={intl}>
Expand Down Expand Up @@ -120,7 +114,7 @@ export default function PatentItem({
id: "patents.item.submission-date",
},
{
date: new Date(patent.submissionDate).toLocaleDateString(
date: new Date(patent.applicationDate).toLocaleDateString(
locale,
{ year: "numeric", month: "long", day: "numeric" }
),
Expand Down
Loading

0 comments on commit b733eb9

Please sign in to comment.