Skip to content
Snippets Groups Projects
Commit 70597315 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '260-min-327-cannot-browse-asthma-map' into 'development'

Resolve "[MIN-327] cannot browse asthma map"

Closes #260

See merge request !218
parents 2caaad05 63679a8a
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!218Resolve "[MIN-327] cannot browse asthma map"
Pipeline #93547 passed
......@@ -70,6 +70,16 @@ describe('map thunks - utils', () => {
expect(backgroundId).toBe(0);
});
it('should return main map background id if query param background id is invalid', () => {
const store: RootState = {
...INITIAL_STORE_STATE_MOCK,
backgrounds: { ...BACKGROUND_INITIAL_STATE_MOCK, data: BACKGROUNDS_MOCK },
};
const backgroundId = getBackgroundId(store, QUERY_DATA_WITH_BG);
expect(backgroundId).toBe(13);
});
});
describe('getInitMapPosition', () => {
......@@ -96,7 +106,7 @@ describe('map thunks - utils', () => {
});
describe('getInitMapSizeAndModelId', () => {
it('should return correct mapsize and modelid when modelId is provided in queryData', () => {
it('should return correct map size and modelId when modelId is provided in queryData', () => {
const payload = getInitMapSizeAndModelId(STATE_WITH_MODELS, QUERY_DATA_WITH_MODELID);
expect(payload).toEqual({
......@@ -104,7 +114,7 @@ describe('map thunks - utils', () => {
size: { height: 1171.9429798877356, maxZoom: 5, minZoom: 2, tileSize: 256, width: 1652.75 },
});
});
it('should return correct mapsize and modelId if query params do not include modelId', () => {
it('should return correct map size and modelId if query params do not include modelId', () => {
const payload = getInitMapSizeAndModelId(STATE_WITH_MODELS, EMPTY_QUERY_DATA);
expect(payload).toEqual({
modelId: 5053,
......@@ -117,6 +127,22 @@ describe('map thunks - utils', () => {
},
});
});
it('should return correct map size and modelId if query params include invalid modelId', () => {
const payload = getInitMapSizeAndModelId(STATE_WITH_MODELS, {
...EMPTY_QUERY_DATA,
modelId: 1234567,
});
expect(payload).toEqual({
modelId: 5053,
size: {
height: 13503,
maxZoom: 9,
minZoom: 2,
tileSize: 256,
width: 26779.25,
},
});
});
});
describe('getOpenedMaps ', () => {
......
......@@ -21,7 +21,10 @@ import {
OppenedMap,
Position,
} from './map.types';
import { mainBackgroundsDataSelector } from '../backgrounds/background.selectors';
import {
backgroundsDataSelector,
mainBackgroundsDataSelector,
} from '../backgrounds/background.selectors';
import {
currentModelSelector,
mainMapModelSelector,
......@@ -37,11 +40,22 @@ import {
INIT_OPENED_MAPS_ERROR_PREFIX,
} from './map.constants';
/** UTILS - in the same file because of dependancy cycle */
/** UTILS - in the same file because of dependency cycle */
export const getBackgroundId = (state: RootState, queryData: QueryData): number => {
const mainMapBackground = mainBackgroundsDataSelector(state);
const backgroundId = queryData?.backgroundId || mainMapBackground?.id || ZERO;
const backgrounds = backgroundsDataSelector(state);
let backgroundId = queryData?.backgroundId || mainMapBackground?.id || ZERO;
if (backgrounds.length > 0) {
if (
backgrounds.filter(background => {
return background.id === backgroundId;
}).length === 0
) {
backgroundId = backgrounds[ZERO].id;
}
}
if (backgroundId !== mainMapBackground?.id) {
PluginsEventBus.dispatchEvent('onBackgroundOverlayChange', backgroundId);
......@@ -50,9 +64,24 @@ export const getBackgroundId = (state: RootState, queryData: QueryData): number
return backgroundId;
};
export const getInitMapPosition = (state: RootState, queryData: QueryData): Position => {
export const getModelId = (state: RootState, queryData: QueryData): number => {
const mainMapModel = mainMapModelSelector(state);
const modelId = queryData?.modelId || mainMapModel?.idObject || ZERO;
const models = modelsDataSelector(state);
let modelId = queryData?.modelId || mainMapModel?.idObject || ZERO;
if (models.length > 0) {
if (
models.filter(model => {
return model.idObject === modelId;
}).length === 0
) {
modelId = models[ZERO].idObject;
}
}
return modelId;
};
export const getInitMapPosition = (state: RootState, queryData: QueryData): Position => {
const modelId = getModelId(state, queryData);
const currentModel = modelByIdSelector(state, modelId);
const position = queryData?.initialPosition;
const HALF = 2;
......@@ -98,7 +127,7 @@ export const getInitMapSizeAndModelId = (
queryData: QueryData,
): MapSizeAndModelId => {
const mainMapModel = mainMapModelSelector(state);
const modelId = queryData?.modelId || mainMapModel?.idObject || ZERO;
const modelId = getModelId(state, queryData);
const currentModel = modelByIdSelector(state, modelId);
if (modelId !== mainMapModel?.idObject) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment