: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): drop a source filter the space has none of (#81241)
Adam Leithe4fdc209d64c
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsxindex ce7d47935bd3..4c4fe6b9cbad 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.test.tsx@@ -174,6 +174,37 @@ describe("ChannelSidebar", () => {expect(screen.queryByText("No sessions yet")).not.toBeInTheDocument();});+ it("gives up a source filter the space you moved to has none of", async () => {+ const user = userEvent.setup({ pointerEventsCheck: 0 });+ mocks.items = [+ item({+ key: "task:slack",+ id: "slack",+ title: "Filed from Slack",+ source: "slack",+ }),+ item({ key: "task:local", id: "local", title: "Started here" }),+ ];+ const { rerender } = renderSidebar();++ await user.click(screen.getByRole("button", { name: "Filter" }));+ await user.click(await screen.findByRole("menuitem", { name: /Source/ }));+ fireEvent.click(+ await screen.findByRole("menuitemradio", { name: "Slack" }),+ );+ expect(screen.queryByText("Started here")).not.toBeInTheDocument();++ // A space with no Slack sessions: the option that narrowed the list is no+ // longer in the menu, so the filter must not be what empties it.+ mocks.items = [+ item({ key: "task:other", id: "other", title: "Somewhere else" }),+ ];+ rerender(sidebar());++ expect(screen.getByText("Somewhere else")).toBeInTheDocument();+ expect(screen.queryByText("No matches")).not.toBeInTheDocument();+ });+it("shows a single empty state when the last item goes away under a search", async () => {const user = userEvent.setup();mocks.items = [item()];diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsxindex 232a01a16847..004c32be694a 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx@@ -307,13 +307,35 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {const { channels } = useChannels();const isPersonalChannel =channels.find((c) => c.id === channelId)?.name === PERSONAL_CHANNEL_NAME;+ // The tab is the list, so everything below it — the filters, the empty state,+ // the sections — is about one kind of thing at a time.+ const tabItems = useMemo(+ () => items.filter((item) => item.kind === tab),+ [items, tab],+ );+ // The menu only offers sources the list holds, so it is built from everything+ // in the tab rather than from what the current filters left behind — picking+ // one source must not be what removes the others from the menu.+ const sources = useMemo(() => channelItemSources(tabItems), [tabItems]);// A canvas has no run, so the three run filters can only ever empty the// canvases tab. Same treatment as createdBy above: neutralised as well as// hidden, or a choice made on the sessions tab would empty this one.+ //+ // A source the tab has none of goes the same way, and for the same reason: it+ // would empty the list while its submenu shows no chosen option, so there'd be+ // nothing to switch off. Rows arriving later put the source back, because the+ // stored filter is untouched.const filters = useMemo<ChannelItemFilters>(() => {- const scoped = isPersonalChannel- ? { ...rawFilters, createdBy: "anyone" as const }- : rawFilters;+ const sourceMissing =+ rawFilters.source !== ANY_SOURCE && !sources.includes(rawFilters.source);+ const scoped =+ isPersonalChannel || sourceMissing+ ? {+ ...rawFilters,+ ...(isPersonalChannel ? { createdBy: "anyone" as const } : {}),+ ...(sourceMissing ? { source: ANY_SOURCE } : {}),+ }+ : rawFilters;return tab === "canvas"? {...scoped,@@ -322,18 +344,8 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {source: ANY_SOURCE,}: scoped;- }, [isPersonalChannel, rawFilters, tab]);+ }, [isPersonalChannel, rawFilters, sources, tab]);const filtersActive = hasActiveChannelItemFilters(filters);- // The tab is the list, so everything below it — the filters, the empty state,- // the sections — is about one kind of thing at a time.- const tabItems = useMemo(- () => items.filter((item) => item.kind === tab),- [items, tab],- );- // The menu only offers sources the list holds, so it is built from everything- // in the tab rather than from what the current filters left behind — picking- // one source must not be what removes the others from the menu.- const sources = useMemo(() => channelItemSources(tabItems), [tabItems]);const base = `/website/${channelId}`;// Activeness is a key comparison rather than a flag baked into each item, so