Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(goal): keep the exploration map's mainline off until toggled (#21121)

Arvin Xu118736acdc2e
diff --git a/src/features/AgentGoals/ProcessControl/Graph/GraphLegend.tsx b/src/features/AgentGoals/ProcessControl/Graph/GraphLegend.tsx
new file mode 100644
index 00000000000..c76d68fd06b
--- /dev/null
+++ b/src/features/AgentGoals/ProcessControl/Graph/GraphLegend.tsx
@@ -0,0 +1,121 @@
+import { createStaticStyles, cssVar, cx, Flexbox } from '@lobehub/ui';
+import { memo, type ReactNode } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { GoalGraphNodeKind } from '../../Experiments/model';
+import { KindDot } from '../shared';
+
+const styles = createStaticStyles(({ css }) => ({
+ legend: css`
+ font-size: 12px;
+ color: ${cssVar.colorTextTertiary};
+ `,
+ legendItem: css`
+ cursor: pointer;
+ user-select: none;
+
+ &:hover {
+ color: ${cssVar.colorText};
+ }
+ `,
+ /* The mainline is drawn as a ring on its cards, so the swatch is a ring too. */
+ legendMainlineSwatch: css`
+ width: 10px;
+ height: 10px;
+ border: 1.5px solid ${cssVar.colorInfo};
+ border-radius: 3px;
+ `,
+ /* A hidden kind stays in the legend as a dimmed toggle — the way back must
+ be exactly where the way in was. */
+ legendOff: css`
+ opacity: 0.35;
+
+ &:hover {
+ opacity: 0.65;
+ }
+ `,
+}));
+
+const LegendToggle = ({
+ children,
+ on,
+ onToggle,
+ title,
+}: {
+ children: ReactNode;
+ on: boolean;
+ onToggle: () => void;
+ title: string;
+}) => (
+ <Flexbox
+ horizontal
+ align={'center'}
+ aria-pressed={on}
+ className={cx(styles.legendItem, !on && styles.legendOff)}
+ gap={4}
+ role={'button'}
+ tabIndex={0}
+ title={title}
+ onClick={onToggle}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter' || event.key === ' ') {
+ event.preventDefault();
+ onToggle();
+ }
+ }}
+ >
+ {children}
+ </Flexbox>
+);
+
+interface GraphLegendProps {
+ hasMainline: boolean;
+ hiddenKinds: ReadonlySet<GoalGraphNodeKind>;
+ kinds: readonly GoalGraphNodeKind[];
+ onToggleKind: (kind: GoalGraphNodeKind) => void;
+ onToggleMainline: () => void;
+ showMainline: boolean;
+}
+
+/**
+ * The map's legend. Each kind is a filter — click it off and the map relayouts
+ * around what remains. 主线 is a highlight, off by default: a finished map reads
+ * plain until the user asks to see the path the wrap-up report marked.
+ */
+const GraphLegend = memo<GraphLegendProps>(
+ ({ hasMainline, hiddenKinds, kinds, onToggleKind, onToggleMainline, showMainline }) => {
+ const { t } = useTranslation('chat');
+ return (
+ <Flexbox horizontal align={'center'} className={styles.legend} gap={10}>
+ {hasMainline && (
+ <LegendToggle
+ on={showMainline}
+ title={t('goalProcess.graph.legend.mainlineHint')}
+ onToggle={onToggleMainline}
+ >
+ <span className={styles.legendMainlineSwatch} />
+ <span>{t('goalProcess.graph.legend.mainline')}</span>
+ </LegendToggle>
+ )}
+ {kinds.map((kind) => {
+ const off = hiddenKinds.has(kind);
+ return (
+ <LegendToggle
+ key={kind}
+ on={!off}
+ title={t(off ? 'goalProcess.graph.legend.show' : 'goalProcess.graph.legend.hide')}
+ onToggle={() => onToggleKind(kind)}
+ >
+ <KindDot kind={kind} />
+ <span>{t(`goalProcess.kind.${kind}` as const)}</span>
+ </LegendToggle>
+ );
+ })}
+ </Flexbox>
+ );
+ },
+);
+
+GraphLegend.displayName = 'GoalGraphLegend';
+
+export default GraphLegend;
diff --git a/src/features/AgentGoals/ProcessControl/Graph/GraphNode.tsx b/src/features/AgentGoals/ProcessControl/Graph/GraphNode.tsx
index 8df4eaab372..01994952ee8 100644
--- a/src/features/AgentGoals/ProcessControl/Graph/GraphNode.tsx
+++ b/src/features/AgentGoals/ProcessControl/Graph/GraphNode.tsx
@@ -194,7 +194,8 @@ const styles = createStaticStyles(({ css }) => ({
`,
/* A ring, not a fill: the kind tint and the state chip must stay readable.
Blue, not `colorPrimary` — the primary is near-black here, so the ring read
- as a heavier version of the plain card border and told nothing apart. */
+ as a heavier version of the plain card border and told nothing apart. The
+ cards carry the mainline; the lines between them stay ordinary. */
mainline: css`
border-color: ${cssVar.colorInfo};
box-shadow: 0 0 0 1px ${cssVar.colorInfo};
diff --git a/src/features/AgentGoals/ProcessControl/Graph/index.tsx b/src/features/AgentGoals/ProcessControl/Graph/index.tsx
index 74c022ab4a8..1f2c0a2e984 100644
--- a/src/features/AgentGoals/ProcessControl/Graph/index.tsx
+++ b/src/features/AgentGoals/ProcessControl/Graph/index.tsx
@@ -53,7 +53,7 @@ import {
isRunningNode,
scopeGraphView,
} from '../goalGraphViewModel';
-import { GATE_COLOR, KindDot, SKILL_COLOR, SKILL_ICON } from '../shared';
+import { GATE_COLOR, SKILL_COLOR, SKILL_ICON } from '../shared';
import {
BatchExperimentProbeGroup,
BatchRoundFrame,
@@ -77,6 +77,7 @@ import ExperimentGroup, { type ExperimentGroupData } from './ExperimentGroup';
import { batchContainerStatus } from './experimentStatus';
import ExplorationEdge from './ExplorationEdge';
import { explorationMap } from './explorationMap';
+import GraphLegend from './GraphLegend';
import GraphNodeView, { GhostNodeView, type GraphNodeData, type StateChip } from './GraphNode';
import { type GraphBridge, hideKinds, type LayoutBox, layoutGraph, NODE_WIDTH } from './layout';
import {
@@ -88,6 +89,7 @@ import {
MUTED_EDGE_OPACITY_DARK,
nodeEmphasis,
resolveMainline,
+ shownMainline,
} from './mainline';
import { flowNodeSize, type MeasuredSizes, mergeMeasuredSizes } from './measuredSizes';
import { revealCenter } from './revealNode';
@@ -129,13 +131,6 @@ const styles = createStaticStyles(({ css }) => ({
stroke-dasharray: 5 4;
}
- /* The wrap-up report's mainline: the path reads as one bold line, and
- everything off it steps back. Selection still lights a muted edge. */
- .react-flow__edge.goal-mainline .react-flow__edge-path {
- stroke: ${cssVar.colorPrimary};
- stroke-width: 2.5;
- }
-
/* A chapter map's detours: the line into a stray card reads in the same
orange dash as the card's own frame. */
.react-flow__edge.goal-detour .react-flow__edge-path {
@@ -153,14 +148,10 @@ const styles = createStaticStyles(({ css }) => ({
stroke-width: 1.75;
}
- .react-flow__edge.goal-mainline.goal-hot .react-flow__edge-path {
- stroke-width: 2.5;
- }
-
/* Off-mainline lines keep their step-back on the light canvas. On the dark
one that same border token at a third opacity turns into background, so
- the line is lifted just enough to read; the mainline stays the boldest
- line on the map either way, so the hierarchy is not flattened. These
+ the line is lifted just enough to read; the mainline's lines stay at full
+ strength either way, so the hierarchy is not flattened. These
dark-theme overrides carry higher specificity, so they sit last to keep
the cascade ascending. */
html[data-theme='dark'] & .react-flow__edge.goal-muted:not(.goal-hot) {
@@ -171,6 +162,16 @@ const styles = createStaticStyles(({ css }) => ({
stroke: ${cssVar.colorTextQuaternary};
}
+ /* The mainline is carried by its cards' ring; its lines stay ordinary, at
+ full strength while the rest steps back. On the dark canvas they take the
+ same lifted token as the muted lines so they never read fainter. */
+ html[data-theme='dark']
+ &
+ .react-flow__edge.goal-mainline:not(.goal-hot)
+ .react-flow__edge-path {
+ stroke: ${cssVar.colorTextQuaternary};
+ }
+
.react-flow__edge-textbg {
fill: ${cssVar.colorBgLayout};
}
@@ -193,38 +194,6 @@ const styles = createStaticStyles(({ css }) => ({
full: css`
height: 100%;
`,
- legend: css`
- font-size: 12px;
- color: ${cssVar.colorTextTertiary};
- `,
- legendItem: css`
- cursor: pointer;
- user-select: none;
-
- &:hover {
- color: ${cssVar.colorText};
- }
- `,
- /* A hidden kind stays in the legend as a dimmed toggle — the way back must
- be exactly where the way in was. */
- /** Not a kind filter: it names the bold line and ring the mainline is drawn with. */
- legendMainline: css`
- cursor: default;
- color: ${cssVar.colorText};
- `,
- legendMainlineSwatch: css`
- width: 14px;
- height: 3px;
- border-radius: 2px;
- background: ${cssVar.colorInfo};
- `,
- legendOff: css`
- opacity: 0.35;
-
- &:hover {
- opacity: 0.65;
- }
- `,
/* Fullscreen chrome floats over the canvas in two corner cards instead of a
full-width bar, so a node panned to the top edge is never hidden behind an
opaque header strip. */
@@ -296,6 +265,12 @@ interface GraphProps {
graph: GoalGraphView;
/** Nodes to call out on the map — a chapter's detours in the report's local map. */
highlightedIds?: ReadonlySet<string>;
+ /**
+ * Whether the report's mainline starts highlighted. Off by default, so a
+ * finished Goal reads as the plain map until 主线 is clicked in the legend;
+ * a report chapter, which is about the mainline, turns it on.
+ */
+ initialShowMainline?: boolean;
onFullscreenChange?: (fullscreen: boolean) => void;
onSelect: (nodeId: string) => void;
/** The coordinator is still decomposing: show ghost task cards under the problem. */
@@ -504,6 +479,7 @@ const Canvas = memo<
navigation?: ReactNode;
/** The batch entered on its own: its units as a grid, round by round. */
scopeBatch?: BatchModel;
+ showMainline: boolean;
}
>(
({
@@ -522,6 +498,7 @@ const Canvas = memo<
onEnter,
navigation,
scopeBatch,
+ showMainline,
view,
}) => {
const { fitView, getInternalNode, getViewport, setCenter } = useReactFlow();
@@ -676,7 +653,7 @@ const Canvas = memo<
[ghosts],
);
- const mainline = useMemo(() => resolveMainline(graph), [graph]);
+ const mainline = useMemo(() => shownMainline(graph, showMainline), [graph, showMainline]);
const emphasisById = useMemo(() => {
const result = new Map<string, ReturnType<typeof nodeEmphasis>>();
if (!mainline) return result;
@@ -1211,6 +1188,7 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
// A batch never folds, so expand/collapse all only means something with experiments.
const hasFoldable = !onlyBatches;
const [hiddenKinds, setHiddenKinds] = useState<ReadonlySet<GoalGraphNodeKind>>(() => new Set());
+ const [showMainline, setShowMainline] = useState(props.initialShowMainline ?? false);
const showPortal = useChatStore(chatPortalSelectors.showPortal);
const currentViewType = useChatStore(chatPortalSelectors.currentViewType);
const clearPortalStack = useChatStore((s) => s.clearPortalStack);
@@ -1227,6 +1205,8 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
});
}, []);
+ const toggleMainline = useCallback(() => setShowMainline((prev) => !prev), []);
+
const selectNode = (nodeId: string) => {
if (isContainerKind(props.graph.byId[nodeId]?.node.kind ?? ('task' as const))) {
navigation.toggle(nodeId);
@@ -1316,57 +1296,23 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
// cards, so the legend never promises a mainline the view decided to drop.
const hasMainline = !!resolveMainline(scopedGraph);
const legend = (
- <Flexbox horizontal align={'center'} className={styles.legend} gap={10}>
- {hasMainline && (
- <Flexbox
- horizontal
- align={'center'}
- className={styles.legendMainline}
- gap={4}
- title={t('goalProcess.graph.legend.mainlineHint')}
- >
- <span className={styles.legendMainlineSwatch} />
- <span>{t('goalProcess.graph.legend.mainline')}</span>
- </Flexbox>
- )}
- {(
- [
- 'problem',
- 'task',
- ...(containers.some((view) => view.node.kind === 'experiment')
- ? ['experiment' as const]
- : []),
- ...(containers.some((view) => view.node.kind === 'batch') ? ['batch' as const] : []),
- 'finding',
- 'decision',
- ] as const
- ).map((kind) => {
- const off = hiddenKinds.has(kind);
- return (
- <Flexbox
- horizontal
- align={'center'}
- aria-pressed={!off}
- className={cx(styles.legendItem, off && styles.legendOff)}
- gap={4}
- key={kind}
- role={'button'}
- tabIndex={0}
- title={t(off ? 'goalProcess.graph.legend.show' : 'goalProcess.graph.legend.hide')}
- onClick={() => toggleKind(kind)}
- onKeyDown={(event) => {
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault();
- toggleKind(kind);
- }
- }}
- >
- <KindDot kind={kind} />
- <span>{t(`goalProcess.kind.${kind}` as const)}</span>
- </Flexbox>
- );
- })}
- </Flexbox>
+ <GraphLegend
+ hasMainline={hasMainline}
+ hiddenKinds={hiddenKinds}
+ showMainline={showMainline}
+ kinds={[
+ 'problem',
+ 'task',
+ ...(containers.some((view) => view.node.kind === 'experiment')
+ ? ['experiment' as const]
+ : []),
+ ...(containers.some((view) => view.node.kind === 'batch') ? ['batch' as const] : []),
+ 'finding',
+ 'decision',
+ ]}
+ onToggleKind={toggleKind}
+ onToggleMainline={toggleMainline}
+ />
);
if (fullscreen)
return (
@@ -1384,6 +1330,7 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
planning={scopeId ? false : props.planning}
refitKey={showPortal}
scopeBatch={scopeBatch}
+ showMainline={showMainline}
view={scopeId ? 'all' : view}
navigation={
<Flexbox gap={8}>
@@ -1449,6 +1396,7 @@ const Graph = memo<GraphProps>(({ extra, fullscreen = false, onFullscreenChange,
navigation={breadcrumbs}
planning={scopeId ? false : props.planning}
scopeBatch={scopeBatch}
+ showMainline={showMainline}
view={scopeId ? 'all' : view}
onEnter={navigation.enter}
onInspect={(id) => openNode(props.graph.goal.id, id)}
diff --git a/src/features/AgentGoals/ProcessControl/Graph/mainline.test.ts b/src/features/AgentGoals/ProcessControl/Graph/mainline.test.ts
index 55cb8c713da..3506c2b30e6 100644
--- a/src/features/AgentGoals/ProcessControl/Graph/mainline.test.ts
+++ b/src/features/AgentGoals/ProcessControl/Graph/mainline.test.ts
@@ -11,6 +11,7 @@ import {
MUTED_EDGE_OPACITY_DARK,
nodeEmphasis,
resolveMainline,
+ shownMainline,
} from './mainline';
const graphWith = (
@@ -178,11 +179,10 @@ describe('off-mainline legibility', () => {
/**
* Regression: the dark canvas turned the border token at a third opacity into
* background, so an off-mainline line and the arrow ending it were barely
- * there. Only the off-mainline tone is lifted; the mainline keeps its own
- * primary line, so the hierarchy is not flattened.
+ * there. Off-mainline lines step back through opacity, so the lifted token
+ * only restores legibility.
*/
- it('lifts only the off-mainline arrow on the dark canvas', () => {
- expect(edgeMarkerColor('mainline', true)).toBe(cssVar.colorPrimary);
+ it('lifts the plain arrow on the dark canvas', () => {
expect(edgeMarkerColor('detour', true)).toBe(cssVar.colorWarning);
// Light mode is unchanged — the same border token as before.
expect(edgeMarkerColor(undefined, false)).toBe(cssVar.colorBorder);
@@ -191,8 +191,30 @@ describe('off-mainline legibility', () => {
expect(edgeMarkerColor('muted', true)).toBe(cssVar.colorTextQuaternary);
});
+ /**
+ * Regression: a colored mainline line — near-black primary, then info blue,
+ * then light blue — read as heavier than the map. The cards carry the
+ * mainline; its lines end in the same ordinary arrow as any other line.
+ */
+ it('ends the mainline in an ordinary arrow', () => {
+ expect(edgeMarkerColor('mainline', false)).toBe(edgeMarkerColor(undefined, false));
+ expect(edgeMarkerColor('mainline', true)).toBe(edgeMarkerColor(undefined, true));
+ });
+
it('is more legible on the dark canvas while still stepping back', () => {
expect(MUTED_EDGE_OPACITY_DARK).toBeGreaterThan(MUTED_EDGE_OPACITY);
expect(MUTED_EDGE_OPACITY_DARK).toBeLessThan(1);
});
});
+
+describe('shownMainline', () => {
+ const graph = graphWith({ edgeIds: ['e1'], nodeIds: ['t1', 't2'] });
+
+ it('leaves a finished map plain until the mainline is turned on', () => {
+ expect(shownMainline(graph, false)).toBeUndefined();
+ });
+
+ it('draws the marked mainline once it is turned on', () => {
+ expect([...shownMainline(graph, true)!.nodeIds]).toEqual(['t1', 't2']);
+ });
+});
diff --git a/src/features/AgentGoals/ProcessControl/Graph/mainline.ts b/src/features/AgentGoals/ProcessControl/Graph/mainline.ts
index a6ae8ce40ef..fb4f37ab789 100644
--- a/src/features/AgentGoals/ProcessControl/Graph/mainline.ts
+++ b/src/features/AgentGoals/ProcessControl/Graph/mainline.ts
@@ -32,6 +32,15 @@ export const resolveMainline = (
return mainlineContrasts(mainline, graph) ? mainline : undefined;
};
+/**
+ * The mainline the map paints. A finished Goal's map reads as the plain map
+ * first: the bold path is drawn only once the user turns 主线 on in the legend.
+ */
+export const shownMainline = (
+ graph: Parameters<typeof resolveMainline>[0],
+ shown: boolean,
+): Mainline | undefined => (shown ? resolveMainline(graph) : undefined);
+
/**
* A card is on the mainline when it was marked, or when it is an experiment
* whose members were — collapsed, the experiment stands in for them. The root
@@ -127,19 +136,19 @@ export const edgeTone = (
* On the light canvas the border token at a third opacity reads as intended —
* clearly behind the mainline, still present. On the dark canvas that same
* combination sinks into the background, so the line is lifted just enough to
- * stay legible. The mainline keeps its own bold primary line either way, so the
+ * stay legible. The mainline's lines stay at full strength either way, so the
* hierarchy is never flattened.
*/
export const MUTED_EDGE_OPACITY = 0.3;
export const MUTED_EDGE_OPACITY_DARK = 0.5;
/**
- * The arrowhead that ends a line, in the same tone as the line itself. An
- * off-mainline marker uses the border token on the light canvas; on the dark one
+ * The arrowhead that ends a line, in the same tone as the line itself. The
+ * mainline's lines are ordinary lines, so they share the plain marker. A plain
+ * marker uses the border token on the light canvas; on the dark one
* that token is nearly invisible, so it borrows the lighter text token.
*/
export const edgeMarkerColor = (tone: EdgeTone, isDarkMode: boolean): string => {
- if (tone === 'mainline') return cssVar.colorPrimary;
if (tone === 'detour') return cssVar.colorWarning;
return isDarkMode ? cssVar.colorTextQuaternary : cssVar.colorBorder;
};
diff --git a/src/features/Portal/GoalReport/Body.tsx b/src/features/Portal/GoalReport/Body.tsx
index 951c77ea859..e92e11f957d 100644
--- a/src/features/Portal/GoalReport/Body.tsx
+++ b/src/features/Portal/GoalReport/Body.tsx
@@ -132,6 +132,7 @@ export const ChapterBody = memo(() => {
</Text>
{map.graph.nodes.length > 0 && (
<Graph
+ initialShowMainline
bridges={map.bridges}
graph={map.graph}
highlightedIds={highlightedIds}