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, Card, 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' | 'disabled' | '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,
54 backgroundColor: 'rgba(0, 0, 0, 0.08)',
59 export type DataTableMultiselectOption = {
61 fn: (checkedList) => void;
64 export interface DataTableMultiselectProps {
67 options: DataTableMultiselectOption[];
68 checkedList: TCheckedList;
71 interface DataTableFMultiselectPopState {
72 anchorEl?: HTMLElement;
75 export const DataTableMultiselectPopover = withStyles(styles)(
76 class extends React.Component<DataTableMultiselectProps & WithStyles<CssRules>, DataTableFMultiselectPopState> {
77 state: DataTableFMultiselectPopState = {
80 icon = React.createRef<HTMLElement>();
83 const { classes, children, options, checkedList, disabled } = this.props;
86 <Tooltip disableFocusListener title='Select Options'>
87 <ButtonBase className={classnames(classes.root)} component='span' onClick={disabled ? () => {} : this.open} disableRipple>
89 <IconButton component='span' classes={{ root: classes.iconButton }} tabIndex={-1}>
91 className={`${classnames(['fas fa-sort-down', classes.icon])}${disabled ? ` ${classes.disabled}` : ''}`}
92 data-fa-transform='shrink-3'
99 anchorEl={this.state.anchorEl}
100 open={!!this.state.anchorEl}
101 anchorOrigin={DefaultTransformOrigin}
102 transformOrigin={DefaultTransformOrigin}
106 <div className={classes.optionsContainer}>
108 options.map((option, i) => (
111 className={classes.option}
113 option.fn(checkedList);
123 <this.MountHandler />
129 this.setState({ anchorEl: this.icon.current || undefined });
132 submit = debounce(() => {
133 // const { onChange } = this.props;
135 // onChange(this.state.filters);
139 MountHandler = () => {
142 this.submit.cancel();
149 this.setState((prev) => ({