Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): add a new space command to the command palette (#91622)

Jovan Sakovic94eaf112a762
diff --git a/products/desktop/packages/shared/src/analytics-events.ts b/products/desktop/packages/shared/src/analytics-events.ts
index 04e869266ff0..30a0b2aabb9c 100644
--- a/products/desktop/packages/shared/src/analytics-events.ts
+++ b/products/desktop/packages/shared/src/analytics-events.ts
@@ -45,6 +45,7 @@ export type SkillButtonId =
export type CommandMenuAction =
| "home"
| "new-task"
+ | "create-channel"
| "settings"
| "logout"
| "toggle-theme"
diff --git a/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx b/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx
index 9aa1a38bb280..8ff00ca3388a 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx
@@ -27,7 +27,10 @@ import {
Switch,
Textarea,
} from "@posthog/quill";
-import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";
+import {
+ ANALYTICS_EVENTS,
+ type ChannelsSurface,
+} from "@posthog/shared/analytics-events";
import { useChannelMutations } from "@posthog/ui/features/canvas/hooks/useChannels";
import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsLayout";
import { useGenerateContext } from "@posthog/ui/features/canvas/hooks/useGenerateContext";
@@ -97,12 +100,14 @@ interface CreateChannelModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
existingContext?: { channelId: string; channelName: string };
+ surface?: ChannelsSurface;
}
export function CreateChannelModal({
open,
onOpenChange,
existingContext,
+ surface = "sidebar",
}: CreateChannelModalProps) {
const isDescribeMode = !!existingContext;
const spacesLayout = useChannelsLayout();
@@ -169,7 +174,7 @@ export function CreateChannelModal({
const channel = await createChannel(trimmedName, { star });
track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
action_type: "create",
- surface: "sidebar",
+ surface,
channel_id: channel.id,
success: true,
});
@@ -177,7 +182,7 @@ export function CreateChannelModal({
} catch (error) {
track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
action_type: "create",
- surface: "sidebar",
+ surface,
success: false,
});
toast.error(`Couldn't create ${spacesLayout ? "space" : "channel"}`, {
diff --git a/products/desktop/packages/ui/src/features/command/CommandMenu.createChannel.test.tsx b/products/desktop/packages/ui/src/features/command/CommandMenu.createChannel.test.tsx
new file mode 100644
index 000000000000..3e8e7d43f995
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/command/CommandMenu.createChannel.test.tsx
@@ -0,0 +1,92 @@
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { describe, expect, it, vi } from "vitest";
+
+vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));
+vi.mock("@posthog/ui/features/auth/authClient", () => ({
+ useOptionalAuthenticatedClient: () => null,
+}));
+vi.mock("@posthog/ui/features/auth/useCurrentUser", () => ({
+ useCurrentUser: () => ({ data: { uuid: "user-1" } }),
+}));
+vi.mock("@posthog/di/container", () => ({
+ resolveService: () => ({}),
+ resolveServiceOptional: () => null,
+}));
+vi.mock("@posthog/ui/features/feature-flags/useFeatureFlag", () => ({
+ useFeatureFlag: () => true,
+}));
+vi.mock("@posthog/ui/features/tasks/useTasks", () => ({
+ useTasks: () => ({ data: [] }),
+}));
+vi.mock("@posthog/ui/features/archive/useArchivedTaskIds", () => ({
+ useArchivedTaskIds: () => new Set(),
+}));
+vi.mock("@posthog/ui/features/archive/useTaskArchive", () => ({
+ useTaskArchive: () => ({
+ requestArchive: vi.fn(),
+ isArchiving: false,
+ dialog: null,
+ }),
+}));
+vi.mock("@posthog/ui/features/workspace/useWorkspace", () => ({
+ useWorkspaces: () => ({ data: [], isFetched: true }),
+}));
+vi.mock("@posthog/ui/features/canvas/hooks/useChannels", () => ({
+ useChannels: () => ({ channels: [], isLoading: false }),
+}));
+vi.mock("@posthog/ui/features/canvas/hooks/useOrgMembers", () => ({
+ useOrgMembers: () => ({
+ members: [],
+ isLoading: false,
+ isError: false,
+ isComplete: true,
+ }),
+}));
+vi.mock("@posthog/ui/features/canvas/hooks/useChannelsLayout", () => ({
+ useChannelsLayout: () => true,
+}));
+vi.mock("@posthog/ui/features/canvas/hooks/useTaskChannelMap", () => ({
+ useTaskChannelMap: () => new Map(),
+}));
+vi.mock("@posthog/ui/features/command/useFileSearchContext", () => ({
+ useFileSearchContext: () => ({ repoPath: null }),
+}));
+vi.mock("@posthog/ui/features/command/useTaskSearch", () => ({
+ useTaskSearch: () => ({ data: [] }),
+}));
+vi.mock("@posthog/ui/features/folders/useFolders", () => ({
+ useFolders: () => ({ folders: [] }),
+}));
+vi.mock("@posthog/ui/router/useAppView", () => ({
+ useAppView: () => ({ type: "home" }),
+}));
+vi.mock("@posthog/ui/features/sidebar/useTaskPrStatus", () => ({
+ useTaskPrStatus: () => ({ prState: null, hasDiff: false, prUrl: null }),
+}));
+vi.mock("@posthog/ui/features/canvas/hooks/useTaskFeedResults", () => ({
+ useTaskFeedResults: () => ({
+ tasks: [],
+ isComplete: true,
+ isLoading: false,
+ issues: [],
+ }),
+ useFeedQueryPlan: () => ({ plan: undefined, isLoading: false }),
+}));
+vi.mock("@posthog/ui/features/canvas/components/CreateChannelModal", () => ({
+ CreateChannelModal: ({ open }: { open: boolean }) =>
+ open ? <div>create space modal</div> : null,
+}));
+
+import { CommandMenu } from "./CommandMenu";
+
+describe("CommandMenu space creation", () => {
+ it("opens the create modal from the New space command", async () => {
+ const user = userEvent.setup();
+ render(<CommandMenu open onOpenChange={vi.fn()} />);
+
+ expect(screen.queryByText("create space modal")).not.toBeInTheDocument();
+ await user.click(await screen.findByText("New space"));
+ expect(await screen.findByText("create space modal")).toBeInTheDocument();
+ });
+});
diff --git a/products/desktop/packages/ui/src/features/command/CommandMenu.tsx b/products/desktop/packages/ui/src/features/command/CommandMenu.tsx
index bc755a4598f5..48328517fb19 100644
--- a/products/desktop/packages/ui/src/features/command/CommandMenu.tsx
+++ b/products/desktop/packages/ui/src/features/command/CommandMenu.tsx
@@ -3,9 +3,11 @@ import {
CaretLeftIcon,
CaretRightIcon,
ChartLine,
+ CubeIcon,
EnvelopeSimple,
Gauge,
GitDiffIcon,
+ HashIcon,
SquaresFourIcon,
} from "@phosphor-icons/react";
import { workspaceIdSet } from "@posthog/core/command-center/eligibility";
@@ -113,7 +115,9 @@ import {
ZoomOutIcon,
} from "@radix-ui/react-icons";
import {
+ lazy,
type KeyboardEvent as ReactKeyboardEvent,
+ Suspense,
useCallback,
useEffect,
useLayoutEffect,
@@ -127,6 +131,13 @@ interface CommandMenuProps {
onOpenChange: (open: boolean) => void;
}
+// Static-importing this pulls the task-creation stack onto the mod+K path.
+const CreateChannelModalLazy = lazy(() =>
+ import("@posthog/ui/features/canvas/components/CreateChannelModal").then(
+ (module) => ({ default: module.CreateChannelModal }),
+ ),
+);
+
const DEFAULT_RESULT_LIMIT = 8;
const COLLAPSED_CHIP_COUNT = 5;
@@ -240,6 +251,8 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
(state) => state.activeTasks,
);
const [query, setQuery] = useState("");
+ const [createChannelOpen, setCreateChannelOpen] = useState(false);
+ const [createChannelUsed, setCreateChannelUsed] = useState(false);
const [recentCommands, setRecentCommands] = useState<Command[]>([]);
const [remoteQuery, setRemoteQuery] = useState("");
// The legacy title search only ever surfaces while the palette is browsing
@@ -474,6 +487,26 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
openTaskInput();
},
},
+ ...(bluebirdEnabled
+ ? [
+ {
+ id: "create-channel",
+ label: spacesLayout ? "New space" : "New channel",
+ keywords: "create add space channel context",
+ icon: spacesLayout ? (
+ <CubeIcon size={12} className="text-gray-11" />
+ ) : (
+ <HashIcon size={12} className="text-gray-11" />
+ ),
+ action: "create-channel" as CommandMenuAction,
+ onRun: () => {
+ closeSettingsDialog();
+ setCreateChannelUsed(true);
+ setCreateChannelOpen(true);
+ },
+ },
+ ]
+ : []),
{
id: "toggle-left-sidebar",
label: "Toggle left sidebar",
@@ -621,6 +654,8 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
loopsEnabled,
inboxAvailable,
spendAnalysisEnabled,
+ bluebirdEnabled,
+ spacesLayout,
]);
const taskSections = useMemo<CommandSection[]>(() => {
@@ -1031,6 +1066,15 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
surface="command_menu"
onCreated={(feed) => navigateToFeed(feed.id)}
/>
+ {createChannelUsed && (
+ <Suspense fallback={null}>
+ <CreateChannelModalLazy
+ open={createChannelOpen}
+ onOpenChange={setCreateChannelOpen}
+ surface="command_menu"
+ />
+ </Suspense>
+ )}
{/* Outlives the palette, which closes as the command runs. */}
{archiveDialog}
</>