Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(topics): add Show unassigned toggle to the Topics actions menu (#19423)

Nimarca501fe59570
diff --git a/web/src/features/topics/CurrentTopics.tsx b/web/src/features/topics/CurrentTopics.tsx
index 9e777a443b..4300bd71ba 100644
--- a/web/src/features/topics/CurrentTopics.tsx
+++ b/web/src/features/topics/CurrentTopics.tsx
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
+import { useMemo } from "react";
import type { TopicTimeRange } from "@langfuse/shared/topics";
import { Alert } from "@/src/components/design-system/Alert/Alert";
import { cn } from "@/src/utils/tailwind";
@@ -16,6 +17,10 @@ import { useIsHandheld } from "@/src/hooks/use-mobile";
import useSessionStorage from "@/src/components/useSessionStorage";
import { useReadPath } from "@/src/features/events/hooks/useReadPath";
import { MobileTopicsView } from "./MobileTopicsView";
+import {
+ facetWithoutUnassigned,
+ mapWithoutUnassigned,
+} from "./prepare-topic-display";
export function CurrentTopics({
projectId,
@@ -27,6 +32,7 @@ export function CurrentTopics({
traceFilters,
onGenerateTopics,
canGenerateTopics,
+ showUnassigned,
}: CurrentTopicsProps) {
const selectedFacet = result.data?.facets.find(
(facet) => facet.facetId === selectedFacetId,
@@ -59,6 +65,7 @@ export function CurrentTopics({
traceFilters={traceFilters}
onGenerateTopics={onGenerateTopics}
canGenerateTopics={canGenerateTopics}
+ showUnassigned={showUnassigned}
/>
)}
</section>
@@ -67,22 +74,39 @@ export function CurrentTopics({
function CurrentFacet({
projectId,
- facet,
+ facet: resultFacet,
timeRange,
view,
tracePanelRef,
traceFilters,
onGenerateTopics,
canGenerateTopics,
+ showUnassigned,
}: CurrentFacetProps) {
const isHandheld = useIsHandheld();
- const mapResult = useCurrentTopicMap(
+ const mapQuery = useCurrentTopicMap(
projectId,
view === "treemap" || view === "treemap-side"
? undefined
- : facet.map?.runId,
+ : resultFacet.map?.runId,
timeRange,
);
+ // Stable identities keep the map camera and grid layout across re-renders.
+ const facet = useMemo(
+ () => (showUnassigned ? resultFacet : facetWithoutUnassigned(resultFacet)),
+ [resultFacet, showUnassigned],
+ );
+ const mapData = useMemo(
+ () =>
+ showUnassigned || !mapQuery.data
+ ? mapQuery.data
+ : mapWithoutUnassigned(
+ mapQuery.data,
+ new Set(facet.rows.map((row) => row.traceId)),
+ ),
+ [mapQuery.data, facet, showUnassigned],
+ );
+ const mapResult = { data: mapData, error: mapQuery.error };
const peekNavigation = usePeekNavigation({
tableName: "topics-traces",
isV4: false,
@@ -163,7 +187,7 @@ function MobileTopics({
| "onGenerateTopics"
| "canGenerateTopics"
> & {
- mapResult: ReturnType<typeof useCurrentTopicMap>;
+ mapResult: Pick<ReturnType<typeof useCurrentTopicMap>, "data" | "error">;
onOpenTrace: (traceId: string) => void;
}) {
const { isV4 } = useReadPath();
@@ -260,6 +284,7 @@ type CurrentTopicsProps = {
traceFilters: ReturnType<typeof useTopicTraceFilters>;
onGenerateTopics: () => void;
canGenerateTopics: boolean;
+ showUnassigned: boolean;
};
type CurrentFacetProps = {
@@ -271,6 +296,7 @@ type CurrentFacetProps = {
traceFilters: ReturnType<typeof useTopicTraceFilters>;
onGenerateTopics: () => void;
canGenerateTopics: boolean;
+ showUnassigned: boolean;
};
type Facet = RouterOutputs["topics"]["currentResults"]["facets"][number];
diff --git a/web/src/features/topics/README.md b/web/src/features/topics/README.md
index 563c75b72d..fb860f8b9a 100644
--- a/web/src/features/topics/README.md
+++ b/web/src/features/topics/README.md
@@ -41,7 +41,7 @@ project permissions. Processing additionally requires the project allowlist.
Saving it stores the models, creates the four built-in facets as evaluators
with a first version, and saves one rule for the filter, idle time, and
sampling rate. A project can have only one Topics rule.
- The header shows the auto-analyze status (`AnalyzeControl`); clicking it opens the Analyze traces dialog with the auto-analyze toggle and sample rate. The overflow menu holds Regenerate topics, History and Settings. Regenerate topics opens the shared manual dialog on its Generate topics tab; the Summarize traces & embed tab stays reachable there. `DialogController` owns the overlay above the page and the mobile actions menu. `ManualTopicsDialog` is the presentational layout shared by the app and its isolated `ManualTopicsDialog.stories.tsx` stories.
+ The header shows the auto-analyze status (`AnalyzeControl`); clicking it opens the Analyze traces dialog with the auto-analyze toggle and sample rate. The overflow menu holds Regenerate topics, History and Settings, plus a Show unassigned toggle (on by default, kept in project-scoped sessionStorage); turning it off makes `CurrentTopics` drop traces and map points without a topic, removing the Unassigned tile and the Outliers and awaiting-assignment map zones in every view. Regenerate topics opens the shared manual dialog on its Generate topics tab; the Summarize traces & embed tab stays reachable there. `DialogController` owns the overlay above the page and the mobile actions menu. `ManualTopicsDialog` is the presentational layout shared by the app and its isolated `ManualTopicsDialog.stories.tsx` stories.
`TopicTraceSelectorView` renders the same filters, batch controls and preview
table in both places; stories supply fixture results without private API calls.
`ManualTopicsFormContent` owns the draft and uses the real trace selector.
diff --git a/web/src/features/topics/TopicsActionsMenu.tsx b/web/src/features/topics/TopicsActionsMenu.tsx
index 2bf7fe6ce3..3e72816cf7 100644
--- a/web/src/features/topics/TopicsActionsMenu.tsx
+++ b/web/src/features/topics/TopicsActionsMenu.tsx
@@ -9,24 +9,37 @@ export function TopicsActionsMenu({
actions: TopicsActions;
closeMenu: (options?: { handoffFocus?: boolean }) => void;
}) {
- return actions.menu.map((action) => {
- const Icon = action.icon;
- function select() {
- closeMenu({ handoffFocus: action.id === "history" });
- action.onSelect();
- }
- return (
- <HeaderActionMenuRow
- key={action.id}
- label={action.label}
- icon={<Icon size="base" color="default" />}
- badge={
- action.badge ? <Badge text={action.badge} size="sm" /> : undefined
+ const { display } = actions;
+ const DisplayIcon = display.icon;
+ return (
+ <>
+ {actions.menu.map((action) => {
+ const Icon = action.icon;
+ function select() {
+ closeMenu({ handoffFocus: action.id === "history" });
+ action.onSelect();
}
- disabled={Boolean(action.disabledReason)}
- disabledReason={action.disabledReason}
- onClick={select}
+ return (
+ <HeaderActionMenuRow
+ key={action.id}
+ label={action.label}
+ icon={<Icon size="base" color="default" />}
+ badge={
+ action.badge ? <Badge text={action.badge} size="sm" /> : undefined
+ }
+ disabled={Boolean(action.disabledReason)}
+ disabledReason={action.disabledReason}
+ onClick={select}
+ />
+ );
+ })}
+ <HeaderActionMenuRow
+ label={display.label}
+ icon={<DisplayIcon size="base" color="default" />}
+ badge={<Badge text={display.checked ? "On" : "Off"} size="sm" />}
+ aria-pressed={display.checked}
+ onClick={() => display.onCheckedChange(!display.checked)}
/>
- );
- });
+ </>
+ );
}
diff --git a/web/src/features/topics/TopicsHeaderActions.stories.tsx b/web/src/features/topics/TopicsHeaderActions.stories.tsx
index 15f344c616..9cebf49268 100644
--- a/web/src/features/topics/TopicsHeaderActions.stories.tsx
+++ b/web/src/features/topics/TopicsHeaderActions.stories.tsx
@@ -15,6 +15,8 @@ const defaultArgs: ComponentProps<typeof TopicsHeaderActions> = {
onConfigure: fn(),
onRegenerate: fn(),
onHistory: fn(),
+ showUnassigned: true,
+ onShowUnassignedChange: fn(),
}),
};
diff --git a/web/src/features/topics/TopicsHeaderActions.tsx b/web/src/features/topics/TopicsHeaderActions.tsx
index d97ed01140..b4f53bb21d 100644
--- a/web/src/features/topics/TopicsHeaderActions.tsx
+++ b/web/src/features/topics/TopicsHeaderActions.tsx
@@ -20,19 +20,30 @@ export function TopicsHeaderActions({ actions }: { actions: TopicsActions }) {
<DropdownMenu
ariaLabel="Topics actions"
placement="bottom-end"
- items={actions.menu.map((action) => ({
- id: action.id,
- type: "item",
- title: action.label,
- icon: action.icon,
- badge: action.badge ? (
- <Badge text={action.badge} size="sm" />
- ) : undefined,
- disabled: action.disabledReason
- ? { reason: action.disabledReason }
- : undefined,
- onClick: action.onSelect,
- }))}
+ items={[
+ ...actions.menu.map((action) => ({
+ id: action.id,
+ type: "item" as const,
+ title: action.label,
+ icon: action.icon,
+ badge: action.badge ? (
+ <Badge text={action.badge} size="sm" />
+ ) : undefined,
+ disabled: action.disabledReason
+ ? { reason: action.disabledReason }
+ : undefined,
+ onClick: action.onSelect,
+ })),
+ { id: "display-separator", type: "separator" },
+ {
+ id: actions.display.id,
+ type: "checkbox",
+ title: actions.display.label,
+ icon: actions.display.icon,
+ checked: actions.display.checked,
+ onCheckedChange: actions.display.onCheckedChange,
+ },
+ ]}
>
{({ getTriggerProps }) => (
<IconButton
diff --git a/web/src/features/topics/TopicsPage.tsx b/web/src/features/topics/TopicsPage.tsx
index 0a5b4d2d44..8ddc4c4a60 100644
--- a/web/src/features/topics/TopicsPage.tsx
+++ b/web/src/features/topics/TopicsPage.tsx
@@ -5,6 +5,7 @@ import { type UseQueryResult } from "@tanstack/react-query";
import { usePeekNavigation } from "@/src/components/table/peek/hooks/usePeekNavigation";
import { TablePeekViewTraceDetail } from "@/src/components/table/peek/TablePeekViewTraceDetail";
import { useRouter } from "next/router";
+import useSessionStorage from "@/src/components/useSessionStorage";
import Page from "@/src/components/layouts/Page";
import { PageHeaderControlsPortal } from "@/src/components/layouts/page-header-controls-slot";
import { TimeRangePicker } from "@/src/components/date-picker";
@@ -187,6 +188,10 @@ function TopicsWorkspaceContent({
}: TopicsWorkspaceContentProps) {
const [historyOpen, setHistoryOpen] = useState(false);
const [resultsView, setResultsView] = useTopicsResultsView();
+ const [showUnassigned, setShowUnassigned] = useSessionStorage(
+ `topics-show-unassigned:${projectId}`,
+ true,
+ );
const [generationRange, setGenerationRange] = useState<{
selection: TimeRange;
bounds: TopicTimeRange;
@@ -473,6 +478,8 @@ function TopicsWorkspaceContent({
onConfigure: configured ? openConfigure : openSetup,
onRegenerate: openTopicGeneration,
onHistory: openHistory,
+ showUnassigned,
+ onShowUnassignedChange: setShowUnassigned,
});
return (
<Page
@@ -664,6 +671,7 @@ function TopicsWorkspaceContent({
tracePanelRef={setTracePanel}
onGenerateTopics={openTopicGeneration}
canGenerateTopics={canWrite && !running && configured}
+ showUnassigned={showUnassigned}
/>
</div>
)}
diff --git a/web/src/features/topics/prepare-topic-display.ts b/web/src/features/topics/prepare-topic-display.ts
index da3d57fc32..4bb1e1a406 100644
--- a/web/src/features/topics/prepare-topic-display.ts
+++ b/web/src/features/topics/prepare-topic-display.ts
@@ -62,3 +62,24 @@ export function prepareTopicDisplay(facet: Facet, view: TopicsResultsView) {
}
return { topics, total: facet.rows.length };
}
+
+/** Drops traces without a topic, which also removes the Unassigned tile and list entry. */
+export function facetWithoutUnassigned(facet: Facet): Facet {
+ return { ...facet, rows: facet.rows.filter((row) => row.topicId) };
+}
+
+/**
+ * Keeps points with a map topic whose trace is still listed, so the map agrees with the
+ * trace table even when a trace's latest assignment differs from the map's discovery one.
+ * Also removes the map's Outliers and awaiting zones.
+ */
+export function mapWithoutUnassigned<
+ T extends { points: { traceId: string; topicId: string | null }[] },
+>(map: T, listedTraceIds: ReadonlySet<string>): T {
+ return {
+ ...map,
+ points: map.points.filter(
+ (point) => point.topicId && listedTraceIds.has(point.traceId),
+ ),
+ };
+}
diff --git a/web/src/features/topics/prepare-topics-actions.ts b/web/src/features/topics/prepare-topics-actions.ts
index ac448640be..11d43d34ed 100644
--- a/web/src/features/topics/prepare-topics-actions.ts
+++ b/web/src/features/topics/prepare-topics-actions.ts
@@ -1,4 +1,5 @@
import {
+ Eye,
History,
Play,
RefreshCw,
@@ -50,6 +51,8 @@ export function prepareTopicsActions({
onConfigure,
onRegenerate,
onHistory,
+ showUnassigned,
+ onShowUnassignedChange,
}: {
automaticProcessing: { state: AutomaticProcessingState; saving: boolean };
canWrite: boolean;
@@ -60,6 +63,8 @@ export function prepareTopicsActions({
onConfigure: () => void;
onRegenerate: () => void;
onHistory: () => void;
+ showUnassigned: boolean;
+ onShowUnassignedChange: (show: boolean) => void;
}) {
const { state, saving } = automaticProcessing;
const reason = processingDisabledReason(state, canWrite, saving);
@@ -111,7 +116,14 @@ export function prepareTopicsActions({
onSelect: onConfigure,
},
);
- return { automatic, menu };
+ const display = {
+ id: "show-unassigned",
+ label: "Show unassigned",
+ icon: Eye,
+ checked: showUnassigned,
+ onCheckedChange: onShowUnassignedChange,
+ } as const;
+ return { automatic, menu, display };
}
export type TopicsActions = ReturnType<typeof prepareTopicsActions>;
diff --git a/web/src/features/topics/topic-map-geometry.clienttest.ts b/web/src/features/topics/topic-map-geometry.clienttest.ts
index 64a0e7eb9c..139a6452ae 100644
--- a/web/src/features/topics/topic-map-geometry.clienttest.ts
+++ b/web/src/features/topics/topic-map-geometry.clienttest.ts
@@ -24,6 +24,7 @@ import {
publishTopicMapFrame,
setTopicMapHover,
} from "./map/topic-map-store";
+import { mapWithoutUnassigned } from "./prepare-topic-display";
const size = { width: 1000, height: 600 };
const bounds = { minX: -100, maxX: 100, minY: -50, maxY: 50 };
@@ -347,6 +348,26 @@ describe("topic map preparation", () => {
}
});
+ it("hides outlier and unavailable zones when unassigned traces are hidden", () => {
+ const model = prepareTopicMap(
+ mapWithoutUnassigned(
+ data([
+ point("invoice", -5, -1),
+ point("resummarized", -4, 2),
+ point("new-request", 0, 8, { topicId: null, outcome: "outlier" }),
+ point("stale-assignment", 0, -8, {
+ topicId: null,
+ outcome: "unassigned",
+ }),
+ ]),
+ new Set(["invoice", "new-request"]),
+ ),
+ topics,
+ );
+ expect(model.zones.map((zone) => zone.id)).toEqual(["billing"]);
+ expect(model.points.map((p) => p.traceId)).toEqual(["invoice"]);
+ });
+
it("keeps depth attached to trace identity across data and topic ordering", () => {
const input = data([
point("invoice", -8, -4),