codemaster08240328 commented on code in PR #19902:
URL: https://github.com/apache/superset/pull/19902#discussion_r863123148
##########
superset-frontend/src/explore/components/controls/ControlPopover/ControlPopover.tsx:
##########
@@ -44,9 +44,14 @@ export type PopoverProps = BasePopoverProps & {
const ControlPopover: React.FC<PopoverProps> = ({
getPopupContainer,
getVisibilityRatio = getElementYVisibilityRatioOnContainer,
+ visible: visibleProp,
...props
}) => {
const triggerElementRef = useRef<HTMLElement>();
+
+ const [visible, setVisible] = useState(
Review Comment:
Totally, I don't think that introducing `visible` state here is a good idea.
We can control `visibleProps`.
Currently you are mixing `visible` state and `visible` props to control
visible, but it is not a good idea.
##########
superset-frontend/src/explore/components/controls/ControlPopover/ControlPopover.tsx:
##########
@@ -89,24 +98,50 @@ const ControlPopover: React.FC<PopoverProps> = ({
const handleOnVisibleChange = useCallback(
(visible: boolean) => {
- if (props.visible === undefined) {
+ if (visible === undefined) {
Review Comment:
Is this correct?
Actually, we will never `visible` state as `undefined`.
I think this should be `visibleProp`?
##########
superset-frontend/src/explore/components/controls/ControlPopover/ControlPopover.tsx:
##########
@@ -89,24 +98,50 @@ const ControlPopover: React.FC<PopoverProps> = ({
const handleOnVisibleChange = useCallback(
(visible: boolean) => {
- if (props.visible === undefined) {
+ if (visible === undefined) {
changeContainerScrollStatus(visible);
}
+ setVisible(!!visible);
props.onVisibleChange?.(visible);
},
[props, changeContainerScrollStatus],
);
+ const handleDocumentKeyDownListener = useCallback(
+ (event: KeyboardEvent) => {
+ if (event.key === 'Escape') {
+ setVisible(false);
+ props.onVisibleChange?.(false);
Review Comment:
`props.onVisibleChange?.(false)` is enough. Why did you introduce `visible`
state and `setVisible`?
##########
superset-frontend/src/explore/components/controls/ControlPopover/ControlPopover.tsx:
##########
@@ -44,9 +44,14 @@ export type PopoverProps = BasePopoverProps & {
const ControlPopover: React.FC<PopoverProps> = ({
getPopupContainer,
getVisibilityRatio = getElementYVisibilityRatioOnContainer,
+ visible: visibleProp,
...props
}) => {
const triggerElementRef = useRef<HTMLElement>();
+
+ const [visible, setVisible] = useState(
+ !!(visibleProp || props.defaultVisible),
Review Comment:
`visibleProp` and `defaultVisible` are `boolean` types, which means that the
above logic maybe wrong in some cases like:
`visibleProp` = false
`defaultVisible` = true
In this case, `visible` state would be set as `true`, even though it should
be set as `false`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]