From b436c3fc36bcc802356baa0359dd1e0d0621ce0f Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Sat, 26 Oct 2024 20:16:38 +0200
Subject: [PATCH] fix validation for old projects

---
 CHANGELOG                                     |  1 +
 .../MapNavigation.component.test.tsx          |  4 +---
 .../BioEntitiesAccordion.component.test.tsx   | 21 +++++++++++++++----
 .../PinsListItem.component.test.tsx           |  5 +++++
 .../mapSingleClick/handleAliasResults.test.ts |  2 --
 src/constants/mocks.ts                        |  6 ++++--
 src/models/bioEntitySchema.ts                 |  8 +++----
 src/models/compartmentPathwaySchema.ts        |  2 +-
 src/models/mapBackground.ts                   |  2 +-
 src/models/overlayLeftBioEntitySchema.ts      |  6 +++---
 src/models/overlayLeftReactionSchema.ts       |  2 +-
 src/models/reaction.ts                        |  2 +-
 src/utils/search/getElementsByCoordinates.ts  |  8 +++++--
 13 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index eb0373fa..347b9405 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 minerva-front (18.0.1) stable; urgency=medium
   * Bug fix: show cookie baner only when cookie baner link is provided (#304)
   * Bug fix: when link to submap is provided add submap name (#303)
+  * Bug fix: some old maps could not be opened (#311)
 
  -- Piotr Gawron <piotr.gawron@uni.lu>  Thu, 24 Oct 2024 13:00:00 +0200
 
diff --git a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx
index 4fae3753..2af7f3fb 100644
--- a/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx
+++ b/src/components/FunctionalArea/MapNavigation/MapNavigation.component.test.tsx
@@ -9,11 +9,9 @@ import {
   getReduxWrapperWithStore,
 } from '@/utils/testing/getReduxWrapperWithStore';
 import { act, render, screen, within } from '@testing-library/react';
+import { HISTAMINE_MAP_ID, MAIN_MAP_ID } from '@/constants/mocks';
 import { MapNavigation } from './MapNavigation.component';
 
-const MAIN_MAP_ID = 5053;
-const HISTAMINE_MAP_ID = 5052;
-
 const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => {
   const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState);
 
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..64d82fab 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
@@ -11,6 +11,7 @@ import {
 } from '@/utils/testing/getReduxWrapperWithStore';
 import { render, screen } from '@testing-library/react';
 import { MockStoreEnhanced } from 'redux-mock-store';
+import { HISTAMINE_MAP_ID, MAIN_MAP_ID, PRKN_SUBSTRATES_MAP_ID } from '@/constants/mocks';
 import { BioEntitiesAccordion } from './BioEntitiesAccordion.component';
 
 const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => {
@@ -95,10 +96,22 @@ describe('BioEntitiesAccordion - component', () => {
       },
     });
 
-    expect(screen.getByText('Content (10)')).toBeInTheDocument();
-    expect(screen.getByText('Core PD map (3)')).toBeInTheDocument();
-    expect(screen.getByText('Histamine signaling (4)')).toBeInTheDocument();
-    expect(screen.getByText('PRKN substrates (3)')).toBeInTheDocument();
+    const countHistamine = bioEntitiesContentFixture.filter(
+      content => content.bioEntity.model === HISTAMINE_MAP_ID,
+    ).length;
+    const countCore = bioEntitiesContentFixture.filter(
+      content => content.bioEntity.model === MAIN_MAP_ID,
+    ).length;
+    const countPrkn = bioEntitiesContentFixture.filter(
+      content => content.bioEntity.model === PRKN_SUBSTRATES_MAP_ID,
+    ).length;
+
+    const countAll = bioEntitiesContentFixture.length;
+
+    expect(screen.getByText(`Content (${countAll})`)).toBeInTheDocument();
+    expect(screen.getByText(`Core PD map (${countCore})`)).toBeInTheDocument();
+    expect(screen.getByText(`Histamine signaling (${countHistamine})`)).toBeInTheDocument();
+    expect(screen.getByText(`PRKN substrates (${countPrkn})`)).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..589688c9 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
@@ -62,6 +62,11 @@ const renderComponent = (
 };
 
 describe('PinsListItem - component ', () => {
+  drugsFixture[0].targets[0].targetParticipants[0].link = 'https://example.com/plugin.js';
+  drugsFixture[0].targets[0].targetParticipants[1].link = 'https://example.com/plugin.js';
+  chemicalsFixture[0].targets[0].targetParticipants[0].link = 'https://example.com/plugin.js';
+  chemicalsFixture[0].targets[0].targetParticipants[1].link = 'https://example.com/plugin.js';
+
   it('should display full name of pin', () => {
     renderComponent(DRUGS_PIN.name, DRUGS_PIN.pin, 'drugs', BIO_ENTITY, INITIAL_STORE_STATE);
 
diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts
index e00535c5..aae76f61 100644
--- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts
+++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts
@@ -209,8 +209,6 @@ describe('handleAliasResults - util', () => {
           'entityNumber/addNumbersToEntityNumberData',
           'project/getBioEntityById/fulfilled',
           'entityNumber/addNumbersToEntityNumberData',
-          'reactions/getByIds/pending',
-          'reactions/getByIds/fulfilled',
           'project/getMultiBioEntity/fulfilled',
           'drawer/selectTab',
           'drawer/openBioEntityDrawerById',
diff --git a/src/constants/mocks.ts b/src/constants/mocks.ts
index d7156f1e..11af1d0a 100644
--- a/src/constants/mocks.ts
+++ b/src/constants/mocks.ts
@@ -1,2 +1,4 @@
-// eslint-disable-next-line no-magic-numbers
-export const MODEL_IDS_MOCK = [5052, 5053, 5054];
+export const MAIN_MAP_ID = 5053;
+export const HISTAMINE_MAP_ID = 5052;
+export const PRKN_SUBSTRATES_MAP_ID = 5054;
+export const MODEL_IDS_MOCK = [HISTAMINE_MAP_ID, MAIN_MAP_ID, PRKN_SUBSTRATES_MAP_ID];
diff --git a/src/models/bioEntitySchema.ts b/src/models/bioEntitySchema.ts
index 187b1982..1e01a1d5 100644
--- a/src/models/bioEntitySchema.ts
+++ b/src/models/bioEntitySchema.ts
@@ -35,7 +35,7 @@ export const bioEntitySchema = z.object({
     .number()
     .optional()
     .transform(height => height ?? ZERO),
-  visibilityLevel: z.string(),
+  visibilityLevel: z.string().nullable(),
   transparencyLevel: z.string().nullable().optional(),
   synonyms: z.array(z.string()),
   formerSymbols: z.array(z.string()).nullable().optional(),
@@ -47,13 +47,13 @@ export const bioEntitySchema = z.object({
   activity: z.boolean().optional(),
   structuralState: z.optional(structuralStateSchema.nullable()),
   hypothetical: z.boolean().nullable().optional(),
-  boundaryCondition: z.boolean().optional(),
-  constant: z.boolean().optional(),
+  boundaryCondition: z.boolean().optional().nullable(),
+  constant: z.boolean().optional().nullable(),
   initialAmount: z.number().nullable().optional(),
   initialConcentration: z.number().nullable().optional(),
   charge: z.number().nullable().optional(),
   substanceUnits: z.string().nullable().optional(),
-  onlySubstanceUnits: z.boolean().optional(),
+  onlySubstanceUnits: z.boolean().optional().nullable(),
   modificationResidues: z.optional(z.array(modificationResiduesSchema)),
   complex: z.number().nullable().optional(),
   compartment: z.number().nullable().optional(),
diff --git a/src/models/compartmentPathwaySchema.ts b/src/models/compartmentPathwaySchema.ts
index 368ff17f..1259fa87 100644
--- a/src/models/compartmentPathwaySchema.ts
+++ b/src/models/compartmentPathwaySchema.ts
@@ -32,7 +32,7 @@ export const compartmentPathwayDetailsSchema = z.object({
   formula: z.null(),
   fullName: z.string().nullable(),
   glyph: z.any(),
-  hierarchyVisibilityLevel: z.string(),
+  hierarchyVisibilityLevel: z.string().nullable(),
   homomultimer: z.null(),
   hypothetical: z.null(),
   id: z.number().gt(-1),
diff --git a/src/models/mapBackground.ts b/src/models/mapBackground.ts
index a8a96052..fe6c6e9e 100644
--- a/src/models/mapBackground.ts
+++ b/src/models/mapBackground.ts
@@ -8,7 +8,7 @@ export const mapBackground = z.object({
   creator: z.object({ login: z.string() }),
   status: z.string(),
   progress: z.number(),
-  description: z.null(),
+  description: z.string().nullable(),
   order: z.number(),
   images: z.array(
     z.object({
diff --git a/src/models/overlayLeftBioEntitySchema.ts b/src/models/overlayLeftBioEntitySchema.ts
index 5e751d72..64d3a1c9 100644
--- a/src/models/overlayLeftBioEntitySchema.ts
+++ b/src/models/overlayLeftBioEntitySchema.ts
@@ -18,7 +18,7 @@ export const overlayLeftBioEntitySchema = z.object({
   fontColor: colorSchema.optional(),
   fillColor: colorSchema.optional(),
   borderColor: colorSchema,
-  visibilityLevel: z.string(),
+  visibilityLevel: z.string().nullable(),
   transparencyLevel: z.string(),
   notes: z.string(),
   symbol: z.string().nullable(),
@@ -40,10 +40,10 @@ export const overlayLeftBioEntitySchema = z.object({
   initialAmount: z.unknown().nullable(),
   charge: z.unknown(),
   initialConcentration: z.number().nullable().optional(),
-  onlySubstanceUnits: z.unknown(),
+  onlySubstanceUnits: z.boolean().nullable().optional(),
   homodimer: z.number().optional(),
   hypothetical: z.unknown(),
-  boundaryCondition: z.boolean().optional(),
+  boundaryCondition: z.boolean().optional().nullable(),
   constant: z.boolean().nullable().optional(),
   modificationResidues: z.unknown(),
   stringType: z.string(),
diff --git a/src/models/overlayLeftReactionSchema.ts b/src/models/overlayLeftReactionSchema.ts
index c47febcf..28a0b9d7 100644
--- a/src/models/overlayLeftReactionSchema.ts
+++ b/src/models/overlayLeftReactionSchema.ts
@@ -17,7 +17,7 @@ export const overlayLeftReactionSchema = z.object({
   upperBound: z.null(),
   subsystem: z.null(),
   geneProteinReaction: z.null(),
-  visibilityLevel: z.string(),
+  visibilityLevel: z.string().nullable(),
   z: z.number(),
   synonyms: z.array(z.unknown()),
   model: z.number(),
diff --git a/src/models/reaction.ts b/src/models/reaction.ts
index 51c7c51b..18a438f7 100644
--- a/src/models/reaction.ts
+++ b/src/models/reaction.ts
@@ -6,7 +6,7 @@ import { referenceSchema } from './referenceSchema';
 
 export const reactionSchema = z.object({
   centerPoint: positionSchema,
-  hierarchyVisibilityLevel: z.string(),
+  hierarchyVisibilityLevel: z.string().nullable(),
   id: z.number(),
   kineticLaw: z.null(),
   lines: z.array(reactionLineSchema),
diff --git a/src/utils/search/getElementsByCoordinates.ts b/src/utils/search/getElementsByCoordinates.ts
index 70e392de..fa54f1de 100644
--- a/src/utils/search/getElementsByCoordinates.ts
+++ b/src/utils/search/getElementsByCoordinates.ts
@@ -25,7 +25,10 @@ export const getFirstVisibleParent = async ({
       apiPath.getElementById(parentId, bioEntity.model),
     );
     const parent = parentResponse.data;
-    if (parseInt(parent.visibilityLevel, 10) > Math.ceil(considerZoomLevel)) {
+    if (
+      parent.visibilityLevel !== null &&
+      parseInt(parent.visibilityLevel, 10) > Math.ceil(considerZoomLevel)
+    ) {
       return getFirstVisibleParent({
         bioEntity: parent,
         considerZoomLevel,
@@ -70,8 +73,9 @@ export const getElementsByPoint = async ({
     );
     const element = elementResponse.data;
     if (
+      element.visibilityLevel != null &&
       parseInt(element.visibilityLevel, 10) - (ONE - FRACTIONAL_ZOOM_AT_WHICH_IMAGE_LAYER_CHANGE) >
-      (considerZoomLevel || Number.MAX_SAFE_INTEGER)
+        (considerZoomLevel || Number.MAX_SAFE_INTEGER)
     ) {
       const visibleParent = await getFirstVisibleParent({
         bioEntity: element,
-- 
GitLab