From b4896ea8e295bddf32438a8bda07fdeab2a4d7dd Mon Sep 17 00:00:00 2001 From: Lior Keren Date: Tue, 19 Mar 2024 13:56:26 +0200 Subject: [PATCH] refactor(CVEs): Add updateRefFuncBuilder helper function to remove code duplication --- src/Components/SmartComponents/CVEs/CVEs.js | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Components/SmartComponents/CVEs/CVEs.js b/src/Components/SmartComponents/CVEs/CVEs.js index d09b4975a..d5ac2c542 100644 --- a/src/Components/SmartComponents/CVEs/CVEs.js +++ b/src/Components/SmartComponents/CVEs/CVEs.js @@ -111,31 +111,32 @@ export const CVEs = ({ rbac }) => { ); }; - const showBusinessRiskModal = (cvesList, goToFirstPage) => { + // helper function for showBusinessRiskModal and showStatusModal: + const updateRefFuncBuilder = (goToFirstPage) => { const { meta } = cves; + + return (() => { + setCauseARerender(!causeARerender); + dispatch(clearCVEsStore()); + updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, parameters, apply); + }); + }; + + const showBusinessRiskModal = (cvesList, goToFirstPage) => { setBusinessRiskModal(() => () => { - setCauseARerender(!causeARerender); - dispatch(clearCVEsStore()); - updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, parameters, apply); - }} + updateRef={updateRefFuncBuilder(goToFirstPage)} /> ); }; const showStatusModal = (cvesList, goToFirstPage) => { - const { meta } = cves; setStatusModal(() => () => { - setCauseARerender(!causeARerender); - dispatch(clearCVEsStore()); - updateRef(goToFirstPage ? { ...meta, page: 1 } : meta, parameters, apply); - }} + updateRef={updateRefFuncBuilder(goToFirstPage)} /> ); };