diff --git a/src/ui/parcellationRegion/region.base.spec.ts b/src/ui/parcellationRegion/region.base.spec.ts index a89baf7b08a98e0260ab68387055e84579c94188..e70c0f3b99b57ce573f7e3cd96b0a1dcf9e474b8 100644 --- a/src/ui/parcellationRegion/region.base.spec.ts +++ b/src/ui/parcellationRegion/region.base.spec.ts @@ -166,6 +166,7 @@ const getRegionInOtherTemplateSelectorBundle = (version: EnumParcRegVersion) => mp1h, mr0lh, mt3, + mr0, mr0rh } @@ -316,6 +317,7 @@ const getRegionInOtherTemplateSelectorBundle = (version: EnumParcRegVersion) => mp1h, mr0lh, mt3, + mr0, mr0rh } } @@ -329,13 +331,13 @@ describe('> region.base.ts', () => { for (const enumKey of Object.keys(EnumParcRegVersion)) { describe(`> selector version for ${enumKey}`, () => { - const { mockFetchedTemplates, mt2, mt0, mp0, mt1, mp1h, mr0lh, mt3, mr0rh } = getRegionInOtherTemplateSelectorBundle(enumKey as EnumParcRegVersion) + const { mockFetchedTemplates, mr0, mt2, mt0, mp0, mt1, mp1h, mr0lh, mt3, mr0rh } = getRegionInOtherTemplateSelectorBundle(enumKey as EnumParcRegVersion) describe('> no hemisphere selected, simulates big brain cyto map', () => { let result: any[] beforeAll(() => { - result = regionInOtherTemplateSelector.projector({ fetchedTemplates: mockFetchedTemplates, templateSelected: mt0 }, { region: mr0 }) + result = regionInOtherTemplateSelector.projector(mockFetchedTemplates, mt0, { region: mr0 }) }) it('> length checks out', () => { @@ -407,7 +409,7 @@ describe('> region.base.ts', () => { describe('> hemisphere data selected (left hemisphere), simulates julich-brain in mni152', () => { let result beforeAll(() => { - result = regionInOtherTemplateSelector.projector({ fetchedTemplates: mockFetchedTemplates, templateSelected: mt2 }, { region: mr0lh }) + result = regionInOtherTemplateSelector.projector(mockFetchedTemplates, mt2, { region: mr0lh }) }) it('> length checks out', () => { diff --git a/src/ui/parcellationRegion/region.base.ts b/src/ui/parcellationRegion/region.base.ts index 55befb6065a25328471d053ccffc60a1dc71887b..7a79f88aa84c12810f52f5c32d5f9a917f776abc 100644 --- a/src/ui/parcellationRegion/region.base.ts +++ b/src/ui/parcellationRegion/region.base.ts @@ -90,7 +90,10 @@ export class RegionBase { const filteredRsInOtherTmpls = [] for (const bundledObj of regionsInOtherTemplates) { const { template, parcellation, region } = bundledObj - const idx = filteredRsInOtherTmpls.findIndex(({ template: _template }) => _template['@id'] === template['@id']) + const idx = filteredRsInOtherTmpls.findIndex(({ template: _template, region: _region }) => { + return _template['@id'] === template['@id'] + && getRegionHemisphere(_region) !== getRegionHemisphere(region) + }) if ( idx < 0 ) { filteredRsInOtherTmpls.push(bundledObj) } else { @@ -254,11 +257,7 @@ export const regionInOtherTemplateSelector = createSelector( const returnArr = [] // const regionOfInterestHemisphere = regionOfInterest.status - const regionOfInterestHemisphere = (regionOfInterest.name.includes('- right hemisphere') || (!!regionOfInterest.status && regionOfInterest.status.includes('right hemisphere'))) - ? EnumHemisphere.RIGHT_HEMISPHERE - : (regionOfInterest.name.includes('- left hemisphere') || (!!regionOfInterest.status && regionOfInterest.status.includes('left hemisphere'))) - ? EnumHemisphere.LEFT_HEMISPHERE - : null + const regionOfInterestHemisphere = getRegionHemisphere(regionOfInterest) const regionOfInterestId = getIdFromFullId(regionOfInterest.fullId) if (!templateSelected) return [] @@ -271,35 +270,29 @@ export const regionInOtherTemplateSelector = createSelector( for (const region of selectableRegions) { const id = getIdFromFullId(region.fullId) - if (!!id) { - const regionHemisphere = (region.name.includes('- right hemisphere') || (!!region.status && region.status.includes('right hemisphere'))) - ? EnumHemisphere.RIGHT_HEMISPHERE - : (region.name.includes('- left hemisphere') || (!!region.status && region.status.includes('left hemisphere'))) - ? EnumHemisphere.LEFT_HEMISPHERE - : null - if (id === regionOfInterestId) { - /** - * if both hemisphere metadatas are defined - */ - if ( - !!regionOfInterestHemisphere && - !!regionHemisphere - ) { - if (regionHemisphere === regionOfInterestHemisphere) { - returnArr.push({ - template, - parcellation, - region, - }) - } - } else { + if (!!id && id === regionOfInterestId) { + const regionHemisphere = getRegionHemisphere(region) + /** + * if both hemisphere metadatas are defined + */ + if ( + !!regionOfInterestHemisphere && + !!regionHemisphere + ) { + if (regionHemisphere === regionOfInterestHemisphere) { returnArr.push({ template, parcellation, region, - hemisphere: regionHemisphere }) } + } else { + returnArr.push({ + template, + parcellation, + region, + hemisphere: regionHemisphere + }) } } } @@ -308,3 +301,11 @@ export const regionInOtherTemplateSelector = createSelector( return returnArr } ) + +export function getRegionHemisphere(region: any):EnumHemisphere{ + return (region.name.includes('- right hemisphere') || (!!region.status && region.status.includes('right hemisphere'))) + ? EnumHemisphere.RIGHT_HEMISPHERE + : (region.name.includes('- left hemisphere') || (!!region.status && region.status.includes('left hemisphere'))) + ? EnumHemisphere.LEFT_HEMISPHERE + : null +} diff --git a/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts b/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts index 3cf92bedded94d7222bbdf48813fb34f4d14d9ef..fceeb0c7046afe38195967825e12cbd82097dde2 100644 --- a/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts +++ b/src/ui/parcellationRegion/regionMenu/regionMenu.component.spec.ts @@ -9,6 +9,7 @@ import { ARIA_LABELS } from 'common/constants' import { By } from "@angular/platform-browser" import { Directive, Input } from "@angular/core" import { NoopAnimationsModule } from "@angular/platform-browser/animations" +import { viewerStateGetSelectedAtlas } from "src/services/state/viewerState/selectors" const mt0 = { name: 'mt0' @@ -113,6 +114,13 @@ describe('> regionMenu.component.ts', () => { }) describe('> regionInOtherTemplatesTmpl', () => { + beforeEach(() => { + const mockStore = TestBed.inject(MockStore) + mockStore.overrideSelector( + viewerStateGetSelectedAtlas, + { parcellations: [] } + ) + }) it('> if selector returns empty array, data-available-in-tmpl-count == 0', () => {