import { partial } from 'lodash'; import React, { FunctionComponent, useMemo } from 'react'; import { wrappable } from 'wdk-client/Utils/ComponentUtils'; import { getNodeId, getChildren as getNodeChildren, nodeSearchPredicate, BasicNodeComponent, CategoryTreeNode } from 'wdk-client/Utils/CategoryUtils'; import { makeSearchHelpText } from 'wdk-client/Utils/SearchUtils'; import CheckboxTree, { LinksPosition, CheckboxTreeStyleSpec } from '@veupathdb/coreui/dist/components/inputs/checkboxes/CheckboxTree/CheckboxTree'; import { getFilteredNodeChildren, nodeSearchPredicateWithHiddenNodes } from 'wdk-client/Utils/CheckboxTreeUtils'; const sharedCheckboxTreeContainerStyleSpec: React.CSSProperties = { position: 'relative', maxHeight: '75vh', overflow: 'hidden', display: 'flex', flexDirection: 'column', }; type ChangeHandler = (ids: string[]) => void; type NodePredicate = (node: CategoryTreeNode) => boolean; type Props = { title?: string; name?: string; /** Hide nodes for which predicate function returns false */ visibilityFilter?: NodePredicate; autoFocusSearchBox?: boolean; searchBoxPlaceholder: string; tree: CategoryTreeNode; /** String name representing what is being searched */ leafType: string, // do not make optional- add this prop to your calling code! selectedLeaves: string[]; currentSelection?: string[]; defaultSelection?: string[]; expandedBranches: string[]; searchTerm: string; searchIconName?: 'search' | 'filter'; searchIconPosition?: 'left' | 'right'; renderNode?: (node: CategoryTreeNode, path?: number[]) => React.ReactNode; isMultiPick?: boolean; onChange: ChangeHandler; onUiChange: ChangeHandler; onSearchTermChange: (term: string) => void; renderNoResults?: (searchTerm: string, tree: CategoryTreeNode) => React.ReactNode; isSelectable?: boolean; disableHelp?: boolean; linksPosition?: LinksPosition; showSearchBox?: boolean; containerClassName?: string; styleOverrides?: CheckboxTreeStyleSpec; /** * Used to apply styling to a container that wraps the CheckboxTree * If omitted, the container uses the sharedCheckboxTreeContainerStyleSpec default styles */ type?: 'headerMenu' | 'searchPane'; }; let CategoriesCheckboxTree: FunctionComponent = props => { let { autoFocusSearchBox, disableHelp, expandedBranches, visibilityFilter, isMultiPick, isSelectable, leafType, name, onChange, onSearchTermChange, onUiChange, renderNoResults, renderNode, searchBoxPlaceholder, searchTerm, searchIconName = 'filter', searchIconPosition = 'left', selectedLeaves, currentSelection, defaultSelection, title, tree, linksPosition, showSearchBox, containerClassName = '', styleOverrides = {}, type, } = props; if (tree.children.length == 0) { return (