From 0ca4e48fa820377056c1076ee53648abaa5d374c Mon Sep 17 00:00:00 2001 From: mariaozamiz Date: Thu, 30 May 2024 12:09:58 +0200 Subject: [PATCH] chore: move onFilterChange function to hook --- .../analysis/steps/1-outliers/OutliersStep.tsx | 12 +----------- .../analysis/steps/1-outliers/useOutliers.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/webapp/pages/analysis/steps/1-outliers/OutliersStep.tsx b/src/webapp/pages/analysis/steps/1-outliers/OutliersStep.tsx index c0e85fe..0bfde0e 100644 --- a/src/webapp/pages/analysis/steps/1-outliers/OutliersStep.tsx +++ b/src/webapp/pages/analysis/steps/1-outliers/OutliersStep.tsx @@ -2,7 +2,6 @@ import React from "react"; import { Dropdown } from "@eyeseetea/d2-ui-components"; import i18n from "$/utils/i18n"; import { algorithmList, thresholdList, useAnalysisOutlier } from "./useOutliers"; -import { Maybe } from "$/utils/ts-utils"; import { StepAnalysis } from "$/webapp/pages/analysis/steps/StepAnalysis"; import { PageStepProps } from "$/webapp/pages/analysis/AnalysisPage"; import { UserFeedbackContainer } from "$/webapp/components/user-feedback-container/UserFeedbackContainer"; @@ -11,7 +10,7 @@ export const OutliersStep: React.FC = React.memo(props => { const { title, analysis, section, updateAnalysis } = props; const [reload, refreshReload] = React.useState(0); - const { runAnalysisOutlier, isLoading, error, qualityFilters, setQualityFilters } = + const { runAnalysisOutlier, isLoading, error, qualityFilters, onFilterChange } = useAnalysisOutlier({ onSucess: qualityAnalysis => { refreshReload(reload + 1); @@ -28,15 +27,6 @@ export const OutliersStep: React.FC = React.memo(props => { ); }; - const onFilterChange = React.useCallback< - (value: Maybe, filterAttribute: string) => void - >( - (value, filterAttribute) => { - setQualityFilters(prev => ({ ...prev, [filterAttribute]: value })); - }, - [setQualityFilters] - ); - if (!analysis) return null; return ( diff --git a/src/webapp/pages/analysis/steps/1-outliers/useOutliers.ts b/src/webapp/pages/analysis/steps/1-outliers/useOutliers.ts index 234ab2d..a81676e 100644 --- a/src/webapp/pages/analysis/steps/1-outliers/useOutliers.ts +++ b/src/webapp/pages/analysis/steps/1-outliers/useOutliers.ts @@ -32,6 +32,15 @@ export function useAnalysisOutlier(props: UseRunAnalysisProps) { const [error, setError] = React.useState>(undefined); const [qualityFilters, setQualityFilters] = React.useState(defaultOutlierParams); + const onFilterChange = React.useCallback< + (value: Maybe, filterAttribute: string) => void + >( + (value, filterAttribute) => { + setQualityFilters(prev => ({ ...prev, [filterAttribute]: value })); + }, + [setQualityFilters] + ); + const runAnalysisOutlier = React.useCallback( (algorithm: string, analysisId: Id, sectionId: Id, threshold: string) => { setLoading(true); @@ -56,7 +65,14 @@ export function useAnalysisOutlier(props: UseRunAnalysisProps) { [compositionRoot.outlier.run, onSucess] ); - return { runAnalysisOutlier, isLoading, error, qualityFilters, setQualityFilters }; + return { + runAnalysisOutlier, + isLoading, + error, + qualityFilters, + setQualityFilters, + onFilterChange, + }; } type UseRunAnalysisProps = { onSucess: (qualityAnalysis: QualityAnalysis) => void };