Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ import React, { FC } from "react";
import Link from "next/link";

type Props = {
projectId: string | null;
href: string;
title: string;
icon: JSX.Element;
isSidebarCollapsed: boolean;
};

export const FavoriteItemTitle: FC<Props> = (props) => {
const { href, title, icon, isSidebarCollapsed } = props;
const { projectId, href, title, icon, isSidebarCollapsed } = props;

const linkClass = "flex items-center gap-1.5 truncate w-full";
const collapsedClass =
"group/project-item cursor-pointer relative group w-full flex items-center justify-center gap-1.5 rounded px-2 py-1 outline-none text-custom-sidebar-text-200 hover:bg-custom-sidebar-background-90 active:bg-custom-sidebar-background-90 truncate p-0 size-8 aspect-square mx-auto";

const handleOnClick = () => {
if (projectId) {
const projectItem = document.getElementById(`${projectId}`);
projectItem?.scrollIntoView({ behavior: "smooth" });
}
};
Comment on lines +20 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using React refs or state management instead of document.getElementById.

The use of document.getElementById is generally discouraged in React as it bypasses the React virtual DOM. Consider using React refs or state management to handle DOM interactions for better integration with React's lifecycle.


return (
<Link href={href} className={isSidebarCollapsed ? collapsedClass : linkClass} draggable>
<Link href={href} className={isSidebarCollapsed ? collapsedClass : linkClass} draggable onClick={handleOnClick}>
<span className="flex items-center justify-center size-5">{icon}</span>
{!isSidebarCollapsed && <span className="text-sm leading-5 font-medium flex-1 truncate">{title}</span>}
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ const entityPaths: Record<string, string> = {
export const generateFavoriteItemLink = (workspaceSlug: string, favorite: IFavorite) => {
const entityPath = entityPaths[favorite.entity_type];
return entityPath
? `/${workspaceSlug}/projects/${favorite.project_id}/${entityPath}/${favorite.entity_identifier || ""}`
? `/${workspaceSlug}/projects/${favorite.project_id}/${entityPath}/${entityPath === "issues" ? "" : favorite.entity_identifier || ""}`
: `/${workspaceSlug}`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ export const FavoriteRoot: FC<Props> = observer((props) => {
<>
<FavoriteItemWrapper elementRef={elementRef} isMenuActive={isMenuActive} sidebarCollapsed={sidebarCollapsed}>
{!sidebarCollapsed && <FavoriteItemDragHandle isDragging={isDragging} sort_order={favorite.sort_order} />}
<FavoriteItemTitle href={itemLink} icon={itemIcon} title={itemTitle} isSidebarCollapsed={!!sidebarCollapsed} />
<FavoriteItemTitle
href={itemLink}
projectId={favorite.project_id}
icon={itemIcon}
title={itemTitle}
isSidebarCollapsed={!!sidebarCollapsed}
/>
{!sidebarCollapsed && (
<FavoriteItemQuickAction
favorite={favorite}
Expand Down
2 changes: 2 additions & 0 deletions web/core/components/workspace/sidebar/projects-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {

useEffect(() => {
if (URLProjectId === project.id) setIsProjectListOpen(true);
else setIsProjectListOpen(false);
}, [URLProjectId]);

return (
Expand All @@ -291,6 +292,7 @@ export const SidebarProjectsListItem: React.FC<Props> = observer((props) => {
"p-0 size-8 aspect-square justify-center mx-auto": isSidebarCollapsed,
}
)}
id={`${project?.id}`}
>
{!disableDrag && (
<Tooltip
Expand Down
4 changes: 3 additions & 1 deletion web/core/hooks/use-favorite-item-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useFavoriteItemDetails = (workspaceSlug: string, favorite: IFavorit

// store hooks
const { getViewById } = useProjectView();
const { currentProjectDetails } = useProject();
const { getProjectById } = useProject();
const { getCycleById } = useCycle();
const { getModuleById } = useModule();

Expand All @@ -23,6 +23,8 @@ export const useFavoriteItemDetails = (workspaceSlug: string, favorite: IFavorit
const cycleDetail = getCycleById(favoriteItemId ?? "");
const moduleDetail = getModuleById(favoriteItemId ?? "");

const currentProjectDetails = getProjectById(favorite.project_id ?? "");

let itemIcon;
let itemTitle;
const itemLink = generateFavoriteItemLink(workspaceSlug.toString(), favorite);
Expand Down