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

show general comments

parent 766fdd05
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...,!201Resolve "[MIN-114] Browse comments on the map"
Pipeline #91819 passed
Showing
with 105 additions and 2 deletions
import { DrawerHeading } from '@/shared/DrawerHeading';
import { useSelector } from 'react-redux';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { CommentItem } from '@/components/Map/Drawer/BioEntityDrawer/Comments/CommentItem.component';
import { ZERO } from '@/constants/common';
import { currentDrawerCommentId } from '@/redux/drawer/drawer.selectors';
import { allCommentsSelectorOfCurrentMap } from '@/redux/comment/comment.selectors';
export const CommentDrawer = (): React.ReactNode => {
const commentId = useSelector(currentDrawerCommentId);
const commentsData = useAppSelector(allCommentsSelectorOfCurrentMap);
const comments = commentsData.filter(commentEntry => commentEntry.id === commentId);
if (comments.length === ZERO) {
return null;
}
return (
<div className="h-full max-h-full" data-testid="reaction-drawer">
<DrawerHeading title={<span className="font-normal">Area: </span>} />
<div className="flex h-[calc(100%-93px)] max-h-[calc(100%-93px)] flex-col gap-6 overflow-y-auto p-6">
<div className="font-bold"> Comments</div>
{comments.map(comment => (
<CommentItem key={comment.id} comment={comment} />
))}
</div>
</div>
);
};
export { CommentDrawer } from './CommentDrawer.component';
...@@ -2,6 +2,7 @@ import { DRAWER_ROLE } from '@/components/Map/Drawer/Drawer.constants'; ...@@ -2,6 +2,7 @@ import { DRAWER_ROLE } from '@/components/Map/Drawer/Drawer.constants';
import { drawerSelector } from '@/redux/drawer/drawer.selectors'; import { drawerSelector } from '@/redux/drawer/drawer.selectors';
import { useAppSelector } from '@/redux/hooks/useAppSelector'; import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
import { CommentDrawer } from '@/components/Map/Drawer/CommentDrawer';
import { AvailablePluginsDrawer } from './AvailablePluginsDrawer'; import { AvailablePluginsDrawer } from './AvailablePluginsDrawer';
import { BioEntityDrawer } from './BioEntityDrawer/BioEntityDrawer.component'; import { BioEntityDrawer } from './BioEntityDrawer/BioEntityDrawer.component';
import { ExportDrawer } from './ExportDrawer'; import { ExportDrawer } from './ExportDrawer';
...@@ -30,6 +31,7 @@ export const Drawer = (): JSX.Element => { ...@@ -30,6 +31,7 @@ export const Drawer = (): JSX.Element => {
{isOpen && drawerName === 'project-info' && <ProjectInfoDrawer />} {isOpen && drawerName === 'project-info' && <ProjectInfoDrawer />}
{isOpen && drawerName === 'export' && <ExportDrawer />} {isOpen && drawerName === 'export' && <ExportDrawer />}
{isOpen && drawerName === 'available-plugins' && <AvailablePluginsDrawer />} {isOpen && drawerName === 'available-plugins' && <AvailablePluginsDrawer />}
{isOpen && drawerName === 'comment' && <CommentDrawer />}
</div> </div>
); );
}; };
...@@ -32,6 +32,9 @@ const INITIAL_STATE: InitialStoreState = { ...@@ -32,6 +32,9 @@ const INITIAL_STATE: InitialStoreState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}, },
drugs: { drugs: {
data: [ data: [
......
...@@ -51,6 +51,9 @@ describe('SearchDrawerWrapper - component', () => { ...@@ -51,6 +51,9 @@ describe('SearchDrawerWrapper - component', () => {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}, },
}); });
...@@ -77,6 +80,9 @@ describe('SearchDrawerWrapper - component', () => { ...@@ -77,6 +80,9 @@ describe('SearchDrawerWrapper - component', () => {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}, },
}); });
......
import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common'; import { SIZE_OF_EMPTY_ARRAY, ZERO } from '@/constants/common';
import { FEATURE_TYPE, PIN_ICON_ANY, SURFACE_ANY } from '@/constants/features'; import { FEATURE_TYPE, PIN_ICON_ANY, SURFACE_ANY } from '@/constants/features';
import { openBioEntityDrawerById, openReactionDrawerById } from '@/redux/drawer/drawer.slice'; import {
openBioEntityDrawerById,
openCommentDrawerById,
openReactionDrawerById,
} from '@/redux/drawer/drawer.slice';
import { AppDispatch } from '@/redux/store'; import { AppDispatch } from '@/redux/store';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus'; import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { FeatureLike } from 'ol/Feature'; import { FeatureLike } from 'ol/Feature';
...@@ -37,7 +41,7 @@ export const handleFeaturesClick = ( ...@@ -37,7 +41,7 @@ export const handleFeaturesClick = (
dispatch(getCommentReaction({ elementId: Number(elementId), modelId })); dispatch(getCommentReaction({ elementId: Number(elementId), modelId }));
dispatch(openReactionDrawerById(Number(elementId))); dispatch(openReactionDrawerById(Number(elementId)));
} else if (type === 'POINT') { } else if (type === 'POINT') {
throw new Error(`Opening point comment is not implemented yet`); dispatch(openCommentDrawerById(Number(pinId)));
} else { } else {
throw new Error(`Unknown comment type${type}`); throw new Error(`Unknown comment type${type}`);
} }
......
...@@ -18,6 +18,9 @@ export const DRAWER_INITIAL_STATE: DrawerState = { ...@@ -18,6 +18,9 @@ export const DRAWER_INITIAL_STATE: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const RESULT_DRAWERS = ['search', 'reaction', 'bio-entity']; export const RESULT_DRAWERS = ['search', 'reaction', 'bio-entity'];
......
...@@ -2,6 +2,7 @@ import { STEP } from '@/constants/searchDrawer'; ...@@ -2,6 +2,7 @@ import { STEP } from '@/constants/searchDrawer';
import type { import type {
DrawerState, DrawerState,
OpenBioEntityDrawerByIdAction, OpenBioEntityDrawerByIdAction,
OpenCommentDrawerByIdAction,
OpenReactionDrawerByIdAction, OpenReactionDrawerByIdAction,
OpenSearchDrawerWithSelectedTabReducerAction, OpenSearchDrawerWithSelectedTabReducerAction,
} from '@/redux/drawer/drawer.types'; } from '@/redux/drawer/drawer.types';
...@@ -113,6 +114,15 @@ export const openBioEntityDrawerByIdReducer = ( ...@@ -113,6 +114,15 @@ export const openBioEntityDrawerByIdReducer = (
state.bioEntityDrawerState.bioentityId = action.payload; state.bioEntityDrawerState.bioentityId = action.payload;
}; };
export const openCommentDrawerByIdReducer = (
state: DrawerState,
action: OpenCommentDrawerByIdAction,
): void => {
state.isOpen = true;
state.drawerName = 'comment';
state.commentDrawerState.commentId = action.payload;
};
export const getBioEntityDrugsForTargetReducers = ( export const getBioEntityDrugsForTargetReducers = (
builder: ActionReducerMapBuilder<DrawerState>, builder: ActionReducerMapBuilder<DrawerState>,
): void => { ): void => {
......
...@@ -43,11 +43,21 @@ export const bioEntityDrawerStateSelector = createSelector( ...@@ -43,11 +43,21 @@ export const bioEntityDrawerStateSelector = createSelector(
state => state.bioEntityDrawerState, state => state.bioEntityDrawerState,
); );
export const commentDrawerStateSelector = createSelector(
drawerSelector,
state => state.commentDrawerState,
);
export const currentSearchedBioEntityId = createSelector( export const currentSearchedBioEntityId = createSelector(
bioEntityDrawerStateSelector, bioEntityDrawerStateSelector,
state => state.bioentityId, state => state.bioentityId,
); );
export const currentDrawerCommentId = createSelector(
commentDrawerStateSelector,
state => state.commentId,
);
export const currentSearchedBioEntityDrugsSelector = createSelector( export const currentSearchedBioEntityDrugsSelector = createSelector(
bioEntityDrawerStateSelector, bioEntityDrawerStateSelector,
currentSearchedBioEntityId, currentSearchedBioEntityId,
......
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
getBioEntityChemicalsForTargetReducers, getBioEntityChemicalsForTargetReducers,
getBioEntityDrugsForTargetReducers, getBioEntityDrugsForTargetReducers,
openBioEntityDrawerByIdReducer, openBioEntityDrawerByIdReducer,
openCommentDrawerByIdReducer,
openDrawerReducer, openDrawerReducer,
openOverlaysDrawerReducer, openOverlaysDrawerReducer,
openReactionDrawerByIdReducer, openReactionDrawerByIdReducer,
...@@ -37,6 +38,7 @@ const drawerSlice = createSlice({ ...@@ -37,6 +38,7 @@ const drawerSlice = createSlice({
displayEntityDetails: displayEntityDetailsReducer, displayEntityDetails: displayEntityDetailsReducer,
openReactionDrawerById: openReactionDrawerByIdReducer, openReactionDrawerById: openReactionDrawerByIdReducer,
openBioEntityDrawerById: openBioEntityDrawerByIdReducer, openBioEntityDrawerById: openBioEntityDrawerByIdReducer,
openCommentDrawerById: openCommentDrawerByIdReducer,
}, },
extraReducers: builder => { extraReducers: builder => {
getBioEntityDrugsForTargetReducers(builder); getBioEntityDrugsForTargetReducers(builder);
...@@ -59,6 +61,7 @@ export const { ...@@ -59,6 +61,7 @@ export const {
displayEntityDetails, displayEntityDetails,
openReactionDrawerById, openReactionDrawerById,
openBioEntityDrawerById, openBioEntityDrawerById,
openCommentDrawerById,
} = drawerSlice.actions; } = drawerSlice.actions;
export default drawerSlice.reducer; export default drawerSlice.reducer;
...@@ -25,6 +25,10 @@ export type BioEntityDrawerState = { ...@@ -25,6 +25,10 @@ export type BioEntityDrawerState = {
chemicals: KeyedFetchDataState<Chemical[], []>; chemicals: KeyedFetchDataState<Chemical[], []>;
}; };
export type CommentDrawerState = {
commentId?: number;
};
export type DrawerState = { export type DrawerState = {
isOpen: boolean; isOpen: boolean;
drawerName: DrawerName; drawerName: DrawerName;
...@@ -32,6 +36,7 @@ export type DrawerState = { ...@@ -32,6 +36,7 @@ export type DrawerState = {
reactionDrawerState: ReactionDrawerState; reactionDrawerState: ReactionDrawerState;
bioEntityDrawerState: BioEntityDrawerState; bioEntityDrawerState: BioEntityDrawerState;
overlayDrawerState: OverlayDrawerState; overlayDrawerState: OverlayDrawerState;
commentDrawerState: CommentDrawerState;
}; };
export type OpenSearchDrawerWithSelectedTabReducerPayload = string; export type OpenSearchDrawerWithSelectedTabReducerPayload = string;
...@@ -46,3 +51,6 @@ export type OpenBioEntityDrawerByIdAction = PayloadAction<OpenBioEntityDrawerByI ...@@ -46,3 +51,6 @@ export type OpenBioEntityDrawerByIdAction = PayloadAction<OpenBioEntityDrawerByI
export type SetSelectedSearchElementPayload = string; export type SetSelectedSearchElementPayload = string;
export type SetSelectedSearchElementAction = PayloadAction<SetSelectedSearchElementPayload>; export type SetSelectedSearchElementAction = PayloadAction<SetSelectedSearchElementPayload>;
export type OpenCommentDrawerByIdPayload = number;
export type OpenCommentDrawerByIdAction = PayloadAction<OpenCommentDrawerByIdPayload>;
...@@ -18,6 +18,9 @@ export const initialStateFixture: DrawerState = { ...@@ -18,6 +18,9 @@ export const initialStateFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const openedDrawerSubmapsFixture: DrawerState = { export const openedDrawerSubmapsFixture: DrawerState = {
...@@ -38,6 +41,9 @@ export const openedDrawerSubmapsFixture: DrawerState = { ...@@ -38,6 +41,9 @@ export const openedDrawerSubmapsFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const drawerSearchStepOneFixture: DrawerState = { export const drawerSearchStepOneFixture: DrawerState = {
...@@ -58,6 +64,9 @@ export const drawerSearchStepOneFixture: DrawerState = { ...@@ -58,6 +64,9 @@ export const drawerSearchStepOneFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const drawerSearchDrugsStepTwoFixture: DrawerState = { export const drawerSearchDrugsStepTwoFixture: DrawerState = {
...@@ -78,6 +87,9 @@ export const drawerSearchDrugsStepTwoFixture: DrawerState = { ...@@ -78,6 +87,9 @@ export const drawerSearchDrugsStepTwoFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const drawerSearchChemicalsStepTwoFixture: DrawerState = { export const drawerSearchChemicalsStepTwoFixture: DrawerState = {
...@@ -98,6 +110,9 @@ export const drawerSearchChemicalsStepTwoFixture: DrawerState = { ...@@ -98,6 +110,9 @@ export const drawerSearchChemicalsStepTwoFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const drawerOverlaysStepOneFixture: DrawerState = { export const drawerOverlaysStepOneFixture: DrawerState = {
...@@ -118,6 +133,9 @@ export const drawerOverlaysStepOneFixture: DrawerState = { ...@@ -118,6 +133,9 @@ export const drawerOverlaysStepOneFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 2, currentStep: 2,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
export const openedExportDrawerFixture: DrawerState = { export const openedExportDrawerFixture: DrawerState = {
...@@ -138,4 +156,7 @@ export const openedExportDrawerFixture: DrawerState = { ...@@ -138,4 +156,7 @@ export const openedExportDrawerFixture: DrawerState = {
overlayDrawerState: { overlayDrawerState: {
currentStep: 0, currentStep: 0,
}, },
commentDrawerState: {
commentId: undefined,
},
}; };
...@@ -9,4 +9,5 @@ export type DrawerName = ...@@ -9,4 +9,5 @@ export type DrawerName =
| 'reaction' | 'reaction'
| 'overlays' | 'overlays'
| 'bio-entity' | 'bio-entity'
| 'comment'
| 'available-plugins'; | 'available-plugins';
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