Skip to content
Snippets Groups Projects
Commit 359c31b8 authored by Adrian Orłów's avatar Adrian Orłów
Browse files

feat: add rfc changes

parent 0dee60b6
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...,!113feat: add graphics full tab business logic (MIN-165)
Pipeline #85122 passed
import { MapModel } from '@/types/models';
import { numberToInt } from '@/utils/number/numberToInt';
import { numberToSafeInt } from '@/utils/number/numberToInt';
import { useCallback, useContext, useEffect } from 'react';
import { ExportContext } from '../../ExportCompound.context';
import { DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '../ImageSize.constants';
......@@ -30,8 +30,8 @@ export const useImageSize = (): UseImageSizeResults => {
const widthMinMax = Math.min(maxWidth, newWidth);
const heightMinMax = Math.min(maxHeight, newHeight);
const widthInt = numberToInt(widthMinMax);
const heightInt = numberToInt(heightMinMax);
const widthInt = numberToSafeInt(widthMinMax);
const heightInt = numberToSafeInt(heightMinMax);
return {
width: widthInt,
......
/* eslint-disable no-magic-numbers */
import { modelsFixture } from '@/models/fixtures/modelsFixture';
import { StoreType } from '@/redux/store';
import {
InitialStoreState,
getReduxWrapperWithStore,
} from '@/utils/testing/getReduxWrapperWithStore';
import { render, screen, waitFor } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { Submap } from './Submap.component';
const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => {
const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState);
return (
render(
<Wrapper>
<Submap />
</Wrapper>,
),
{
store,
}
);
};
const CHECKBOX_ELEMENT_NAME = modelsFixture[0].name;
describe('Submap - component', () => {
it('should display submaps checkboxes when fetching data is successful', async () => {
renderComponent({
models: {
data: modelsFixture,
loading: 'succeeded',
error: {
message: '',
name: '',
},
},
});
expect(screen.queryByTestId('checkbox-filter')).not.toBeVisible();
const navigationButton = screen.getByTestId('accordion-item-button');
act(() => {
navigationButton.click();
});
expect(screen.getByText('Submap')).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByTestId('checkbox-filter')).toBeInTheDocument();
expect(screen.getByLabelText('search-input')).toBeInTheDocument();
expect(screen.getByLabelText(CHECKBOX_ELEMENT_NAME)).toBeInTheDocument();
});
});
it('should not display submaps checkboxes when fetching data fails', async () => {
renderComponent({
models: {
data: [],
loading: 'failed',
error: {
message: '',
name: '',
},
},
});
expect(screen.getByText('Submap')).toBeInTheDocument();
const navigationButton = screen.getByTestId('accordion-item-button');
act(() => {
navigationButton.click();
});
expect(screen.queryByTestId('checkbox-filter')).not.toBeInTheDocument();
});
it('should not display submaps checkboxes when fetched data is empty', async () => {
renderComponent({
models: {
data: [],
loading: 'succeeded',
error: {
message: '',
name: '',
},
},
});
expect(screen.getByText('Submap')).toBeInTheDocument();
const navigationButton = screen.getByTestId('accordion-item-button');
act(() => {
navigationButton.click();
});
expect(screen.queryByTestId('checkbox-filter')).not.toBeInTheDocument();
});
it('should display loading message when fetching data is pending', async () => {
renderComponent({
models: {
data: [],
loading: 'pending',
error: {
message: '',
name: '',
},
},
});
expect(screen.getByText('Submap')).toBeInTheDocument();
const navigationButton = screen.getByTestId('accordion-item-button');
act(() => {
navigationButton.click();
});
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
});
......@@ -8,7 +8,7 @@ import { ExportContext } from '../ExportCompound.context';
export const Submap = (): React.ReactNode => {
const { setModels, data } = useContext(ExportContext);
const currentModels = data.models;
const currentSelectedModels = data.models;
const models = useAppSelector(modelsDataSelector);
const loadingModels = useAppSelector(loadingModelsSelector);
const isPending = loadingModels === 'pending';
......@@ -24,7 +24,7 @@ export const Submap = (): React.ReactNode => {
{!isPending && mappedElementAnnotations && mappedElementAnnotations.length > ZERO && (
<CheckboxFilter
options={mappedElementAnnotations}
currentOptions={currentModels}
currentOptions={currentSelectedModels}
onCheckedChange={setModels}
type="radio"
/>
......
......@@ -3,6 +3,12 @@ import { MapModel } from '@/types/models';
const ZOOM_BASE = 6;
/*
* Width of exported image for zoom=1 is 128, for zoom=2 is 256, for zoom=3 is 1024
* So zoom level holds pattern of log2(width) with base of log2(128)=7
* Zoom base defined in this file is 6 as we need to provide minumum zoom of 1
*/
export const getModelExportZoom = (exportWidth: number, model?: MapModel): number => {
// log2 of zero is -Infty
if (!model || model.width === ZERO) {
......
import { PROJECT_ID } from '@/constants';
import { PerfectSearchParams } from '@/types/search';
import { Point } from '@/types/map';
import { PerfectSearchParams } from '@/types/search';
export const apiPath = {
getBioEntityContentsStringWithQuery: ({
......
......@@ -101,12 +101,7 @@ export const imageFormatsEntriesSelector = createSelector(
imageFormatsSelector,
(modelFormats): Record<string, ConfigurationFormatSchema> => {
return Object.fromEntries(
(modelFormats || [])
.flat()
.filter((format: ConfigurationFormatSchema): format is ConfigurationFormatSchema =>
Boolean(format),
)
.map((format: ConfigurationFormatSchema) => [format.name, format]),
(modelFormats || []).flat().map((format: ConfigurationFormatSchema) => [format.name, format]),
);
},
);
......
import { ZERO } from '@/constants/common';
export const numberToInt = (num: number): number => {
export const numberToSafeInt = (num: number): number => {
// zero or NaN
if (!num) {
return ZERO;
......
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