mirror of https://github.com/apache/druid.git
Web console: Column counter (#9334)
* Column counter * more general test
This commit is contained in:
parent
ef3d24e886
commit
c294e0b7c6
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue