-
Notifications
You must be signed in to change notification settings - Fork 3.5k
refactor: favorites sidebar implementation #6716
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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,41 @@ | ||
| import { Briefcase, ContrastIcon, FileText, Layers, LucideIcon } from "lucide-react"; | ||
| // plane imports | ||
| import { IFavorite } from "@plane/types"; | ||
| import { DiceIcon, FavoriteFolderIcon, ISvgIcons } from "@plane/ui"; | ||
|
|
||
| export const FAVORITE_ITEM_ICONS: Record<string, React.FC<ISvgIcons> | LucideIcon> = { | ||
| page: FileText, | ||
| project: Briefcase, | ||
| view: Layers, | ||
| module: DiceIcon, | ||
| cycle: ContrastIcon, | ||
| folder: FavoriteFolderIcon, | ||
| }; | ||
|
|
||
| export const FAVORITE_ITEM_LINKS: { | ||
| [key: string]: { | ||
| itemLevel: "project" | "workspace"; | ||
| getLink: (favorite: IFavorite) => string; | ||
| }; | ||
| } = { | ||
| project: { | ||
| itemLevel: "project", | ||
| getLink: () => `issues`, | ||
| }, | ||
| cycle: { | ||
| itemLevel: "project", | ||
| getLink: (favorite) => `cycles/${favorite.entity_identifier}`, | ||
| }, | ||
| module: { | ||
| itemLevel: "project", | ||
| getLink: (favorite) => `modules/${favorite.entity_identifier}`, | ||
| }, | ||
| view: { | ||
| itemLevel: "project", | ||
| getLink: (favorite) => `views/${favorite.entity_identifier}`, | ||
| }, | ||
| page: { | ||
| itemLevel: "project", | ||
| getLink: (favorite) => `pages/${favorite.entity_identifier}`, | ||
| }, | ||
| }; | ||
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,26 @@ | ||
| // plane imports | ||
| import { IFavorite } from "@plane/types"; | ||
| // components | ||
| import { getFavoriteItemIcon } from "@/components/workspace/sidebar/favorites/favorite-items/common"; | ||
|
|
||
| export const useAdditionalFavoriteItemDetails = () => { | ||
| const getAdditionalFavoriteItemDetails = (_workspaceSlug: string, favorite: IFavorite) => { | ||
| const { entity_type: favoriteItemEntityType } = favorite; | ||
| const favoriteItemName = favorite?.entity_data?.name || favorite?.name; | ||
|
|
||
| let itemIcon; | ||
| let itemTitle; | ||
|
|
||
| switch (favoriteItemEntityType) { | ||
| default: | ||
| itemTitle = favoriteItemName; | ||
| itemIcon = getFavoriteItemIcon(favoriteItemEntityType); | ||
| break; | ||
| } | ||
| return { itemIcon, itemTitle }; | ||
| }; | ||
|
|
||
| return { | ||
| getAdditionalFavoriteItemDetails, | ||
| }; | ||
| }; |
71 changes: 31 additions & 40 deletions
71
web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.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,49 +1,40 @@ | ||
| "use client"; | ||
| // lucide | ||
| import { Briefcase, FileText, Layers } from "lucide-react"; | ||
| // types | ||
|
|
||
| import { FileText } from "lucide-react"; | ||
| // plane imports | ||
| import { IFavorite, TLogoProps } from "@plane/types"; | ||
| // ui | ||
| import { ContrastIcon, DiceIcon, FavoriteFolderIcon } from "@plane/ui"; | ||
| // components | ||
| import { Logo } from "@/components/common"; | ||
| // plane web constants | ||
| import { FAVORITE_ITEM_ICONS, FAVORITE_ITEM_LINKS } from "@/plane-web/constants"; | ||
|
|
||
| const iconClassName = `flex-shrink-0 size-4 stroke-[1.5] m-auto`; | ||
| export const getFavoriteItemIcon = (type: string, logo?: TLogoProps | undefined) => { | ||
| const Icon = FAVORITE_ITEM_ICONS[type] || FileText; | ||
|
|
||
| export const FAVORITE_ITEM_ICON: Record<string, JSX.Element> = { | ||
| page: <FileText className={iconClassName} />, | ||
| project: <Briefcase className={iconClassName} />, | ||
| view: <Layers className={iconClassName} />, | ||
| module: <DiceIcon className={iconClassName} />, | ||
| cycle: <ContrastIcon className={iconClassName} />, | ||
| folder: <FavoriteFolderIcon className={iconClassName} />, | ||
| }; | ||
|
|
||
| export const getFavoriteItemIcon = (type: string, logo?: TLogoProps | undefined) => ( | ||
| <> | ||
| <div className="hidden group-hover:flex items-center justify-center size-5"> | ||
| {FAVORITE_ITEM_ICON[type] || <FileText className={iconClassName} />} | ||
| </div> | ||
| <div className="flex items-center justify-center size-5 group-hover:hidden"> | ||
| {logo?.in_use ? ( | ||
| <Logo logo={logo} size={16} type={type === "project" ? "material" : "lucide"} /> | ||
| ) : ( | ||
| FAVORITE_ITEM_ICON[type] || <FileText className={iconClassName} /> | ||
| )} | ||
| </div> | ||
| </> | ||
| ); | ||
|
|
||
| const entityPaths: Record<string, string> = { | ||
| project: "issues", | ||
| cycle: "cycles", | ||
| module: "modules", | ||
| view: "views", | ||
| page: "pages", | ||
| return ( | ||
| <> | ||
| <div className="hidden group-hover:flex items-center justify-center size-5"> | ||
| <Icon className="flex-shrink-0 size-4 stroke-[1.5] m-auto" /> | ||
| </div> | ||
| <div className="flex items-center justify-center size-5 group-hover:hidden"> | ||
| {logo?.in_use ? ( | ||
| <Logo logo={logo} size={16} type={type === "project" ? "material" : "lucide"} /> | ||
| ) : ( | ||
| <Icon className="flex-shrink-0 size-4 stroke-[1.5] m-auto" /> | ||
| )} | ||
| </div> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export const generateFavoriteItemLink = (workspaceSlug: string, favorite: IFavorite) => { | ||
| const entityPath = entityPaths[favorite.entity_type]; | ||
| return entityPath | ||
| ? `/${workspaceSlug}/projects/${favorite.project_id}/${entityPath}/${entityPath === "issues" ? "" : favorite.entity_identifier || ""}` | ||
| : `/${workspaceSlug}`; | ||
| const entityLinkDetails = FAVORITE_ITEM_LINKS[favorite.entity_type]; | ||
aaryan610 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (entityLinkDetails.itemLevel === "workspace") { | ||
| return `/${workspaceSlug}/${entityLinkDetails.getLink(favorite)}`; | ||
| } else if (entityLinkDetails.itemLevel === "project") { | ||
| return `/${workspaceSlug}/projects/${favorite.project_id}/${entityLinkDetails.getLink(favorite)}`; | ||
| } else { | ||
| return `/${workspaceSlug}`; | ||
| } | ||
| }; | ||
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
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 @@ | ||
| export * from "./sidebar-favorites"; |
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 @@ | ||
| export * from "ce/constants/sidebar-favorites"; |
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 @@ | ||
| export * from "ce/hooks/use-additional-favorite-item-details"; |
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.