Skip to content

Commit

Permalink
feat: define and use FILTERS as enumeration options
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlukasse committed Jan 31, 2025
1 parent 6a8d79c commit a613c16
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import Covariates from './Covariates';
import PhenotypeHistogram from '../Diagrams/PhenotypeHistogram/PhenotypeHistogram';
import './Covariates.css';
import FILTERS from '../../../SharedUtils/FiltersEnumeration';

const ContinuousCovariates = ({
dispatch,
Expand Down Expand Up @@ -36,14 +37,14 @@ const ContinuousCovariates = ({
const filters = prevSelected.filters ? [...prevSelected.filters] : [];

// Find the index of the ">=" filter
const minFilterIndex = filters.findIndex((filter) => filter.type === ">=");
const minFilterIndex = filters.findIndex((filter) => filter.type === FILTERS.greaterThanOrEqualTo);

if (minFilterIndex !== -1) {
// Update the existing ">=" filter
filters[minFilterIndex] = { type: ">=", value: minOutlierCutoff };
filters[minFilterIndex] = { type: FILTERS.greaterThanOrEqualTo, value: minOutlierCutoff };
} else {
// Add a new ">=" filter
filters.push({ type: ">=", value: minOutlierCutoff });
filters.push({ type: FILTERS.greaterThanOrEqualTo, value: minOutlierCutoff });
}

return { ...prevSelected, filters };
Expand All @@ -56,14 +57,14 @@ const ContinuousCovariates = ({
const filters = prevSelected.filters ? [...prevSelected.filters] : [];

// Find the index of the "<=" filter
const maxFilterIndex = filters.findIndex((filter) => filter.type === "<=");
const maxFilterIndex = filters.findIndex((filter) => filter.type === FILTERS.lessThanOrEqualTo);

if (maxFilterIndex !== -1) {
// Update the existing "<=" filter
filters[maxFilterIndex] = { type: "<=", value: maxOutlierCutoff };
filters[maxFilterIndex] = { type: FILTERS.lessThanOrEqualTo, value: maxOutlierCutoff };
} else {
// Add a new "<=" filter
filters.push({ type: "<=", value: maxOutlierCutoff });
filters.push({ type: FILTERS.lessThanOrEqualTo, value: maxOutlierCutoff });
}

return { ...prevSelected, filters };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Histogram from '../../../../SharedUtils/DataViz/Histogram/Histogram';
import { useSourceContext } from '../../../Utils/Source';
import ACTIONS from '../../../Utils/StateManagement/Actions';
import { MESSAGES } from '../../../Utils/constants';
import FILTERS from '../../../../SharedUtils/FiltersEnumeration';

const PhenotypeHistogram = ({
dispatch,
Expand Down Expand Up @@ -87,8 +88,8 @@ const PhenotypeHistogram = ({
xAxisLegend: selectedContinuousItem.concept_name,
yAxisLegend: 'Persons',
useAnimation,
minCutoff: selectedContinuousItem.filters?.find(filter => filter.type === '>=')?.value ?? undefined,
maxCutoff: selectedContinuousItem.filters?.find(filter => filter.type === '<=')?.value ?? undefined,
minCutoff: selectedContinuousItem.filters?.find(filter => filter.type === FILTERS.greaterThanOrEqualTo)?.value ?? undefined,
maxCutoff: selectedContinuousItem.filters?.find(filter => filter.type === FILTERS.lessThanOrEqualTo)?.value ?? undefined,
};
return (
<React.Fragment>
Expand Down
9 changes: 9 additions & 0 deletions src/Analysis/SharedUtils/FiltersEnumeration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const FILTERS = {
greaterThanOrEqualTo: '>=',
lessThanOrEqualTo: '<=',
equalTo: '=',
differentFrom: '!=',
in: 'in',
};

export default FILTERS;

0 comments on commit a613c16

Please sign in to comment.