import * as React from "react" ; import * as MaterialUI from "@material-ui/core" ; import { Classifier , Category } from "@piximi/types" ; type HideOtherCategoriesProps = { classifier : Classifier ; categoryProp : Category ; closeMenu : ( ) => void ; makeCategoryInvisible : ( categoryIdentifier : string , visibility : boolean ) => void ; } ; export const HideOtherCategoriesMenuItem = ( props ) => { const { classifier , categoryProp , closeMenu , makeCategoryInvisible } = props ; const isOnlyVisibleCategory = classifier . categories . filter ( ( category ) => category . identifier !== categoryProp . identifier ) . filter ( ( category ) => category . visualization . visible ) . length === 0 ; const listItemText = isOnlyVisibleCategory ? "Show other categories" : "Hide other categories" ; const onClick = ( ) => { closeMenu ( ) ; classifier . categories . forEach ( ( category ) => { if ( category . identifier !== categoryProp . identifier ) { makeCategoryInvisible ( category . identifier , isOnlyVisibleCategory ) ; } } ) ; } ; return ( < MaterialUI . MenuItem onClick = { onClick } > < MaterialUI . ListItemText primary = { listItemText } /> < /MaterialUI.MenuItem>); } ;