[WEB-5609] fix: extended sidebar item pin/unpin #8287
This commit is contained in:
parent
a55253d242
commit
df1a512a80
1 changed files with 27 additions and 26 deletions
|
|
@ -17,9 +17,8 @@ import { cn } from "@plane/utils";
|
||||||
import { SidebarNavItem } from "@/components/sidebar/sidebar-navigation";
|
import { SidebarNavItem } from "@/components/sidebar/sidebar-navigation";
|
||||||
// hooks
|
// hooks
|
||||||
import { useAppTheme } from "@/hooks/store/use-app-theme";
|
import { useAppTheme } from "@/hooks/store/use-app-theme";
|
||||||
import { useWorkspace } from "@/hooks/store/use-workspace";
|
|
||||||
import { useUser, useUserPermissions } from "@/hooks/store/user";
|
import { useUser, useUserPermissions } from "@/hooks/store/user";
|
||||||
// plane web imports
|
import { useWorkspaceNavigationPreferences } from "@/hooks/use-navigation-preferences";
|
||||||
// local imports
|
// local imports
|
||||||
import { UpgradeBadge } from "../upgrade-badge";
|
import { UpgradeBadge } from "../upgrade-badge";
|
||||||
import { getSidebarNavigationItemIcon } from "./helper";
|
import { getSidebarNavigationItemIcon } from "./helper";
|
||||||
|
|
@ -50,33 +49,16 @@ export const ExtendedSidebarItem = observer(function ExtendedSidebarItem(props:
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { workspaceSlug } = useParams();
|
const { workspaceSlug } = useParams();
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getNavigationPreferences, updateSidebarPreference } = useWorkspace();
|
|
||||||
const { toggleExtendedSidebar } = useAppTheme();
|
const { toggleExtendedSidebar } = useAppTheme();
|
||||||
const { data } = useUser();
|
const { data } = useUser();
|
||||||
const { allowPermissions } = useUserPermissions();
|
const { allowPermissions } = useUserPermissions();
|
||||||
|
const { preferences: workspacePreferences, toggleWorkspaceItem } = useWorkspaceNavigationPreferences();
|
||||||
|
|
||||||
// derived values
|
// derived values
|
||||||
const sidebarPreference = getNavigationPreferences(workspaceSlug.toString());
|
const isPinned = workspacePreferences.items[item.key]?.is_pinned ?? false;
|
||||||
const isPinned = sidebarPreference?.[item.key]?.is_pinned;
|
|
||||||
|
|
||||||
const handleLinkClick = () => toggleExtendedSidebar(true);
|
const handleLinkClick = () => toggleExtendedSidebar(true);
|
||||||
|
|
||||||
const itemHref =
|
|
||||||
item.key === "your_work"
|
|
||||||
? `/${workspaceSlug.toString()}${item.href}${data?.id}`
|
|
||||||
: `/${workspaceSlug.toString()}${item.href}`;
|
|
||||||
const isActive = itemHref === pathname;
|
|
||||||
|
|
||||||
const pinNavigationItem = (workspaceSlug: string, key: string) => {
|
|
||||||
updateSidebarPreference(workspaceSlug, key, { is_pinned: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
const unPinNavigationItem = (workspaceSlug: string, key: string) => {
|
|
||||||
updateSidebarPreference(workspaceSlug, key, { is_pinned: false });
|
|
||||||
};
|
|
||||||
|
|
||||||
const icon = getSidebarNavigationItemIcon(item.key);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const element = navigationIemRef.current;
|
const element = navigationIemRef.current;
|
||||||
const dragHandleElement = dragHandleRef.current;
|
const dragHandleElement = dragHandleRef.current;
|
||||||
|
|
@ -146,6 +128,22 @@ export const ExtendedSidebarItem = observer(function ExtendedSidebarItem(props:
|
||||||
);
|
);
|
||||||
}, [isLastChild, handleOnNavigationItemDrop, disableDrag, disableDrop, item.key]);
|
}, [isLastChild, handleOnNavigationItemDrop, disableDrag, disableDrop, item.key]);
|
||||||
|
|
||||||
|
const itemHref =
|
||||||
|
item.key === "your_work"
|
||||||
|
? `/${workspaceSlug.toString()}${item.href}${data?.id}`
|
||||||
|
: `/${workspaceSlug.toString()}${item.href}`;
|
||||||
|
const isActive = itemHref === pathname;
|
||||||
|
|
||||||
|
const pinNavigationItem = (key: string) => {
|
||||||
|
toggleWorkspaceItem(key, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const unPinNavigationItem = (key: string) => {
|
||||||
|
toggleWorkspaceItem(key, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const icon = getSidebarNavigationItemIcon(item.key);
|
||||||
|
|
||||||
if (!allowPermissions(item.access as any, EUserPermissionsLevel.WORKSPACE, workspaceSlug.toString())) {
|
if (!allowPermissions(item.access as any, EUserPermissionsLevel.WORKSPACE, workspaceSlug.toString())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +151,9 @@ export const ExtendedSidebarItem = observer(function ExtendedSidebarItem(props:
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
id={`sidebar-${item.key}`}
|
id={`sidebar-${item.key}`}
|
||||||
className={cn("relative", { "bg-custom-sidebar-background-80 opacity-60": isDragging })}
|
className={cn("relative", {
|
||||||
|
"bg-custom-sidebar-background-80 opacity-60": isDragging,
|
||||||
|
})}
|
||||||
ref={navigationIemRef}
|
ref={navigationIemRef}
|
||||||
>
|
>
|
||||||
<DropIndicator classNames="absolute top-0" isVisible={instruction === "DRAG_OVER"} />
|
<DropIndicator classNames="absolute top-0" isVisible={instruction === "DRAG_OVER"} />
|
||||||
|
|
@ -167,15 +167,16 @@ export const ExtendedSidebarItem = observer(function ExtendedSidebarItem(props:
|
||||||
<Tooltip
|
<Tooltip
|
||||||
// isMobile={isMobile}
|
// isMobile={isMobile}
|
||||||
tooltipContent={t("drag_to_rearrange")}
|
tooltipContent={t("drag_to_rearrange")}
|
||||||
position="top-end"
|
position="top-start"
|
||||||
disabled={isDragging}
|
disabled={isDragging}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center justify-center absolute top-1/2 -left-3 -translate-y-1/2 rounded text-custom-sidebar-text-400 cursor-grab",
|
"flex items-center justify-center absolute top-1/2 -left-3 -translate-y-1/2 rounded text-custom-sidebar-text-400 cursor-grab group-hover/project-item:opacity-100 opacity-0",
|
||||||
{
|
{
|
||||||
"cursor-grabbing": isDragging,
|
"cursor-grabbing": isDragging,
|
||||||
|
"opacity-100": isDragging,
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
ref={dragHandleRef}
|
ref={dragHandleRef}
|
||||||
|
|
@ -201,14 +202,14 @@ export const ExtendedSidebarItem = observer(function ExtendedSidebarItem(props:
|
||||||
<Tooltip tooltipContent="Unpin">
|
<Tooltip tooltipContent="Unpin">
|
||||||
<PinOff
|
<PinOff
|
||||||
className="size-3.5 flex-shrink-0 hover:text-custom-text-300 outline-none text-custom-text-400"
|
className="size-3.5 flex-shrink-0 hover:text-custom-text-300 outline-none text-custom-text-400"
|
||||||
onClick={() => unPinNavigationItem(workspaceSlug.toString(), item.key)}
|
onClick={() => unPinNavigationItem(item.key)}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
) : (
|
) : (
|
||||||
<Tooltip tooltipContent="Pin">
|
<Tooltip tooltipContent="Pin">
|
||||||
<Pin
|
<Pin
|
||||||
className="size-3.5 flex-shrink-0 hover:text-custom-text-300 outline-none text-custom-text-400"
|
className="size-3.5 flex-shrink-0 hover:text-custom-text-300 outline-none text-custom-text-400"
|
||||||
onClick={() => pinNavigationItem(workspaceSlug.toString(), item.key)}
|
onClick={() => pinNavigationItem(item.key)}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue