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 be08de7583aae7aaf5a9ed607c8b4613823b77e2..6c34319e26351bcdb07db049cfe3bf06206b67b1 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.component.test.tsx +++ b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.component.test.tsx @@ -220,7 +220,7 @@ describe('UserOverlayForm - Component', () => { .onPost(apiPath.uploadOverlayFileContent(createdOverlayFileFixture.id)) .reply(HttpStatusCode.Ok, uploadedOverlayFileContentFixture); - mockedAxiosClient + mockedAxiosNewClient .onPost(apiPath.createOverlay(projectFixture.projectId)) .reply(HttpStatusCode.Ok, overlayFixture); @@ -286,7 +286,7 @@ describe('UserOverlayForm - Component', () => { .onPost(apiPath.uploadOverlayFileContent(createdOverlayFileFixture.id)) .reply(HttpStatusCode.Ok, uploadedOverlayFileContentFixture); - mockedAxiosClient + mockedAxiosNewClient .onPost(apiPath.createOverlay(projectFixture.projectId)) .reply(HttpStatusCode.Ok, overlayFixture); diff --git a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts index 079266ef48dbdf129fbf46778c7b09a6e79db8a6..7f477bc9ffeff424b4764da339d7806e16fe3416 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts +++ b/src/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/hooks/useUserOverlayForm.ts @@ -114,6 +114,7 @@ export const useUserOverlayForm = (): ReturnType => { name, projectId, type: type.id, + group, }), ); diff --git a/src/components/Map/Drawer/OverlaysDrawer/UserOverlays/UserOverlays.component.tsx b/src/components/Map/Drawer/OverlaysDrawer/UserOverlays/UserOverlays.component.tsx index 99b5704639c122dc610a5929a1c1096a1644bb7d..06fad4e27ca14b70af9397e950c9fc269b5899fd 100644 --- a/src/components/Map/Drawer/OverlaysDrawer/UserOverlays/UserOverlays.component.tsx +++ b/src/components/Map/Drawer/OverlaysDrawer/UserOverlays/UserOverlays.component.tsx @@ -7,10 +7,13 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { authenticatedUserSelector, loadingUserSelector } from '@/redux/user/user.selectors'; import { Button } from '@/shared/Button'; import { userOverlaysDataSelector } from '@/redux/overlays/overlays.selectors'; +import { overlayGroupsSelector } from '@/redux/overlayGroup/overlayGroup.selectors'; +import React from 'react'; import { UserOverlaysGroup } from './UserOverlaysGroup'; export const UserOverlays = (): JSX.Element => { const userOverlays = useAppSelector(userOverlaysDataSelector); + const overlayGroups = useAppSelector(overlayGroupsSelector); const dispatch = useAppDispatch(); const loadingUser = useAppSelector(loadingUserSelector); @@ -48,11 +51,14 @@ export const UserOverlays = (): JSX.Element => { Add overlay </Button> </div> - <UserOverlaysGroup - groupName="Without group" - groupId={null} - overlays={userOverlays || []} - /> + {overlayGroups.map(group => ( + <UserOverlaysGroup + key={group.id} + groupName={group.name} + groupId={group.id} + overlays={(userOverlays || []).filter(overlay => overlay.group === group.id)} + /> + ))} </> )} </div> diff --git a/src/redux/overlays/overlays.mock.ts b/src/redux/overlays/overlays.mock.ts index 7a22bee0c7e3fdf821e383fadc5a634e958665da..cc43a9ac1928804ab55050fe856cd70a3c50c801 100644 --- a/src/redux/overlays/overlays.mock.ts +++ b/src/redux/overlays/overlays.mock.ts @@ -1,5 +1,6 @@ import { DEFAULT_ERROR } from '@/constants/errors'; import { MapOverlay } from '@/types/models'; +import { DEFAULT_GROUP } from '@/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.constants'; import { OverlaysState } from './overlays.types'; export const OVERLAYS_INITIAL_STATE_MOCK: OverlaysState = { @@ -120,6 +121,7 @@ export const ADD_OVERLAY_MOCK = { name: 'test', projectId: 'pd', type: 'GENERIC', + group: DEFAULT_GROUP, }; export const USER_OVERLAYS_MOCK: MapOverlay[] = [ diff --git a/src/redux/overlays/overlays.reducers.test.ts b/src/redux/overlays/overlays.reducers.test.ts index f61c776646496e1e3cfa8b45b9353fba11255f89..d1ac1b6fc55ea08ead5970e68e85b68129076263 100644 --- a/src/redux/overlays/overlays.reducers.test.ts +++ b/src/redux/overlays/overlays.reducers.test.ts @@ -139,7 +139,9 @@ describe('overlays reducer', () => { .onPost(apiPath.uploadOverlayFileContent(123)) .reply(HttpStatusCode.Ok, uploadedOverlayFileContentFixture); - mockedAxiosClient.onPost(apiPath.createOverlay('pd')).reply(HttpStatusCode.Ok, overlayFixture); + mockedAxiosNewClient + .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 b87588f5b83f5d432089186a420aa846b202b095..94f292ae709be30c85f77ef68f0d1fde340f6b41 100644 --- a/src/redux/overlays/overlays.thunks.ts +++ b/src/redux/overlays/overlays.thunks.ts @@ -5,7 +5,7 @@ import { uploadedOverlayFileContentSchema, } from '@/models/mapOverlaySchema'; import { axiosInstance, axiosInstanceNewAPI } from '@/services/api/utils/axiosInstance'; -import { CreatedOverlayFile, MapOverlay, PageOf } from '@/types/models'; +import { CreatedOverlayFile, MapOverlay, OverlayGroup, PageOf } from '@/types/models'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { createAsyncThunk } from '@reduxjs/toolkit'; import { z } from 'zod'; @@ -155,6 +155,7 @@ type CreatedOverlayArgs = { name: string; type: string; projectId: string; + group: OverlayGroup; }; const creteOverlay = async ({ @@ -163,20 +164,26 @@ const creteOverlay = async ({ type, name, projectId, + group, }: CreatedOverlayArgs): Promise<MapOverlay | undefined> => { const data = { name, description, filename: createdFile.filename, - type, + colorSchemaType: type, fileId: createdFile.id.toString(), + group: group.id, + public: false, + orderIndex: 1, }; - const overlay = new URLSearchParams(data); - - const response = await axiosInstance.post<MapOverlay>(apiPath.createOverlay(projectId), overlay, { - withCredentials: true, - }); + const response = await axiosInstanceNewAPI.post<MapOverlay>( + apiPath.createOverlay(projectId), + data, + { + withCredentials: true, + }, + ); PluginsEventBus.dispatchEvent('onAddDataOverlay', response.data); @@ -192,12 +199,13 @@ type AddOverlayArgs = { type: string; name: string; projectId: string; + group: OverlayGroup; }; export const addOverlay = createAsyncThunk<undefined, AddOverlayArgs, ThunkConfig>( 'overlays/addOverlay', async ( - { filename, content, description, name, type, projectId }, + { filename, content, description, name, type, projectId, group }, { dispatch }, // eslint-disable-next-line consistent-return ) => { @@ -218,6 +226,7 @@ export const addOverlay = createAsyncThunk<undefined, AddOverlayArgs, ThunkConfi name, type, projectId, + group, }); await dispatch(getAllUserOverlaysByCreator()); diff --git a/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts b/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts index 25e36dc905ea589626f20e041fba9468a4d0e5ee..e1bbdd741561eab9d4b9a14b09ed10c876ea10fd 100644 --- a/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts +++ b/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.test.ts @@ -13,6 +13,7 @@ import { ERROR_OVERLAY_NAME_NOT_PROVIDED, ERROR_PROJECT_ID_NOT_FOUND, } from '@/services/pluginsManager/errorMessages'; +import { DEFAULT_GROUP } from '@/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.constants'; import { addDataOverlay } from './addDataOverlay'; import { DEFAULT_FILE_NAME, DEFAULT_TYPE } from './addDataOverlay.constants'; @@ -69,6 +70,7 @@ describe('addDataOverlay', () => { name: overlay.name, projectId: projectFixture.projectId, type: overlay.type, + group: DEFAULT_GROUP, }); }); @@ -119,6 +121,7 @@ describe('addDataOverlay', () => { name: overlay.name, projectId: projectFixture.projectId, type: DEFAULT_TYPE, + group: DEFAULT_GROUP, }); }); }); diff --git a/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.ts b/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.ts index d52b351825e267b798ec76fd8851bba800fd9823..c74771d9d09fc749aa2d834f2d4e06fea74edd42 100644 --- a/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.ts +++ b/src/services/pluginsManager/map/overlays/addDataOverlay/addDataOverlay.ts @@ -5,6 +5,8 @@ import { ERROR_OVERLAY_NAME_NOT_PROVIDED, ERROR_PROJECT_ID_NOT_FOUND, } from '@/services/pluginsManager/errorMessages'; +import { OverlayGroup } from '@/types/models'; +import { DEFAULT_GROUP } from '@/components/Map/Drawer/OverlaysDrawer/UserOverlayForm/UserOverlayForm.constants'; import { DEFAULT_FILE_NAME, DEFAULT_TYPE } from './addDataOverlay.constants'; import { getOverlayContent } from './addDataOverlay.utils'; @@ -14,6 +16,7 @@ type AddDataOverlayArgs = { filename?: string; fileContent: string; type?: string; + group?: OverlayGroup; }; export const addDataOverlay = async ({ @@ -22,6 +25,7 @@ export const addDataOverlay = async ({ filename, fileContent, type, + group, }: AddDataOverlayArgs): Promise<void> => { const { dispatch, getState } = store; const projectId = projectIdSelector(getState()); @@ -40,6 +44,7 @@ export const addDataOverlay = async ({ name, projectId, type: type || DEFAULT_TYPE, + group: group || DEFAULT_GROUP, }), ); };