1
0
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:
FredrikOseberg 2025-10-21 13:23:34 +02:00
parent 39c1a963b5
commit d9503de15c
No known key found for this signature in database
GPG Key ID: 282FD8A6D8F9BCF0
3 changed files with 1 additions and 115 deletions

View File

@ -29,41 +29,10 @@ import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useCh
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests'; import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
import useToast from 'hooks/useToast'; import useToast from 'hooks/useToast';
import type { UpdateMilestoneProgressionSchema } from 'openapi'; 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 { MilestoneAutomationSection } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/MilestoneAutomationSection.tsx';
import { MilestoneTransitionDisplay } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/MilestoneTransitionDisplay.tsx'; import { MilestoneTransitionDisplay } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/MilestoneTransitionDisplay.tsx';
import type { MilestoneStatus } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/ReleasePlanMilestoneStatus.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 }) => ({ const StyledTabs = styled(Tabs)(({ theme }) => ({
display: 'flex', display: 'flex',
flexFlow: 'column', flexFlow: 'column',
@ -339,20 +308,7 @@ const CreateMilestoneProgression: FC<{
(milestone) => milestone.id === change.payload.sourceMilestone, (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 ( return (
<ReleasePlanProvider getPendingProgressionChange={getPendingProgressionChange}>
<StyledTabs> <StyledTabs>
<ChangeItemWrapper> <ChangeItemWrapper>
<ChangeItemInfo> <ChangeItemInfo>
@ -422,7 +378,6 @@ const CreateMilestoneProgression: FC<{
/> />
</TabPanel> </TabPanel>
</StyledTabs> </StyledTabs>
</ReleasePlanProvider>
); );
}; };
@ -482,20 +437,7 @@ const UpdateMilestoneProgression: FC<{
(milestone) => milestone.id === change.payload.sourceMilestoneId, (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 ( return (
<ReleasePlanProvider getPendingProgressionChange={getPendingProgressionChange}>
<StyledTabs> <StyledTabs>
<ChangeItemWrapper> <ChangeItemWrapper>
<ChangeItemInfo> <ChangeItemInfo>
@ -563,7 +505,6 @@ const UpdateMilestoneProgression: FC<{
/> />
</TabPanel> </TabPanel>
</StyledTabs> </StyledTabs>
</ReleasePlanProvider>
); );
}; };
@ -689,11 +630,7 @@ const ConsolidatedProgressionChanges: FC<{
return `${action} automation for ${sourceName}`; return `${action} automation for ${sourceName}`;
}); });
// Create a function to get pending progression changes for the context
const getPendingProgressionChange = createGetPendingProgressionChange(progressionChanges);
return ( return (
<ReleasePlanProvider getPendingProgressionChange={getPendingProgressionChange}>
<StyledTabs> <StyledTabs>
<ChangeItemWrapper> <ChangeItemWrapper>
<ChangeItemInfo> <ChangeItemInfo>
@ -783,7 +720,6 @@ const ConsolidatedProgressionChanges: FC<{
/> />
</TabPanel> </TabPanel>
</StyledTabs> </StyledTabs>
</ReleasePlanProvider>
); );
}; };

View File

@ -26,7 +26,6 @@ import type {
CreateMilestoneProgressionSchema, CreateMilestoneProgressionSchema,
UpdateMilestoneProgressionSchema, UpdateMilestoneProgressionSchema,
} from 'openapi'; } from 'openapi';
import { ReleasePlanProvider } from './ReleasePlanContext.tsx';
import { ReleasePlanMilestoneItem } from './ReleasePlanMilestoneItem/ReleasePlanMilestoneItem.tsx'; import { ReleasePlanMilestoneItem } from './ReleasePlanMilestoneItem/ReleasePlanMilestoneItem.tsx';
const StyledContainer = styled('div')(({ theme }) => ({ const StyledContainer = styled('div')(({ theme }) => ({
@ -381,9 +380,6 @@ export const ReleasePlan = ({
); );
return ( return (
<ReleasePlanProvider
getPendingProgressionChange={getPendingProgressionChange}
>
<StyledContainer> <StyledContainer>
<StyledHeader> <StyledHeader>
<StyledHeaderGroup> <StyledHeaderGroup>
@ -464,6 +460,5 @@ export const ReleasePlan = ({
/> />
)} )}
</StyledContainer> </StyledContainer>
</ReleasePlanProvider>
); );
}; };

View File

@ -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>
);
};