: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): normalize new space names (#81296)
Peter Kirkhamd2287af8f378
diff --git a/products/desktop/packages/core/src/canvas/channelName.test.ts b/products/desktop/packages/core/src/canvas/channelName.test.tsindex 9f9ad18732d7..18c837134ae3 100644--- a/products/desktop/packages/core/src/canvas/channelName.test.ts+++ b/products/desktop/packages/core/src/canvas/channelName.test.ts@@ -1,5 +1,30 @@import { describe, expect, it } from "vitest";-import { validateChannelName } from "./channelName";+import {+ normalizeChannelName,+ normalizeChannelNameInput,+ validateChannelName,+} from "./channelName";++describe("normalizeChannelName", () => {+ it.each([+ ["My New Space", "my-new-space"],+ [" Product Analytics ", "product-analytics"],+ ["Mobile_App.v2", "mobile-app-v2"],+ ["already-valid", "already-valid"],+ ["café 🚀", "caf"],+ ])("normalizes %j to %j", (name, expected) => {+ expect(normalizeChannelName(name)).toBe(expected);+ });++ it("preserves separators while a multi-word name is typed", () => {+ const normalized = [..."My New Space"].reduce(+ (name, character) => normalizeChannelNameInput(name + character),+ "",+ );++ expect(normalized).toBe("my-new-space");+ });+});describe("validateChannelName", () => {it.each([diff --git a/products/desktop/packages/core/src/canvas/channelName.ts b/products/desktop/packages/core/src/canvas/channelName.tsindex 6d1af1fc9cb1..f5dd87e2e0be 100644--- a/products/desktop/packages/core/src/canvas/channelName.ts+++ b/products/desktop/packages/core/src/canvas/channelName.ts@@ -2,6 +2,18 @@// so it must be directory-safe: lowercase letters, numbers, and hyphens only.export const CHANNEL_NAME_PATTERN = /^[a-z0-9-]+$/;+function replaceChannelNameSeparators(name: string): string {+ return name.toLowerCase().replace(/[^a-z0-9]+/g, "-");+}++export function normalizeChannelNameInput(name: string): string {+ return replaceChannelNameSeparators(name).replace(/^-+/, "");+}++export function normalizeChannelName(name: string): string {+ return normalizeChannelNameInput(name).replace(/-+$/, "");+}+// Returns an error message for an invalid name, or null when valid. Empty is// treated as valid here — callers already gate on a non-empty trimmed value, so// this validator only judges the character set.diff --git a/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx b/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsxindex de8cf0e24239..9b52863c5484 100644--- a/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/CreateChannelModal.tsx@@ -1,4 +1,8 @@-import { validateChannelName } from "@posthog/core/canvas/channelName";+import {+ normalizeChannelName,+ normalizeChannelNameInput,+ validateChannelName,+} from "@posthog/core/canvas/channelName";import {Button,Dialog,@@ -164,7 +168,7 @@ export function CreateChannelModal({}}- const trimmedName = name.trim();+ const trimmedName = normalizeChannelName(name);const trimmedDescription = description.trim();const remaining = MAX_CONTEXT_NAME_LENGTH - name.length;const nameError = isDescribeMode ? null : validateChannelName(trimmedName);@@ -374,6 +378,10 @@ export function CreateChannelModal({<DialogTitle>Create a {spacesLayout ? "space" : "channel"}</DialogTitle>+ <DialogDescription>+ Create a {spacesLayout ? "space" : "channel"} to keep related+ work and context together.+ </DialogDescription></DialogHeader><DialogBody className="flex max-h-[55vh] flex-col gap-4">@@ -386,7 +394,10 @@ export function CreateChannelModal({placeholder="e.g. mobile"maxLength={MAX_CONTEXT_NAME_LENGTH}disabled={busy}- onChange={(e) => setName(e.target.value)}+ onChange={(e) =>+ setName(normalizeChannelNameInput(e.target.value))+ }+ onBlur={() => setName(normalizeChannelName(name))}onKeyDown={(e) => {if (e.key === "Enter") {e.preventDefault();@@ -394,6 +405,9 @@ export function CreateChannelModal({}}}/>+ <FieldDescription>+ Names use lowercase letters, numbers, and hyphens.+ </FieldDescription>{nameError ? (<FieldError>{nameError}</FieldError>) : (