1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

refactor AddRemoveButtons's renderButtons method to be just a filter map (#2210)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-04-22 08:14:10 -04:00 committed by GitHub
parent 21585d882d
commit 9191533634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,8 @@ export interface AddRemoveButtonsProps extends React.HTMLAttributes<any> {
export class AddRemoveButtons extends React.PureComponent<AddRemoveButtonsProps> {
renderButtons() {
const { onRemove, onAdd, addTooltip, removeTooltip } = this.props;
const buttons = [
return [
{
onClick: onRemove,
className: "remove-button",
@ -28,20 +29,13 @@ export class AddRemoveButtons extends React.PureComponent<AddRemoveButtonsProps>
icon: "add",
tooltip: addTooltip,
},
];
return buttons.map(button => {
if (!button.onClick) {
return null;
}
const { onClick, className, icon, tooltip } = button;
return (
<Button key={icon} big round primary onClick={onClick} className={className} tooltip={tooltip}>
<Icon material={icon}/>
]
.filter(button => button.onClick)
.map(({ icon, ...props }) => (
<Button key={icon} big round primary {...props}>
<Icon material={icon} />
</Button>
);
});
));
}
render() {