1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { useEffect } from 'react';
6 import { WithStyles, withStyles, ButtonBase, StyleRulesCallback, Theme, Popover, Button, Card, CardActions, Tooltip, IconButton } from '@material-ui/core';
7 import classnames from 'classnames';
8 import { DefaultTransformOrigin } from 'components/popover/helpers';
9 import debounce from 'lodash/debounce';
10 import { grey } from '@material-ui/core/colors';
11 import { TCheckedList } from 'components/data-table/data-table';
13 export type CssRules = 'root' | 'icon' | 'iconButton' | 'optionsContainer' | 'option';
15 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
19 backgroundColor: grey[200],
22 color: theme.palette.text.primary,
30 color: theme.palette.text.primary,
35 color: theme.palette.text.primary,
51 backgroundColor: 'rgba(0, 0, 0, 0.08)',
56 export type DataTableMultiselectOption = {
58 fn: (checkedList) => void;
61 export interface DataTableMultiselectProps {
63 options: DataTableMultiselectOption[];
64 checkedList: TCheckedList;
67 interface DataTableFMultiselectPopState {
68 anchorEl?: HTMLElement;
71 export const DataTableMultiselectPopover = withStyles(styles)(
72 class extends React.Component<DataTableMultiselectProps & WithStyles<CssRules>, DataTableFMultiselectPopState> {
73 state: DataTableFMultiselectPopState = {
76 icon = React.createRef<HTMLElement>();
79 const { classes, children, options, checkedList } = this.props;
82 <Tooltip disableFocusListener title='Select Options'>
83 <ButtonBase className={classnames(classes.root)} component='span' onClick={this.open} disableRipple>
85 <IconButton component='span' classes={{ root: classes.iconButton }} tabIndex={-1}>
86 <i className={classnames(['fas fa-sort-down', classes.icon])} data-fa-transform='shrink-3' ref={this.icon} />
91 anchorEl={this.state.anchorEl}
92 open={!!this.state.anchorEl}
93 anchorOrigin={DefaultTransformOrigin}
94 transformOrigin={DefaultTransformOrigin}
98 <div className={classes.optionsContainer}>
100 options.map((option, i) => (
103 className={classes.option}
105 option.fn(checkedList);
115 <this.MountHandler />
121 this.setState({ anchorEl: this.icon.current || undefined });
124 submit = debounce(() => {
125 // const { onChange } = this.props;
127 // onChange(this.state.filters);
131 MountHandler = () => {
134 this.submit.cancel();
141 this.setState((prev) => ({