1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { useEffect } from 'react';
20 } from '@material-ui/core';
21 import classnames from 'classnames';
22 import { DefaultTransformOrigin } from 'components/popover/helpers';
23 import debounce from 'lodash/debounce';
24 import { grey } from '@material-ui/core/colors';
26 export type CssRules = 'root' | 'icon' | 'iconButton' | 'optionsContainer' | 'option';
28 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
32 backgroundColor: grey[200],
35 color: theme.palette.text.primary,
43 color: theme.palette.text.primary,
48 color: theme.palette.text.primary,
64 backgroundColor: 'rgba(0, 0, 0, 0.08)',
69 export type DataTableMultiselectOption = {
71 fn: (checkedList) => void;
74 export interface DataTableMultiselectProps {
76 options: DataTableMultiselectOption[];
77 checkedList: Record<string, boolean>;
80 interface DataTableFMultiselectPopState {
81 anchorEl?: HTMLElement;
84 export const DataTableMultiselectPopover = withStyles(styles)(
85 class extends React.Component<DataTableMultiselectProps & WithStyles<CssRules>, DataTableFMultiselectPopState> {
86 state: DataTableFMultiselectPopState = {
89 icon = React.createRef<HTMLElement>();
92 const { name, classes, children, options, checkedList } = this.props;
95 <Tooltip disableFocusListener title='Select Options'>
96 <ButtonBase className={classnames(classes.root)} component='span' onClick={this.open} disableRipple>
98 <IconButton component='span' classes={{ root: classes.iconButton }} tabIndex={-1}>
99 <i className={classnames(['fas fa-sort-down', classes.icon])} data-fa-transform='shrink-3' ref={this.icon} />
104 anchorEl={this.state.anchorEl}
105 open={!!this.state.anchorEl}
106 anchorOrigin={DefaultTransformOrigin}
107 transformOrigin={DefaultTransformOrigin}
111 <div className={classes.optionsContainer}>
113 options.map((option, i) => (
116 className={classes.option}
118 option.fn(checkedList);
127 <Button color='primary' variant='outlined' size='small' onClick={this.close}>
133 <this.MountHandler />
139 this.setState({ anchorEl: this.icon.current || undefined });
142 submit = debounce(() => {
143 // const { onChange } = this.props;
145 // onChange(this.state.filters);
149 MountHandler = () => {
152 this.submit.cancel();
159 this.setState((prev) => ({