Skip to content

Commit

Permalink
fix: Time filter position and click in Horizontal FilterBar (apache#2…
Browse files Browse the repository at this point in the history
…2338)

(cherry picked from commit f64423a)
  • Loading branch information
geido authored and jinghua-qa committed Dec 10, 2022
1 parent c1012af commit c1d6d99
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe('Time range filter', () => {
});
cy.get('[data-test=cancel-button]').click();
cy.wait(500);
cy.get('.ant-popover').should('not.be.visible');
cy.get('.ant-popover').should('not.exist');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getSectionContainerElement = () =>

const getElementYVisibilityRatioOnContainer = (node: HTMLElement) => {
const containerHeight = window?.innerHeight;
const nodePositionInViewport = node.getBoundingClientRect()?.top;
const nodePositionInViewport = node?.getBoundingClientRect()?.top;
if (!containerHeight || !nodePositionInViewport) {
return 0;
}
Expand All @@ -45,6 +45,7 @@ const ControlPopover: React.FC<PopoverProps> = ({
getPopupContainer,
getVisibilityRatio = getElementYVisibilityRatioOnContainer,
visible: visibleProp,
destroyTooltipOnHide = false,
...props
}) => {
const triggerElementRef = useRef<HTMLElement>();
Expand All @@ -56,10 +57,9 @@ const ControlPopover: React.FC<PopoverProps> = ({

const calculatePlacement = useCallback(() => {
const visibilityRatio = getVisibilityRatio(triggerElementRef.current!);

if (visibilityRatio < 0.35) {
if (visibilityRatio < 0.35 && placement !== 'rightTop') {
setPlacement('rightTop');
} else if (visibilityRatio > 0.65) {
} else if (visibilityRatio > 0.65 && placement !== 'rightBottom') {
setPlacement('rightBottom');
} else {
setPlacement('right');
Expand All @@ -68,10 +68,6 @@ const ControlPopover: React.FC<PopoverProps> = ({

const changeContainerScrollStatus = useCallback(
visible => {
if (triggerElementRef.current && visible) {
calculatePlacement();
}

const element = getSectionContainerElement();
if (element) {
element.style.setProperty(
Expand All @@ -87,9 +83,6 @@ const ControlPopover: React.FC<PopoverProps> = ({
const handleGetPopupContainer = useCallback(
(triggerNode: HTMLElement) => {
triggerElementRef.current = triggerNode;
setTimeout(() => {
calculatePlacement();
}, 0);

return getPopupContainer?.(triggerNode) || document.body;
},
Expand Down Expand Up @@ -140,6 +133,12 @@ const ControlPopover: React.FC<PopoverProps> = ({
};
}, [handleDocumentKeyDownListener, visible]);

useEffect(() => {
if (visible) {
calculatePlacement();
}
}, [visible, calculatePlacement]);

return (
<Popover
{...props}
Expand All @@ -148,6 +147,7 @@ const ControlPopover: React.FC<PopoverProps> = ({
placement={placement}
onVisibleChange={handleOnVisibleChange}
getPopupContainer={handleGetPopupContainer}
destroyTooltipOnHide={destroyTooltipOnHide}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export default function DateFilterLabel(props: DateFilterControlProps) {
onOpenPopover = noOp,
onClosePopover = noOp,
overlayStyle = 'Popover',
isOverflowingFilterBar = false,
} = props;
const defaultTimeFilter = useDefaultTimeFilter();

Expand Down Expand Up @@ -356,6 +357,12 @@ export default function DateFilterLabel(props: DateFilterControlProps) {
visible={show}
onVisibleChange={toggleOverlay}
overlayStyle={{ width: '600px' }}
getPopupContainer={triggerNode =>
isOverflowingFilterBar
? (triggerNode.parentNode as HTMLElement)
: document.body
}
destroyTooltipOnHide
>
<Tooltip placement="top" title={tooltipTitle}>
<DateLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ export interface DateFilterControlProps {
onOpenPopover?: () => void;
onClosePopover?: () => void;
overlayStyle?: 'Modal' | 'Popover';
isOverflowingFilterBar?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function TimeFilterPlugin(props: PluginFilterTimeProps) {
height,
filterState,
inputRef,
isOverflowingFilterBar = false,
} = props;

const handleTimeRangeChange = useCallback(
Expand Down Expand Up @@ -97,6 +98,7 @@ export default function TimeFilterPlugin(props: PluginFilterTimeProps) {
onChange={handleTimeRangeChange}
onOpenPopover={() => setFilterActive(true)}
onClosePopover={() => setFilterActive(false)}
isOverflowingFilterBar={isOverflowingFilterBar}
/>
</ControlContainer>
</TimeFilterStyles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ export default function transformProps(chartProps: ChartProps) {
width,
inputRef,
filterBarOrientation: displaySettings?.filterBarOrientation,
isOverflowingFilterBar: displaySettings?.isOverflowingFilterBar,
};
}
1 change: 1 addition & 0 deletions superset-frontend/src/filters/components/Time/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type PluginFilterTimeProps = PluginFilterStylesProps & {
formData: PluginFilterSelectQueryFormData;
filterState: FilterState;
inputRef: RefObject<HTMLInputElement>;
isOverflowingFilterBar?: boolean;
} & PluginFilterHooks;

export const DEFAULT_FORM_DATA: PluginFilterTimeCustomizeProps = {
Expand Down

0 comments on commit c1d6d99

Please sign in to comment.