From f62726cd94d16f8b521dc5fb651ac67918daef77 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Fri, 13 Sep 2024 14:15:18 +0200
Subject: [PATCH] when fetching overlay dont fetch data for connected submaps,
 but compute them

---
 src/redux/apiPath.ts                          |  2 +-
 .../overlayBioEntity.selector.ts              | 35 ++++++++++++++++++-
 src/redux/root/init.thunks.ts                 |  3 ++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/redux/apiPath.ts b/src/redux/apiPath.ts
index 423aefbf..944cfa00 100644
--- a/src/redux/apiPath.ts
+++ b/src/redux/apiPath.ts
@@ -63,7 +63,7 @@ export const apiPath = {
   getConfigurationOptions: (): string => 'configuration/options/',
   getConfiguration: (): string => 'configuration/',
   getOverlayBioEntity: ({ overlayId, modelId }: { overlayId: number; modelId: number }): string =>
-    `projects/${PROJECT_ID}/overlays/${overlayId}/models/${modelId}/bioEntities/?includeIndirect=true`,
+    `projects/${PROJECT_ID}/overlays/${overlayId}/models/${modelId}/bioEntities/`,
   createOverlay: (projectId: string): string => `projects/${projectId}/overlays/`,
   createOverlayFile: (): string => `files/`,
   uploadOverlayFileContent: (fileId: number): string => `files/${fileId}:uploadContent`,
diff --git a/src/redux/overlayBioEntity/overlayBioEntity.selector.ts b/src/redux/overlayBioEntity/overlayBioEntity.selector.ts
index f6ad669d..2b96a538 100644
--- a/src/redux/overlayBioEntity/overlayBioEntity.selector.ts
+++ b/src/redux/overlayBioEntity/overlayBioEntity.selector.ts
@@ -1,5 +1,6 @@
 import { OverlayBioEntityRender } from '@/types/OLrendering';
 import { createSelector } from '@reduxjs/toolkit';
+import { allSubmapConnectionsBioEntitySelector } from '@/redux/bioEntity/bioEntity.selectors';
 import { currentSearchedBioEntityId } from '../drawer/drawer.selectors';
 import { currentModelIdSelector } from '../models/models.selectors';
 import {
@@ -34,7 +35,8 @@ export const overlayBioEntitiesForCurrentModelSelector = createSelector(
   overlayBioEntityDataSelector,
   activeOverlaysIdSelector,
   currentModelIdSelector,
-  (data, activeOverlaysIds, currentModelId) => {
+  allSubmapConnectionsBioEntitySelector,
+  (data, activeOverlaysIds, currentModelId, submapConnections) => {
     const result: OverlayBioEntityRender[] = [];
 
     activeOverlaysIds.forEach(overlayId => {
@@ -43,6 +45,37 @@ export const overlayBioEntitiesForCurrentModelSelector = createSelector(
       }
     });
 
+    submapConnections.forEach(submapConnection => {
+      if (submapConnection.model === currentModelId) {
+        const submapId = submapConnection?.submodel?.mapId;
+        if (submapId) {
+          activeOverlaysIds.forEach(overlayId => {
+            if (data[overlayId]?.[submapId]) {
+              data[overlayId][submapId].forEach(overlayBioEntityRender => {
+                const newOverlayBioEntityRender = {
+                  id: submapConnection.id,
+                  modelId: submapConnection.model,
+                  x1: submapConnection.x,
+                  y2: submapConnection.y,
+                  x2: submapConnection.x + submapConnection.width,
+                  y1: submapConnection.y + submapConnection.height,
+                  width: submapConnection.width,
+                  height: submapConnection.height,
+                  value: overlayBioEntityRender.value,
+                  overlayId: overlayBioEntityRender.overlayId,
+                  color: overlayBioEntityRender.color,
+                  hexColor: overlayBioEntityRender.hexColor,
+                  type: overlayBioEntityRender.type,
+                  geneVariants: overlayBioEntityRender.geneVariants,
+                  name: overlayBioEntityRender.name,
+                };
+                result.push(newOverlayBioEntityRender);
+              });
+            }
+          });
+        }
+      }
+    });
     return result;
   },
 );
diff --git a/src/redux/root/init.thunks.ts b/src/redux/root/init.thunks.ts
index 1d8a39b5..20a722af 100644
--- a/src/redux/root/init.thunks.ts
+++ b/src/redux/root/init.thunks.ts
@@ -14,6 +14,7 @@ import {
 } from '@/redux/autocomplete/autocomplete.thunks';
 import { openSelectProjectModal } from '@/redux/modal/modal.slice';
 import { getProjects } from '@/redux/projects/projects.thunks';
+import { getSubmapConnectionsBioEntity } from '@/redux/bioEntity/thunks/getSubmapConnectionsBioEntity';
 import { getAllBackgroundsByProjectId } from '../backgrounds/backgrounds.thunks';
 import { getConfiguration, getConfigurationOptions } from '../configuration/configuration.thunks';
 import {
@@ -98,6 +99,8 @@ export const fetchInitialAppData = createAsyncThunk<
   dispatch(getDrugAutocomplete());
   dispatch(getChemicalAutocomplete());
 
+  dispatch(getSubmapConnectionsBioEntity());
+
   /** Trigger search */
   if (queryData.searchValue) {
     dispatch(setPerfectMatch(queryData.perfectMatch));
-- 
GitLab