From d1c9360aef4418a15eda2a2684c34461ace32bdc Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Fri, 4 Oct 2024 09:40:04 +0200
Subject: [PATCH] bioEntity has SBO term instead of stringType

---
 .../BioEntityDrawer.component.test.tsx                |  5 ++++-
 .../BioEntityDrawer/BioEntityDrawer.component.tsx     |  5 ++++-
 .../BioEntitiesPinsListItem.component.test.tsx        |  5 +++--
 .../BioEntitiesPinsListItem.component.tsx             |  5 ++++-
 .../BioEntitiesPinsListItem.types.ts                  |  2 +-
 .../BioEntitiesAccordion.component.test.tsx           |  4 ++--
 .../PinsListItem/PinsListItem.component.test.tsx      |  6 +++---
 .../PinsList/PinsListItem/PinsListItem.component.tsx  | 11 +++++------
 src/models/bioEntitySchema.ts                         |  2 +-
 src/models/overlayLeftBioEntitySchema.ts              |  2 +-
 src/models/overlayLeftReactionSchema.ts               |  2 +-
 src/utils/bioEntity/getTypeBySBOTerm.ts               |  3 +++
 12 files changed, 32 insertions(+), 20 deletions(-)
 create mode 100644 src/utils/bioEntity/getTypeBySBOTerm.ts

diff --git a/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.test.tsx b/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.test.tsx
index b2fad199..d72d546a 100644
--- a/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.test.tsx
+++ b/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.test.tsx
@@ -17,6 +17,7 @@ import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreA
 import { InitialStoreState } from '@/utils/testing/getReduxWrapperWithStore';
 import { act, render, screen } from '@testing-library/react';
 import { MockStoreEnhanced } from 'redux-mock-store';
+import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
 import { BioEntityDrawer } from './BioEntityDrawer.component';
 
 const renderComponent = (
@@ -91,7 +92,9 @@ describe('BioEntityDrawer - component', () => {
         },
       });
 
-      expect(screen.getByText(bioEntity.stringType, { exact: false })).toBeInTheDocument();
+      const bioEntityType = getTypeBySBOTerm(bioEntity.sboTerm);
+
+      expect(screen.getByText(bioEntityType, { exact: false })).toBeInTheDocument();
       expect(screen.getByText(bioEntity.name, { exact: false })).toBeInTheDocument();
     });
 
diff --git a/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx b/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx
index 06e815d3..42c5a1f9 100644
--- a/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx
+++ b/src/components/Map/Drawer/BioEntityDrawer/BioEntityDrawer.component.tsx
@@ -13,6 +13,7 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector';
 import { DrawerHeading } from '@/shared/DrawerHeading';
 import { ElementSearchResultType } from '@/types/models';
 import { CommentItem } from '@/components/Map/Drawer/BioEntityDrawer/Comments/CommentItem.component';
+import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
 import { CollapsibleSection } from '../ExportDrawer/CollapsibleSection';
 import { AnnotationItem } from './AnnotationItem';
 import { AssociatedSubmap } from './AssociatedSubmap';
@@ -43,12 +44,14 @@ export const BioEntityDrawer = (): React.ReactNode => {
   const isReferenceAvailable = bioEntityData.references.length > ZERO;
   const isCommentAvailable = commentsData.length > ZERO;
 
+  const type = getTypeBySBOTerm(bioEntityData.sboTerm);
+
   return (
     <div className="h-calc-drawer" data-testid="bioentity-drawer">
       <DrawerHeading
         title={
           <>
-            <span className="font-normal">{bioEntityData.stringType}:</span>&nbsp;
+            <span className="font-normal">{type}:</span>&nbsp;
             {bioEntityData.name}
           </>
         }
diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx
index cbf1cca8..e2d365f6 100644
--- a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx
+++ b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx
@@ -13,6 +13,7 @@ import {
 import { render, screen } from '@testing-library/react';
 import { act } from 'react-dom/test-utils';
 import { MockStoreEnhanced } from 'redux-mock-store';
+import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
 import { BioEntitiesPinsListItem } from './BioEntitiesPinsListItem.component';
 import { PinListBioEntity } from './BioEntitiesPinsListItem.types';
 
@@ -97,9 +98,9 @@ describe('BioEntitiesPinsListItem - component ', () => {
   it('should display string type of bio entity element', () => {
     renderComponent(BIO_ENTITY.name, BIO_ENTITY, INITIAL_STORE_WITH_ENTITY_NUMBER);
 
-    const bioEntityStringType = BIO_ENTITY.stringType;
+    const bioEntityType = getTypeBySBOTerm(BIO_ENTITY.sboTerm);
 
-    expect(screen.getByText(bioEntityStringType, { exact: false })).toBeInTheDocument();
+    expect(screen.getByText(bioEntityType, { exact: false })).toBeInTheDocument();
   });
   it('should display synonyms of bio entity element', () => {
     renderComponent(BIO_ENTITY.name, BIO_ENTITY, INITIAL_STORE_WITH_ENTITY_NUMBER);
diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.tsx
index 65f10b30..852b85e7 100644
--- a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.tsx
+++ b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.tsx
@@ -16,6 +16,7 @@ import { setMapPosition } from '@/redux/map/map.slice';
 import { resetReactionsData } from '@/redux/reactions/reactions.slice';
 import { getSearchData } from '@/redux/search/search.thunks';
 import { twMerge } from 'tailwind-merge';
+import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
 import { PinListBioEntity } from './BioEntitiesPinsListItem.types';
 import { isPinWithCoordinates } from './BioEntitiesPinsListItem.utils';
 
@@ -59,6 +60,8 @@ export const BioEntitiesPinsListItem = ({
     dispatch(openSearchDrawerWithSelectedTab(getDefaultSearchTab(searchValues)));
   };
 
+  const type = getTypeBySBOTerm(pin.sboTerm);
+
   return (
     <div className="mb-4 flex w-full flex-col gap-3 rounded-lg border-[1px] border-solid border-greyscale-500 p-4">
       <div className="flex w-full flex-row items-center gap-2">
@@ -71,7 +74,7 @@ export const BioEntitiesPinsListItem = ({
           <img src={pinIconCanvas.toDataURL()} alt="pin icon" />
         </button>
         <p>
-          {pin.stringType ? `${pin.stringType}: ` : ''}
+          {type ? `${type}: ` : ''}
           <span
             className="w-full cursor-pointer font-bold underline"
             onClick={handleSearchMapForPin}
diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.types.ts b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.types.ts
index 4fe4314a..a916a1dc 100644
--- a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.types.ts
+++ b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.types.ts
@@ -2,11 +2,11 @@ import { BioEntity } from '@/types/models';
 
 export type PinListBioEntity = Pick<BioEntity, 'synonyms' | 'references'> & {
   symbol?: BioEntity['symbol'];
-  stringType?: BioEntity['stringType'];
   fullName?: BioEntity['fullName'];
   x?: BioEntity['x'];
   y?: BioEntity['y'];
   elementId?: BioEntity['elementId'];
+  sboTerm?: BioEntity['sboTerm'];
 };
 
 export type PinListBioEntityWithCoords = PinListBioEntity & {
diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx
index a1bec280..5067368d 100644
--- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx
+++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx
@@ -96,9 +96,9 @@ describe('BioEntitiesAccordion - component', () => {
     });
 
     expect(screen.getByText('Content (10)')).toBeInTheDocument();
-    expect(screen.getByText('Core PD map (3)')).toBeInTheDocument();
+    expect(screen.getByText('Core PD map (4)')).toBeInTheDocument();
     expect(screen.getByText('Histamine signaling (4)')).toBeInTheDocument();
-    expect(screen.getByText('PRKN substrates (3)')).toBeInTheDocument();
+    expect(screen.getByText('PRKN substrates (2)')).toBeInTheDocument();
   });
 
   it('should fire toggleIsContentTabOpened on accordion item button click', () => {
diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx
index b1d74b81..bcb63ba4 100644
--- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx
+++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx
@@ -144,7 +144,7 @@ describe('PinsListItem - component ', () => {
 
     expect(screen.queryByText('Available in submaps:')).toBeNull();
   });
-  it('should call setMapPosition if coordinates exist in bioentity element', () => {
+  it('should call setMapPosition if coordinates exist in bioEntity element', () => {
     const { store } = renderComponent(
       DRUGS_PIN.name,
       DRUGS_PIN.pin,
@@ -159,7 +159,7 @@ describe('PinsListItem - component ', () => {
         map: {
           data: {
             ...initialMapDataFixture,
-            modelId: 5053,
+            modelId: BIO_ENTITY.model,
           },
           loading: 'succeeded',
           error: { message: '', name: '' },
@@ -192,7 +192,7 @@ describe('PinsListItem - component ', () => {
         map: {
           data: {
             ...initialMapDataFixture,
-            modelId: 5053,
+            modelId: BIO_ENTITY.model,
           },
           loading: 'succeeded',
           error: { message: '', name: '' },
diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx
index 2ec3d41b..510763ad 100644
--- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx
+++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx
@@ -91,15 +91,14 @@ export const PinsListItem = ({
         <div className="font-bold">Elements:</div>
         {'targetParticipants' in pin &&
           pin.targetParticipants.map(participant => {
-            if (!participant?.link) {
-              return null;
-            }
-
             return (
               // participant.id is almost always = 0
-              <li key={`${participant.id}-${participant.link}`} className="my-2 px-2">
+              <li
+                key={`${participant.id}-${participant.type}-${participant.resource}`}
+                className="my-2 px-2"
+              >
                 <a
-                  href={participant.link}
+                  href={participant.link ? participant.link : undefined}
                   target="_blank"
                   className="cursor-pointer text-primary-500 underline"
                 >
diff --git a/src/models/bioEntitySchema.ts b/src/models/bioEntitySchema.ts
index 187b1982..ee025b2c 100644
--- a/src/models/bioEntitySchema.ts
+++ b/src/models/bioEntitySchema.ts
@@ -12,7 +12,6 @@ import { submodelSchema } from './submodelSchema';
 
 export const bioEntitySchema = z.object({
   id: z.union([z.number().int().positive(), z.string()]),
-  stringType: z.string(),
   name: z.string(),
   elementId: z.string(),
   model: z.number(),
@@ -91,4 +90,5 @@ export const bioEntitySchema = z.object({
   processCoordinates: z.optional(z.null()),
   line: z.optional(lineSchema),
   operators: z.optional(z.array(operatorSchema)),
+  sboTerm: z.string(),
 });
diff --git a/src/models/overlayLeftBioEntitySchema.ts b/src/models/overlayLeftBioEntitySchema.ts
index 5e751d72..bd0431d4 100644
--- a/src/models/overlayLeftBioEntitySchema.ts
+++ b/src/models/overlayLeftBioEntitySchema.ts
@@ -46,7 +46,7 @@ export const overlayLeftBioEntitySchema = z.object({
   boundaryCondition: z.boolean().optional(),
   constant: z.boolean().nullable().optional(),
   modificationResidues: z.unknown(),
-  stringType: z.string(),
   substanceUnits: z.boolean().nullable().optional(),
   references: z.array(referenceSchema),
+  sboTerm: z.string(),
 });
diff --git a/src/models/overlayLeftReactionSchema.ts b/src/models/overlayLeftReactionSchema.ts
index c47febcf..b7663c41 100644
--- a/src/models/overlayLeftReactionSchema.ts
+++ b/src/models/overlayLeftReactionSchema.ts
@@ -24,11 +24,11 @@ export const overlayLeftReactionSchema = z.object({
   kinetics: z.null(),
   line: lineSchema,
   processCoordinates: z.null(),
-  stringType: z.string(),
   modifiers: z.array(reactionProduct),
   reactants: z.array(reactionProduct),
   products: z.array(reactionProduct),
   elementId: z.string(),
   operators: z.array(z.unknown()),
   references: z.array(referenceSchema),
+  sboTerm: z.string(),
 });
diff --git a/src/utils/bioEntity/getTypeBySBOTerm.ts b/src/utils/bioEntity/getTypeBySBOTerm.ts
new file mode 100644
index 00000000..b3d536a2
--- /dev/null
+++ b/src/utils/bioEntity/getTypeBySBOTerm.ts
@@ -0,0 +1,3 @@
+export const getTypeBySBOTerm = (sbo: string | undefined): string => {
+  return sbo || '';
+};
-- 
GitLab