Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions apps/web/core/components/navigation/top-nav-power-k.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { cn } from "@plane/utils";
// power-k
import type { TPowerKCommandConfig, TPowerKContext } from "@/components/power-k/core/types";
import { ProjectsAppPowerKCommandsList } from "@/components/power-k/ui/modal/commands-list";
import { powerKCommandFilter } from "@/components/power-k/ui/modal/filter";
import { PowerKModalFooter } from "@/components/power-k/ui/modal/footer";
import { useIssueDetail } from "@/hooks/store/use-issue-detail";
import { usePowerK } from "@/hooks/store/use-power-k";
Expand Down Expand Up @@ -256,11 +257,7 @@ export const TopNavPowerK = observer(() => {
>
{isOpen && (
<Command
filter={(i18nValue: string, search: string) => {
if (i18nValue === "no-results") return 1;
if (i18nValue.toLowerCase().includes(search.toLowerCase())) return 1;
return 0;
}}
filter={powerKCommandFilter}
shouldFilter={searchTerm.length > 0}
className="flex h-full w-full flex-col"
>
Expand Down
28 changes: 28 additions & 0 deletions apps/web/core/components/power-k/ui/modal/filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/

/**
* Prefix marking a `Command.Item` whose match was decided by the search API
* rather than by the text cmdk can see.
*/
export const POWER_K_SERVER_RESULT_PREFIX = "server-result:";

/**
* Filter for the Power-K palette.
*
* Static commands still match on their visible label. Server-driven search
* results are passed through untouched: the API matched them against fields
* the palette never renders — a work item's description, for one — so
* re-filtering here on the visible title would silently discard exactly the
* results the search was meant to surface. It would also drop multi-word
* matches whose words are not adjacent in the title, since this is a
* contiguous substring test.
*/
export const powerKCommandFilter = (value: string, search: string): number => {
if (value === "no-results") return 1;
if (value.startsWith(POWER_K_SERVER_RESULT_PREFIX)) return 1;
return value.toLowerCase().includes(search.toLowerCase()) ? 1 : 0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { IWorkspaceSearchResults } from "@plane/types";
import { useAppRouter } from "@/hooks/use-app-router";
// helpers
import { PowerKModalCommandItem } from "./command-item";
import { POWER_K_SERVER_RESULT_PREFIX } from "./filter";
import { POWER_K_SEARCH_RESULTS_GROUPS_MAP } from "./search-results-map";

type Props = {
Expand Down Expand Up @@ -40,7 +41,7 @@ export const PowerKModalSearchResults = observer(function PowerKModalSearchResul
return (
<Command.Group key={key} heading={currentSection.title}>
{section.map((item) => {
let value = `${key}-${item?.id}-${item.name}`;
let value = `${POWER_K_SERVER_RESULT_PREFIX}${key}-${item?.id}-${item.name}`;

if ("project__identifier" in item) {
value = `${value}-${item.project__identifier}`;
Expand Down
7 changes: 2 additions & 5 deletions apps/web/core/components/power-k/ui/modal/wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { usePowerK } from "@/hooks/store/use-power-k";
// local imports
import type { TPowerKCommandConfig, TPowerKContext } from "../../core/types";
import type { TPowerKCommandsListProps } from "./commands-list";
import { powerKCommandFilter } from "./filter";
import { PowerKModalFooter } from "./footer";
import { PowerKModalHeader } from "./header";

Expand Down Expand Up @@ -145,11 +146,7 @@ export const ProjectsAppPowerKModalWrapper = observer(function ProjectsAppPowerK
>
<Dialog.Panel className="divide-opacity-10 relative flex w-full max-w-2xl transform flex-col items-center justify-center divide-y divide-subtle-1 rounded-lg bg-surface-1 shadow-raised-200 transition-all">
<Command
filter={(i18nValue: string, search: string) => {
if (i18nValue === "no-results") return 1;
if (i18nValue.toLowerCase().includes(search.toLowerCase())) return 1;
return 0;
}}
filter={powerKCommandFilter}
shouldFilter={searchTerm.length > 0}
onKeyDown={handleKeyDown}
className="w-full"
Expand Down