diff --git a/package-lock.json b/package-lock.json index 6b0f180ae1af3034b094315e8ebee545c8a592f0..9c9854d83d715efae2ea01fb13a68e977737cfa3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,6 @@ "react-accessible-accordion": "^5.0.0", "react-dom": "18.2.0", "react-redux": "^8.1.2", - "redux-thunk": "^2.4.2", "tailwind-merge": "^1.14.0", "tailwindcss": "3.3.3", "ts-deepmerge": "^6.2.0", @@ -71,6 +70,7 @@ "prettier-2": "npm:prettier@^2", "prettier-plugin-tailwindcss": "^0.5.6", "redux-mock-store": "^1.5.4", + "redux-thunk": "^2.4.2", "typescript": "^5.2.2", "zod-fixture": "^2.5.0" } diff --git a/package.json b/package.json index c5b84e0b7f15fcc134842f6d3965fdad63c86bac..c0d980a3a0f073e84c5d02f0530d70bf681acbf9 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "react-accessible-accordion": "^5.0.0", "react-dom": "18.2.0", "react-redux": "^8.1.2", - "redux-thunk": "^2.4.2", "tailwind-merge": "^1.14.0", "tailwindcss": "3.3.3", "ts-deepmerge": "^6.2.0", @@ -85,6 +84,7 @@ "prettier-2": "npm:prettier@^2", "prettier-plugin-tailwindcss": "^0.5.6", "redux-mock-store": "^1.5.4", + "redux-thunk": "^2.4.2", "typescript": "^5.2.2", "zod-fixture": "^2.5.0" }, diff --git a/src/components/Map/MapViewer/utils/listeners/onMapSingleClick.test.ts b/src/components/Map/MapViewer/utils/listeners/onMapSingleClick.test.ts index 184c604e0beef021d101047566bd4aa0ee4edb4c..cd40e1377518ea4b23cdf2391f6d6790767d2bf4 100644 --- a/src/components/Map/MapViewer/utils/listeners/onMapSingleClick.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/onMapSingleClick.test.ts @@ -8,7 +8,7 @@ import { } from '@/models/mocks/elementSearchResultMock'; import { apiPath } from '@/redux/apiPath'; import { mockNetworkNewAPIResponse, mockNetworkResponse } from '@/utils/mockNetworkResponse'; -import { getReduxStoreActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; +import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreActionsListener'; import { waitFor } from '@testing-library/react'; import { HttpStatusCode } from 'axios'; import { MapBrowserEvent } from 'ol'; @@ -31,7 +31,7 @@ describe('onMapSingleClick - util', () => { }); describe('when searchResults are undefined', () => { - const { store } = getReduxStoreActionsListener(); + const { store } = getReduxStoreWithActionsListener(); const { dispatch } = store; const modelId = 1000; const mapSize = { @@ -58,7 +58,7 @@ describe('onMapSingleClick - util', () => { }); describe('when searchResults are empty', () => { - const { store } = getReduxStoreActionsListener(); + const { store } = getReduxStoreWithActionsListener(); const { dispatch } = store; const modelId = 1000; @@ -88,7 +88,7 @@ describe('onMapSingleClick - util', () => { describe('when searchResults are valid', () => { describe('when results type is ALIAS', () => { - const { store } = getReduxStoreActionsListener(); + const { store } = getReduxStoreWithActionsListener(); const { dispatch } = store; const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_ALIAS; const mapSize = { @@ -125,7 +125,7 @@ describe('onMapSingleClick - util', () => { }); describe('when results type is REACTION', () => { - const { store } = getReduxStoreActionsListener(); + const { store } = getReduxStoreWithActionsListener(); const { dispatch } = store; const { modelId } = ELEMENT_SEARCH_RESULT_MOCK_REACTION; const mapSize = { @@ -167,7 +167,7 @@ describe('onMapSingleClick - util', () => { }); describe('handleAliasResults - util', () => { - const { store } = getReduxStoreActionsListener(); + const { store } = getReduxStoreWithActionsListener(); const { dispatch } = store; mockedAxiosOldClient @@ -192,7 +192,7 @@ describe('handleAliasResults - util', () => { }); describe('handleReactionResults - util', () => { - const { store } = getReduxStoreActionsListener(); + const { store } = getReduxStoreWithActionsListener(); const { dispatch } = store; mockedAxiosNewClient diff --git a/src/models/reaction.ts b/src/models/reaction.ts index 7b2dd7b1454b314195af963dc315e1cf13de6ba6..7cc4e1add7f33494e45ba990b031c4a03a512642 100644 --- a/src/models/reaction.ts +++ b/src/models/reaction.ts @@ -1,6 +1,7 @@ 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({ @@ -8,13 +9,7 @@ export const reactionSchema = z.object({ hierarchyVisibilityLevel: z.string(), id: z.number(), kineticLaw: z.null(), - lines: z.array( - z.object({ - start: positionSchema, - end: positionSchema, - type: z.string(), - }), - ), + lines: z.array(reactionLineSchema), modelId: z.number(), modifiers: z.array(z.unknown()), name: z.string(), diff --git a/src/models/reactionLineSchema.ts b/src/models/reactionLineSchema.ts new file mode 100644 index 0000000000000000000000000000000000000000..4be9fa0c959b2fbe78bb38bc3d53a829db7d4eda --- /dev/null +++ b/src/models/reactionLineSchema.ts @@ -0,0 +1,8 @@ +import { z } from 'zod'; +import { positionSchema } from './positionSchema'; + +export const reactionLineSchema = z.object({ + start: positionSchema, + end: positionSchema, + type: z.string(), +}); diff --git a/src/redux/models/models.selectors.ts b/src/redux/models/models.selectors.ts index 70a6671c5bb2f6aef66ac96c76c9f447a12e314b..a71c53eb1faa4cc00595fa382bd5096309866db9 100644 --- a/src/redux/models/models.selectors.ts +++ b/src/redux/models/models.selectors.ts @@ -1,7 +1,7 @@ import { rootSelector } from '@/redux/root/root.selectors'; import { createSelector } from '@reduxjs/toolkit'; -import { mapDataSelector } from '../map/map.selectors'; import { MODEL_ID_DEFAULT } from '../map/map.constants'; +import { mapDataSelector } from '../map/map.selectors'; export const modelsSelector = createSelector(rootSelector, state => state.models); @@ -15,7 +15,6 @@ export const currentModelSelector = createSelector( export const currentModelIdSelector = createSelector( currentModelSelector, - // eslint-disable-next-line no-magic-numbers model => model?.idObject || MODEL_ID_DEFAULT, ); export const modelByIdSelector = createSelector( diff --git a/src/redux/reactions/reactions.thunks.ts b/src/redux/reactions/reactions.thunks.ts index 51ef6bfa992578d3a90ded8ea377de68c6f077a3..dbbf7fc725b6501dc9f4136705df1ae56b539ba4 100644 --- a/src/redux/reactions/reactions.thunks.ts +++ b/src/redux/reactions/reactions.thunks.ts @@ -6,16 +6,14 @@ import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { createAsyncThunk } from '@reduxjs/toolkit'; import { z } from 'zod'; -const ZERO = 0; - export const getReactionsByIds = createAsyncThunk<Reaction[] | undefined, number[]>( 'reactions/getByIds', async (ids: number[]): Promise<Reaction[] | undefined> => { const response = await axiosInstance.get<Reaction[]>(apiPath.getReactionsWithIds(ids)); const isDataValid = validateDataUsingZodSchema(response.data, z.array(reactionSchema)); - if (!isDataValid || response?.data?.length === ZERO) { - return isDataValid ? response.data : undefined; + if (!isDataValid) { + return undefined; } return response.data; diff --git a/src/utils/map/getPointOffset.ts b/src/utils/map/getPointOffset.ts index 6a1c66294f1e93789a74b9dde710b77d429e47f9..aaedb56044621c4fc4c1c35c08a7169e438294fc 100644 --- a/src/utils/map/getPointOffset.ts +++ b/src/utils/map/getPointOffset.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-magic-numbers */ /* due to math nature of this algo */ import { VALID_MAP_SIZE_SCHEMA } from '@/constants/map'; import { MapSize } from '@/redux/map/map.types'; import { Point } from '@/types/map'; @@ -9,17 +8,20 @@ interface GetPointOffsetResults extends Point { zoomFactor: number; } +const SHIFT_MULTIPLIER = 2; +const DIVIDE_TO_CENTER = 2; + export const getPointOffset = (point: Point, mapSize: MapSize): GetPointOffsetResults => { // parse throws error if map size may lead to invalid results VALID_MAP_SIZE_SCHEMA.parse(mapSize); const longestSide = Math.max(mapSize.width, mapSize.height); - const minZoomShifted = mapSize.minZoom * 2 ** mapSize.minZoom; - const zoomFactor = longestSide / (mapSize.tileSize / minZoomShifted) / 2; + const minZoomShifted = mapSize.minZoom * SHIFT_MULTIPLIER ** mapSize.minZoom; + const zoomFactor = longestSide / (mapSize.tileSize / minZoomShifted) / DIVIDE_TO_CENTER; const pointOrigin: Point = { - x: mapSize.tileSize / 2, - y: mapSize.tileSize / 2, + x: mapSize.tileSize / DIVIDE_TO_CENTER, + y: mapSize.tileSize / DIVIDE_TO_CENTER, }; const pointShifted: Point = { diff --git a/src/utils/testing/getReduxStoreActionsListener.tsx b/src/utils/testing/getReduxStoreActionsListener.tsx index 22c12cd0e7bc8a8d832788d4895a4b9765cac19a..56c21265cfe8787e34d672de681fe3b87dde512a 100644 --- a/src/utils/testing/getReduxStoreActionsListener.tsx +++ b/src/utils/testing/getReduxStoreActionsListener.tsx @@ -10,12 +10,12 @@ interface WrapperProps { export type InitialStoreState = Partial<RootState>; -type GetReduxStoreActionsListener = (initialState?: InitialStoreState) => { +type GetReduxStoreWithActionsListener = (initialState?: InitialStoreState) => { Wrapper: ({ children }: WrapperProps) => JSX.Element; store: MockStoreEnhanced<Partial<RootState>, AppDispatch>; }; -export const getReduxStoreActionsListener: GetReduxStoreActionsListener = ( +export const getReduxStoreWithActionsListener: GetReduxStoreWithActionsListener = ( preloadedState: InitialStoreState = {}, ) => { const testStore = configureStore<Partial<RootState>, AppDispatch>([thunk, ...middlewares])( diff --git a/yarn.lock b/yarn.lock index e5bd596f461837f6b40744e75a28af01684831e7..54e2c71b6b3f6141ad2346981e051763c0a1c80e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -847,49 +847,9 @@ "resolved" "https://registry.npmjs.org/@next/font/-/font-13.5.4.tgz" "version" "13.5.4" -"@next/swc-darwin-x64@13.4.19": - "integrity" "sha512-jyzO6wwYhx6F+7gD8ddZfuqO4TtpJdw3wyOduR4fxTUCm3aLw7YmHGYNjS0xRSYGAkLpBkH1E0RcelyId6lNsw==" - "resolved" "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-darwin-x64@13.4.19": - "integrity" "sha512-jyzO6wwYhx6F+7gD8ddZfuqO4TtpJdw3wyOduR4fxTUCm3aLw7YmHGYNjS0xRSYGAkLpBkH1E0RcelyId6lNsw==" - "resolved" "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-linux-arm64-gnu@13.4.19": - "integrity" "sha512-vdlnIlaAEh6H+G6HrKZB9c2zJKnpPVKnA6LBwjwT2BTjxI7e0Hx30+FoWCgi50e+YO49p6oPOtesP9mXDRiiUg==" - "resolved" "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-linux-arm64-musl@13.4.19": - "integrity" "sha512-aU0HkH2XPgxqrbNRBFb3si9Ahu/CpaR5RPmN2s9GiM9qJCiBBlZtRTiEca+DC+xRPyCThTtWYgxjWHgU7ZkyvA==" - "resolved" "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-linux-x64-gnu@13.4.19": - "integrity" "sha512-htwOEagMa/CXNykFFeAHHvMJeqZfNQEoQvHfsA4wgg5QqGNqD5soeCer4oGlCol6NGUxknrQO6VEustcv+Md+g==" - "resolved" "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-linux-x64-musl@13.4.19": - "integrity" "sha512-4Gj4vvtbK1JH8ApWTT214b3GwUh9EKKQjY41hH/t+u55Knxi/0wesMzwQRhppK6Ddalhu0TEttbiJ+wRcoEj5Q==" - "resolved" "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-win32-arm64-msvc@13.4.19": - "integrity" "sha512-bUfDevQK4NsIAHXs3/JNgnvEY+LRyneDN788W2NYiRIIzmILjba7LaQTfihuFawZDhRtkYCv3JDC3B4TwnmRJw==" - "resolved" "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-win32-ia32-msvc@13.4.19": - "integrity" "sha512-Y5kikILFAr81LYIFaw6j/NrOtmiM4Sf3GtOc0pn50ez2GCkr+oejYuKGcwAwq3jiTKuzF6OF4iT2INPoxRycEA==" - "resolved" "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.19.tgz" - "version" "13.4.19" - -"@next/swc-win32-x64-msvc@13.4.19": - "integrity" "sha512-YzA78jBDXMYiINdPdJJwGgPNT3YqBNNGhsthsDoWHL9p24tEJn9ViQf/ZqTbwSpX/RrkPupLfuuTH2sf73JBAw==" - "resolved" "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.19.tgz" +"@next/swc-darwin-arm64@13.4.19": + "integrity" "sha512-vv1qrjXeGbuF2mOkhkdxMDtv9np7W4mcBtaDnHU+yJG+bBwa6rYsYSCI/9Xm5+TuF5SbZbrWO6G1NfTh1TMjvQ==" + "resolved" "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.19.tgz" "version" "13.4.19" "@nodelib/fs.scandir@2.1.5":