import { isEqual, orderBy } from 'lodash'; import React from 'react'; import { State } from 'wdk-client/StoreModules/MatchedTranscriptsFilterStoreModule'; import { makeClassNameHelper } from 'wdk-client/Utils/ComponentUtils'; import './MatchedTranscriptsFilter.scss'; import { FilterSummary } from 'wdk-client/Actions/MatchedTranscriptsFilterActions'; const cx = makeClassNameHelper('MatchedTranscriptsFilter'); type Props = Required & { filterValue: { values: string[]; }; description: string; optionLeadin: string; optionLabel: Record, toggleExpansion: (expand: boolean) => void; updateFilter: (selection: string[]) => void; updateSelection: (selections: string[]) => void; }; export default function MatchedTranscriptsFilter(props: Props) { const { expanded, summary, selection = props.filterValue.values, description, optionLabel, optionLeadin, toggleExpansion, updateFilter, updateSelection, filterValue, } = props; if (!hasMissingTranscripts(summary)) return null; const buttonDisabled = isEqual(selection, filterValue.values); const sortedKeys = orderBy( Object.keys(summary), entry => entry.replace(/Y/g, '0').replace(/N/g, '1') ); return (
{description}
{expanded &&
{optionLeadin}:
{sortedKeys.map(criteria => { const inputId = `MatchedTranscript--${criteria}`; const isSelected = selection.includes(criteria); const isDisabled = summary[criteria] == 0; return (
{summary[criteria].toLocaleString()}
transcripts
); function handleChange() { const newSelection = sortedKeys.filter(key => key === criteria ? !isSelected : selection.includes(key) ); updateSelection(newSelection); } })}
}
); } function hasMissingTranscripts(summary: FilterSummary) { return Object.keys(summary) .some(key => key.includes('N') && summary[key] > 0); }