From ce6ff2578a2990658b96ea5f738d79c82e5bd890 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Fri, 16 Jun 2023 13:36:23 +0200 Subject: [PATCH] fix: can review CR with skip change request (#3998) --- .../ChangeRequestOverview/ChangeRequestOverview.tsx | 5 +++-- frontend/src/hooks/useChangeRequestsEnabled.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx index 6ce0391e34..323668bc61 100644 --- a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx @@ -83,13 +83,14 @@ export const ChangeRequestOverview: FC = () => { const { refetch: refetchChangeRequestOpen } = usePendingChangeRequests(projectId); const { setToastData, setToastApiError } = useToast(); - const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId); + const { isChangeRequestConfiguredForReview } = + useChangeRequestsEnabled(projectId); if (!changeRequest) { return null; } - const allowChangeRequestActions = isChangeRequestConfigured( + const allowChangeRequestActions = isChangeRequestConfiguredForReview( changeRequest.environment ); diff --git a/frontend/src/hooks/useChangeRequestsEnabled.ts b/frontend/src/hooks/useChangeRequestsEnabled.ts index da487d3465..b53839ce3c 100644 --- a/frontend/src/hooks/useChangeRequestsEnabled.ts +++ b/frontend/src/hooks/useChangeRequestsEnabled.ts @@ -25,6 +25,18 @@ export const useChangeRequestsEnabled = (projectId: string) => { [JSON.stringify(data)] ); + const isChangeRequestConfiguredForReview = React.useCallback( + (environment: string): boolean => { + return data.some(draft => { + return ( + draft.environment === environment && + draft.changeRequestEnabled + ); + }); + }, + [JSON.stringify(data)] + ); + const isChangeRequestConfiguredInAnyEnv = React.useCallback((): boolean => { return data.some(draft => draft.changeRequestEnabled); }, [JSON.stringify(data)]); @@ -32,5 +44,6 @@ export const useChangeRequestsEnabled = (projectId: string) => { return { isChangeRequestConfigured, isChangeRequestConfiguredInAnyEnv, + isChangeRequestConfiguredForReview, }; };