-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[WEB-5256]chore: quick actions refactor #8019
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
Open
vamsikrishnamathala
wants to merge
9
commits into
preview
Choose a base branch
from
chore-quick_actions_refactor
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+364
−249
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fc9e8d5
chore: quick actions refactor
vamsikrishnamathala 4e9d942
chore: lint fix
vamsikrishnamathala 33b2a79
chore: unified factory for actions
vamsikrishnamathala bc0bc86
chore: lint fix
vamsikrishnamathala ac398db
* chore: removed redundant files
vamsikrishnamathala 2eeda5a
chore: updated interfaces to types
vamsikrishnamathala ece3e39
Merge branch 'preview' of github.com:makeplane/plane into chore-quick…
vamsikrishnamathala 6f29210
chore: updated undefined handling
vamsikrishnamathala cd741d8
Merge branch 'preview' into chore-quick_actions_refactor
vamsikrishnamathala 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import type { ICycle, IModule, IProjectView, IWorkspaceView } from "@plane/types"; | ||
| import type { TContextMenuItem } from "@plane/ui"; | ||
| import { useQuickActionsFactory } from "@/components/common/quick-actions-factory"; | ||
|
|
||
| // Cycles | ||
| export interface UseCycleMenuItemsProps { | ||
| cycleDetails: ICycle; | ||
| isEditingAllowed: boolean; | ||
| workspaceSlug: string; | ||
| projectId: string; | ||
| cycleId: string; | ||
| handleEdit: () => void; | ||
| handleArchive: () => void; | ||
| handleRestore: () => void; | ||
| handleDelete: () => void; | ||
| handleCopyLink: () => void; | ||
| handleOpenInNewTab: () => void; | ||
| } | ||
|
|
||
| export const useCycleMenuItems = (props: UseCycleMenuItemsProps): MenuResult => { | ||
| const factory = useQuickActionsFactory(); | ||
| const { cycleDetails, isEditingAllowed, ...handlers } = props; | ||
|
|
||
| const isArchived = !!cycleDetails?.archived_at; | ||
| const isCompleted = cycleDetails?.status?.toLowerCase() === "completed"; | ||
|
|
||
| return { | ||
| items: [ | ||
| factory.createEditMenuItem(handlers.handleEdit, isEditingAllowed && !isCompleted && !isArchived), | ||
| factory.createOpenInNewTabMenuItem(handlers.handleOpenInNewTab), | ||
| factory.createCopyLinkMenuItem(handlers.handleCopyLink), | ||
| factory.createArchiveMenuItem(handlers.handleArchive, { | ||
| shouldRender: isEditingAllowed && !isArchived, | ||
| disabled: !isCompleted, | ||
| description: isCompleted ? undefined : "Only completed cycles can be archived", | ||
| }), | ||
| factory.createRestoreMenuItem(handlers.handleRestore, isEditingAllowed && isArchived), | ||
| factory.createDeleteMenuItem(handlers.handleDelete, isEditingAllowed && !isCompleted && !isArchived), | ||
| ], | ||
| modals: null, | ||
| }; | ||
| }; | ||
|
|
||
| // Modules | ||
| export interface UseModuleMenuItemsProps { | ||
| moduleDetails: IModule; | ||
| isEditingAllowed: boolean; | ||
| workspaceSlug: string; | ||
| projectId: string; | ||
| moduleId: string; | ||
| handleEdit: () => void; | ||
| handleArchive: () => void; | ||
| handleRestore: () => void; | ||
| handleDelete: () => void; | ||
| handleCopyLink: () => void; | ||
| handleOpenInNewTab: () => void; | ||
| } | ||
|
|
||
| export const useModuleMenuItems = (props: UseModuleMenuItemsProps): MenuResult => { | ||
| const factory = useQuickActionsFactory(); | ||
| const { moduleDetails, isEditingAllowed, ...handlers } = props; | ||
|
|
||
| const isArchived = !!moduleDetails?.archived_at; | ||
| const moduleState = moduleDetails?.status?.toLocaleLowerCase(); | ||
| const isInArchivableGroup = !!moduleState && ["completed", "cancelled"].includes(moduleState); | ||
|
|
||
| return { | ||
| items: [ | ||
| factory.createEditMenuItem(handlers.handleEdit, isEditingAllowed && !isArchived), | ||
| factory.createOpenInNewTabMenuItem(handlers.handleOpenInNewTab), | ||
| factory.createCopyLinkMenuItem(handlers.handleCopyLink), | ||
| factory.createArchiveMenuItem(handlers.handleArchive, { | ||
| shouldRender: isEditingAllowed && !isArchived, | ||
| disabled: !isInArchivableGroup, | ||
| description: isInArchivableGroup ? undefined : "Only completed or cancelled modules can be archived", | ||
| }), | ||
| factory.createRestoreMenuItem(handlers.handleRestore, isEditingAllowed && isArchived), | ||
| factory.createDeleteMenuItem(handlers.handleDelete, isEditingAllowed), | ||
| ], | ||
| modals: null, | ||
| }; | ||
| }; | ||
|
|
||
| // Views | ||
| export interface UseViewMenuItemsProps { | ||
| isOwner: boolean; | ||
| isAdmin: boolean; | ||
| workspaceSlug: string; | ||
| projectId?: string; | ||
| view: IProjectView | IWorkspaceView; | ||
| handleEdit: () => void; | ||
| handleDelete: () => void; | ||
| handleCopyLink: () => void; | ||
| handleOpenInNewTab: () => void; | ||
| } | ||
|
|
||
| export const useViewMenuItems = (props: UseViewMenuItemsProps): MenuResult => { | ||
| const factory = useQuickActionsFactory(); | ||
|
|
||
| return { | ||
| items: [ | ||
| factory.createEditMenuItem(props.handleEdit, props.isOwner), | ||
| factory.createOpenInNewTabMenuItem(props.handleOpenInNewTab), | ||
| factory.createCopyLinkMenuItem(props.handleCopyLink), | ||
| factory.createDeleteMenuItem(props.handleDelete, props.isOwner || props.isAdmin), | ||
| ], | ||
| modals: null, | ||
| }; | ||
| }; | ||
|
|
||
| export interface UseLayoutMenuItemsProps { | ||
| workspaceSlug: string; | ||
| projectId: string; | ||
| storeType: "PROJECT" | "EPIC"; | ||
| handleCopyLink: () => void; | ||
| handleOpenInNewTab: () => void; | ||
| } | ||
|
|
||
| export type MenuResult = { | ||
| items: TContextMenuItem[]; | ||
| modals: JSX.Element | null; | ||
| }; | ||
|
|
||
| export const useLayoutMenuItems = (props: UseLayoutMenuItemsProps): MenuResult => { | ||
| const factory = useQuickActionsFactory(); | ||
|
|
||
| return { | ||
| items: [ | ||
| factory.createOpenInNewTab(props.handleOpenInNewTab), | ||
| factory.createCopyLayoutLinkMenuItem(props.handleCopyLink), | ||
| ], | ||
| modals: null, | ||
| }; | ||
| }; | ||
|
|
||
| export const useIntakeHeaderMenuItems = (props: { | ||
| workspaceSlug: string; | ||
| projectId: string; | ||
| handleCopyLink: () => void; | ||
| }): MenuResult => { | ||
| const factory = useQuickActionsFactory(); | ||
|
|
||
| return { | ||
| items: [factory.createCopyLinkMenuItem(props.handleCopyLink)], | ||
| modals: null, | ||
| }; | ||
| }; | ||
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,2 +1 @@ | ||
| export * from "./modal"; | ||
| export * from "./use-end-cycle"; |
This file was deleted.
Oops, something went wrong.
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
121 changes: 121 additions & 0 deletions
121
apps/web/core/components/common/quick-actions-factory.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 |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { | ||
| Pencil, | ||
| ExternalLink, | ||
| Link, | ||
| Trash2, | ||
| ArchiveRestoreIcon, | ||
| StopCircle, | ||
| Download, | ||
| Lock, | ||
| LockOpen, | ||
| } from "lucide-react"; | ||
| import { useTranslation } from "@plane/i18n"; | ||
| import { ArchiveIcon } from "@plane/propel/icons"; | ||
| import type { TContextMenuItem } from "@plane/ui"; | ||
|
|
||
| /** | ||
| * Unified factory for creating menu items across all entities (cycles, modules, views, epics) | ||
| * Contains ALL menu item creators including EE-specific ones | ||
| */ | ||
| export const useQuickActionsFactory = () => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| return { | ||
| // Common menu items | ||
| createEditMenuItem: (handler: () => void, shouldRender: boolean = true): TContextMenuItem => ({ | ||
| key: "edit", | ||
| title: t("edit"), | ||
| icon: Pencil, | ||
| action: handler, | ||
| shouldRender, | ||
| }), | ||
|
|
||
| createOpenInNewTabMenuItem: (handler: () => void): TContextMenuItem => ({ | ||
| key: "open-new-tab", | ||
| title: t("open_in_new_tab"), | ||
| icon: ExternalLink, | ||
| action: handler, | ||
| }), | ||
|
|
||
| createCopyLinkMenuItem: (handler: () => void): TContextMenuItem => ({ | ||
| key: "copy-link", | ||
| title: t("copy_link"), | ||
| icon: Link, | ||
| action: handler, | ||
| }), | ||
vamsikrishnamathala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| createArchiveMenuItem: ( | ||
| handler: () => void, | ||
| opts: { shouldRender?: boolean; disabled?: boolean; description?: string } | ||
| ): TContextMenuItem => ({ | ||
| key: "archive", | ||
| title: t("archive"), | ||
| icon: ArchiveIcon, | ||
| action: handler, | ||
| className: "items-start", | ||
| iconClassName: "mt-1", | ||
| description: opts.description, | ||
| disabled: opts.disabled, | ||
| shouldRender: opts.shouldRender, | ||
| }), | ||
|
|
||
| createRestoreMenuItem: (handler: () => void, shouldRender: boolean = true): TContextMenuItem => ({ | ||
| key: "restore", | ||
| title: t("restore"), | ||
| icon: ArchiveRestoreIcon, | ||
| action: handler, | ||
| shouldRender, | ||
| }), | ||
|
|
||
| createDeleteMenuItem: (handler: () => void, shouldRender: boolean = true): TContextMenuItem => ({ | ||
| key: "delete", | ||
| title: t("delete"), | ||
| icon: Trash2, | ||
| action: handler, | ||
| shouldRender, | ||
| }), | ||
|
|
||
| // EE-specific menu items (defined in core but used only in EE) | ||
| createEndCycleMenuItem: (handler: () => void, shouldRender: boolean = true): TContextMenuItem => ({ | ||
| key: "end-cycle", | ||
| title: "End Cycle", | ||
| icon: StopCircle, | ||
| action: handler, | ||
| shouldRender, | ||
| }), | ||
vamsikrishnamathala marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| createExportMenuItem: (handler: () => void, shouldRender: boolean = true): TContextMenuItem => ({ | ||
| key: "export", | ||
| title: "Export", | ||
| icon: Download, | ||
| action: handler, | ||
| shouldRender, | ||
| }), | ||
|
|
||
| createLockMenuItem: ( | ||
| handler: () => void, | ||
| opts: { isLocked: boolean; shouldRender?: boolean } | ||
| ): TContextMenuItem => ({ | ||
| key: "toggle-lock", | ||
| title: opts.isLocked ? "Unlock" : "Lock", | ||
| icon: opts.isLocked ? LockOpen : Lock, | ||
| action: handler, | ||
| shouldRender: opts.shouldRender, | ||
| }), | ||
|
|
||
| // Layout-level actions (for issues/epics list views) | ||
| createOpenInNewTab: (handler: () => void): TContextMenuItem => ({ | ||
| key: "open-in-new-tab", | ||
| title: "Open in new tab", | ||
| icon: ExternalLink, | ||
| action: handler, | ||
| }), | ||
|
|
||
| createCopyLayoutLinkMenuItem: (handler: () => void): TContextMenuItem => ({ | ||
| key: "copy-link", | ||
| title: "Copy link", | ||
| icon: Link, | ||
| action: handler, | ||
| }), | ||
vamsikrishnamathala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| }; | ||
Oops, something went wrong.
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.