Skip to content

Commit e72c5b8

Browse files
fix(ui): stop archived and deleted tasks from showing in global search (#3162)
Co-authored-by: Charles Vien <charles.v@posthog.com>
1 parent 2cdb169 commit e72c5b8

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

packages/ui/src/features/command/CommandMenu.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ChartLine,
55
EnvelopeSimple,
66
} from "@phosphor-icons/react";
7+
import { workspaceIdSet } from "@posthog/core/command-center/eligibility";
78
import { resolveService } from "@posthog/di/container";
89
import {
910
HOST_TRPC_CLIENT,
@@ -28,6 +29,7 @@ import {
2829
type CommandMenuAction,
2930
} from "@posthog/shared/analytics-events";
3031
import type { Task } from "@posthog/shared/domain-types";
32+
import { useArchivedTaskIds } from "@posthog/ui/features/archive/useArchivedTaskIds";
3133
import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";
3234
import { useTaskChannelMap } from "@posthog/ui/features/canvas/hooks/useTaskChannelMap";
3335
import { useReviewNavigationStore } from "@posthog/ui/features/code-review/reviewNavigationStore";
@@ -40,6 +42,7 @@ import {
4042
import { useFileSearchContext } from "@posthog/ui/features/command/useFileSearchContext";
4143
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
4244
import { useFolders } from "@posthog/ui/features/folders/useFolders";
45+
import { useProvisioningStore } from "@posthog/ui/features/provisioning/store";
4346
import {
4447
closeSettings,
4548
openSettings,
@@ -48,6 +51,7 @@ import { TaskIcon } from "@posthog/ui/features/sidebar/components/items/TaskIcon
4851
import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";
4952
import { useTaskPrStatus } from "@posthog/ui/features/sidebar/useTaskPrStatus";
5053
import { useTasks } from "@posthog/ui/features/tasks/useTasks";
54+
import { useWorkspaces } from "@posthog/ui/features/workspace/useWorkspace";
5155
import {
5256
goBackInHistory,
5357
goForwardInHistory,
@@ -152,6 +156,11 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
152156
(state) => state.getReviewMode,
153157
);
154158
const { data: tasks = [] } = useTasks();
159+
const archivedTaskIds = useArchivedTaskIds();
160+
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
161+
const provisioningTaskIds = useProvisioningStore(
162+
(state) => state.activeTasks,
163+
);
155164
const [query, setQuery] = useState("");
156165
const { repoPath } = useFileSearchContext();
157166
const canSearchFiles = !!repoPath;
@@ -447,11 +456,19 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
447456
]);
448457

449458
const taskSections = useMemo<CommandSection[]>(() => {
450-
if (tasks.length === 0) return [];
459+
const workspaceIds = workspaceIdSet(workspaces);
460+
const visibleTasks = tasks.filter(
461+
(task) =>
462+
!archivedTaskIds.has(task.id) &&
463+
(!workspacesFetched ||
464+
workspaceIds.has(task.id) ||
465+
provisioningTaskIds.has(task.id)),
466+
);
467+
if (visibleTasks.length === 0) return [];
451468
return [
452469
{
453470
label: "Tasks",
454-
items: tasks.map((task) => {
471+
items: visibleTasks.map((task) => {
455472
const channel = taskChannelMap.get(task.id);
456473
return {
457474
id: `task-${task.id}`,
@@ -477,7 +494,16 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
477494
}),
478495
},
479496
];
480-
}, [tasks, taskChannelMap, bluebirdEnabled, closeSettingsDialog]);
497+
}, [
498+
tasks,
499+
archivedTaskIds,
500+
workspaces,
501+
workspacesFetched,
502+
provisioningTaskIds,
503+
taskChannelMap,
504+
bluebirdEnabled,
505+
closeSettingsDialog,
506+
]);
481507

482508
const channelSections = useMemo<CommandSection[]>(() => {
483509
if (channels.length === 0) return [];

0 commit comments

Comments
 (0)