diff --git a/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx b/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx index 873cdf573c813ff7e0b09adffe05dcd3e5a1133a..973785e63078e5201eac60db07a5f1ecda9bb398 100644 --- a/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx +++ b/src/components/FunctionalArea/ContextMenu/ContextMenu.component.tsx @@ -9,7 +9,7 @@ import { twMerge } from 'tailwind-merge'; import { FIRST_ARRAY_ELEMENT, SECOND_ARRAY_ELEMENT, ZERO } from '@/constants/common'; import { PluginsContextMenu } from '@/services/pluginsManager/pluginContextMenu/pluginsContextMenu'; -import { BioEntity, Reaction } from '@/types/models'; +import { BioEntity, NewReaction } from '@/types/models'; import { ClickCoordinates } from '@/services/pluginsManager/pluginContextMenu/pluginsContextMenu.types'; import { currentModelSelector } from '@/redux/models/models.selectors'; import { mapDataLastPositionSelector } from '@/redux/map/map.selectors'; @@ -44,7 +44,7 @@ export const ContextMenu = (): React.ReactNode => { const modelId = model ? model.idObject : ZERO; const handleCallback = ( - callback: (coordinates: ClickCoordinates, element: BioEntity | Reaction | undefined) => void, + callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void, ) => { return () => { dispatch(closeContextMenu()); diff --git a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts b/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts index 5282e2464e30e3b39011d1bb8cac05c8185a9ad5..bc97ee988bf06edff21883922842d542deb3176e 100644 --- a/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts +++ b/src/components/Map/MapViewer/MapViewerVector/listeners/mouseClick/clickHandleReaction.test.ts @@ -2,7 +2,6 @@ import { openReactionDrawerById, selectTab } from '@/redux/drawer/drawer.slice'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds'; -import { reactionsFixture } from '@/models/fixtures/reactionFixture'; import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse'; import { apiPath } from '@/redux/apiPath'; import { HttpStatusCode } from 'axios'; @@ -30,26 +29,24 @@ describe('clickHandleReaction', () => { return { unwrap: jest.fn().mockResolvedValue([]), payload: { - data: [reactionsFixture[0]], + data: [newReactionFixture], }, }; }); - reactionId = reactionsFixture[0].id; - modelId = reactionsFixture[0].modelId; + reactionId = newReactionFixture.id; + modelId = newReactionFixture.model; mockedAxiosClient .onGet(apiPath.getReactionByIdInNewApi(reactionId, modelId)) .reply(HttpStatusCode.Ok, bioEntityFixture); [ - ...reactionsFixture[0].products, - ...reactionsFixture[0].reactants, - ...reactionsFixture[0].modifiers, + ...newReactionFixture.products, + ...newReactionFixture.reactants, + ...newReactionFixture.modifiers, ].forEach(element => { mockedAxiosClient - .onGet( - apiPath.getElementById('aliasId' in element ? element.aliasId : element.element, modelId), - ) + .onGet(apiPath.getElementById(element.element, modelId)) .reply(HttpStatusCode.Ok, bioEntityFixture); }); clickHandleReaction(dispatch, hasFitBounds)( diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts index bf2bb6fdbe22a515f4cc02dd9de5e8798180f514..de879d60f75db85294989510cba362fd9826c5cd 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleReactionResults.test.ts @@ -1,7 +1,6 @@ /* eslint-disable no-magic-numbers */ import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture'; -import { reactionsFixture } from '@/models/fixtures/reactionFixture'; import { ELEMENT_SEARCH_RESULT_MOCK_ALIAS, ELEMENT_SEARCH_RESULT_MOCK_REACTION, @@ -186,7 +185,7 @@ describe('handleReactionResults - util', () => { products: [], modifiers: [ { - ...reactionsFixture[0].modifiers[0], + ...newReactionFixture.modifiers[0], aliasId: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id, }, ], diff --git a/src/models/fixtures/reactionFixture.ts b/src/models/fixtures/reactionFixture.ts deleted file mode 100644 index 703e8be58ae84570971fe358c02eec6d2b0ecac6..0000000000000000000000000000000000000000 --- a/src/models/fixtures/reactionFixture.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ZOD_SEED } from '@/constants'; -import { z } from 'zod'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { createFixture } from 'zod-fixture'; -import { reactionSchema } from '../reaction'; - -export const reactionsFixture = createFixture(z.array(reactionSchema), { - seed: ZOD_SEED, - array: { min: 2, max: 2 }, -}); diff --git a/src/models/reaction.ts b/src/models/reaction.ts deleted file mode 100644 index 18a438f72386e9f790394dca2cf37114a9d24c29..0000000000000000000000000000000000000000 --- a/src/models/reaction.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { z } from 'zod'; -import { positionSchema } from './positionSchema'; -import { productsSchema } from './products'; -import { reactionLineSchema } from './reactionLineSchema'; -import { referenceSchema } from './referenceSchema'; - -export const reactionSchema = z.object({ - centerPoint: positionSchema, - hierarchyVisibilityLevel: z.string().nullable(), - id: z.number(), - kineticLaw: z.null(), - lines: z.array(reactionLineSchema), - modelId: z.number(), - modifiers: z.array(productsSchema), - name: z.string(), - notes: z.string(), - products: z.array(productsSchema), - reactants: z.array(productsSchema), - reactionId: z.string(), - references: z.array(referenceSchema), - type: z.string(), -}); diff --git a/src/redux/reactions/utils/getFilteredReferences.test.ts b/src/redux/reactions/utils/getFilteredReferences.test.ts index b02b2cc3dc556abcfc96ad22e59e6563751dfef7..a194ab9e23e5d93bf3c1cd163047009d8686c7f3 100644 --- a/src/redux/reactions/utils/getFilteredReferences.test.ts +++ b/src/redux/reactions/utils/getFilteredReferences.test.ts @@ -2,12 +2,12 @@ import { REFERENCES_MOCK_ALL_INVALID, REFERENCES_MOCK_ALL_VALID, } from '@/models/mocks/referencesMock'; -import { Reaction } from '@/types/models'; import { ReferenceFiltered } from '@/types/reference'; +import { NewReaction } from '@/types/models'; import { getReferencesWithoutEmptyLink } from './getFilteredReferences'; describe('getFilteredReferences - subUtil', () => { - const cases: [Pick<Reaction, 'references'>, ReferenceFiltered[]][] = [ + const cases: [Pick<NewReaction, 'references'>, ReferenceFiltered[]][] = [ [ { references: REFERENCES_MOCK_ALL_VALID, diff --git a/src/redux/reactions/utils/getFilteredReferences.ts b/src/redux/reactions/utils/getFilteredReferences.ts index 987eb1a0637a0b901dcb1a8ea13df76196190ef2..bdd85d952e3faabdbd2ee8b4bc6ded0d3ac976e2 100644 --- a/src/redux/reactions/utils/getFilteredReferences.ts +++ b/src/redux/reactions/utils/getFilteredReferences.ts @@ -1,7 +1,7 @@ -import { Reaction } from '@/types/models'; +import { NewReaction } from '@/types/models'; import { ReferenceFiltered } from '@/types/reference'; -type InputReaction = Pick<Reaction, 'references'>; +type InputReaction = Pick<NewReaction, 'references'>; export const getReferencesWithoutEmptyLink = ( reaction: InputReaction | undefined, diff --git a/src/services/pluginsManager/pluginContextMenu/pluginsContextMenu.types.ts b/src/services/pluginsManager/pluginContextMenu/pluginsContextMenu.types.ts index 0a54586b39e154501e2118311e0abbfeef7c1dcf..0ea6b81167c6eb565b6097aac0fef7c49008edc0 100644 --- a/src/services/pluginsManager/pluginContextMenu/pluginsContextMenu.types.ts +++ b/src/services/pluginsManager/pluginContextMenu/pluginsContextMenu.types.ts @@ -1,4 +1,4 @@ -import { BioEntity, Reaction } from '@/types/models'; +import { BioEntity, NewReaction } from '@/types/models'; export type ClickCoordinates = { modelId: number; @@ -13,7 +13,7 @@ export type PluginContextMenuItemType = { name: string; style: string; enabled: boolean; - callback: (coordinates: ClickCoordinates, element: BioEntity | Reaction | undefined) => void; + callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void; }; export type PluginsContextMenuType = { @@ -23,7 +23,7 @@ export type PluginsContextMenuType = { name: string, style: string, enabled: boolean, - callback: (coordinates: ClickCoordinates, element: BioEntity | Reaction | undefined) => void, + callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void, ) => string; removeMenu: (hash: string, id: string) => void; updateMenu: (hash: string, id: string, name: string, style: string, enabled: boolean) => void; diff --git a/src/types/models.ts b/src/types/models.ts index c814d1b08c9ec031a0b4d54272736b16a9032f69..bf000af7c89fe392d6027ed1247acccca810e941 100644 --- a/src/types/models.ts +++ b/src/types/models.ts @@ -50,7 +50,6 @@ import { pluginSchema } from '@/models/pluginSchema'; import { projectSchema } from '@/models/projectSchema'; import { publicationsResponseSchema } from '@/models/publicationsResponseSchema'; import { publicationSchema } from '@/models/publicationsSchema'; -import { reactionSchema } from '@/models/reaction'; import { reactionLineSchema } from '@/models/reactionLineSchema'; import { referenceSchema } from '@/models/referenceSchema'; import { sessionSchemaValid } from '@/models/sessionValidSchema'; @@ -120,7 +119,6 @@ export type BioEntity = z.infer<typeof bioEntitySchema>; export type BioEntityContent = z.infer<typeof bioEntityContentSchema>; export type BioEntityResponse = z.infer<typeof bioEntityResponseSchema>; export type Chemical = z.infer<typeof chemicalSchema>; -export type Reaction = z.infer<typeof reactionSchema>; export type NewReaction = z.infer<typeof newReactionSchema>; const newReactionsSchema = pageableSchema(newReactionSchema); export type NewReactions = z.infer<typeof newReactionsSchema>; diff --git a/src/utils/reaction/mapNewReactionToReaction.test.ts b/src/utils/reaction/mapNewReactionToReaction.test.ts deleted file mode 100644 index 23097b83e3ec53126b3216e239a4ae9a8946e463..0000000000000000000000000000000000000000 --- a/src/utils/reaction/mapNewReactionToReaction.test.ts +++ /dev/null @@ -1,193 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import mapNewReactionToReaction from '@/utils/reaction/mapNewReactionToReaction'; - -describe('mapNewReactionToReaction', () => { - const newReaction = { - id: 31141, - notes: '', - idReaction: 're22', - name: '', - reversible: false, - symbol: null, - abbreviation: null, - formula: null, - mechanicalConfidenceScore: null, - lowerBound: null, - upperBound: null, - subsystem: null, - geneProteinReaction: null, - visibilityLevel: '', - z: 45, - synonyms: [], - model: 137, - kinetics: null, - line: { - id: 109668, - width: 1, - color: { - alpha: 255, - rgb: -16777216, - }, - z: 0, - segments: [ - { - x1: 149.31765717927775, - y1: 319.13724818355684, - x2: 142.5553586937381, - y2: 314.86275181644316, - }, - ], - startArrow: { - arrowType: 'NONE', - angle: 2.748893571891069, - lineType: 'SOLID', - length: 15, - }, - endArrow: { - arrowType: 'NONE', - angle: 2.748893571891069, - lineType: 'SOLID', - length: 15, - }, - lineType: 'SOLID', - }, - processCoordinates: null, - modifiers: [], - products: [ - { - id: 85169, - line: { - id: 109670, - width: 1, - color: { - alpha: 255, - rgb: -16777216, - }, - z: 0, - segments: [ - { - x1: 142.5553586937381, - y1: 314.86275181644316, - x2: 122.2063492063492, - y2: 302, - }, - ], - startArrow: { - arrowType: 'NONE', - angle: 2.748893571891069, - lineType: 'SOLID', - length: 15, - }, - endArrow: { - arrowType: 'OPEN', - angle: 2.748893571891069, - lineType: 'SOLID', - length: 15, - }, - lineType: 'SOLID', - }, - stoichiometry: null, - element: 58886, - }, - ], - reactants: [ - { - id: 85168, - line: { - id: 109669, - width: 1, - color: { - alpha: 255, - rgb: -16777216, - }, - z: 0, - segments: [ - { - x1: 169.66666666666666, - y1: 332, - x2: 149.31765717927775, - y2: 319.13724818355684, - }, - ], - startArrow: { - arrowType: 'NONE', - angle: 2.748893571891069, - lineType: 'SOLID', - length: 15, - }, - endArrow: { - arrowType: 'NONE', - angle: 2.748893571891069, - lineType: 'SOLID', - length: 15, - }, - lineType: 'SOLID', - }, - stoichiometry: null, - element: 58872, - }, - ], - operators: [], - elementId: 're22', - references: [], - sboTerm: 'SBO:0000171', - }; - const expectedReaction = { - centerPoint: { - x: 0, - y: 0, - }, - hierarchyVisibilityLevel: '', - id: 31141, - kineticLaw: null, - lines: [ - { - start: { - x: 149.31765717927775, - y: 319.13724818355684, - }, - end: { - x: 142.5553586937381, - y: 314.86275181644316, - }, - type: '', - }, - { - start: { - x: 142.5553586937381, - y: 314.86275181644316, - }, - end: { - x: 122.2063492063492, - y: 302, - }, - type: '', - }, - { - start: { - x: 169.66666666666666, - y: 332, - }, - end: { - x: 149.31765717927775, - y: 319.13724818355684, - }, - type: '', - }, - ], - modelId: 137, - modifiers: [], - name: '', - notes: '', - products: [], - reactants: [], - reactionId: 're22', - references: [], - type: 'Positive influence', - }; - - it('should return correct reaction object from new reaction object', () => { - const result = mapNewReactionToReaction(newReaction); - expect(result).toEqual(expectedReaction); - }); -}); diff --git a/src/utils/reaction/mapNewReactionToReaction.ts b/src/utils/reaction/mapNewReactionToReaction.ts deleted file mode 100644 index a5fbd0e4f144430e5adbeeece3230e3baa352e59..0000000000000000000000000000000000000000 --- a/src/utils/reaction/mapNewReactionToReaction.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* eslint-disable no-magic-numbers */ -import { NewReaction, Reaction, ReactionLine } from '@/types/models'; -import ReactionTypeEnum from '@/utils/reaction/ReactionTypeEnum'; - -type ReactionTypeKey = keyof typeof ReactionTypeEnum; - -export default function mapNewReactionToReaction(newReaction: NewReaction): Reaction { - const lines: Array<ReactionLine> = []; - let start; - let end; - newReaction.line.segments.forEach(segment => { - start = { x: segment.x1, y: segment.y1 }; - end = { x: segment.x2, y: segment.y2 }; - lines.push({ start, end, type: '' }); - }); - [ - ...newReaction.products, - ...newReaction.reactants, - ...newReaction.modifiers, - ...newReaction.operators, - ].forEach(element => { - element.line.segments.forEach(segment => { - start = { x: segment.x1, y: segment.y1 }; - end = { x: segment.x2, y: segment.y2 }; - lines.push({ start, end, type: '' }); - }); - }); - - return { - centerPoint: { x: 0, y: 0 }, - hierarchyVisibilityLevel: '', - id: newReaction.id, - kineticLaw: null, - lines, - modelId: newReaction.model, - modifiers: [], - name: '', - notes: newReaction.notes, - products: [], - reactants: [], - reactionId: newReaction.idReaction, - references: newReaction.references, - type: ReactionTypeEnum[newReaction.sboTerm as ReactionTypeKey], - }; -}