From 580e8ac0922867e9d1afa2d656fffe258acdea10 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <p.gawron@atcomp.pl> Date: Wed, 22 Jan 2025 15:14:58 +0100 Subject: [PATCH] open link automatically on element click when the link is in the model --- CHANGELOG | 2 ++ public/config.js | 5 +++-- .../ProjectInfoDrawer.component.tsx | 3 --- .../BioEntitiesAccordion.component.test.tsx | 6 ++++-- .../PinsListItem.component.test.tsx | 5 ++++- .../mapSingleClick/handleAliasResults.ts | 5 ++++- .../mapSingleClick/handleOpenImmediateLink.ts | 17 +++++++++++++++++ src/models/bioEntitySchema.ts | 1 + 8 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleOpenImmediateLink.ts diff --git a/CHANGELOG b/CHANGELOG index c918ec8a..902cddca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ minerva-front (18.0.8) stable; urgency=medium + * Small improvement: support for links that should be opened immediately + (#342) * Bug fix: data overlay removal did not work (#333) * Bug fix: submap download did not download selected map (#337) diff --git a/public/config.js b/public/config.js index 4d245aa0..b9e38b92 100644 --- a/public/config.js +++ b/public/config.js @@ -1,11 +1,12 @@ // const root = 'https://minerva-dev.lcsb.uni.lu'; // const root = 'https://scimap.lcsb.uni.lu'; -const root = 'https://lux1.atcomp.pl'; +// const root = 'https://lux1.atcomp.pl'; +const root = 'http://localhost:8080'; window.config = { BASE_API_URL: `${root}/minerva/api`, BASE_NEW_API_URL: `${root}/minerva/new_api/`, - BASE_MAP_IMAGES_URL: `${root}/`, + BASE_MAP_IMAGES_URL: `${root}`, DEFAULT_PROJECT_ID: 'sample', ADMIN_PANEL_URL: `${root}/minerva/admin.xhtml`, }; diff --git a/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.tsx b/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.tsx index 80c6cd35..f1a8a2b8 100644 --- a/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.tsx +++ b/src/components/Map/Drawer/ProjectInfoDrawer/ProjectInfoDrawer.component.tsx @@ -31,9 +31,6 @@ export const ProjectInfoDrawer = (): JSX.Element => { const sourceDownloadLink = BASE_API_URL + apiPath.getSourceFile(); - // eslint-disable-next-line no-console - console.log(sourceDownloadLink); - let licenseName: string = ''; if (project) { licenseName = project.license ? project.license.name : project.customLicenseName; 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 64d82fab..2f20b71d 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 @@ -1,4 +1,4 @@ -import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; +import { FIRST_ARRAY_ELEMENT, ZERO } from '@/constants/common'; import { bioEntitiesContentFixture } from '@/models/fixtures/bioEntityContentsFixture'; import { MODELS_MOCK } from '@/models/mocks/modelsMock'; import { INITIAL_STORE_STATE_MOCK } from '@/redux/root/root.fixtures'; @@ -110,7 +110,9 @@ describe('BioEntitiesAccordion - component', () => { expect(screen.getByText(`Content (${countAll})`)).toBeInTheDocument(); expect(screen.getByText(`Core PD map (${countCore})`)).toBeInTheDocument(); - expect(screen.getByText(`Histamine signaling (${countHistamine})`)).toBeInTheDocument(); + if (countHistamine > ZERO) { + expect(screen.getByText(`Histamine signaling (${countHistamine})`)).toBeInTheDocument(); + } expect(screen.getByText(`PRKN substrates (${countPrkn})`)).toBeInTheDocument(); }); 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 589688c9..75723b88 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 @@ -25,7 +25,10 @@ const CHEMICALS_PIN = { }; const PIN_NUMBER = 10; -const BIO_ENTITY = bioEntitiesContentFixture[0].bioEntity; +const BIO_ENTITY = { + ...bioEntitiesContentFixture[0].bioEntity, + model: 5053, +}; const INITIAL_STORE_STATE: InitialStoreState = { models: MODELS_DATA_MOCK_WITH_MAIN_MAP, diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts index c3d05aba..a0f97e16 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.ts @@ -6,6 +6,8 @@ import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { clearBioEntities } from '@/redux/bioEntity/bioEntity.slice'; import { Point } from '@/types/map'; import { getMultiBioEntityByIds } from '@/redux/bioEntity/thunks/getMultiBioEntity'; +import { handleOpenImmediateLink } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleOpenImmediateLink'; +import { ZERO } from '@/constants/common'; import { findClosestBioEntityPoint } from './findClosestBioEntityPoint'; type SearchConfig = { @@ -40,12 +42,13 @@ export const handleAliasResults = dispatch(clearBioEntities()); return; } + + handleOpenImmediateLink(bioEntities[ZERO]); } dispatch(selectTab(`${id}`)); dispatch(openBioEntityDrawerById(id)); - PluginsEventBus.dispatchEvent('onSearch', { type: 'bioEntity', searchValues: [closestSearchResult], diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleOpenImmediateLink.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleOpenImmediateLink.ts new file mode 100644 index 00000000..360df8c0 --- /dev/null +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleOpenImmediateLink.ts @@ -0,0 +1,17 @@ +import { BioEntity } from '@/types/models'; +import { showToast } from '@/utils/showToast'; + +export const handleOpenImmediateLink = (bioEntity: BioEntity): void => { + const link = bioEntity.immediateLink; + if (link !== null) { + const tab = window.open(link, '_blank'); + if (tab) { + tab.focus(); + } else { + showToast({ + type: 'error', + message: `Browser prevented minerva from opening link: <a href="${link}" target="_blank">${link}</a>`, + }); + } + } +}; diff --git a/src/models/bioEntitySchema.ts b/src/models/bioEntitySchema.ts index 1e01a1d5..bd96f4c6 100644 --- a/src/models/bioEntitySchema.ts +++ b/src/models/bioEntitySchema.ts @@ -13,6 +13,7 @@ import { submodelSchema } from './submodelSchema'; export const bioEntitySchema = z.object({ id: z.union([z.number().int().positive(), z.string()]), stringType: z.string(), + immediateLink: z.string().nullable(), name: z.string(), elementId: z.string(), model: z.number(), -- GitLab