Skip to content

Commit

Permalink
Update useFixers hook for compatibility with type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nateweller committed Oct 2, 2024
1 parent 39dd7ed commit 47af3ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions projects/plugins/protect/src/js/hooks/use-fixers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const fixerTimestampIsStale = ( lastUpdatedTimestamp: string ) => {
};

export const fixerStatusIsStale = ( fixerStatus: ThreatFixStatus ) => {
return fixerStatus.status === 'in_progress' && fixerTimestampIsStale( fixerStatus.last_updated );
return (
'status' in fixerStatus &&
fixerStatus.status === 'in_progress' &&
fixerTimestampIsStale( fixerStatus.last_updated )
);
};

type UseFixersResult = {
Expand All @@ -40,13 +44,20 @@ export default function useFixers(): UseFixersResult {

const isThreatFixInProgress = useCallback(
( threatId: number ) => {
return fixersStatus?.threats?.[ threatId ]?.status === 'in_progress';
if ( fixersStatus.ok === false ) {
return false;
}
const threatFix = fixersStatus.threats?.[ threatId ];
return 'status' in threatFix && threatFix.status === 'in_progress';
},
[ fixersStatus ]
);

const isThreatFixStale = useCallback(
( threatId: number ) => {
if ( fixersStatus.ok === false ) {
return false;
}
const threatFixStatus = fixersStatus?.threats?.[ threatId ];
return threatFixStatus ? fixerStatusIsStale( threatFixStatus ) : false;
},
Expand Down
2 changes: 2 additions & 0 deletions projects/plugins/protect/src/js/types/fixers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ export type ThreatFixStatusSuccess = {
status: FixerStatus; // Threat fix status (one of 'not_started', 'in_progress', etc.)
last_updated: string; // Last updated timestamp
};

export type ThreatFixStatus = ThreatFixError | ThreatFixStatusSuccess;

0 comments on commit 47af3ae

Please sign in to comment.