From 48ed731a99d2838e8b6c1ea3e4a6f7e15a858440 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <p.gawron@atcomp.pl>
Date: Wed, 5 Feb 2025 11:35:16 +0100
Subject: [PATCH] overlay structures merged

---
 public/config.js                              |  2 ++
 .../UserOverlayForm.component.test.tsx        |  8 ++---
 src/models/fixtures/overlaysFixture.ts        | 14 +++-----
 .../{mapOverlay.ts => mapOverlaySchema.ts}    | 14 +-------
 src/redux/overlays/overlays.reducers.test.ts  |  9 ++---
 src/redux/overlays/overlays.thunks.ts         | 33 ++++++++++---------
 .../addDataOverlay/addDataOverlay.test.ts     |  4 +--
 .../pluginsEventBus/pluginsEventBus.test.ts   |  6 ++--
 .../pluginsEventBus/pluginsEventBus.ts        |  4 +--
 .../pluginsEventBus/pluginsEventBus.types.ts  | 10 +-----
 src/types/models.ts                           |  5 ++-
 11 files changed, 41 insertions(+), 68 deletions(-)
 rename src/models/{mapOverlay.ts => mapOverlaySchema.ts} (64%)

diff --git a/public/config.js b/public/config.js
index 5a90943d..dfa92d75 100644
--- a/public/config.js
+++ b/public/config.js
@@ -1,5 +1,7 @@
 // const root = 'https://minerva-dev.lcsb.uni.lu';
 // const root = 'https://scimap.lcsb.uni.lu';
+// const root = 'https://imsavar.elixir-luxembourg.org';
+// const root = 'https://pdmap.uni.lu';
 
 const root = 'https://lux1.atcomp.pl';
 // const root = 'http://localhost:8080';
diff --git a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.component.test.tsx b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.component.test.tsx
index 35943150..be08de75 100644
--- a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.component.test.tsx
+++ b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.component.test.tsx
@@ -15,7 +15,7 @@ import { HttpStatusCode } from 'axios';
 import { apiPath } from '@/redux/apiPath';
 import {
   createdOverlayFileFixture,
-  createdOverlayFixture,
+  overlayFixture,
   overlaysPageFixture,
   uploadedOverlayFileContentFixture,
 } from '@/models/fixtures/overlaysFixture';
@@ -92,7 +92,7 @@ describe('UserOverlayForm - Component', () => {
 
     mockedAxiosClient
       .onPost(apiPath.createOverlay(projectFixture.projectId))
-      .reply(HttpStatusCode.Ok, createdOverlayFixture);
+      .reply(HttpStatusCode.Ok, overlayFixture);
 
     renderComponent({
       project: {
@@ -222,7 +222,7 @@ describe('UserOverlayForm - Component', () => {
 
     mockedAxiosClient
       .onPost(apiPath.createOverlay(projectFixture.projectId))
-      .reply(HttpStatusCode.Ok, createdOverlayFixture);
+      .reply(HttpStatusCode.Ok, overlayFixture);
 
     mockedAxiosNewClient
       .onGet(apiPath.getAllUserOverlaysByCreatorQuery({ creator: 'test', publicOverlay: false }))
@@ -288,7 +288,7 @@ describe('UserOverlayForm - Component', () => {
 
     mockedAxiosClient
       .onPost(apiPath.createOverlay(projectFixture.projectId))
-      .reply(HttpStatusCode.Ok, createdOverlayFixture);
+      .reply(HttpStatusCode.Ok, overlayFixture);
 
     mockedAxiosNewClient
       .onGet(apiPath.getAllUserOverlaysByCreatorQuery({ creator: 'test', publicOverlay: false }))
diff --git a/src/models/fixtures/overlaysFixture.ts b/src/models/fixtures/overlaysFixture.ts
index efb684ca..88ec2e6b 100644
--- a/src/models/fixtures/overlaysFixture.ts
+++ b/src/models/fixtures/overlaysFixture.ts
@@ -4,17 +4,16 @@ import { createFixture } from 'zod-fixture';
 import { pageableSchema } from '@/models/pageableSchema';
 import {
   createdOverlayFileSchema,
-  createdOverlaySchema,
-  mapOverlay,
+  mapOverlaySchema,
   uploadedOverlayFileContentSchema,
-} from '../mapOverlay';
+} from '../mapOverlaySchema';
 
-export const overlaysPageFixture = createFixture(pageableSchema(mapOverlay), {
+export const overlaysPageFixture = createFixture(pageableSchema(mapOverlaySchema), {
   seed: ZOD_SEED,
   array: { min: 2, max: 2 },
 });
 
-export const overlayFixture = createFixture(mapOverlay, {
+export const overlayFixture = createFixture(mapOverlaySchema, {
   seed: ZOD_SEED,
   array: { min: 1, max: 1 },
 });
@@ -26,11 +25,8 @@ export const createdOverlayFileFixture = createFixture(createdOverlayFileSchema,
 export const uploadedOverlayFileContentFixture = createFixture(uploadedOverlayFileContentSchema, {
   seed: ZOD_SEED,
 });
-export const createdOverlayFixture = createFixture(createdOverlaySchema, {
-  seed: ZOD_SEED,
-});
 
-export const emptyPageFixture = createFixture(pageableSchema(mapOverlay), {
+export const emptyPageFixture = createFixture(pageableSchema(mapOverlaySchema), {
   seed: ZOD_SEED,
   array: { min: 0, max: 0 },
 });
diff --git a/src/models/mapOverlay.ts b/src/models/mapOverlaySchema.ts
similarity index 64%
rename from src/models/mapOverlay.ts
rename to src/models/mapOverlaySchema.ts
index d9b645eb..d6460bfc 100644
--- a/src/models/mapOverlay.ts
+++ b/src/models/mapOverlaySchema.ts
@@ -1,7 +1,7 @@
 import { z } from 'zod';
 import { ZERO } from '@/constants/common';
 
-export const mapOverlay = z.object({
+export const mapOverlaySchema = z.object({
   idObject: z.number(),
   name: z.string(),
   order: z.number().int().gte(ZERO),
@@ -22,15 +22,3 @@ export const createdOverlayFileSchema = z.object({
 });
 
 export const uploadedOverlayFileContentSchema = createdOverlayFileSchema.extend({});
-
-export const createdOverlaySchema = z.object({
-  name: z.string(),
-  creator: z.string(),
-  description: z.string(),
-  genomeType: z.string().nullable(),
-  genomeVersion: z.string().nullable(),
-  idObject: z.number(),
-  publicOverlay: z.boolean(),
-  type: z.string(),
-  order: z.number(),
-});
diff --git a/src/redux/overlays/overlays.reducers.test.ts b/src/redux/overlays/overlays.reducers.test.ts
index fda71acd..f4945820 100644
--- a/src/redux/overlays/overlays.reducers.test.ts
+++ b/src/redux/overlays/overlays.reducers.test.ts
@@ -2,7 +2,6 @@
 import { PROJECT_ID } from '@/constants';
 import {
   createdOverlayFileFixture,
-  createdOverlayFixture,
   overlayFixture,
   overlaysPageFixture,
   uploadedOverlayFileContentFixture,
@@ -121,9 +120,7 @@ describe('overlays reducer', () => {
       .onPost(apiPath.uploadOverlayFileContent(123))
       .reply(HttpStatusCode.Ok, uploadedOverlayFileContentFixture);
 
-    mockedAxiosClient
-      .onPost(apiPath.createOverlay('pd'))
-      .reply(HttpStatusCode.Ok, createdOverlayFixture);
+    mockedAxiosClient.onPost(apiPath.createOverlay('pd')).reply(HttpStatusCode.Ok, overlayFixture);
 
     await store.dispatch(addOverlay(ADD_OVERLAY_MOCK));
     const { loading } = store.getState().overlays.addOverlay;
@@ -142,9 +139,7 @@ describe('overlays reducer', () => {
       .onPost(apiPath.uploadOverlayFileContent(123))
       .reply(HttpStatusCode.Ok, uploadedOverlayFileContentFixture);
 
-    mockedAxiosClient
-      .onPost(apiPath.createOverlay('pd'))
-      .reply(HttpStatusCode.Ok, createdOverlayFixture);
+    mockedAxiosClient.onPost(apiPath.createOverlay('pd')).reply(HttpStatusCode.Ok, overlayFixture);
 
     await store.dispatch(addOverlay(ADD_OVERLAY_MOCK));
     const { loading, error } = store.getState().overlays.addOverlay;
diff --git a/src/redux/overlays/overlays.thunks.ts b/src/redux/overlays/overlays.thunks.ts
index 57698bf4..5c87fa7f 100644
--- a/src/redux/overlays/overlays.thunks.ts
+++ b/src/redux/overlays/overlays.thunks.ts
@@ -1,12 +1,11 @@
 /* eslint-disable no-magic-numbers */
 import {
   createdOverlayFileSchema,
-  createdOverlaySchema,
-  mapOverlay,
+  mapOverlaySchema,
   uploadedOverlayFileContentSchema,
-} from '@/models/mapOverlay';
+} from '@/models/mapOverlaySchema';
 import { axiosInstance, axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance';
-import { CreatedOverlay, CreatedOverlayFile, MapOverlay, PageOf } from '@/types/models';
+import { CreatedOverlayFile, MapOverlay, PageOf } from '@/types/models';
 import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
 import { createAsyncThunk } from '@reduxjs/toolkit';
 import { z } from 'zod';
@@ -40,7 +39,10 @@ export const getAllPublicOverlaysByProjectId = createAsyncThunk<MapOverlay[], st
         apiPath.getAllOverlaysByProjectIdQuery(projectId, { publicOverlay: true }),
       );
 
-      const isDataValid = validateDataUsingZodSchema(response.data, pageableSchema(mapOverlay));
+      const isDataValid = validateDataUsingZodSchema(
+        response.data,
+        pageableSchema(mapOverlaySchema),
+      );
 
       return isDataValid ? response.data.content : [];
     } catch (error) {
@@ -67,7 +69,10 @@ export const getAllUserOverlaysByCreator = createAsyncThunk<MapOverlay[], void,
         },
       );
 
-      const isDataValid = validateDataUsingZodSchema(response.data, pageableSchema(mapOverlay));
+      const isDataValid = validateDataUsingZodSchema(
+        response.data,
+        pageableSchema(mapOverlaySchema),
+      );
 
       const sortByOrder = (userOverlayA: MapOverlay, userOverlayB: MapOverlay): number => {
         if (userOverlayA.order > userOverlayB.order) return 1;
@@ -158,7 +163,7 @@ const creteOverlay = async ({
   type,
   name,
   projectId,
-}: CreatedOverlayArgs): Promise<CreatedOverlay | undefined> => {
+}: CreatedOverlayArgs): Promise<MapOverlay | undefined> => {
   const data = {
     name,
     description,
@@ -169,17 +174,13 @@ const creteOverlay = async ({
 
   const overlay = new URLSearchParams(data);
 
-  const response = await axiosInstance.post<CreatedOverlay>(
-    apiPath.createOverlay(projectId),
-    overlay,
-    {
-      withCredentials: true,
-    },
-  );
+  const response = await axiosInstance.post<MapOverlay>(apiPath.createOverlay(projectId), overlay, {
+    withCredentials: true,
+  });
 
   PluginsEventBus.dispatchEvent('onAddDataOverlay', response.data);
 
-  const isDataValid = validateDataUsingZodSchema(response.data, createdOverlaySchema);
+  const isDataValid = validateDataUsingZodSchema(response.data, mapOverlaySchema);
 
   return isDataValid ? response.data : undefined;
 };
@@ -256,7 +257,7 @@ export const updateOverlays = createAsyncThunk<undefined, MapOverlay[], ThunkCon
         updatedUserOverlay => updatedUserOverlay.data,
       );
 
-      validateDataUsingZodSchema(updatedUserOverlays, z.array(mapOverlay));
+      validateDataUsingZodSchema(updatedUserOverlays, z.array(mapOverlaySchema));
 
       showToast({ type: 'success', message: USER_OVERLAY_UPDATE_SUCCESS_MESSAGE });
     } catch (error) {
diff --git a/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts b/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts
index 729d53cb..25e36dc9 100644
--- a/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts
+++ b/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts
@@ -1,6 +1,6 @@
 import {
   createdOverlayFileFixture,
-  createdOverlayFixture,
+  overlayFixture,
   uploadedOverlayFileContentFixture,
 } from '@/models/fixtures/overlaysFixture';
 import { projectFixture } from '@/models/fixtures/projectFixture';
@@ -56,7 +56,7 @@ describe('addDataOverlay', () => {
 
     mockedAxiosClient
       .onPost(apiPath.createOverlay(projectFixture.projectId))
-      .reply(HttpStatusCode.Ok, createdOverlayFixture);
+      .reply(HttpStatusCode.Ok, overlayFixture);
 
     getStateSpy.mockImplementation(() => MOCK_STATE as RootState);
 
diff --git a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.test.ts b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.test.ts
index c90919b4..af3b56bf 100644
--- a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.test.ts
+++ b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.test.ts
@@ -1,5 +1,4 @@
 /* eslint-disable no-magic-numbers */
-import { createdOverlayFixture } from '@/models/fixtures/overlaysFixture';
 import { RootState, store } from '@/redux/store';
 
 import { PLUGINS_MOCK } from '@/models/mocks/pluginsMock';
@@ -9,6 +8,7 @@ import {
   PLUGINS_INITIAL_STATE_MOCK,
 } from '@/redux/plugins/plugins.mock';
 import { showToast } from '@/utils/showToast';
+import { overlayFixture } from '@/models/fixtures/overlaysFixture';
 import { PluginsEventBus } from './pluginsEventBus';
 import { ERROR_INVALID_EVENT_TYPE, ERROR_PLUGIN_CRASH } from '../errorMessages';
 
@@ -39,14 +39,14 @@ describe('PluginsEventBus', () => {
   it('should dispatch event correctly', () => {
     const callback = jest.fn();
     PluginsEventBus.addListener(plugin.hash, plugin.name, 'onAddDataOverlay', callback);
-    PluginsEventBus.dispatchEvent('onAddDataOverlay', createdOverlayFixture);
+    PluginsEventBus.dispatchEvent('onAddDataOverlay', overlayFixture);
 
     expect(callback).toHaveBeenCalled();
   });
 
   it('should throw error if event type is incorrect', () => {
     // eslint-disable-next-line @typescript-eslint/no-explicit-any
-    expect(() => PluginsEventBus.dispatchEvent('onData' as any, createdOverlayFixture)).toThrow(
+    expect(() => PluginsEventBus.dispatchEvent('onData' as any, overlayFixture)).toThrow(
       ERROR_INVALID_EVENT_TYPE('onData'),
     );
   });
diff --git a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.ts b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.ts
index afd61150..6e9d3def 100644
--- a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.ts
+++ b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.ts
@@ -1,5 +1,5 @@
 /* eslint-disable no-magic-numbers */
-import { CreatedOverlay, MapOverlay } from '@/types/models';
+import { MapOverlay } from '@/types/models';
 import { showToast } from '@/utils/showToast';
 import { ERROR_INVALID_EVENT_TYPE, ERROR_PLUGIN_CRASH } from '../errorMessages';
 import {
@@ -22,7 +22,7 @@ import type {
 } from './pluginsEventBus.types';
 
 export function dispatchEvent(type: 'onPluginUnload', data: PluginUnloaded): void;
-export function dispatchEvent(type: 'onAddDataOverlay', createdOverlay: CreatedOverlay): void;
+export function dispatchEvent(type: 'onAddDataOverlay', createdOverlay: MapOverlay): void;
 export function dispatchEvent(type: 'onRemoveDataOverlay', overlayId: number): void;
 export function dispatchEvent(type: 'onShowOverlay', overlay: MapOverlay): void;
 export function dispatchEvent(type: 'onHideOverlay', overlay: MapOverlay): void;
diff --git a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts
index 935487c6..d7bc2d51 100644
--- a/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts
+++ b/src/services/pluginsManager/pluginsEventBus/pluginsEventBus.types.ts
@@ -1,11 +1,4 @@
-import {
-  BioEntityContent,
-  Chemical,
-  CreatedOverlay,
-  Drug,
-  ElementSearchResult,
-  MapOverlay,
-} from '@/types/models';
+import { BioEntityContent, Chemical, Drug, ElementSearchResult, MapOverlay } from '@/types/models';
 import { dispatchEvent } from './pluginsEventBus';
 
 export type BackgroundEvents = 'onBackgroundOverlayChange';
@@ -88,7 +81,6 @@ export type SearchData =
   | SearchDataReaction;
 
 export type EventsData =
-  | CreatedOverlay
   | number
   | MapOverlay
   | ZoomChanged
diff --git a/src/types/models.ts b/src/types/models.ts
index 756f345a..b432fbfa 100644
--- a/src/types/models.ts
+++ b/src/types/models.ts
@@ -11,7 +11,7 @@ import { exportElementsSchema, exportNetworkchema } from '@/models/exportSchema'
 import { geneVariant } from '@/models/geneVariant';
 import { lineSchema } from '@/models/lineSchema';
 import { loginSchema } from '@/models/loginSchema';
-import { createdOverlayFileSchema, createdOverlaySchema, mapOverlay } from '@/models/mapOverlay';
+import { createdOverlayFileSchema, mapOverlaySchema } from '@/models/mapOverlaySchema';
 import {
   markerLineSchema,
   markerPinSchema,
@@ -100,7 +100,7 @@ export type Shape = z.infer<typeof shapeSchema>;
 export type ShapeRelAbs = z.infer<typeof shapeRelAbsSchema>;
 export type ShapeRelAbsBezierPoint = z.infer<typeof shapeRelAbsBezierPointSchema>;
 export type Modification = z.infer<typeof modelElementModificationSchema>;
-export type MapOverlay = z.infer<typeof mapOverlay>;
+export type MapOverlay = z.infer<typeof mapOverlaySchema>;
 export type Drug = z.infer<typeof drugSchema>;
 export type PinDetailsItem = z.infer<typeof targetSchema>;
 export type BioEntity = z.infer<typeof bioEntitySchema>;
@@ -129,7 +129,6 @@ export type OverlayLeftBioEntity = z.infer<typeof overlayLeftBioEntitySchema>;
 export type OverlayLeftReaction = z.infer<typeof overlayLeftReactionSchema>;
 export type Line = z.infer<typeof lineSchema>;
 export type CreatedOverlayFile = z.infer<typeof createdOverlayFileSchema>;
-export type CreatedOverlay = z.infer<typeof createdOverlaySchema>;
 export type Color = z.infer<typeof colorSchema>;
 export type Statistics = z.infer<typeof statisticsSchema>;
 export type Publication = z.infer<typeof publicationSchema>;
-- 
GitLab