From 3695e1af4a53309a452e460c69b41049e7caedf7 Mon Sep 17 00:00:00 2001 From: dkmyta Date: Wed, 28 Aug 2024 12:52:31 -0700 Subject: [PATCH] Use fixableThreats prop from scan status --- .../protect/src/js/hooks/use-fixers.ts | 40 +------------------ 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/projects/plugins/protect/src/js/hooks/use-fixers.ts b/projects/plugins/protect/src/js/hooks/use-fixers.ts index e4eee1cd19003..c8c6e67506d7c 100644 --- a/projects/plugins/protect/src/js/hooks/use-fixers.ts +++ b/projects/plugins/protect/src/js/hooks/use-fixers.ts @@ -1,4 +1,3 @@ -import { useMemo } from 'react'; import useFixersMutation from '../data/scan/use-fixers-mutation'; import useFixersQuery from '../data/scan/use-fixers-query'; import useScanStatusQuery from '../data/scan/use-scan-status-query'; @@ -10,45 +9,10 @@ import useScanStatusQuery from '../data/scan/use-scan-status-query'; */ export default function useFixers() { const { data: status } = useScanStatusQuery(); + const { fixableThreats } = status; const fixersMutation = useFixersMutation(); - const fixableThreats = useMemo( () => { - const result = []; - status.core?.threats.forEach( threat => { - if ( threat.fixable ) { - result.push( threat ); - } - } ); - status.plugins?.forEach( plugin => { - plugin.threats.forEach( threat => { - if ( threat.fixable ) { - result.push( threat ); - } - } ); - } ); - status.themes?.forEach( theme => { - theme.threats.forEach( threat => { - if ( threat.fixable ) { - result.push( threat ); - } - } ); - } ); - status.files?.forEach( threat => { - if ( threat.fixable ) { - result.push( threat ); - } - } ); - status.database?.forEach( threat => { - if ( threat.fixable ) { - result.push( threat ); - } - } ); - return result; - }, [ status ] ); - - const { data: fixersStatus } = useFixersQuery( { - threatIds: fixableThreats.map( threat => parseInt( threat.id ) ), - } ); + const { data: fixersStatus } = useFixersQuery( { threatIds: fixableThreats } ); const fixThreats = async ( threatIds: number[] ) => fixersMutation.mutateAsync( threatIds );