-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(patents): update patents with new index, change types also
- Loading branch information
Showing
8 changed files
with
133 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 74 additions & 76 deletions
150
client/src/pages/patents/[id]/components/actors/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.