Skip to content

Commit

Permalink
[filters] terms with no selection = no filtering
Browse files Browse the repository at this point in the history
relates #130
  • Loading branch information
paulgirard committed Jan 30, 2024
1 parent 54eaf12 commit 75d4063
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/GraphFilters/TermsFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FC, useEffect, useState } from "react";
import Select from "react-select";

import { TermsFilterType } from "../../core/filters/types";
import { graphDatasetAtom, parentFilteredGraphAtom } from "../../core/graph";
import { useFiltersActions } from "../../core/context/dataContexts";
import { countBy, flatMap, identity, sortBy, toPairs } from "lodash";
import { toString } from "../../core/utils/casting";
import { useTranslation } from "react-i18next";
import { useFiltersActions } from "../../core/context/dataContexts";
import { TermsFilterType } from "../../core/filters/types";
import { graphDatasetAtom, parentFilteredGraphAtom } from "../../core/graph";
import { useReadAtom } from "../../core/utils/atoms";
import { toString } from "../../core/utils/casting";
import { DEFAULT_SELECT_PROPS } from "../consts";

const TermsFilterEditor: FC<{ filter: TermsFilterType }> = ({ filter }) => {
Expand All @@ -34,7 +34,8 @@ const TermsFilterEditor: FC<{ filter: TermsFilterType }> = ({ filter }) => {
{...DEFAULT_SELECT_PROPS}
value={filter.terms ? Array.from(filter.terms).map((t) => ({ label: t, value: t })) : []}
onChange={(options) => {
replaceCurrentFilter({ ...filter, terms: new Set(options.map((o) => o.value)) });
const selectedValues = new Set(options.map((o) => o.value))
replaceCurrentFilter({ ...filter, terms: selectedValues.size > 0 ? selectedValues : undefined });
}}
isMulti
options={sortBy(toPairs(dataTerms), ([_term, nbOcc]) => -1 * nbOcc).map(([term, nbOcc]) => ({
Expand Down

0 comments on commit 75d4063

Please sign in to comment.