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
class="bp3-button-text"
>
Columns
Columns
<span
class="counter"
>
(2/3)
</span>
</span>
<span
class="bp3-icon bp3-icon-caret-down"

View File

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

View File

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

View File

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