Skip to content

Commit

Permalink
Use fixableThreats prop from scan status
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmyta committed Aug 28, 2024
1 parent 49fda28 commit 3695e1a
Showing 1 changed file with 2 additions and 38 deletions.
40 changes: 2 additions & 38 deletions projects/plugins/protect/src/js/hooks/use-fixers.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 );

Expand Down

0 comments on commit 3695e1a

Please sign in to comment.