Skip to content

Commit

Permalink
fix projects in sidenav fetch on item click from breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymikhadyuk committed Oct 24, 2023
1 parent 742d3fc commit 7d47273
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export default function CreateCommonModal(props: CreateCommonModalProps) {
image: createdCommonData.common.image,
name: createdCommonData.common.name,
directParent: createdCommonData.common.directParent,
rootCommonId: createdCommonData.common.rootCommonId,
hasMembership: true,
hasPermissionToAddProject,
notificationsAmount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CommonCreation: FC = () => {
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
hasMembership: true,
hasPermissionToAddProject,
notificationsAmount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const ProjectCreation: FC<ProjectCreationProps> = (props) => {
image: createdProject.image,
name: createdProject.name,
directParent: createdProject.directParent,
rootCommonId: createdProject.rootCommonId,
hasMembership: true,
hasPermissionToAddProject: Object.values(governance.circles).some(
(circle) => circle.allowedActions[GovernanceActions.CREATE_PROJECT],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const getProjectItemFromCommon = async (
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
};

if (initialItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface BreadcrumbsItemProps {
onCommonCreate?: () => void;
withMenu?: boolean;
isLoading?: boolean;
onClick?: () => void;
}

const BreadcrumbsItem: FC<BreadcrumbsItemProps> = (props) => {
Expand All @@ -23,6 +24,7 @@ const BreadcrumbsItem: FC<BreadcrumbsItemProps> = (props) => {
onCommonCreate,
withMenu = true,
isLoading = false,
onClick,
} = props;
const history = useHistory();
const { getCommonPagePath } = useRoutesContext();
Expand All @@ -32,6 +34,7 @@ const BreadcrumbsItem: FC<BreadcrumbsItemProps> = (props) => {
const handleButtonClick = () => {
if (!withMenu) {
history.push(getCommonPagePath(activeItem.commonId));
onClick?.();
return;
}
if (containerRef.current) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { FC } from "react";
import { MultipleSpacesLayoutFeedItemBreadcrumbs } from "@/store/states";
import { useDispatch, useSelector } from "react-redux";
import {
commonLayoutActions,
MultipleSpacesLayoutFeedItemBreadcrumbs,
ProjectsStateItem,
selectCommonLayoutCommonId,
} from "@/store/states";
import { useGoToCreateCommon } from "../../../../../../hooks";
import { LoadingBreadcrumbsItem } from "../LoadingBreadcrumbsItem";
import { Separator } from "../Separator";
Expand All @@ -13,8 +19,21 @@ interface FeedItemBreadcrumbsProps {

const FeedItemBreadcrumbs: FC<FeedItemBreadcrumbsProps> = (props) => {
const { breadcrumbs, itemsWithMenus } = props;
const dispatch = useDispatch();
const currentLayoutCommonId = useSelector(selectCommonLayoutCommonId);
const goToCreateCommon = useGoToCreateCommon();

const handleItemClick = (item: ProjectsStateItem) => {
if (
currentLayoutCommonId &&
item.rootCommonId &&
item.rootCommonId !== currentLayoutCommonId
) {
dispatch(commonLayoutActions.setCurrentCommonId(item.rootCommonId));
dispatch(commonLayoutActions.clearProjects());
}
};

return (
<ul className={styles.container}>
{breadcrumbs.areItemsLoading && <LoadingBreadcrumbsItem />}
Expand All @@ -26,6 +45,7 @@ const FeedItemBreadcrumbs: FC<FeedItemBreadcrumbsProps> = (props) => {
activeItem={item}
onCommonCreate={index === 0 ? goToCreateCommon : undefined}
withMenu={itemsWithMenus}
onClick={() => handleItemClick(item)}
/>
</React.Fragment>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

type FeedBreadcrumbsItemProps = Pick<
BreadcrumbsItemProps,
"activeItem" | "onCommonCreate" | "withMenu"
"activeItem" | "onCommonCreate" | "withMenu" | "onClick"
>;

const getItemsByParentId = (
Expand Down
1 change: 1 addition & 0 deletions src/store/states/commonLayout/saga/getCommons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function* getCommons(
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
hasMembership,
hasPermissionToAddProject,
notificationsAmount: 0,
Expand Down
1 change: 1 addition & 0 deletions src/store/states/commonLayout/saga/getProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function* getProjects(
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
hasMembership,
hasPermissionToAddProject,
notificationsAmount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const fetchProjectsInfoByActiveCommonId = async (
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
hasMembership: true,
}));
};
Expand Down
1 change: 1 addition & 0 deletions src/store/states/projects/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function* getProjects(action: ReturnType<typeof actions.getProjects.request>) {
image: common.image,
name: common.name,
directParent: common.directParent,
rootCommonId: common.rootCommonId,
hasMembership,
notificationsAmount: 0,
}),
Expand Down

0 comments on commit 7d47273

Please sign in to comment.