-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-4779] chore: app sidebar wrapper component for consistency and reusability #7655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
529e6f4
chore: app sidebar ui enhancements and code refactor
anmolsinghbhatia 10821c0
Merge branch 'preview' of github.com:makeplane/plane into chore-app-s…
anmolsinghbhatia 1c24479
chore: code refactor
anmolsinghbhatia 7e5e6ae
chore: code refactor
anmolsinghbhatia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 11 additions & 61 deletions
72
apps/web/app/(all)/[workspaceSlug]/(projects)/sidebar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,92 +1,42 @@ | ||
| import { FC, useEffect, useRef } from "react"; | ||
| import { FC } from "react"; | ||
| import isEmpty from "lodash/isEmpty"; | ||
| import { observer } from "mobx-react"; | ||
| // plane helpers | ||
| import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants"; | ||
| import { useOutsideClickDetector } from "@plane/hooks"; | ||
| // components | ||
| import { AppSidebarToggleButton } from "@/components/sidebar/sidebar-toggle-button"; | ||
| import { SidebarDropdown } from "@/components/workspace/sidebar/dropdown"; | ||
| import { SidebarWrapper } from "@/components/sidebar/sidebar-wrapper"; | ||
| import { SidebarFavoritesMenu } from "@/components/workspace/sidebar/favorites/favorites-menu"; | ||
| import { HelpMenu } from "@/components/workspace/sidebar/help-menu"; | ||
| import { SidebarProjectsList } from "@/components/workspace/sidebar/projects-list"; | ||
| import { SidebarQuickActions } from "@/components/workspace/sidebar/quick-actions"; | ||
| import { SidebarMenuItems } from "@/components/workspace/sidebar/sidebar-menu-items"; | ||
| // hooks | ||
| import { useAppTheme } from "@/hooks/store/use-app-theme"; | ||
| import { useFavorite } from "@/hooks/store/use-favorite"; | ||
| import { useUserPermissions } from "@/hooks/store/user"; | ||
| import { useAppRail } from "@/hooks/use-app-rail"; | ||
| import useSize from "@/hooks/use-window-size"; | ||
| // plane web components | ||
| import { WorkspaceEditionBadge } from "@/plane-web/components/workspace/edition-badge"; | ||
| import { SidebarTeamsList } from "@/plane-web/components/workspace/sidebar/teams-sidebar-list"; | ||
|
|
||
| export const AppSidebar: FC = observer(() => { | ||
| // store hooks | ||
| const { allowPermissions } = useUserPermissions(); | ||
| const { toggleSidebar, sidebarCollapsed } = useAppTheme(); | ||
| const { shouldRenderAppRail, isEnabled: isAppRailEnabled } = useAppRail(); | ||
| const { groupedFavorites } = useFavorite(); | ||
| const windowSize = useSize(); | ||
| // refs | ||
| const ref = useRef<HTMLDivElement>(null); | ||
|
|
||
| // derived values | ||
| const canPerformWorkspaceMemberActions = allowPermissions( | ||
| [EUserPermissions.ADMIN, EUserPermissions.MEMBER], | ||
| EUserPermissionsLevel.WORKSPACE | ||
| ); | ||
|
|
||
| useOutsideClickDetector(ref, () => { | ||
| if (sidebarCollapsed === false) { | ||
| if (window.innerWidth < 768) { | ||
| toggleSidebar(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (windowSize[0] < 768 && !sidebarCollapsed) toggleSidebar(); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [windowSize]); | ||
|
|
||
| const isFavoriteEmpty = isEmpty(groupedFavorites); | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex flex-col gap-3 px-3"> | ||
| {/* Workspace switcher and settings */} | ||
| {!shouldRenderAppRail && <SidebarDropdown />} | ||
|
|
||
| {isAppRailEnabled && ( | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <span className="text-md text-custom-text-200 font-medium pt-1">Projects</span> | ||
| <div className="flex items-center gap-2"> | ||
| <AppSidebarToggleButton /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| {/* Quick actions */} | ||
| <SidebarQuickActions /> | ||
| </div> | ||
| <div className="flex flex-col gap-3 overflow-x-hidden scrollbar-sm h-full w-full overflow-y-auto vertical-scrollbar px-3 pt-3 pb-0.5"> | ||
| <SidebarMenuItems /> | ||
| {/* Favorites Menu */} | ||
| {canPerformWorkspaceMemberActions && !isFavoriteEmpty && <SidebarFavoritesMenu />} | ||
| {/* Teams List */} | ||
| <SidebarTeamsList /> | ||
| {/* Projects List */} | ||
| <SidebarProjectsList /> | ||
| </div> | ||
| {/* Help Section */} | ||
| <div className="flex items-center justify-between p-3 border-t border-custom-border-200 bg-custom-sidebar-background-100 h-12"> | ||
| <WorkspaceEditionBadge /> | ||
| <div className="flex items-center gap-2"> | ||
| {!shouldRenderAppRail && <HelpMenu />} | ||
| {!isAppRailEnabled && <AppSidebarToggleButton />} | ||
| </div> | ||
| </div> | ||
| </> | ||
| <SidebarWrapper title="Projects" quickActions={<SidebarQuickActions />}> | ||
| <SidebarMenuItems /> | ||
| {/* Favorites Menu */} | ||
| {canPerformWorkspaceMemberActions && !isFavoriteEmpty && <SidebarFavoritesMenu />} | ||
| {/* Teams List */} | ||
| <SidebarTeamsList /> | ||
| {/* Projects List */} | ||
| <SidebarProjectsList /> | ||
| </SidebarWrapper> | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { FC, useEffect, useRef } from "react"; | ||
| import { observer } from "mobx-react"; | ||
| // plane helpers | ||
| import { useOutsideClickDetector } from "@plane/hooks"; | ||
| // components | ||
| import { AppSidebarToggleButton } from "@/components/sidebar/sidebar-toggle-button"; | ||
| import { SidebarDropdown } from "@/components/workspace/sidebar/dropdown"; | ||
| import { HelpMenu } from "@/components/workspace/sidebar/help-menu"; | ||
| // hooks | ||
| import { useAppTheme } from "@/hooks/store/use-app-theme"; | ||
| import { useAppRail } from "@/hooks/use-app-rail"; | ||
| import useSize from "@/hooks/use-window-size"; | ||
| // plane web components | ||
| import { WorkspaceEditionBadge } from "@/plane-web/components/workspace/edition-badge"; | ||
|
|
||
| type TSidebarWrapperProps = { | ||
| title: string; | ||
| children: React.ReactNode; | ||
| quickActions?: React.ReactNode; | ||
| }; | ||
|
|
||
| export const SidebarWrapper: FC<TSidebarWrapperProps> = observer((props) => { | ||
| const { children, title, quickActions } = props; | ||
| // store hooks | ||
| const { toggleSidebar, sidebarCollapsed } = useAppTheme(); | ||
| const { shouldRenderAppRail, isEnabled: isAppRailEnabled } = useAppRail(); | ||
| const windowSize = useSize(); | ||
| // refs | ||
| const ref = useRef<HTMLDivElement>(null); | ||
|
|
||
| useOutsideClickDetector(ref, () => { | ||
| if (sidebarCollapsed === false && window.innerWidth < 768) { | ||
| toggleSidebar(); | ||
| } | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (windowSize[0] < 768 && !sidebarCollapsed) toggleSidebar(); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [windowSize]); | ||
|
|
||
| return ( | ||
| <div ref={ref} className="flex flex-col h-full w-full"> | ||
| <div className="flex flex-col gap-3 px-3"> | ||
| {/* Workspace switcher and settings */} | ||
| {!shouldRenderAppRail && <SidebarDropdown />} | ||
|
|
||
| {isAppRailEnabled && ( | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <span className="text-md text-custom-text-200 font-medium pt-1">{title}</span> | ||
| <div className="flex items-center gap-2"> | ||
| <AppSidebarToggleButton /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| {/* Quick actions */} | ||
| {quickActions} | ||
| </div> | ||
| <div className="flex flex-col gap-3 overflow-x-hidden scrollbar-sm h-full w-full overflow-y-auto vertical-scrollbar px-3 pt-3 pb-0.5"> | ||
| {children} | ||
| </div> | ||
| {/* Help Section */} | ||
| <div className="flex items-center justify-between p-3 border-t border-custom-border-200 bg-custom-sidebar-background-100 h-12"> | ||
| <WorkspaceEditionBadge /> | ||
| <div className="flex items-center gap-2"> | ||
| {!shouldRenderAppRail && <HelpMenu />} | ||
| {!isAppRailEnabled && <AppSidebarToggleButton />} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.