Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add search box to hide columns popup #1128

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,19 @@
.StatementResult-column-toggle-menu {
max-height: 200px;
overflow-y: auto;
.hide-column-search-bar-wrapper {
.SearchBar {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see the same css repeated in #1136 (review)
can you make it a shared class under SearchBar.scss?

display: flex;
flex-direction: row;
.DebouncedInput {
flex: 9;
}
.SearchIcon {
flex: 1;
}
.Button{
flex: 1;
}
}
}
}
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,57 @@ const ColumnToggleMenuButton: React.FC<{
}> = ({ columnNames, columnVisibility, toggleVisibility }) => {
const buttonRef = React.useRef<HTMLAnchorElement>();
const [showPopover, _, toggleShowPopover] = useToggleState(false);
const [filteredColumnNames, setFilteredColumnNames] = useState(columnNames);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have filteredColumnNames a useMemo based on keyword and columnNames

const [keyword, setKeyword] = useState('');
const isAllSelected = useMemo(
() => columnNames.every((columnName) => columnVisibility[columnName]),
[columnNames, columnVisibility]
);

const updateKeyword = (keyword: string) => {
const filtered = columnNames.filter((names) => {
return `${names.toLowerCase()}`.includes(keyword.toLowerCase());
});
setKeyword(keyword);
setFilteredColumnNames(filtered);
};

const getPopoverContent = () => (
<div className="StatementResult-column-toggle-menu">
<div
className="hide-column-search-bar-wrapper"
onClick={stopPropagation}
>
<SearchBar
value={keyword}
onSearch={updateKeyword}
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