You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/03/11 10:44:03 UTC

[GitHub] [superset] michael-s-molina commented on a change in pull request #13547: test: Adds storybook and tests to PopoverDropdown component

michael-s-molina commented on a change in pull request #13547:
URL: https://github.com/apache/superset/pull/13547#discussion_r592252703



##########
File path: superset-frontend/src/components/PopoverDropdown/index.tsx
##########
@@ -71,58 +75,44 @@ const MenuItem = styled(Menu.Item)`
   }
 `;
 
-interface HandleSelectProps {
-  key: React.Key;
-}
-
-class PopoverDropdown extends React.PureComponent<PopoverDropdownProps> {
-  constructor(props: PopoverDropdownProps) {
-    super(props);
-
-    this.handleSelect = this.handleSelect.bind(this);
-  }
-
-  handleSelect({ key }: HandleSelectProps) {
-    this.props.onChange(key);
-  }
-
-  static defaultProps = {
-    renderButton: (option: OptionProps) => option.label,
-    renderOption: (option: OptionProps) => (
+const PopoverDropdown = (props: PopoverDropdownProps) => {
+  const {
+    value,
+    options,
+    theme,
+    onChange,
+    renderButton = (option: OptionProps) => option.label,
+    renderOption = (option: OptionProps) => (
       <div className={option.className}>{option.label}</div>
     ),
-  };
-
-  render() {
-    const { value, options, renderButton, renderOption, theme } = this.props;
-    const selected = options.find(opt => opt.value === value);
-    return (
-      <Dropdown
-        trigger={['click']}
-        overlayStyle={{ zIndex: theme.zIndex.max }}
-        overlay={
-          <Menu onClick={this.handleSelect}>
-            {options.map(option => (
-              <MenuItem
-                id="menu-item"
-                key={option.value}
-                className={cx('dropdown-item', {
-                  active: option.value === value,
-                })}
-              >
-                {renderOption(option)}
-              </MenuItem>
-            ))}
-          </Menu>
-        }
-      >
-        <div role="button" css={{ display: 'flex', alignItems: 'center' }}>
-          {selected && renderButton(selected)}
-          <Icon name="caret-down" css={{ marginTop: 4 }} />
-        </div>
-      </Dropdown>
-    );
-  }
-}
+  } = props;
+  const selected = options.find(opt => opt.value === value);
+  return (
+    <Dropdown
+      trigger={['click']}
+      overlayStyle={{ zIndex: theme.zIndex.max }}
+      overlay={
+        <Menu onClick={({ key }: HandleSelectProps) => onChange(key)}>
+          {options.map(option => (
+            <MenuItem
+              id="menu-item"
+              key={option.value}
+              className={cx('dropdown-item', {
+                active: option.value === value,
+              })}
+            >
+              {renderOption(option)}
+            </MenuItem>
+          ))}
+        </Menu>
+      }
+    >
+      <div role="button" css={{ display: 'flex', alignItems: 'center' }}>
+        {selected && renderButton(selected)}
+        <Icon name="caret-down" css={{ marginTop: 4 }} />
+      </div>
+    </Dropdown>
+  );
+};
 
 export default withTheme(PopoverDropdown);

Review comment:
       Thanks for catching that! I did the suggested change.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org