mirror of
https://github.com/grafana/grafana.git
synced 2025-09-27 07:33:57 +08:00

* Table: Adds column filters * Refactor: adds filter by value function * Refactor: some styling and sorting * Refactor: Moves filterByValue to utils * Tests: add filterByValue tests * Refactor: simplifies filteredValues * Refactor: adds dropshadow * Refactor: keeps icons together with label and aligns with column alignment * Refactor: hides clear filter if no filter is active * Refactor: changes how values in filter are populated * Refactor: adds filterable field override * Tests: fixed broken tests * Refactor: adds FilterList * Refactor: adds blanks entry for non value labels * Refactor: using preFilteredRows in filter list * Refactor: adds filter input * Refactor: fixes issue found by e2e * Refactor: changes after PR comments * Docs: adds documentation for Column filter * Refactor: moves functions to utils and adds tests * Refactor: memoizes filter function * Docs: reverts docs for now
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { PureComponent } from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
|
|
export interface Props {
|
|
/**
|
|
* When clicking outside of current element
|
|
*/
|
|
onClick: () => void;
|
|
/**
|
|
* Runs the 'onClick' function when pressing a key outside of the current element. Defaults to true.
|
|
*/
|
|
includeButtonPress: boolean;
|
|
parent: Window | Document;
|
|
|
|
/**
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener. Defaults to false.
|
|
*/
|
|
useCapture?: boolean;
|
|
}
|
|
|
|
interface State {
|
|
hasEventListener: boolean;
|
|
}
|
|
|
|
export class ClickOutsideWrapper extends PureComponent<Props, State> {
|
|
static defaultProps = {
|
|
includeButtonPress: true,
|
|
parent: window,
|
|
useCapture: false,
|
|
};
|
|
state = {
|
|
hasEventListener: false,
|
|
};
|
|
|
|
componentDidMount() {
|
|
this.props.parent.addEventListener('click', this.onOutsideClick, this.props.useCapture);
|
|
if (this.props.includeButtonPress) {
|
|
// Use keyup since keydown already has an eventlistener on window
|
|
this.props.parent.addEventListener('keyup', this.onOutsideClick, this.props.useCapture);
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.props.parent.removeEventListener('click', this.onOutsideClick, this.props.useCapture);
|
|
if (this.props.includeButtonPress) {
|
|
this.props.parent.removeEventListener('keyup', this.onOutsideClick, this.props.useCapture);
|
|
}
|
|
}
|
|
|
|
onOutsideClick = (event: any) => {
|
|
const domNode = ReactDOM.findDOMNode(this) as Element;
|
|
|
|
if (!domNode || !domNode.contains(event.target)) {
|
|
this.props.onClick();
|
|
}
|
|
};
|
|
|
|
render() {
|
|
return this.props.children;
|
|
}
|
|
}
|