diff --git a/CHANGELOG b/CHANGELOG index 93c128e9222c9e45a60b57fed4fd41275c9258e2..c918ec8ab49aae104a394936ea74f7cda8599e5f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ minerva-front (18.0.8) stable; urgency=medium * Bug fix: data overlay removal did not work (#333) + * Bug fix: submap download did not download selected map (#337) -- Piotr Gawron <piotr.gawron@uni.lu> Fri, 13 Dec 2024 13:00:00 +0200 diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx index a30986f5e018ce2af17e0dfd92dcf99a029c0bad..d90df2bbd42fe43adc8322bb2b90aae6f553d8ce 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.test.tsx @@ -87,7 +87,7 @@ const renderComponent = (initialStoreState: InitialStoreState = {}): { store: St return ( render( <Wrapper> - <DownloadSubmap /> + <DownloadSubmap modelId={VALID_MODEL_ID} /> </Wrapper>, ), { @@ -136,7 +136,7 @@ describe('DownloadSubmap - component', () => { const list = screen.getByTestId('download-submap-list'); const validHrefs = CONFIGURATION_FORMATS_MOCK.map(({ handler }) => - getSubmapDownloadUrl({ handler }), + getSubmapDownloadUrl({ handler, modelId: VALID_MODEL_ID }), ); const validNames = CONFIGURATION_FORMATS_TYPES_MOCK; const allAnchors = [...list.getElementsByTagName('a')]; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx index 316528128b6a0dec97b0fd16761961f47b2ed60e..5f047bc2b1dfbd4ef413291f67a9489f87ba8f16 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/DownloadSubmap.component.tsx @@ -9,7 +9,11 @@ import { downloadFileFromUrl } from '@/redux/export/export.utils'; import { SUBMAP_DOWNLOAD_HANDLERS_NAMES } from './DownloadSubmap.constants'; import { useGetSubmapDownloadUrl } from './utils/useGetSubmapDownloadUrl'; -export const DownloadSubmap = (): React.ReactNode => { +interface DownloadSubmapProps { + modelId: number; +} + +export const DownloadSubmap = ({ modelId }: DownloadSubmapProps): React.ReactNode => { const formatsHandlers = useSelector(formatsHandlersSelector); const formatsHandlersItems = Object.entries(formatsHandlers); const getSubmapDownloadUrl = useGetSubmapDownloadUrl(); @@ -24,7 +28,7 @@ export const DownloadSubmap = (): React.ReactNode => { return function () { closeMenu(); setIsDownloading(true); - downloadFileFromUrl(getSubmapDownloadUrl({ handler })).finally(function () { + downloadFileFromUrl(getSubmapDownloadUrl({ handler, modelId })).finally(function () { setIsDownloading(false); }); }; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts index c8f335bff701d4fdeef65f9f815dcfe6dbc1fab2..5a911656b7c814dc5268db6c0ebb7c95c790059c 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.test.ts @@ -91,7 +91,7 @@ describe('useGetSubmapDownloadUrl - hook', () => { result: { current: getSubmapDownloadUrl }, } = renderHook(() => useGetSubmapDownloadUrl(), { wrapper: Wrapper }); - expect(getSubmapDownloadUrl({ handler })).toBe(''); + expect(getSubmapDownloadUrl({ handler, modelId: 0 })).toBe(''); }); }); @@ -109,7 +109,7 @@ describe('useGetSubmapDownloadUrl - hook', () => { result: { current: getSubmapDownloadUrl }, } = renderHook(() => useGetSubmapDownloadUrl(), { wrapper: Wrapper }); - expect(getSubmapDownloadUrl({ handler: VALID_HANDLER })).toBe( + expect(getSubmapDownloadUrl({ handler: VALID_HANDLER, modelId: 5052 })).toBe( `${BASE_API_URL}/projects/${PROJECT_ID}/models/5052:downloadModel?backgroundOverlayId=53&handlerClass=lcsb.mapviewer.wikipathway.GpmlParser&zoomLevel=9`, ); }); diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts index e003af360c856d2e254ea8f0a1252391c7e6610d..34c33260f7b63b39f1ff7655a77c323a06b3144c 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/DownloadSubmap/utils/useGetSubmapDownloadUrl.ts @@ -1,18 +1,22 @@ import { BASE_API_URL, PROJECT_ID } from '@/constants'; import { currentBackgroundSelector } from '@/redux/backgrounds/background.selectors'; import { mapDataSizeSelector } from '@/redux/map/map.selectors'; -import { currentModelSelector } from '@/redux/models/models.selectors'; import { useSelector } from 'react-redux'; -export type GetSubmapDownloadUrl = ({ handler }: { handler: string }) => string; +export type GetSubmapDownloadUrl = ({ + handler, + modelId, +}: { + handler: string; + modelId: number; +}) => string; export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { - const model = useSelector(currentModelSelector); const background = useSelector(currentBackgroundSelector); const mapSize = useSelector(mapDataSizeSelector); - const getSubmapDownloadUrl: GetSubmapDownloadUrl = ({ handler }) => { - const allParamsValid = [model?.idObject, background?.id, mapSize.maxZoom, handler].reduce( + const getSubmapDownloadUrl: GetSubmapDownloadUrl = ({ handler, modelId }) => { + const allParamsValid = [modelId, background?.id, mapSize.maxZoom, handler].reduce( (a, b) => Boolean(a) && Boolean(b), true, ); @@ -20,7 +24,7 @@ export const useGetSubmapDownloadUrl = (): GetSubmapDownloadUrl => { return ''; } - return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${model?.idObject}:downloadModel?backgroundOverlayId=${background?.id}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; + return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${modelId}:downloadModel?backgroundOverlayId=${background?.id}&handlerClass=${handler}&zoomLevel=${mapSize.maxZoom}`; }; return getSubmapDownloadUrl; diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/SubmapItem.component.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/SubmapItem.component.tsx index a7a38dfae9cb989d98e2bbb2e8be273f4b8cf0aa..d766af5e3bce60c7f55aafa44daee9e23d18ab99 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/SubmapItem.component.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapItem/SubmapItem.component.tsx @@ -2,15 +2,16 @@ import { IconButton } from '@/shared/IconButton'; import { DownloadSubmap } from './DownloadSubmap'; interface SubmapItemProps { + modelId: number; modelName: string; onOpenClick: () => void; } -export const SubmpamItem = ({ modelName, onOpenClick }: SubmapItemProps): JSX.Element => ( +export const SubmpamItem = ({ modelName, onOpenClick, modelId }: SubmapItemProps): JSX.Element => ( <div className="flex flex-row flex-nowrap items-center justify-between border-b py-6"> {modelName} <div className="flex flex-row flex-nowrap items-center"> - <DownloadSubmap /> + <DownloadSubmap modelId={modelId} /> <IconButton icon="chevron-right" className="h-6 w-6 bg-white-pearl" diff --git a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx index eb15bad6dc36b3d802de9ec7f45a942b11b813b6..185dbdc59237f03f5c799641f3d11704a6f2516a 100644 --- a/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx +++ b/src/components/Map/Drawer/SubmapsDrawer/SubmapsDrawer.tsx @@ -36,6 +36,7 @@ export const SubmapsDrawer = (): JSX.Element => { {models.map(model => ( <SubmpamItem key={model.idObject} + modelId={model.idObject} modelName={model.name} onOpenClick={(): void => onSubmapOpenClick(model)} />