From c2af25442e3198a4e1806abc2ff9e6ff51e7ac34 Mon Sep 17 00:00:00 2001 From: Greg Thompson Date: Fri, 30 Oct 2020 11:17:25 -0600 Subject: [PATCH] cases status useCallback --- .../cases/components/case_status/index.tsx | 103 +++++++++--------- .../cases/components/case_view/index.tsx | 9 +- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/x-pack/plugins/security_solution/public/cases/components/case_status/index.tsx b/x-pack/plugins/security_solution/public/cases/components/case_status/index.tsx index db008707280f0..2d3a7850eb0b6 100644 --- a/x-pack/plugins/security_solution/public/cases/components/case_status/index.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/case_status/index.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; +import React, { useCallback } from 'react'; import styled, { css } from 'styled-components'; import { EuiBadge, @@ -62,57 +62,62 @@ const CaseStatusComp: React.FC = ({ title, toggleStatusCase, value, -}) => ( - - - - - - {i18n.STATUS} - - - {status} - - +}) => { + const handleToggleStatusCase = useCallback(() => { + toggleStatusCase(!isSelected); + }, [toggleStatusCase, isSelected]); + return ( + + + + + + {i18n.STATUS} + + + {status} + + + + + {title} + + + + + + + + + + + + {i18n.CASE_REFRESH} + - {title} - - - + + {buttonLabel} + + + + - - - - - - - {i18n.CASE_REFRESH} - - - - toggleStatusCase(!isSelected)} - > - {buttonLabel} - - - - - - - - -); + + + ); +}; export const CaseStatus = React.memo(CaseStatusComp); diff --git a/x-pack/plugins/security_solution/public/cases/components/case_view/index.tsx b/x-pack/plugins/security_solution/public/cases/components/case_view/index.tsx index b81bba9e67e9a..7ee2b856f8786 100644 --- a/x-pack/plugins/security_solution/public/cases/components/case_view/index.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/case_view/index.tsx @@ -307,6 +307,11 @@ export const CaseComponent = React.memo( [allCasesLink] ); + const isSelected = useMemo(() => caseStatusData.isSelected, [caseStatusData]); + const handleToggleStatusCase = useCallback(() => { + toggleStatusCase(!isSelected); + }, [toggleStatusCase, isSelected]); + return ( <> @@ -330,7 +335,7 @@ export const CaseComponent = React.memo( disabled={!userCanCrud} isLoading={isLoading && updateKey === 'status'} onRefresh={handleRefresh} - toggleStatusCase={() => toggleStatusCase(!caseStatusData.isSelected)} + toggleStatusCase={handleToggleStatusCase} {...caseStatusData} /> @@ -364,7 +369,7 @@ export const CaseComponent = React.memo( isDisabled={!userCanCrud} isLoading={isLoading && updateKey === 'status'} fill={caseStatusData.isSelected} - onClick={() => toggleStatusCase(!caseStatusData.isSelected)} + onClick={handleToggleStatusCase} > {caseStatusData.buttonLabel}