Fix numbering

This commit is contained in:
Connor Yoh 2025-08-12 11:20:51 +01:00
parent adf6feea27
commit 1bf9da08af
2 changed files with 26 additions and 13 deletions

View File

@ -7,7 +7,6 @@ import { TooltipTip } from '../../shared/tooltip/TooltipContent';
interface ToolStepContextType { interface ToolStepContextType {
visibleStepCount: number; visibleStepCount: number;
getStepNumber: () => number;
} }
const ToolStepContext = createContext<ToolStepContextType | null>(null); const ToolStepContext = createContext<ToolStepContextType | null>(null);
@ -22,6 +21,7 @@ export interface ToolStepProps {
completedMessage?: string; completedMessage?: string;
helpText?: string; helpText?: string;
showNumber?: boolean; showNumber?: boolean;
_stepNumber?: number; // Internal prop set by ToolStepContainer
tooltip?: { tooltip?: {
content?: React.ReactNode; content?: React.ReactNode;
tips?: TooltipTip[]; tips?: TooltipTip[];
@ -74,6 +74,7 @@ const ToolStep = ({
completedMessage, completedMessage,
helpText, helpText,
showNumber, showNumber,
_stepNumber,
tooltip tooltip
}: ToolStepProps) => { }: ToolStepProps) => {
if (!isVisible) return null; if (!isVisible) return null;
@ -86,7 +87,7 @@ const ToolStep = ({
return parent ? parent.visibleStepCount >= 3 : false; return parent ? parent.visibleStepCount >= 3 : false;
}, [showNumber, parent]); }, [showNumber, parent]);
const stepNumber = parent?.getStepNumber?.() || 1; const stepNumber = _stepNumber || 1;
return ( return (
<Paper <Paper
@ -163,9 +164,24 @@ export interface ToolStepContainerProps {
} }
export const ToolStepContainer = ({ children }: ToolStepContainerProps) => { export const ToolStepContainer = ({ children }: ToolStepContainerProps) => {
const stepCounterRef = useRef(0); // Process children and inject step numbers for visible ToolSteps
const processedChildren = useMemo(() => {
let visibleStepNumber = 1;
return React.Children.map(children, (child) => {
if (React.isValidElement(child) && child.type === ToolStep) {
const isVisible = (child.props as ToolStepProps).isVisible !== false;
if (isVisible) {
return React.cloneElement(child, {
...child.props,
_stepNumber: visibleStepNumber++
} as ToolStepProps);
}
}
return child;
});
}, [children]);
// Count visible ToolStep children
const visibleStepCount = useMemo(() => { const visibleStepCount = useMemo(() => {
let count = 0; let count = 0;
React.Children.forEach(children, (child) => { React.Children.forEach(children, (child) => {
@ -178,15 +194,12 @@ export const ToolStepContainer = ({ children }: ToolStepContainerProps) => {
}, [children]); }, [children]);
const contextValue = useMemo(() => ({ const contextValue = useMemo(() => ({
visibleStepCount, visibleStepCount
getStepNumber: () => ++stepCounterRef.current
}), [visibleStepCount]); }), [visibleStepCount]);
stepCounterRef.current = 0;
return ( return (
<ToolStepContext.Provider value={contextValue}> <ToolStepContext.Provider value={contextValue}>
{children} {processedChildren}
</ToolStepContext.Provider> </ToolStepContext.Provider>
); );
} }

View File

@ -96,8 +96,8 @@ const OCR = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
); );
return ( return (
<ToolStepContainer>
<Stack gap="sm" h="100%" p="sm" style={{ overflow: 'auto' }}> <Stack gap="sm" h="100%" p="sm" style={{ overflow: 'auto' }}>
<ToolStepContainer>
{/* Files Step */} {/* Files Step */}
<ToolStep <ToolStep
title="Files" title="Files"
@ -210,8 +210,8 @@ const OCR = ({ onPreviewFile, onComplete, onError }: BaseToolProps) => {
/> />
</Stack> </Stack>
</ToolStep> </ToolStep>
</Stack>
</ToolStepContainer> </ToolStepContainer>
</Stack>
); );
} }