Skip to content

Commit

Permalink
refactor(CVEs): Replace isFirstLoad with causeARerender to reduce unn…
Browse files Browse the repository at this point in the history
…ecessary rerenders
  • Loading branch information
LiorKGOW committed Mar 19, 2024
1 parent c10a980 commit 6ae2a33
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Components/SmartComponents/CVEs/CVEs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const CVEs = ({ rbac }) => {
const dispatch = useDispatch();
const [CveStatusModal, setStatusModal] = useState(() => () => null);
const [CveBusinessRiskModal, setBusinessRiskModal] = useState(() => () => null);
const [isFirstLoad, setFirstLoad] = useState(true);

// This state causes a re-render when updateRef is called in <BusinessRiskModal> and <StatusModal>
// to fetch the updated status of the CVEs
const [causeARerender, setCauseARerender] = useState(false);

const [[
canEditStatusOrBusinessRisk,
Expand Down Expand Up @@ -81,14 +84,9 @@ export const CVEs = ({ rbac }) => {
}, [shouldUseHybridSystemFilter]);

useEffect(() => {
if (isFirstLoad) {
setFirstLoad(false);
}
else {
dispatch(fetchCveListByAccount(parameters, shouldUseHybridSystemFilter));
setUrlParam({ ...parameters });
}
}, [parameters, isFirstLoad, shouldUseHybridSystemFilter]);
dispatch(fetchCveListByAccount(parameters, shouldUseHybridSystemFilter));
setUrlParam({ ...parameters });
}, [parameters, causeARerender, shouldUseHybridSystemFilter]);

useEffect(() => {
return () => {
Expand Down Expand Up @@ -119,7 +117,7 @@ export const CVEs = ({ rbac }) => {
<BusinessRiskModal
cves={cvesList}
updateRef={() => {
setFirstLoad(true);
setCauseARerender(!causeARerender);
dispatch(clearCVEsStore());
updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, parameters, apply);
}}
Expand All @@ -134,7 +132,7 @@ export const CVEs = ({ rbac }) => {
cves={cvesList}
canEditPairStatus={canEditPairStatus}
updateRef={() => {
setFirstLoad(true);
setCauseARerender(!causeARerender);
dispatch(clearCVEsStore());
updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, parameters, apply);
}}
Expand Down

0 comments on commit 6ae2a33

Please sign in to comment.