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,
47 color: theme.palette.text.primary,
63 backgroundColor: 'rgba(0, 0, 0, 0.08)',
68 export type DataTableMultiselectOption = {
70 fn: (checkedList) => void;
73 export interface DataTableMultiselectProps {
75 options: DataTableMultiselectOption[];
76 checkedList: Record<string, boolean>;
79 interface DataTableFMultiselectPopState {
80 anchorEl?: HTMLElement;
83 export const DataTableMultiselectPopover = withStyles(styles)(
84 class extends React.Component<DataTableMultiselectProps & WithStyles<CssRules>, DataTableFMultiselectPopState> {
85 state: DataTableFMultiselectPopState = {
88 icon = React.createRef<HTMLElement>();
91 const { name, classes, children, options, checkedList } = this.props;
94 <Tooltip disableFocusListener title='Multiselect Actions'>
95 <ButtonBase className={classnames(classes.root)} component='span' onClick={this.open} disableRipple>
97 <IconButton component='span' classes={{ root: classes.iconButton }} tabIndex={-1}>
98 <i className={classnames(['fas fa-sort-down', classes.icon])} data-fa-transform='shrink-3' ref={this.icon} />
103 anchorEl={this.state.anchorEl}
104 open={!!this.state.anchorEl}
105 anchorOrigin={DefaultTransformOrigin}
106 transformOrigin={DefaultTransformOrigin}
111 <Typography variant='caption'>{name}</Typography>
113 <div className={classes.optionsContainer}>
115 options.map((option, i) => (
116 <div key={i} className={classes.option} onClick={() => option.fn(checkedList)}>
122 <Button color='primary' variant='outlined' size='small' onClick={this.close}>
128 <this.MountHandler />
134 this.setState({ anchorEl: this.icon.current || undefined });
137 submit = debounce(() => {
138 // const { onChange } = this.props;
140 // onChange(this.state.filters);
144 MountHandler = () => {
147 this.submit.cancel();
154 this.setState((prev) => ({