From cfc3a6c7fdca99fe33c03fefcabfa411489269a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com> Date: Fri, 1 Dec 2023 09:19:29 +0100 Subject: [PATCH] refactor(mirnas): removed mirnas from source code --- .../GroupedSearchResults.component.tsx | 2 - .../MirnaAccordion.component.test.tsx | 108 ------------------ .../MirnaAccordion.component.tsx | 38 ------ .../MirnaAccordion/index.ts | 1 - .../PinsList/PinsList.component.test.tsx | 12 -- .../PinsList/PinsList.component.tsx | 10 -- .../ResultsList/PinsList/PinsList.types.tsx | 4 +- .../PinsListItem/PinsListItem.component.tsx | 4 +- .../PinsListItem.component.utils.ts | 1 - .../SearchDrawerWrapper.component.tsx | 8 +- .../pinsLayer/getBioEntititesFeatures.test.ts | 2 +- .../getBioEntitySingleFeature.test.ts | 2 +- src/constants/canvas.ts | 1 - src/constants/index.ts | 2 +- src/models/fixtures/mirnasFixture.ts | 10 -- src/models/mirnaSchema.ts | 8 -- src/redux/apiPath.test.ts | 6 - src/redux/apiPath.ts | 2 - src/redux/bioEntity/bioEntity.thunks.ts | 4 +- src/redux/drawer/drawer.reducers.ts | 6 - src/redux/drawer/drawer.selectors.ts | 13 +-- src/redux/drawer/drawer.slice.ts | 3 - src/redux/drawer/drawer.types.ts | 6 +- src/redux/drawer/drawerFixture.ts | 13 --- src/redux/mirnas/mirnas.mock.ts | 8 -- src/redux/mirnas/mirnas.reducers.test.ts | 103 ----------------- src/redux/mirnas/mirnas.reducers.ts | 43 ------- src/redux/mirnas/mirnas.selectors.ts | 28 ----- src/redux/mirnas/mirnas.slice.ts | 21 ---- src/redux/mirnas/mirnas.thunks.test.ts | 39 ------- src/redux/mirnas/mirnas.thunks.ts | 31 ----- src/redux/mirnas/mirnas.types.ts | 4 - src/redux/root/root.fixtures.ts | 2 - src/redux/search/search.thunks.ts | 2 - src/redux/store.ts | 2 - src/types/models.ts | 2 - src/types/pin.ts | 2 +- 37 files changed, 18 insertions(+), 535 deletions(-) delete mode 100644 src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.test.tsx delete mode 100644 src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.tsx delete mode 100644 src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/index.ts delete mode 100644 src/models/fixtures/mirnasFixture.ts delete mode 100644 src/models/mirnaSchema.ts delete mode 100644 src/redux/mirnas/mirnas.mock.ts delete mode 100644 src/redux/mirnas/mirnas.reducers.test.ts delete mode 100644 src/redux/mirnas/mirnas.reducers.ts delete mode 100644 src/redux/mirnas/mirnas.selectors.ts delete mode 100644 src/redux/mirnas/mirnas.slice.ts delete mode 100644 src/redux/mirnas/mirnas.thunks.test.ts delete mode 100644 src/redux/mirnas/mirnas.thunks.ts delete mode 100644 src/redux/mirnas/mirnas.types.ts diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/GroupedSearchResults.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/GroupedSearchResults.component.tsx index 2da2f10d..eef4ed38 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/GroupedSearchResults.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/GroupedSearchResults.component.tsx @@ -1,7 +1,6 @@ import { BioEntitiesAccordion } from '@/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion'; import { DrugsAccordion } from '@/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/DrugsAccordion'; import { ChemicalsAccordion } from '@/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/ChemicalsAccordion'; -import { MirnaAccordion } from '@/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion'; import { Accordion } from '@/shared/Accordion'; export const CLOSE_BUTTON_ROLE = 'close-drawer-button'; @@ -14,7 +13,6 @@ export const GroupedSearchResults = (): JSX.Element => { <BioEntitiesAccordion /> <DrugsAccordion /> <ChemicalsAccordion /> - <MirnaAccordion /> </Accordion> </div> </div> diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.test.tsx deleted file mode 100644 index 5a535d5a..00000000 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.test.tsx +++ /dev/null @@ -1,108 +0,0 @@ -import { act, render, screen } from '@testing-library/react'; -import { StoreType } from '@/redux/store'; -import { - InitialStoreState, - getReduxWrapperWithStore, -} from '@/utils/testing/getReduxWrapperWithStore'; -import { Accordion } from '@/shared/Accordion'; -import { - drawerSearchStepOneFixture, - drawerSearchMirnaStepTwoFixture, -} from '@/redux/drawer/drawerFixture'; -import { mirnasFixture } from '@/models/fixtures/mirnasFixture'; -import { MirnaAccordion } from './MirnaAccordion.component'; - -const SECOND_STEP = 2; - -const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => { - const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState); - - return ( - render( - <Wrapper> - <Accordion> - <MirnaAccordion /> - </Accordion> - </Wrapper>, - ), - { - store, - } - ); -}; - -describe('MirnaAccordion - component', () => { - it('should display mirna number after succesfull mirna search', () => { - renderComponent({ - mirnas: { - data: [ - { - searchQueryElement: '', - loading: 'succeeded', - error: { name: '', message: '' }, - data: mirnasFixture, - }, - ], - loading: 'succeeded', - error: { name: '', message: '' }, - }, - }); - expect(screen.getByText('MiRNA (4)')).toBeInTheDocument(); - }); - it('should display loading indicator while waiting for mirna search response', () => { - renderComponent({ - mirnas: { data: [], loading: 'pending', error: { name: '', message: '' } }, - }); - expect(screen.getByText('MiRNA (Loading...)')).toBeInTheDocument(); - }); - it('should navigate user to mirnas results list after clicking button', async () => { - const { store } = renderComponent({ - mirnas: { - data: [ - { - searchQueryElement: '', - loading: 'succeeded', - error: { name: '', message: '' }, - data: mirnasFixture, - }, - ], - loading: 'succeeded', - error: { name: '', message: '' }, - }, - drawer: drawerSearchMirnaStepTwoFixture, - }); - - const navigationButton = screen.getByTestId('accordion-item-button'); - await act(() => { - navigationButton.click(); - }); - - const { - drawer: { - searchDrawerState: { stepType, selectedValue, currentStep }, - }, - } = store.getState(); - - expect(stepType).toBe('mirna'); - expect(selectedValue).toBe(undefined); - expect(currentStep).toBe(SECOND_STEP); - }); - it('should disable navigation button when there is no mirnas', async () => { - renderComponent({ - mirnas: { data: [], loading: 'succeeded', error: { name: '', message: '' } }, - drawer: drawerSearchStepOneFixture, - }); - - const navigationButton = screen.getByTestId('accordion-item-button'); - expect(navigationButton).toBeDisabled(); - }); - it('should disable navigation button when waiting for api response', async () => { - renderComponent({ - mirnas: { data: [], loading: 'pending', error: { name: '', message: '' } }, - drawer: drawerSearchStepOneFixture, - }); - - const navigationButton = screen.getByTestId('accordion-item-button'); - expect(navigationButton).toBeDisabled(); - }); -}); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.tsx deleted file mode 100644 index a6fdf742..00000000 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/MirnaAccordion.component.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { displayMirnaList } from '@/redux/drawer/drawer.slice'; -import { useAppDispatch } from '@/redux/hooks/useAppDispatch'; -import { useAppSelector } from '@/redux/hooks/useAppSelector'; -import { - numberOfMirnasSelector, - loadingMirnasStatusSelector, -} from '@/redux/mirnas/mirnas.selectors'; -import { AccordionItem, AccordionItemHeading, AccordionItemButton } from '@/shared/Accordion'; - -export const MirnaAccordion = (): JSX.Element => { - const dispatch = useAppDispatch(); - const mirnaNumber = useAppSelector(numberOfMirnasSelector); - const mirnaState = useAppSelector(loadingMirnasStatusSelector); - - const isPending = mirnaState === 'pending'; - const isSucceeded = mirnaState === 'succeeded'; - const isDrugsEmpty = mirnaNumber === SIZE_OF_EMPTY_ARRAY; - - const onAccordionClick = (): void => { - dispatch(displayMirnaList()); - }; - return ( - <AccordionItem> - <AccordionItemHeading> - <AccordionItemButton - variant="non-expandable" - onClick={onAccordionClick} - disabled={isPending || isDrugsEmpty} - > - MiRNA - {isPending && ' (Loading...)'} - {isSucceeded && ` (${mirnaNumber})`} - </AccordionItemButton> - </AccordionItemHeading> - </AccordionItem> - ); -}; diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/index.ts b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/index.ts deleted file mode 100644 index 69f2736c..00000000 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/MirnaAccordion/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { MirnaAccordion } from './MirnaAccordion.component'; diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.test.tsx index a2e76b2a..ec423275 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.test.tsx @@ -1,6 +1,5 @@ import { chemicalsFixture } from '@/models/fixtures/chemicalsFixture'; import { drugsFixture } from '@/models/fixtures/drugFixtures'; -import { mirnasFixture } from '@/models/fixtures/mirnasFixture'; import { StoreType } from '@/redux/store'; import { InitialStoreState, @@ -22,12 +21,6 @@ const CHEMICALS_PINS_LIST = chemicalsFixture.map(chemical => ({ data: chemical, })); -const MIRNA_PINS_LIST = mirnasFixture.map(mirna => ({ - id: mirna.id, - name: mirna.name, - data: mirna, -})); - const renderComponent = ( pinsList: PinItem[], type: PinTypeWithNone, @@ -68,11 +61,6 @@ describe('PinsList - component ', () => { expect(screen.getByTestId('accordions-details')).toBeInTheDocument(); }); - it('should display list of mirnas targets', () => { - renderComponent(MIRNA_PINS_LIST, 'mirna'); - - expect(screen.getByTestId('pins-list')).toBeInTheDocument(); - }); it('should not display list of bio enities when bioEntity is searched', () => { renderComponent([], 'bioEntity'); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.tsx index dcf4217c..1ab513f9 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.component.tsx @@ -38,16 +38,6 @@ export const PinsList = ({ pinsList, type }: PinsListProps): JSX.Element => { </ul> </div> ); - case 'mirna': - return ( - <ul className="h-[calc(100vh-198px)] overflow-auto px-6 py-2" data-testid="pins-list"> - {pinsList.map(result => { - return result.data.targets.map(pin => ( - <PinsListItem key={pin.name} name={pin.name} type={type} pin={pin} /> - )); - })} - </ul> - ); case 'none': return <div />; default: diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.types.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.types.tsx index 7bd32b0e..f9707cb2 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.types.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsList.types.tsx @@ -1,10 +1,10 @@ -import { Chemical, Drug, Mirna } from '@/types/models'; +import { Chemical, Drug } from '@/types/models'; import { PinType } from '@/types/pin'; export type PinItem = { id: string | number; name: string; - data: Drug | Chemical | Mirna; + data: Drug | Chemical; }; export type PinTypeWithNone = PinType | 'none'; diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx index e2f3f609..88bdb4bd 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx @@ -4,13 +4,13 @@ import { twMerge } from 'tailwind-merge'; import { PinTypeWithNone } from '../PinsList.types'; import { getPinColor } from './PinsListItem.component.utils'; -interface MirnaPinsListItemProps { +interface PinsListItemProps { name: string; type: PinTypeWithNone; pin: PinDetailsItem; } -export const PinsListItem = ({ name, type, pin }: MirnaPinsListItemProps): JSX.Element => { +export const PinsListItem = ({ name, type, pin }: PinsListItemProps): JSX.Element => { return ( <div className="mb-4 flex w-full flex-col gap-3 rounded-lg border-[1px] border-solid border-greyscale-500 p-4"> <div className="flex w-full flex-row items-center gap-2"> diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts index 8cc48465..49c0547a 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.utils.ts @@ -5,7 +5,6 @@ export const getPinColor = (type: PinTypeWithNone): string => { bioEntity: 'fill-primary-500', drugs: 'fill-orange', chemicals: 'fill-purple', - mirna: 'fill-pink', none: 'none', }; diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/SearchDrawerWrapper.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/SearchDrawerWrapper.component.tsx index 865a6262..77f0275e 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/SearchDrawerWrapper.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/SearchDrawerWrapper.component.tsx @@ -1,4 +1,4 @@ -import { BIO_ENTITY, DRUGS_CHEMICALS_MIRNA } from '@/constants'; +import { BIO_ENTITY, DRUGS_CHEMICALS } from '@/constants'; import { STEP } from '@/constants/searchDrawer'; import { currentStepDrawerStateSelector, @@ -16,7 +16,7 @@ export const SearchDrawerWrapper = (): JSX.Element => { const stepType = useSelector(stepTypeDrawerSelector); const isBioEntityType = stepType === BIO_ENTITY; - const isChemicalsDrugsOrMirnaType = DRUGS_CHEMICALS_MIRNA.includes(stepType); + const isChemicalsOrDrugsType = DRUGS_CHEMICALS.includes(stepType); return ( <> @@ -31,8 +31,8 @@ export const SearchDrawerWrapper = (): JSX.Element => { <BioEntitiesResultsList /> </div> )} - {/* 2nd step for drugs,chemicals,mirna */} - {currentStep === STEP.SECOND && isChemicalsDrugsOrMirnaType && ( + {/* 2nd step for drugs,chemicals */} + {currentStep === STEP.SECOND && isChemicalsOrDrugsType && ( <div data-testid="search-second-step"> <ResultsList /> </div> diff --git a/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts b/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts index 32e40c74..04f1f793 100644 --- a/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts +++ b/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts @@ -29,7 +29,7 @@ describe('getBioEntitiesFeatures - subUtil', () => { const bioEntities = bioEntititesContent.map(({ bioEntity }) => bioEntity); const pointToProjection = getPointToProjection(Wrapper); - const pinTypes: PinType[] = ['bioEntity', 'drugs', 'chemicals', 'mirna']; + const pinTypes: PinType[] = ['bioEntity', 'drugs', 'chemicals']; it.each(pinTypes)('should return array of instances of Feature with Style type=%s', type => { const result = getBioEntitiesFeatures(bioEntities, { diff --git a/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntitySingleFeature.test.ts b/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntitySingleFeature.test.ts index 0f861285..0a4f03d0 100644 --- a/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntitySingleFeature.test.ts +++ b/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntitySingleFeature.test.ts @@ -38,7 +38,7 @@ describe('getBioEntitySingleFeature - subUtil', () => { const pointToProjection = getPointToProjection(Wrapper); const value = 1448; - const pinTypes: PinType[] = ['bioEntity', 'drugs', 'chemicals', 'mirna']; + const pinTypes: PinType[] = ['bioEntity', 'drugs', 'chemicals']; it.each(pinTypes)('should return instance of Feature with Style type=%s', type => { const result = getBioEntitySingleFeature(bioEntity, { diff --git a/src/constants/canvas.ts b/src/constants/canvas.ts index 8db09cda..3c033ad5 100644 --- a/src/constants/canvas.ts +++ b/src/constants/canvas.ts @@ -12,7 +12,6 @@ export const PINS_COLORS: Record<PinType, string> = { drugs: '#F48C41', chemicals: '#640CE3', bioEntity: '#106AD7', - mirna: '#F1009F', }; export const LINE_COLOR = '#00AAFF'; diff --git a/src/constants/index.ts b/src/constants/index.ts index e85e24dc..70fa367a 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -6,4 +6,4 @@ export const BASE_NEW_API_URL = process.env.NEXT_PUBLIC_BASE_NEW_API_URL || ''; export const PROJECT_ID = process.env.NEXT_PUBLIC_PROJECT_ID || ''; export const ZOD_SEED = parseInt(process.env.ZOD_SEED || '123', 10); export const BIO_ENTITY = 'bioEntity'; -export const DRUGS_CHEMICALS_MIRNA = ['drugs', 'chemicals', 'mirna']; +export const DRUGS_CHEMICALS = ['drugs', 'chemicals']; diff --git a/src/models/fixtures/mirnasFixture.ts b/src/models/fixtures/mirnasFixture.ts deleted file mode 100644 index 129ee9a7..00000000 --- a/src/models/fixtures/mirnasFixture.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ZOD_SEED } from '@/constants'; -import { mirnaSchema } from '@/models/mirnaSchema'; -import { z } from 'zod'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { createFixture } from 'zod-fixture'; - -export const mirnasFixture = createFixture(z.array(mirnaSchema), { - seed: ZOD_SEED, - array: { min: 2, max: 2 }, -}); diff --git a/src/models/mirnaSchema.ts b/src/models/mirnaSchema.ts deleted file mode 100644 index ff4d0fd2..00000000 --- a/src/models/mirnaSchema.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { z } from 'zod'; -import { targetSchema } from './targetSchema'; - -export const mirnaSchema = z.object({ - id: z.string(), - name: z.string(), - targets: z.array(targetSchema), -}); diff --git a/src/redux/apiPath.test.ts b/src/redux/apiPath.test.ts index 92b662bc..4d3ff11d 100644 --- a/src/redux/apiPath.test.ts +++ b/src/redux/apiPath.test.ts @@ -8,12 +8,6 @@ describe('api path', () => { ); }); - it('should return url string for miRNA', () => { - expect(apiPath.getMirnasStringWithQuery('hsa-miR-302b-3p')).toBe( - `projects/${PROJECT_ID}/miRnas:search?query=hsa-miR-302b-3p`, - ); - }); - it('should return url string for bio entity content', () => { expect( apiPath.getBioEntityContentsStringWithQuery({ searchQuery: 'park7', isPerfectMatch: false }), diff --git a/src/redux/apiPath.ts b/src/redux/apiPath.ts index 3a296d15..42711404 100644 --- a/src/redux/apiPath.ts +++ b/src/redux/apiPath.ts @@ -19,8 +19,6 @@ export const apiPath = { `projects/${PROJECT_ID}/models/*/bioEntities/reactions/?id=${ids.join(',')}&size=1000`, getDrugsStringWithQuery: (searchQuery: string): string => `projects/${PROJECT_ID}/drugs:search?query=${searchQuery}`, - getMirnasStringWithQuery: (searchQuery: string): string => - `projects/${PROJECT_ID}/miRnas:search?query=${searchQuery}`, getModelsString: (): string => `projects/${PROJECT_ID}/models/`, getChemicalsStringWithQuery: (searchQuery: string): string => `projects/${PROJECT_ID}/chemicals:search?query=${searchQuery}`, diff --git a/src/redux/bioEntity/bioEntity.thunks.ts b/src/redux/bioEntity/bioEntity.thunks.ts index 496299c2..e1b59d1e 100644 --- a/src/redux/bioEntity/bioEntity.thunks.ts +++ b/src/redux/bioEntity/bioEntity.thunks.ts @@ -32,10 +32,10 @@ export const getMultiBioEntity = createAsyncThunk( { searchQueries, isPerfectMatch }: GetMultiBioEntityProps, { dispatch }, ): Promise<void> => { - const asyncGetMirnasFunctions = searchQueries.map(searchQuery => + const asyncGetBioEntityFunctions = searchQueries.map(searchQuery => dispatch(getBioEntity({ searchQuery, isPerfectMatch })), ); - await Promise.all(asyncGetMirnasFunctions); + await Promise.all(asyncGetBioEntityFunctions); }, ); diff --git a/src/redux/drawer/drawer.reducers.ts b/src/redux/drawer/drawer.reducers.ts index 44812e00..6c335e96 100644 --- a/src/redux/drawer/drawer.reducers.ts +++ b/src/redux/drawer/drawer.reducers.ts @@ -55,12 +55,6 @@ export const displayChemicalsListReducer = (state: DrawerState): void => { state.searchDrawerState.stepType = 'chemicals'; }; -export const displayMirnaListReducer = (state: DrawerState): void => { - state.drawerName = 'search'; - state.searchDrawerState.currentStep = STEP.SECOND; - state.searchDrawerState.stepType = 'mirna'; -}; - export const displayBioEntitiesListReducer = ( state: DrawerState, action: PayloadAction<DrawerState['searchDrawerState']['listOfBioEnitites']>, diff --git a/src/redux/drawer/drawer.selectors.ts b/src/redux/drawer/drawer.selectors.ts index dc8cb74d..6a667716 100644 --- a/src/redux/drawer/drawer.selectors.ts +++ b/src/redux/drawer/drawer.selectors.ts @@ -41,7 +41,7 @@ export const resultListSelector = createSelector( currentStepTypeSelector, currentSelectedSearchElement, (state, selectedType, currentSearchElement) => { - const { drugs, chemicals, mirnas } = state; + const { drugs, chemicals } = state; switch (selectedType) { case 'drugs': { @@ -67,17 +67,6 @@ export const resultListSelector = createSelector( } case 'bioEntity': return undefined; - case 'mirna': { - const currentMirna = mirnas.data.find( - ({ searchQueryElement }) => searchQueryElement === currentSearchElement, - ); - - return (currentMirna?.data || []).map(mirna => ({ - id: mirna.id, - name: mirna.name, - data: mirna, - })); - } case 'none': return undefined; default: diff --git a/src/redux/drawer/drawer.slice.ts b/src/redux/drawer/drawer.slice.ts index b0a9e52c..6bf629a3 100644 --- a/src/redux/drawer/drawer.slice.ts +++ b/src/redux/drawer/drawer.slice.ts @@ -6,7 +6,6 @@ import { displayDrugsListReducer, displayEntityDetailsReducer, displayGroupedSearchResultsReducer, - displayMirnaListReducer, openDrawerReducer, openReactionDrawerByIdReducer, openSearchDrawerWithSelectedTabReducer, @@ -26,7 +25,6 @@ const drawerSlice = createSlice({ closeDrawer: closeDrawerReducer, displayDrugsList: displayDrugsListReducer, displayChemicalsList: displayChemicalsListReducer, - displayMirnaList: displayMirnaListReducer, displayBioEntitiesList: displayBioEntitiesListReducer, displayGroupedSearchResults: displayGroupedSearchResultsReducer, displayEntityDetails: displayEntityDetailsReducer, @@ -42,7 +40,6 @@ export const { closeDrawer, displayDrugsList, displayChemicalsList, - displayMirnaList, displayBioEntitiesList, displayGroupedSearchResults, displayEntityDetails, diff --git a/src/redux/drawer/drawer.types.ts b/src/redux/drawer/drawer.types.ts index 3046389c..4afafc2e 100644 --- a/src/redux/drawer/drawer.types.ts +++ b/src/redux/drawer/drawer.types.ts @@ -1,11 +1,11 @@ import type { DrawerName } from '@/types/drawerName'; -import { BioEntityContent, Chemical, Drug, Mirna } from '@/types/models'; +import { BioEntityContent, Chemical, Drug } from '@/types/models'; import { PayloadAction } from '@reduxjs/toolkit'; export type SearchDrawerState = { currentStep: number; - stepType: 'bioEntity' | 'drugs' | 'mirna' | 'chemicals' | 'none'; - selectedValue: BioEntityContent | Drug | Mirna | Chemical | undefined; + stepType: 'bioEntity' | 'drugs' | 'chemicals' | 'none'; + selectedValue: BioEntityContent | Drug | Chemical | undefined; listOfBioEnitites: BioEntityContent[]; selectedSearchElement: string; }; diff --git a/src/redux/drawer/drawerFixture.ts b/src/redux/drawer/drawerFixture.ts index 734cbbb1..37ec0adc 100644 --- a/src/redux/drawer/drawerFixture.ts +++ b/src/redux/drawer/drawerFixture.ts @@ -64,16 +64,3 @@ export const drawerSearchChemicalsStepTwoFixture: DrawerState = { }, reactionDrawerState: {}, }; - -export const drawerSearchMirnaStepTwoFixture: DrawerState = { - isOpen: true, - drawerName: 'search', - searchDrawerState: { - currentStep: 2, - stepType: 'mirna', - selectedValue: undefined, - listOfBioEnitites: [], - selectedSearchElement: '', - }, - reactionDrawerState: {}, -}; diff --git a/src/redux/mirnas/mirnas.mock.ts b/src/redux/mirnas/mirnas.mock.ts deleted file mode 100644 index bf91490a..00000000 --- a/src/redux/mirnas/mirnas.mock.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { DEFAULT_ERROR } from '@/constants/errors'; -import { MirnasState } from './mirnas.types'; - -export const MIRNAS_INITIAL_STATE_MOCK: MirnasState = { - data: [], - loading: 'idle', - error: DEFAULT_ERROR, -}; diff --git a/src/redux/mirnas/mirnas.reducers.test.ts b/src/redux/mirnas/mirnas.reducers.test.ts deleted file mode 100644 index 6f5b594b..00000000 --- a/src/redux/mirnas/mirnas.reducers.test.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { mirnasFixture } from '@/models/fixtures/mirnasFixture'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { - ToolkitStoreWithSingleSlice, - createStoreInstanceUsingSliceReducer, -} from '@/utils/createStoreInstanceUsingSliceReducer'; -import { HttpStatusCode } from 'axios'; -import { apiPath } from '@/redux/apiPath'; -import { DEFAULT_ERROR } from '@/constants/errors'; -import { getMirnas } from './mirnas.thunks'; -import mirnasReducer from './mirnas.slice'; -import { MirnasState } from './mirnas.types'; - -const mockedAxiosClient = mockNetworkResponse(); -const SEARCH_QUERY = 'hsa-miR-302b-3p'; - -const INITIAL_STATE: MirnasState = { - data: [], - loading: 'idle', - error: { name: '', message: '' }, -}; - -describe('mirnas reducer', () => { - let store = {} as ToolkitStoreWithSingleSlice<MirnasState>; - beforeEach(() => { - store = createStoreInstanceUsingSliceReducer('mirnas', mirnasReducer); - }); - - it('should match initial state', () => { - const action = { type: 'unknown' }; - - expect(mirnasReducer(undefined, action)).toEqual(INITIAL_STATE); - }); - - it('should update store after succesfull getMirnas query', async () => { - mockedAxiosClient - .onGet(apiPath.getMirnasStringWithQuery(SEARCH_QUERY)) - .reply(HttpStatusCode.Ok, mirnasFixture); - - const { type } = await store.dispatch(getMirnas(SEARCH_QUERY)); - const { data } = store.getState().mirnas; - const mirnasWithSearchElement = data.find(mirna => mirna.searchQueryElement === SEARCH_QUERY); - - expect(type).toBe('project/getMirnas/fulfilled'); - expect(mirnasWithSearchElement).toEqual({ - searchQueryElement: SEARCH_QUERY, - data: mirnasFixture, - loading: 'succeeded', - error: DEFAULT_ERROR, - }); - }); - - it('should update store after failed getMirnas query', async () => { - mockedAxiosClient - .onGet(apiPath.getMirnasStringWithQuery(SEARCH_QUERY)) - .reply(HttpStatusCode.NotFound, []); - - const { type } = await store.dispatch(getMirnas(SEARCH_QUERY)); - const { data } = store.getState().mirnas; - const mirnasWithSearchElement = data.find(mirna => mirna.searchQueryElement === SEARCH_QUERY); - - expect(type).toBe('project/getMirnas/rejected'); - expect(mirnasWithSearchElement).toEqual({ - searchQueryElement: SEARCH_QUERY, - data: undefined, - loading: 'failed', - error: DEFAULT_ERROR, - }); - }); - - it('should update store on loading getMirnas query', async () => { - mockedAxiosClient - .onGet(apiPath.getMirnasStringWithQuery(SEARCH_QUERY)) - .reply(HttpStatusCode.Ok, mirnasFixture); - - const mirnasPromise = store.dispatch(getMirnas(SEARCH_QUERY)); - - const { data } = store.getState().mirnas; - const mirnasWithSearchElement = data.find(mirna => mirna.searchQueryElement === SEARCH_QUERY); - - expect(mirnasWithSearchElement).toEqual({ - searchQueryElement: SEARCH_QUERY, - data: undefined, - loading: 'pending', - error: DEFAULT_ERROR, - }); - - mirnasPromise.then(() => { - const { data: dataPromiseFulfilled } = store.getState().mirnas; - - const mirnasWithSearchElementFulfilled = dataPromiseFulfilled.find( - mirna => mirna.searchQueryElement === SEARCH_QUERY, - ); - - expect(mirnasWithSearchElementFulfilled).toEqual({ - searchQueryElement: SEARCH_QUERY, - data: mirnasFixture, - loading: 'succeeded', - error: DEFAULT_ERROR, - }); - }); - }); -}); diff --git a/src/redux/mirnas/mirnas.reducers.ts b/src/redux/mirnas/mirnas.reducers.ts deleted file mode 100644 index 874adcb8..00000000 --- a/src/redux/mirnas/mirnas.reducers.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { ActionReducerMapBuilder } from '@reduxjs/toolkit'; -import { DEFAULT_ERROR } from '@/constants/errors'; -import { MirnasState } from './mirnas.types'; -import { getMirnas, getMultiMirnas } from './mirnas.thunks'; - -export const getMirnasReducer = (builder: ActionReducerMapBuilder<MirnasState>): void => { - builder.addCase(getMirnas.pending, (state, action) => { - state.data.push({ - searchQueryElement: action.meta.arg, - data: undefined, - loading: 'pending', - error: DEFAULT_ERROR, - }); - }); - builder.addCase(getMirnas.fulfilled, (state, action) => { - const mirnas = state.data.find(mirna => mirna.searchQueryElement === action.meta.arg); - if (mirnas) { - mirnas.data = action.payload; - mirnas.loading = 'succeeded'; - } - }); - builder.addCase(getMirnas.rejected, (state, action) => { - const mirnas = state.data.find(mirna => mirna.searchQueryElement === action.meta.arg); - if (mirnas) { - mirnas.loading = 'failed'; - // TODO: error management to be discussed in the team - } - }); -}; - -export const getMultiMirnasReducer = (builder: ActionReducerMapBuilder<MirnasState>): void => { - builder.addCase(getMultiMirnas.pending, state => { - state.data = []; - state.loading = 'pending'; - }); - builder.addCase(getMultiMirnas.fulfilled, state => { - state.loading = 'succeeded'; - }); - builder.addCase(getMultiMirnas.rejected, state => { - state.loading = 'failed'; - // TODO: error management to be discussed in the team - }); -}; diff --git a/src/redux/mirnas/mirnas.selectors.ts b/src/redux/mirnas/mirnas.selectors.ts deleted file mode 100644 index e7ec9708..00000000 --- a/src/redux/mirnas/mirnas.selectors.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; -import { rootSelector } from '@/redux/root/root.selectors'; -import { createSelector } from '@reduxjs/toolkit'; -import { MultiSearchData } from '@/types/fetchDataState'; -import { Mirna } from '@/types/models'; -import { currentSelectedSearchElement } from '../drawer/drawer.selectors'; - -export const mirnasSelector = createSelector(rootSelector, state => state.mirnas); - -export const mirnasForSelectedSearchElementSelector = createSelector( - mirnasSelector, - currentSelectedSearchElement, - (mirnasState, currentSearchElement): MultiSearchData<Mirna[]> | undefined => - mirnasState.data.find(({ searchQueryElement }) => searchQueryElement === currentSearchElement), -); - -export const loadingMirnasStatusSelector = createSelector(mirnasSelector, state => state.loading); - -export const numberOfMirnasSelector = createSelector( - mirnasForSelectedSearchElementSelector, - state => { - if (!state || !state?.data) { - return SIZE_OF_EMPTY_ARRAY; - } - - return state.data.length && state.data.map(e => e.targets.length)?.reduce((a, b) => a + b); - }, -); diff --git a/src/redux/mirnas/mirnas.slice.ts b/src/redux/mirnas/mirnas.slice.ts deleted file mode 100644 index a3cab00e..00000000 --- a/src/redux/mirnas/mirnas.slice.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { createSlice } from '@reduxjs/toolkit'; -import { MirnasState } from '@/redux/mirnas/mirnas.types'; -import { getMirnasReducer, getMultiMirnasReducer } from './mirnas.reducers'; - -const initialState: MirnasState = { - data: [], - loading: 'idle', - error: { name: '', message: '' }, -}; - -export const mirnasSlice = createSlice({ - name: 'mirnas', - initialState, - reducers: {}, - extraReducers: builder => { - getMirnasReducer(builder); - getMultiMirnasReducer(builder); - }, -}); - -export default mirnasSlice.reducer; diff --git a/src/redux/mirnas/mirnas.thunks.test.ts b/src/redux/mirnas/mirnas.thunks.test.ts deleted file mode 100644 index 2712a5ff..00000000 --- a/src/redux/mirnas/mirnas.thunks.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { mirnasFixture } from '@/models/fixtures/mirnasFixture'; -import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { - ToolkitStoreWithSingleSlice, - createStoreInstanceUsingSliceReducer, -} from '@/utils/createStoreInstanceUsingSliceReducer'; -import { HttpStatusCode } from 'axios'; -import { apiPath } from '@/redux/apiPath'; -import { getMirnas } from './mirnas.thunks'; -import mirnasReducer from './mirnas.slice'; -import { MirnasState } from './mirnas.types'; - -const mockedAxiosClient = mockNetworkResponse(); -const SEARCH_QUERY = 'hsa-miR-302b-3p'; - -describe('mirnas thunks', () => { - let store = {} as ToolkitStoreWithSingleSlice<MirnasState>; - beforeEach(() => { - store = createStoreInstanceUsingSliceReducer('mirnas', mirnasReducer); - }); - describe('getMirnas', () => { - it('should return data when data response from API is valid', async () => { - mockedAxiosClient - .onGet(apiPath.getMirnasStringWithQuery(SEARCH_QUERY)) - .reply(HttpStatusCode.Ok, mirnasFixture); - - const { payload } = await store.dispatch(getMirnas(SEARCH_QUERY)); - expect(payload).toEqual(mirnasFixture); - }); - it('should return undefined when data response from API is not valid ', async () => { - mockedAxiosClient - .onGet(apiPath.getMirnasStringWithQuery(SEARCH_QUERY)) - .reply(HttpStatusCode.Ok, { randomProperty: 'randomValue' }); - - const { payload } = await store.dispatch(getMirnas(SEARCH_QUERY)); - expect(payload).toEqual(undefined); - }); - }); -}); diff --git a/src/redux/mirnas/mirnas.thunks.ts b/src/redux/mirnas/mirnas.thunks.ts deleted file mode 100644 index 4190946d..00000000 --- a/src/redux/mirnas/mirnas.thunks.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { z } from 'zod'; -import { createAsyncThunk } from '@reduxjs/toolkit'; -import { axiosInstance } from '@/services/api/utils/axiosInstance'; -import { Mirna } from '@/types/models'; -import { mirnaSchema } from '@/models/mirnaSchema'; -import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; -import { apiPath } from '@/redux/apiPath'; - -export const getMirnas = createAsyncThunk( - 'project/getMirnas', - async (searchQuery: string): Promise<Mirna[] | undefined> => { - const response = await axiosInstance.get<Mirna[]>( - apiPath.getMirnasStringWithQuery(searchQuery), - ); - - const isDataValid = validateDataUsingZodSchema(response.data, z.array(mirnaSchema)); - - return isDataValid ? response.data : undefined; - }, -); - -export const getMultiMirnas = createAsyncThunk( - 'project/getMultiMirnas', - async (searchQueries: string[], { dispatch }): Promise<void> => { - const asyncGetMirnasFunctions = searchQueries.map(searchQuery => - dispatch(getMirnas(searchQuery)), - ); - - await Promise.all(asyncGetMirnasFunctions); - }, -); diff --git a/src/redux/mirnas/mirnas.types.ts b/src/redux/mirnas/mirnas.types.ts deleted file mode 100644 index 30f16132..00000000 --- a/src/redux/mirnas/mirnas.types.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { MultiFetchDataState } from '@/types/fetchDataState'; -import { Mirna } from '@/types/models'; - -export type MirnasState = MultiFetchDataState<Mirna[]>; diff --git a/src/redux/root/root.fixtures.ts b/src/redux/root/root.fixtures.ts index b310aceb..bf70be50 100644 --- a/src/redux/root/root.fixtures.ts +++ b/src/redux/root/root.fixtures.ts @@ -4,7 +4,6 @@ import { CHEMICALS_INITIAL_STATE_MOCK } from '../chemicals/chemicals.mock'; import { initialStateFixture as drawerInitialStateMock } from '../drawer/drawerFixture'; import { DRUGS_INITIAL_STATE_MOCK } from '../drugs/drugs.mock'; import { initialMapStateFixture } from '../map/map.fixtures'; -import { MIRNAS_INITIAL_STATE_MOCK } from '../mirnas/mirnas.mock'; import { MODELS_INITIAL_STATE_MOCK } from '../models/models.mock'; import { OVERLAYS_INITIAL_STATE_MOCK } from '../overlays/overlays.mock'; import { PROJECT_STATE_INITIAL_MOCK } from '../project/project.mock'; @@ -16,7 +15,6 @@ export const INITIAL_STORE_STATE_MOCK: RootState = { search: SEARCH_STATE_INITIAL_MOCK, project: PROJECT_STATE_INITIAL_MOCK, drugs: DRUGS_INITIAL_STATE_MOCK, - mirnas: MIRNAS_INITIAL_STATE_MOCK, chemicals: CHEMICALS_INITIAL_STATE_MOCK, models: MODELS_INITIAL_STATE_MOCK, bioEntity: BIOENTITY_INITIAL_STATE_MOCK, diff --git a/src/redux/search/search.thunks.ts b/src/redux/search/search.thunks.ts index 910e7091..ad39272c 100644 --- a/src/redux/search/search.thunks.ts +++ b/src/redux/search/search.thunks.ts @@ -1,7 +1,6 @@ import { getMultiBioEntity } from '@/redux/bioEntity/bioEntity.thunks'; import { getMultiChemicals } from '@/redux/chemicals/chemicals.thunks'; import { getMultiDrugs } from '@/redux/drugs/drugs.thunks'; -import { getMultiMirnas } from '@/redux/mirnas/mirnas.thunks'; import { PerfectMultiSearchParams } from '@/types/search'; import { createAsyncThunk } from '@reduxjs/toolkit'; @@ -14,7 +13,6 @@ export const getSearchData = createAsyncThunk( dispatch(getMultiBioEntity({ searchQueries, isPerfectMatch })), dispatch(getMultiDrugs(searchQueries)), dispatch(getMultiChemicals(searchQueries)), - dispatch(getMultiMirnas(searchQueries)), ]); }, ); diff --git a/src/redux/store.ts b/src/redux/store.ts index 147673c2..d98c85c3 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -4,7 +4,6 @@ import chemicalsReducer from '@/redux/chemicals/chemicals.slice'; import drawerReducer from '@/redux/drawer/drawer.slice'; import drugsReducer from '@/redux/drugs/drugs.slice'; import mapReducer from '@/redux/map/map.slice'; -import mirnasReducer from '@/redux/mirnas/mirnas.slice'; import modelsReducer from '@/redux/models/models.slice'; import overlaysReducer from '@/redux/overlays/overlays.slice'; import projectReducer from '@/redux/project/project.slice'; @@ -23,7 +22,6 @@ export const reducers = { search: searchReducer, project: projectReducer, drugs: drugsReducer, - mirnas: mirnasReducer, chemicals: chemicalsReducer, bioEntity: bioEntityReducer, drawer: drawerReducer, diff --git a/src/types/models.ts b/src/types/models.ts index 5b997016..f83079f1 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -7,7 +7,6 @@ import { drugSchema } from '@/models/drugSchema'; import { elementSearchResult, elementSearchResultType } from '@/models/elementSearchResult'; import { mapBackground } from '@/models/mapBackground'; import { mapOverlay } from '@/models/mapOverlay'; -import { mirnaSchema } from '@/models/mirnaSchema'; import { mapModelSchema } from '@/models/modelSchema'; import { organism } from '@/models/organism'; import { overviewImageView } from '@/models/overviewImageView'; @@ -26,7 +25,6 @@ export type MapBackground = z.infer<typeof mapBackground>; export type Organism = z.infer<typeof organism>; export type Disease = z.infer<typeof disease>; export type Drug = z.infer<typeof drugSchema>; -export type Mirna = z.infer<typeof mirnaSchema>; export type PinDetailsItem = z.infer<typeof targetSchema>; export type BioEntity = z.infer<typeof bioEntitySchema>; export type BioEntityContent = z.infer<typeof bioEntityContentSchema>; diff --git a/src/types/pin.ts b/src/types/pin.ts index 031433b9..ffb2ab26 100644 --- a/src/types/pin.ts +++ b/src/types/pin.ts @@ -1 +1 @@ -export type PinType = 'chemicals' | 'drugs' | 'mirna' | 'bioEntity'; +export type PinType = 'chemicals' | 'drugs' | 'bioEntity'; -- GitLab