Skip to content

Commit

Permalink
chore: move onFilterChange function to hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mariaozamiz committed May 30, 2024
1 parent be7f27f commit 0ca4e48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/webapp/pages/analysis/steps/1-outliers/OutliersStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -11,7 +10,7 @@ export const OutliersStep: React.FC<PageStepProps> = 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);
Expand All @@ -28,15 +27,6 @@ export const OutliersStep: React.FC<PageStepProps> = React.memo(props => {
);
};

const onFilterChange = React.useCallback<
(value: Maybe<string>, filterAttribute: string) => void
>(
(value, filterAttribute) => {
setQualityFilters(prev => ({ ...prev, [filterAttribute]: value }));
},
[setQualityFilters]
);

if (!analysis) return null;

return (
Expand Down
18 changes: 17 additions & 1 deletion src/webapp/pages/analysis/steps/1-outliers/useOutliers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export function useAnalysisOutlier(props: UseRunAnalysisProps) {
const [error, setError] = React.useState<Maybe<string>>(undefined);
const [qualityFilters, setQualityFilters] = React.useState(defaultOutlierParams);

const onFilterChange = React.useCallback<
(value: Maybe<string>, 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);
Expand All @@ -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 };

0 comments on commit 0ca4e48

Please sign in to comment.