Skip to content

Commit 1bf683e

Browse files
improvement: command palette search results (#6761)
1 parent 8071486 commit 1bf683e

6 files changed

Lines changed: 27 additions & 15 deletions

File tree

packages/constants/src/workspace.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TStaticViewTypes } from "@plane/types";
1+
import { TStaticViewTypes, IWorkspaceSearchResults } from "@plane/types";
22
import { EUserWorkspaceRoles } from "./user";
33

44
export const ORGANIZATION_SIZE = [
@@ -324,3 +324,15 @@ export const WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS_LINKS: IWorkspaceSidebarN
324324
WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS["inbox"],
325325
WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS["projects"],
326326
];
327+
328+
export const WORKSPACE_DEFAULT_SEARCH_RESULT: IWorkspaceSearchResults = {
329+
results: {
330+
workspace: [],
331+
project: [],
332+
issue: [],
333+
cycle: [],
334+
module: [],
335+
issue_view: [],
336+
page: [],
337+
},
338+
};

web/core/components/command-palette/helpers.tsx renamed to web/ce/components/command-palette/helpers.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import { generateWorkItemLink } from "@/helpers/issue.helper";
1616
// plane web components
1717
import { IssueIdentifier } from "@/plane-web/components/issues";
1818

19-
export const commandGroups: {
19+
export type TCommandGroups = {
2020
[key: string]: {
2121
icon: JSX.Element | null;
2222
itemName: (item: any) => React.ReactNode;
2323
path: (item: any, projectId: string | undefined) => string;
2424
title: string;
2525
};
26-
} = {
26+
};
27+
28+
export const commandGroups: TCommandGroups = {
2729
cycle: {
2830
icon: <ContrastIcon className="h-3 w-3" />,
2931
itemName: (cycle: IWorkspaceDefaultSearchResult) => (
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./actions";
2+
export * from "./modals";
3+
export * from "./helpers";

web/core/components/command-palette/actions/search-results.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import { Command } from "cmdk";
44
import { useParams } from "next/navigation";
5-
// types
5+
// plane imports
66
import { IWorkspaceSearchResults } from "@plane/types";
7-
// helpers
8-
import { commandGroups } from "@/components/command-palette";
97
// hooks
108
import { useAppRouter } from "@/hooks/use-app-router";
9+
// plane web imports
10+
import { commandGroups } from "@/plane-web/components/command-palette";
1111

1212
type Props = {
1313
closePalette: () => void;
@@ -25,9 +25,9 @@ export const CommandPaletteSearchResults: React.FC<Props> = (props) => {
2525
return (
2626
<>
2727
{Object.keys(results.results).map((key) => {
28+
// TODO: add type for results
2829
const section = (results.results as any)[key];
2930
const currentSection = commandGroups[key];
30-
3131
if (!currentSection) return null;
3232
if (section.length > 0) {
3333
return (

web/core/components/command-palette/command-modal.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useSWR from "swr";
88
import { CommandIcon, FolderPlus, Search, Settings, X } from "lucide-react";
99
import { Dialog, Transition } from "@headlessui/react";
1010
// plane imports
11-
import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
11+
import { EUserPermissions, EUserPermissionsLevel, WORKSPACE_DEFAULT_SEARCH_RESULT } from "@plane/constants";
1212
import { useTranslation } from "@plane/i18n";
1313
import { IWorkspaceSearchResults } from "@plane/types";
1414
import { LayersIcon, Loader, ToggleSwitch } from "@plane/ui";
@@ -58,9 +58,7 @@ export const CommandModal: React.FC = observer(() => {
5858
const [isLoading, setIsLoading] = useState(false);
5959
const [isSearching, setIsSearching] = useState(false);
6060
const [searchTerm, setSearchTerm] = useState("");
61-
const [results, setResults] = useState<IWorkspaceSearchResults>({
62-
results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] },
63-
});
61+
const [results, setResults] = useState<IWorkspaceSearchResults>(WORKSPACE_DEFAULT_SEARCH_RESULT);
6462
const [isWorkspaceLevel, setIsWorkspaceLevel] = useState(false);
6563
const [pages, setPages] = useState<string[]>([]);
6664
const [searchInIssue, setSearchInIssue] = useState(false);
@@ -151,9 +149,7 @@ export const CommandModal: React.FC = observer(() => {
151149
setIsSearching(false);
152150
});
153151
} else {
154-
setResults({
155-
results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] },
156-
});
152+
setResults(WORKSPACE_DEFAULT_SEARCH_RESULT);
157153
setIsLoading(false);
158154
setIsSearching(false);
159155
}

web/core/components/command-palette/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ export * from "./actions";
22
export * from "./shortcuts-modal";
33
export * from "./command-modal";
44
export * from "./command-palette";
5-
export * from "./helpers";

0 commit comments

Comments
 (0)