Web console: Column counter (#9334)

* Column counter

* more general test
This commit is contained in:
Vadim Ogievetsky 2020-02-27 12:04:27 -08:00 committed by GitHub
parent ef3d24e886
commit c294e0b7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View File

@ -14,7 +14,12 @@ exports[`table column matches snapshot 1`] = `
<span <span
class="bp3-button-text" class="bp3-button-text"
> >
Columns Columns
<span
class="counter"
>
(2/3)
</span>
</span> </span>
<span <span
class="bp3-icon bp3-icon-caret-down" class="bp3-icon bp3-icon-caret-down"

View File

@ -20,6 +20,10 @@
position: absolute; position: absolute;
right: 0; right: 0;
margin: 0; margin: 0;
.counter {
opacity: 0.5;
}
} }
// This will be mounted in a portal // This will be mounted in a portal

View File

@ -27,7 +27,7 @@ describe('table column', () => {
<TableColumnSelector <TableColumnSelector
columns={['a', 'b', 'c']} columns={['a', 'b', 'c']}
onChange={() => {}} onChange={() => {}}
tableColumnsHidden={['a', 'b', 'c']} tableColumnsHidden={['b']}
/> />
); );
const { container } = render(tableColumn); const { container } = render(tableColumn);

View File

@ -34,26 +34,33 @@ export const TableColumnSelector = React.memo(function TableColumnSelector(
props: TableColumnSelectorProps, props: TableColumnSelectorProps,
) { ) {
const { columns, onChange, tableColumnsHidden } = props; const { columns, onChange, tableColumnsHidden } = props;
const isColumnShown = (column: string) => !tableColumnsHidden.includes(column);
const checkboxes = ( const checkboxes = (
<Menu className="table-column-selector-menu"> <Menu className="table-column-selector-menu">
{columns.map(column => ( {columns.map(column => (
<MenuCheckbox <MenuCheckbox
label={column} label={column}
key={column} key={column}
checked={!tableColumnsHidden.includes(column)} checked={isColumnShown(column)}
onChange={() => onChange(column)} onChange={() => onChange(column)}
/> />
))} ))}
</Menu> </Menu>
); );
const counterText = `(${columns.filter(isColumnShown).length}/${columns.length})`;
return ( return (
<Popover <Popover
className="table-column-selector" className="table-column-selector"
content={checkboxes} content={checkboxes}
position={Position.BOTTOM_RIGHT} position={Position.BOTTOM_RIGHT}
> >
<Button rightIcon={IconNames.CARET_DOWN} text="Columns" /> <Button rightIcon={IconNames.CARET_DOWN}>
Columns <span className="counter">{counterText}</span>
</Button>
</Popover> </Popover>
); );
}); });