Skip to content

Commit

Permalink
feat: add search box to hide columns popup (pinterest#1128)
Browse files Browse the repository at this point in the history
* feat: add search box to hide columns popup

* feat: add clear button to hide columns search bar

* chore: refactor filteredColumnNames and SearchBar
  • Loading branch information
lilyli9 authored and rohan-sh1 committed Apr 11, 2023
1 parent 07681a2 commit 36bef2c
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useImmer } from 'hooks/useImmer';
import { useToggleState } from 'hooks/useToggleState';
import { getSelectStatementLimit } from 'lib/sql-helper/sql-limiter';
import { formatNumber } from 'lib/utils/number';
import { stopPropagation } from 'lib/utils/noop';
import { IStoreState } from 'redux/store/types';
import { TextButton } from 'ui/Button/Button';
import { InfoButton } from 'ui/Button/InfoButton';
Expand All @@ -21,6 +22,7 @@ import { Loading } from 'ui/Loading/Loading';
import { Message } from 'ui/Message/Message';
import { Popover } from 'ui/Popover/Popover';
import { PrettyNumber } from 'ui/PrettyNumber/PrettyNumber';
import { SearchBar } from 'ui/SearchBar/SearchBar';
import { IOptions, makeSelectOptions, Select } from 'ui/Select/Select';
import { ShowMoreText } from 'ui/ShowMoreText/ShowMoreText';
import { AccentText } from 'ui/StyledText/StyledText';
Expand Down Expand Up @@ -397,29 +399,52 @@ const ColumnToggleMenuButton: React.FC<{
}> = ({ columnNames, columnVisibility, toggleVisibility }) => {
const buttonRef = React.useRef<HTMLAnchorElement>();
const [showPopover, _, toggleShowPopover] = useToggleState(false);
const [keyword, setKeyword] = useState('');
const filteredColumnNames = useMemo(
() =>
columnNames.filter((names) =>
names.toLowerCase().includes(keyword.toLowerCase())
),
[columnNames, keyword]
);
const isAllSelected = useMemo(
() => columnNames.every((columnName) => columnVisibility[columnName]),
[columnNames, columnVisibility]
);

const getPopoverContent = () => (
<div className="StatementResult-column-toggle-menu">
<div onClick={stopPropagation}>
<SearchBar
value={keyword}
onSearch={setKeyword}
placeholder="Search"
transparent
delayMethod="throttle"
hasClearSearch={true}
/>
</div>
<div key="all">
<Checkbox
title={isAllSelected ? 'Hide All' : 'Select All'}
title={
(isAllSelected ? 'Hide All' : 'Select All') +
(keyword === '' ? '' : ' Visible')
}
value={isAllSelected}
onChange={() => {
if (isAllSelected) {
columnNames.map((col) => toggleVisibility(col));
filteredColumnNames.map((col) =>
toggleVisibility(col)
);
} else {
columnNames
filteredColumnNames
.filter((col) => !columnVisibility[col])
.map((column) => toggleVisibility(column));
}
}}
/>
</div>
{columnNames.map((columnName) => (
{filteredColumnNames.map((columnName) => (
<div key={columnName}>
<Checkbox
title={columnName}
Expand Down

0 comments on commit 36bef2c

Please sign in to comment.