Skip to content
Open
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
25 changes: 22 additions & 3 deletions packages/ui/src/features/command/CommandMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
EnvelopeSimple,
HashIcon,
} from "@phosphor-icons/react";
import { workspaceIdSet } from "@posthog/core/command-center/eligibility";
import {
Autocomplete,
AutocompleteCollection,
Expand All @@ -23,6 +24,7 @@ import {
type CommandMenuAction,
} from "@posthog/shared/analytics-events";
import type { Task } from "@posthog/shared/domain-types";
import { useArchivedTaskIds } from "@posthog/ui/features/archive/useArchivedTaskIds";
import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";
import { useTaskChannelMap } from "@posthog/ui/features/canvas/hooks/useTaskChannelMap";
import { useReviewNavigationStore } from "@posthog/ui/features/code-review/reviewNavigationStore";
Expand All @@ -43,6 +45,7 @@ import { TaskIcon } from "@posthog/ui/features/sidebar/components/items/TaskIcon
import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";
import { useTaskPrStatus } from "@posthog/ui/features/sidebar/useTaskPrStatus";
import { useTasks } from "@posthog/ui/features/tasks/useTasks";
import { useWorkspaces } from "@posthog/ui/features/workspace/useWorkspace";
import {
goBackInHistory,
goForwardInHistory,
Expand Down Expand Up @@ -143,6 +146,8 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
(state) => state.getReviewMode,
);
const { data: tasks = [] } = useTasks();
const archivedTaskIds = useArchivedTaskIds();
const { data: workspaces, isFetched: workspacesFetched } = useWorkspaces();
const [query, setQuery] = useState("");
const { repoPath } = useFileSearchContext();
const canSearchFiles = !!repoPath;
Expand Down Expand Up @@ -387,11 +392,17 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
]);

const taskSections = useMemo<CommandSection[]>(() => {
if (tasks.length === 0) return [];
const workspaceIds = workspaceIdSet(workspaces);
const visibleTasks = tasks.filter(
(task) =>
!archivedTaskIds.has(task.id) &&
(!workspacesFetched || workspaceIds.has(task.id)),
);
Comment thread
igennova marked this conversation as resolved.
if (!visibleTasks.length) return [];
return [
Comment on lines +396 to 402

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tasks hidden while workspaces are loading

When the component first mounts and the workspaces query hasn't resolved yet, workspaces is undefined, so Boolean(workspaces?.[task.id]) is false for every task — the command menu shows zero tasks until the query returns. The sidebar guards against this exact scenario by checking isWorkspacesFetched before treating an empty list as real data. Since useWorkspaces has a staleTime of one minute and the sidebar loads it on startup, the window is narrow in practice, but users who open the command menu during a cold load or after a cache miss will briefly see no tasks at all.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied both suggestion in 6585b3b

{
label: "Tasks",
items: tasks.map((task) => {
items: visibleTasks.map((task) => {
const channel = taskChannelMap.get(task.id);
return {
id: `task-${task.id}`,
Expand All @@ -417,7 +428,15 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
}),
},
];
}, [tasks, taskChannelMap, bluebirdEnabled, closeSettingsDialog]);
}, [
tasks,
archivedTaskIds,
workspaces,
workspacesFetched,
taskChannelMap,
bluebirdEnabled,
closeSettingsDialog,
]);

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