diff --git a/src/shared/components/Chat/ChatMessage/utils/getTextFromSystemMessage.tsx b/src/shared/components/Chat/ChatMessage/utils/getTextFromSystemMessage.tsx index 8a8005b47d..f4419b09b9 100644 --- a/src/shared/components/Chat/ChatMessage/utils/getTextFromSystemMessage.tsx +++ b/src/shared/components/Chat/ChatMessage/utils/getTextFromSystemMessage.tsx @@ -1,6 +1,7 @@ import React from "react"; import { NavLink } from "react-router-dom"; import { CommonService, UserService } from "@/services"; +import { store } from "@/shared/appConfig"; import { SystemDiscussionMessageType } from "@/shared/constants"; import { Common, @@ -16,6 +17,7 @@ import { getCommonPagePath, getUserName, } from "@/shared/utils"; +import { commonLayoutActions } from "@/store/states"; import { UserMention } from "../components"; import { Text, TextData } from "../types"; import { getFeedItemDisplayingData } from "./getFeedItemDisplayingData"; @@ -31,6 +33,14 @@ const getCommon = async (commonId: string): Promise => const getCommonTypeText = (commonType: SystemMessageCommonType): string => commonType === SystemMessageCommonType.Common ? "common" : "space"; +const handleCommonClick = (commonId: string, rootCommonId?: string) => { + store.dispatch( + commonLayoutActions.resetCurrentCommonIdAndProjects( + rootCommonId || commonId, + ), + ); +}; + const renderUserMention = ( user: User | null, data: TextData, @@ -48,8 +58,8 @@ const renderUserMention = ( defaultName ); -const renderLink = (to: string, name: string): Text => ( - +const renderLink = (to: string, name: string, onClick?: () => void): Text => ( + {name} ); @@ -82,6 +92,7 @@ const getCommonCreatedSystemMessageText = async ( {renderLink( (data.getCommonPagePath || getCommonPagePath)(common.id), common.name, + () => handleCommonClick(common.id, common.rootCommonId), )} ) : ( @@ -95,7 +106,10 @@ const getCommonEditedSystemMessageText = async ( systemMessageData: CommonEditedSystemMessage["systemMessageData"], data: TextData, ): Promise => { - const user = await getUser(systemMessageData.userId, data.users); + const [user, common] = await Promise.all([ + getUser(systemMessageData.userId, data.users), + getCommon(systemMessageData.commonId), + ]); const userEl = renderUserMention(user, data); return [ @@ -105,6 +119,7 @@ const getCommonEditedSystemMessageText = async ( systemMessageData.commonId, ), "info", + () => handleCommonClick(systemMessageData.commonId, common?.rootCommonId), ), " was edited by ", userEl, diff --git a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx index 4e77edcce6..eec107a6e0 100644 --- a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx +++ b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Breadcrumbs/components/FeedItemBreadcrumbs/FeedItemBreadcrumbs.tsx @@ -1,5 +1,5 @@ import React, { FC, useEffect } from "react"; -import { useDispatch, useSelector } from "react-redux"; +import { useDispatch } from "react-redux"; import { CommonEvent, CommonEventEmitter } from "@/events"; import { CommonService } from "@/services"; import { useIsTabletView } from "@/shared/hooks/viewport"; @@ -7,7 +7,6 @@ import { commonLayoutActions, MultipleSpacesLayoutFeedItemBreadcrumbs, ProjectsStateItem, - selectCommonLayoutCommonId, } from "@/store/states"; import { useGoToCreateCommon } from "../../../../../../hooks"; import { Separator } from "../Separator"; @@ -23,7 +22,6 @@ interface FeedItemBreadcrumbsProps { const FeedItemBreadcrumbs: FC = (props) => { const { breadcrumbs, itemsWithMenus, truncate } = props; const dispatch = useDispatch(); - const currentLayoutCommonId = useSelector(selectCommonLayoutCommonId); const goToCreateCommon = useGoToCreateCommon(); const isMobileView = useIsTabletView(); const breadcrumbsItems = truncate @@ -31,13 +29,10 @@ const FeedItemBreadcrumbs: FC = (props) => { : breadcrumbs.items; const handleItemClick = (item: ProjectsStateItem) => { - if ( - currentLayoutCommonId && - item.rootCommonId && - item.rootCommonId !== currentLayoutCommonId - ) { - dispatch(commonLayoutActions.setCurrentCommonId(item.rootCommonId)); - dispatch(commonLayoutActions.clearProjects()); + if (item.rootCommonId) { + dispatch( + commonLayoutActions.resetCurrentCommonIdAndProjects(item.rootCommonId), + ); } }; diff --git a/src/shared/layouts/SidenavLayout/components/SidenavContent/components/ProjectsTree/components/TreeItem/TreeItem.tsx b/src/shared/layouts/SidenavLayout/components/SidenavContent/components/ProjectsTree/components/TreeItem/TreeItem.tsx index 8fca4c1e71..4436f04e64 100644 --- a/src/shared/layouts/SidenavLayout/components/SidenavContent/components/ProjectsTree/components/TreeItem/TreeItem.tsx +++ b/src/shared/layouts/SidenavLayout/components/SidenavContent/components/ProjectsTree/components/TreeItem/TreeItem.tsx @@ -30,7 +30,7 @@ const TreeItem: FC = (props) => { const hasNestedContent = Boolean(children); useEffect(() => { - if (isActive && hasNestedContent) { + if ((isActive || hasActiveChild) && hasNestedContent) { setIsOpen(true); return; } diff --git a/src/store/states/commonLayout/actions.ts b/src/store/states/commonLayout/actions.ts index d848e9cfef..4a30e86b4b 100644 --- a/src/store/states/commonLayout/actions.ts +++ b/src/store/states/commonLayout/actions.ts @@ -33,6 +33,10 @@ export const setCurrentCommonId = createStandardAction( CommonLayoutActionType.SET_CURRENT_COMMON_ID, )(); +export const resetCurrentCommonIdAndProjects = createStandardAction( + CommonLayoutActionType.RESET_CURRENT_COMMON_ID_AND_PROJECTS, +)(); + export const setLastCommonFromFeed = createStandardAction( CommonLayoutActionType.SET_LAST_COMMON_FROM_FEED, )(); diff --git a/src/store/states/commonLayout/constants.ts b/src/store/states/commonLayout/constants.ts index 5ac407dafb..4089fafbfd 100644 --- a/src/store/states/commonLayout/constants.ts +++ b/src/store/states/commonLayout/constants.ts @@ -13,6 +13,8 @@ export enum CommonLayoutActionType { SET_CURRENT_COMMON_ID = "@COMMON_LAYOUT/SET_CURRENT_COMMON_ID", + RESET_CURRENT_COMMON_ID_AND_PROJECTS = "@COMMON_LAYOUT/RESET_CURRENT_COMMON_ID_AND_PROJECTS", + SET_LAST_COMMON_FROM_FEED = "@COMMON_LAYOUT/SET_LAST_COMMON_FROM_FEED", CLEAR_DATA = "@COMMON_LAYOUT/CLEAR_DATA", diff --git a/src/store/states/commonLayout/saga/index.ts b/src/store/states/commonLayout/saga/index.ts index 458b7041d9..326d86ac77 100644 --- a/src/store/states/commonLayout/saga/index.ts +++ b/src/store/states/commonLayout/saga/index.ts @@ -2,8 +2,13 @@ import { takeLatest } from "redux-saga/effects"; import * as actions from "../actions"; import { getCommons } from "./getCommons"; import { getProjects } from "./getProjects"; +import { resetCurrentCommonIdAndProjects } from "./resetCurrentCommonIdAndProjects"; export function* mainSaga() { yield takeLatest(actions.getCommons.request, getCommons); yield takeLatest(actions.getProjects.request, getProjects); + yield takeLatest( + actions.resetCurrentCommonIdAndProjects, + resetCurrentCommonIdAndProjects, + ); } diff --git a/src/store/states/commonLayout/saga/resetCurrentCommonIdAndProjects.ts b/src/store/states/commonLayout/saga/resetCurrentCommonIdAndProjects.ts new file mode 100644 index 0000000000..cc23f7416d --- /dev/null +++ b/src/store/states/commonLayout/saga/resetCurrentCommonIdAndProjects.ts @@ -0,0 +1,17 @@ +import { put, select } from "redux-saga/effects"; +import { selectCommonLayoutCommonId } from "@/store/states"; +import * as actions from "../actions"; + +export function* resetCurrentCommonIdAndProjects( + action: ReturnType, +) { + const { payload: commonId } = action; + const currentCommonId = (yield select(selectCommonLayoutCommonId)) as + | string + | null; + + if (currentCommonId && commonId && commonId !== currentCommonId) { + yield put(actions.setCurrentCommonId(commonId)); + yield put(actions.clearProjects()); + } +}