-
Notifications
You must be signed in to change notification settings - Fork 3.6k
refactor: enhance command palette modularity #6139
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
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export type TCommandPaletteActionList = Record< | ||
| string, | ||
| { title: string; description: string; action: () => void } | ||
| >; | ||
|
|
||
| export type TCommandPaletteShortcutList = { | ||
| key: string; | ||
| title: string; | ||
| shortcuts: TCommandPaletteShortcut[]; | ||
| }; | ||
|
|
||
| export type TCommandPaletteShortcut = { | ||
| keys: string; // comma separated keys | ||
| description: string; | ||
| }; |
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,3 @@ | ||
| export * from "./workspace-level"; | ||
| export * from "./project-level"; | ||
| export * from "./issue-level"; |
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,73 @@ | ||
| import { observer } from "mobx-react"; | ||
| import { useParams, usePathname } from "next/navigation"; | ||
| import useSWR from "swr"; | ||
| // components | ||
| import { BulkDeleteIssuesModal } from "@/components/core"; | ||
| import { CreateUpdateIssueModal, DeleteIssueModal } from "@/components/issues"; | ||
| // constants | ||
| import { ISSUE_DETAILS } from "@/constants/fetch-keys"; | ||
| // hooks | ||
| import { useCommandPalette, useUser } from "@/hooks/store"; | ||
| import { useAppRouter } from "@/hooks/use-app-router"; | ||
| import { useIssuesStore } from "@/hooks/use-issue-layout-store"; | ||
| // services | ||
| import { IssueService } from "@/services/issue"; | ||
|
|
||
| // services | ||
| const issueService = new IssueService(); | ||
|
|
||
| export const IssueLevelModals = observer(() => { | ||
| // router | ||
| const pathname = usePathname(); | ||
| const { workspaceSlug, projectId, issueId, cycleId, moduleId } = useParams(); | ||
| const router = useAppRouter(); | ||
| // store hooks | ||
| const { data: currentUser } = useUser(); | ||
| const { | ||
| issues: { removeIssue }, | ||
| } = useIssuesStore(); | ||
| const { | ||
| isCreateIssueModalOpen, | ||
| toggleCreateIssueModal, | ||
| isDeleteIssueModalOpen, | ||
| toggleDeleteIssueModal, | ||
| isBulkDeleteIssueModalOpen, | ||
| toggleBulkDeleteIssueModal, | ||
| } = useCommandPalette(); | ||
| // derived values | ||
| const isDraftIssue = pathname?.includes("draft-issues") || false; | ||
|
|
||
| const { data: issueDetails } = useSWR( | ||
| workspaceSlug && projectId && issueId ? ISSUE_DETAILS(issueId as string) : null, | ||
| workspaceSlug && projectId && issueId | ||
| ? () => issueService.retrieve(workspaceSlug as string, projectId as string, issueId as string) | ||
| : null | ||
| ); | ||
prateekshourya29 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <> | ||
| <CreateUpdateIssueModal | ||
| isOpen={isCreateIssueModalOpen} | ||
| onClose={() => toggleCreateIssueModal(false)} | ||
| data={cycleId ? { cycle_id: cycleId.toString() } : moduleId ? { module_ids: [moduleId.toString()] } : undefined} | ||
| isDraft={isDraftIssue} | ||
| /> | ||
| {workspaceSlug && projectId && issueId && issueDetails && ( | ||
| <DeleteIssueModal | ||
| handleClose={() => toggleDeleteIssueModal(false)} | ||
| isOpen={isDeleteIssueModalOpen} | ||
| data={issueDetails} | ||
| onSubmit={async () => { | ||
| await removeIssue(workspaceSlug.toString(), projectId.toString(), issueId.toString()); | ||
| router.push(`/${workspaceSlug}/projects/${projectId}/issues`); | ||
| }} | ||
prateekshourya29 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| )} | ||
| <BulkDeleteIssuesModal | ||
| isOpen={isBulkDeleteIssueModalOpen} | ||
| onClose={() => toggleBulkDeleteIssueModal(false)} | ||
| user={currentUser} | ||
| /> | ||
| </> | ||
| ); | ||
| }); | ||
59 changes: 59 additions & 0 deletions
59
web/ce/components/command-palette/modals/project-level.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,59 @@ | ||
| import { observer } from "mobx-react"; | ||
| // components | ||
| import { CycleCreateUpdateModal } from "@/components/cycles"; | ||
| import { CreateUpdateModuleModal } from "@/components/modules"; | ||
| import { CreatePageModal } from "@/components/pages"; | ||
| import { CreateUpdateProjectViewModal } from "@/components/views"; | ||
| // hooks | ||
| import { useCommandPalette } from "@/hooks/store"; | ||
|
|
||
| export type TProjectLevelModalsProps = { | ||
| workspaceSlug: string; | ||
| projectId: string; | ||
| }; | ||
|
|
||
| export const ProjectLevelModals = observer((props: TProjectLevelModalsProps) => { | ||
| const { workspaceSlug, projectId } = props; | ||
| // store hooks | ||
| const { | ||
| isCreateCycleModalOpen, | ||
| toggleCreateCycleModal, | ||
| isCreateModuleModalOpen, | ||
| toggleCreateModuleModal, | ||
| isCreateViewModalOpen, | ||
| toggleCreateViewModal, | ||
| createPageModal, | ||
| toggleCreatePageModal, | ||
| } = useCommandPalette(); | ||
|
|
||
| return ( | ||
| <> | ||
| <CycleCreateUpdateModal | ||
| isOpen={isCreateCycleModalOpen} | ||
| handleClose={() => toggleCreateCycleModal(false)} | ||
| workspaceSlug={workspaceSlug.toString()} | ||
| projectId={projectId.toString()} | ||
| /> | ||
| <CreateUpdateModuleModal | ||
| isOpen={isCreateModuleModalOpen} | ||
| onClose={() => toggleCreateModuleModal(false)} | ||
| workspaceSlug={workspaceSlug.toString()} | ||
| projectId={projectId.toString()} | ||
| /> | ||
| <CreateUpdateProjectViewModal | ||
| isOpen={isCreateViewModalOpen} | ||
| onClose={() => toggleCreateViewModal(false)} | ||
| workspaceSlug={workspaceSlug.toString()} | ||
| projectId={projectId.toString()} | ||
| /> | ||
| <CreatePageModal | ||
| workspaceSlug={workspaceSlug.toString()} | ||
| projectId={projectId.toString()} | ||
| isModalOpen={createPageModal.isOpen} | ||
| pageAccess={createPageModal.pageAccess} | ||
| handleModalClose={() => toggleCreatePageModal({ isOpen: false })} | ||
| redirectionEnabled | ||
| /> | ||
| </> | ||
| ); | ||
| }); |
25 changes: 25 additions & 0 deletions
25
web/ce/components/command-palette/modals/workspace-level.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,25 @@ | ||
| import { observer } from "mobx-react"; | ||
| // components | ||
| import { CreateProjectModal } from "@/components/project"; | ||
| // hooks | ||
| import { useCommandPalette } from "@/hooks/store"; | ||
|
|
||
| export type TWorkspaceLevelModalsProps = { | ||
| workspaceSlug: string; | ||
| }; | ||
|
|
||
| export const WorkspaceLevelModals = observer((props: TWorkspaceLevelModalsProps) => { | ||
| const { workspaceSlug } = props; | ||
| // store hooks | ||
| const { isCreateProjectModalOpen, toggleCreateProjectModal } = useCommandPalette(); | ||
|
|
||
| return ( | ||
| <> | ||
| <CreateProjectModal | ||
| isOpen={isCreateProjectModalOpen} | ||
| onClose={() => toggleCreateProjectModal(false)} | ||
| workspaceSlug={workspaceSlug.toString()} | ||
| /> | ||
| </> | ||
| ); | ||
| }); |
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,95 @@ | ||
| // types | ||
| import { TCommandPaletteActionList, TCommandPaletteShortcut, TCommandPaletteShortcutList } from "@plane/types"; | ||
| // store | ||
| import { store } from "@/lib/store-context"; | ||
|
|
||
| export const getGlobalShortcutsList: () => TCommandPaletteActionList = () => { | ||
| const { toggleCreateIssueModal } = store.commandPalette; | ||
|
|
||
| return { | ||
| c: { | ||
| title: "Create a new issue", | ||
| description: "Create a new issue in the current project", | ||
| action: () => toggleCreateIssueModal(true), | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| export const getWorkspaceShortcutsList: () => TCommandPaletteActionList = () => { | ||
| const { toggleCreateProjectModal } = store.commandPalette; | ||
|
|
||
| return { | ||
| p: { | ||
| title: "Create a new project", | ||
| description: "Create a new project in the current workspace", | ||
| action: () => toggleCreateProjectModal(true), | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| export const getProjectShortcutsList: () => TCommandPaletteActionList = () => { | ||
| const { | ||
| toggleCreatePageModal, | ||
| toggleCreateModuleModal, | ||
| toggleCreateCycleModal, | ||
| toggleCreateViewModal, | ||
| toggleBulkDeleteIssueModal, | ||
| } = store.commandPalette; | ||
|
|
||
| return { | ||
| d: { | ||
| title: "Create a new page", | ||
| description: "Create a new page in the current project", | ||
| action: () => toggleCreatePageModal({ isOpen: true }), | ||
| }, | ||
| m: { | ||
| title: "Create a new module", | ||
| description: "Create a new module in the current project", | ||
| action: () => toggleCreateModuleModal(true), | ||
| }, | ||
| q: { | ||
| title: "Create a new cycle", | ||
| description: "Create a new cycle in the current project", | ||
| action: () => toggleCreateCycleModal(true), | ||
| }, | ||
| v: { | ||
| title: "Create a new view", | ||
| description: "Create a new view in the current project", | ||
| action: () => toggleCreateViewModal(true), | ||
| }, | ||
| backspace: { | ||
| title: "Bulk delete issues", | ||
| description: "Bulk delete issues in the current project", | ||
| action: () => toggleBulkDeleteIssueModal(true), | ||
| }, | ||
| delete: { | ||
| title: "Bulk delete issues", | ||
| description: "Bulk delete issues in the current project", | ||
| action: () => toggleBulkDeleteIssueModal(true), | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| export const handleAdditionalKeyDownEvents = (e: KeyboardEvent) => null; | ||
prateekshourya29 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const getNavigationShortcutsList = (): TCommandPaletteShortcut[] => [ | ||
| { keys: "Ctrl,K", description: "Open command menu" }, | ||
| ]; | ||
|
|
||
| export const getCommonShortcutsList = (platform: string): TCommandPaletteShortcut[] => [ | ||
| { keys: "P", description: "Create project" }, | ||
| { keys: "C", description: "Create issue" }, | ||
| { keys: "Q", description: "Create cycle" }, | ||
| { keys: "M", description: "Create module" }, | ||
| { keys: "V", description: "Create view" }, | ||
| { keys: "D", description: "Create page" }, | ||
| { keys: "Delete", description: "Bulk delete issues" }, | ||
| { keys: "Shift,/", description: "Open shortcuts guide" }, | ||
| { | ||
| keys: platform === "MacOS" ? "Ctrl,control,C" : "Ctrl,Alt,C", | ||
| description: "Copy issue URL from the issue details page", | ||
| }, | ||
| ]; | ||
|
|
||
| export const getAdditionalShortcutsList = (): TCommandPaletteShortcutList[] => []; | ||
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,12 @@ | ||
| import { makeObservable } from "mobx"; | ||
| // types / constants | ||
| import { BaseCommandPaletteStore, IBaseCommandPaletteStore } from "@/store/base-command-palette.store"; | ||
|
|
||
| export type ICommandPaletteStore = IBaseCommandPaletteStore; | ||
|
|
||
| export class CommandPaletteStore extends BaseCommandPaletteStore implements ICommandPaletteStore { | ||
| constructor() { | ||
| super(); | ||
| makeObservable(this, {}); | ||
| } | ||
| } |
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.