mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	refactor: remove ReleasePlanContext in favor of props
Completed migration from context-based to props-based architecture by removing ReleasePlanContext and ReleasePlanProvider. Changes: - Deleted ReleasePlanContext.tsx (no longer needed) - Removed ReleasePlanProvider wrapper from ReleasePlan.tsx - Removed ReleasePlanProvider wrappers from ReleasePlanChange.tsx (3 instances) - All pending progression change data now passed explicitly via props Benefits: - Simpler architecture with explicit data flow - No hidden dependencies via context - Easier to understand and maintain - TypeScript compilation passes ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
		
							parent
							
								
									39c1a963b5
								
							
						
					
					
						commit
						d9503de15c
					
				@ -29,41 +29,10 @@ import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useCh
 | 
			
		||||
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
 | 
			
		||||
import useToast from 'hooks/useToast';
 | 
			
		||||
import type { UpdateMilestoneProgressionSchema } from 'openapi';
 | 
			
		||||
import { ReleasePlanProvider } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanContext.tsx';
 | 
			
		||||
import { MilestoneAutomationSection } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/MilestoneAutomationSection.tsx';
 | 
			
		||||
import { MilestoneTransitionDisplay } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/MilestoneTransitionDisplay.tsx';
 | 
			
		||||
import type { MilestoneStatus } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/ReleasePlanMilestoneStatus.tsx';
 | 
			
		||||
 | 
			
		||||
// Indicates that a change is in draft and not yet part of a change request
 | 
			
		||||
const PENDING_CHANGE_REQUEST_ID = -1;
 | 
			
		||||
 | 
			
		||||
// Helper function to create getPendingProgressionChange for context
 | 
			
		||||
const createGetPendingProgressionChange = (
 | 
			
		||||
    progressionChanges: (IChangeRequestCreateMilestoneProgression | IChangeRequestUpdateMilestoneProgression | IChangeRequestDeleteMilestoneProgression)[]
 | 
			
		||||
) => {
 | 
			
		||||
    return (sourceMilestoneId: string) => {
 | 
			
		||||
        const change = progressionChanges.find(
 | 
			
		||||
            (progressionChange) =>
 | 
			
		||||
                (progressionChange.action === 'updateMilestoneProgression' &&
 | 
			
		||||
                    (progressionChange.payload.sourceMilestoneId === sourceMilestoneId ||
 | 
			
		||||
                        progressionChange.payload.sourceMilestone === sourceMilestoneId)) ||
 | 
			
		||||
                (progressionChange.action === 'deleteMilestoneProgression' &&
 | 
			
		||||
                    (progressionChange.payload.sourceMilestoneId === sourceMilestoneId ||
 | 
			
		||||
                        progressionChange.payload.sourceMilestone === sourceMilestoneId)) ||
 | 
			
		||||
                (progressionChange.action === 'createMilestoneProgression' &&
 | 
			
		||||
                    progressionChange.payload.sourceMilestone === sourceMilestoneId),
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        if (!change) return null;
 | 
			
		||||
 | 
			
		||||
        return {
 | 
			
		||||
            action: change.action,
 | 
			
		||||
            payload: change.payload,
 | 
			
		||||
            changeRequestId: PENDING_CHANGE_REQUEST_ID,
 | 
			
		||||
        };
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const StyledTabs = styled(Tabs)(({ theme }) => ({
 | 
			
		||||
    display: 'flex',
 | 
			
		||||
    flexFlow: 'column',
 | 
			
		||||
@ -339,20 +308,7 @@ const CreateMilestoneProgression: FC<{
 | 
			
		||||
        (milestone) => milestone.id === change.payload.sourceMilestone,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // Create a function to get this specific change for the context
 | 
			
		||||
    const getPendingProgressionChange = (sourceMilestoneId: string) => {
 | 
			
		||||
        if (sourceMilestoneId === change.payload.sourceMilestone) {
 | 
			
		||||
            return {
 | 
			
		||||
                action: change.action,
 | 
			
		||||
                payload: change.payload,
 | 
			
		||||
                changeRequestId: -1,
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <ReleasePlanProvider getPendingProgressionChange={getPendingProgressionChange}>
 | 
			
		||||
        <StyledTabs>
 | 
			
		||||
            <ChangeItemWrapper>
 | 
			
		||||
                <ChangeItemInfo>
 | 
			
		||||
@ -422,7 +378,6 @@ const CreateMilestoneProgression: FC<{
 | 
			
		||||
                />
 | 
			
		||||
            </TabPanel>
 | 
			
		||||
        </StyledTabs>
 | 
			
		||||
        </ReleasePlanProvider>
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -482,20 +437,7 @@ const UpdateMilestoneProgression: FC<{
 | 
			
		||||
        (milestone) => milestone.id === change.payload.sourceMilestoneId,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // Create a function to get this specific change for the context
 | 
			
		||||
    const getPendingProgressionChange = (sourceMilestoneId: string) => {
 | 
			
		||||
        if (sourceMilestoneId === sourceId) {
 | 
			
		||||
            return {
 | 
			
		||||
                action: change.action,
 | 
			
		||||
                payload: change.payload,
 | 
			
		||||
                changeRequestId: -1,
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <ReleasePlanProvider getPendingProgressionChange={getPendingProgressionChange}>
 | 
			
		||||
        <StyledTabs>
 | 
			
		||||
            <ChangeItemWrapper>
 | 
			
		||||
                <ChangeItemInfo>
 | 
			
		||||
@ -563,7 +505,6 @@ const UpdateMilestoneProgression: FC<{
 | 
			
		||||
                />
 | 
			
		||||
            </TabPanel>
 | 
			
		||||
        </StyledTabs>
 | 
			
		||||
        </ReleasePlanProvider>
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -689,11 +630,7 @@ const ConsolidatedProgressionChanges: FC<{
 | 
			
		||||
        return `${action} automation for ${sourceName}`;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // Create a function to get pending progression changes for the context
 | 
			
		||||
    const getPendingProgressionChange = createGetPendingProgressionChange(progressionChanges);
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <ReleasePlanProvider getPendingProgressionChange={getPendingProgressionChange}>
 | 
			
		||||
        <StyledTabs>
 | 
			
		||||
            <ChangeItemWrapper>
 | 
			
		||||
                <ChangeItemInfo>
 | 
			
		||||
@ -783,7 +720,6 @@ const ConsolidatedProgressionChanges: FC<{
 | 
			
		||||
                />
 | 
			
		||||
            </TabPanel>
 | 
			
		||||
        </StyledTabs>
 | 
			
		||||
        </ReleasePlanProvider>
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,6 @@ import type {
 | 
			
		||||
    CreateMilestoneProgressionSchema,
 | 
			
		||||
    UpdateMilestoneProgressionSchema,
 | 
			
		||||
} from 'openapi';
 | 
			
		||||
import { ReleasePlanProvider } from './ReleasePlanContext.tsx';
 | 
			
		||||
import { ReleasePlanMilestoneItem } from './ReleasePlanMilestoneItem/ReleasePlanMilestoneItem.tsx';
 | 
			
		||||
 | 
			
		||||
const StyledContainer = styled('div')(({ theme }) => ({
 | 
			
		||||
@ -381,10 +380,7 @@ export const ReleasePlan = ({
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <ReleasePlanProvider
 | 
			
		||||
            getPendingProgressionChange={getPendingProgressionChange}
 | 
			
		||||
        >
 | 
			
		||||
            <StyledContainer>
 | 
			
		||||
        <StyledContainer>
 | 
			
		||||
                <StyledHeader>
 | 
			
		||||
                    <StyledHeaderGroup>
 | 
			
		||||
                        <StyledHeaderTitleLabel>
 | 
			
		||||
@ -464,6 +460,5 @@ export const ReleasePlan = ({
 | 
			
		||||
                />
 | 
			
		||||
            )}
 | 
			
		||||
        </StyledContainer>
 | 
			
		||||
        </ReleasePlanProvider>
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,45 +0,0 @@
 | 
			
		||||
import { createContext, useContext, type ReactNode } from 'react';
 | 
			
		||||
 | 
			
		||||
interface PendingProgressionChange {
 | 
			
		||||
    action: string;
 | 
			
		||||
    payload: any;
 | 
			
		||||
    changeRequestId: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface ReleasePlanContextType {
 | 
			
		||||
    getPendingProgressionChange: (
 | 
			
		||||
        sourceMilestoneId: string,
 | 
			
		||||
    ) => PendingProgressionChange | null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const ReleasePlanContext = createContext<ReleasePlanContextType | null>(null);
 | 
			
		||||
 | 
			
		||||
export const useReleasePlanContext = () => {
 | 
			
		||||
    const context = useContext(ReleasePlanContext);
 | 
			
		||||
    if (!context) {
 | 
			
		||||
        // Return a fallback context that returns null for all milestone IDs
 | 
			
		||||
        // This allows the component to work without the provider (e.g., in change request views)
 | 
			
		||||
        return {
 | 
			
		||||
            getPendingProgressionChange: () => null,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
    return context;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
interface ReleasePlanProviderProps {
 | 
			
		||||
    children: ReactNode;
 | 
			
		||||
    getPendingProgressionChange: (
 | 
			
		||||
        sourceMilestoneId: string,
 | 
			
		||||
    ) => PendingProgressionChange | null;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const ReleasePlanProvider = ({
 | 
			
		||||
    children,
 | 
			
		||||
    getPendingProgressionChange,
 | 
			
		||||
}: ReleasePlanProviderProps) => {
 | 
			
		||||
    return (
 | 
			
		||||
        <ReleasePlanContext.Provider value={{ getPendingProgressionChange }}>
 | 
			
		||||
            {children}
 | 
			
		||||
        </ReleasePlanContext.Provider>
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user