fix: flashElement scrolls canvas too much. (#7547)

This commit is contained in:
Ashok Kumar M 2021-09-16 22:24:12 +05:30 committed by GitHub
parent 1d101300a5
commit 34c4dad0ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 17 deletions

View File

@ -45,10 +45,12 @@ export const useNavigateToWidget = () => {
selectWidget(widgetId, false); selectWidget(widgetId, false);
navigateToCanvas(params, window.location.pathname, pageId, widgetId); navigateToCanvas(params, window.location.pathname, pageId, widgetId);
flashElementsById(widgetId);
// Navigating to a widget from query pane seems to make the property pane // Navigating to a widget from query pane seems to make the property pane
// appear below the entity explorer hence adding a timeout here // appear below the entity explorer hence adding a timeout here
setTimeout(() => { setTimeout(() => {
if (params.pageId === pageId) {
flashElementsById(widgetId);
}
dispatch(forceOpenPropertyPane(widgetId)); dispatch(forceOpenPropertyPane(widgetId));
}, 0); }, 0);
}; };

View File

@ -173,8 +173,8 @@ export const flashElementsById = (id: string | string[], timeout = 0) => {
el?.scrollIntoView({ el?.scrollIntoView({
behavior: "smooth", behavior: "smooth",
block: "nearest", block: "center",
inline: "nearest", inline: "center",
}); });
if (el) flashElement(el); if (el) flashElement(el);

View File

@ -10,6 +10,7 @@ import WidgetStyleContainer, {
} from "components/designSystems/appsmith/WidgetStyleContainer"; } from "components/designSystems/appsmith/WidgetStyleContainer";
import { pick } from "lodash"; import { pick } from "lodash";
import { ComponentProps } from "widgets/BaseComponent"; import { ComponentProps } from "widgets/BaseComponent";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
const scrollContents = css` const scrollContents = css`
overflow-y: auto; overflow-y: auto;
@ -50,10 +51,9 @@ const StyledContainerComponent = styled.div<
} }
}`; }`;
function ContainerComponent(props: ContainerComponentProps) { function ContainerComponentWrapper(props: ContainerComponentProps) {
const containerStyle = props.containerStyle || "card"; const containerStyle = props.containerStyle || "card";
const containerRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null); const containerRef: RefObject<HTMLDivElement> = useRef<HTMLDivElement>(null);
useCanvasMinHeightUpdateHook(props.widgetId, props.minHeight);
useEffect(() => { useEffect(() => {
if (!props.shouldScrollContents) { if (!props.shouldScrollContents) {
const supportsNativeSmoothScroll = const supportsNativeSmoothScroll =
@ -68,6 +68,26 @@ function ContainerComponent(props: ContainerComponentProps) {
} }
}, [props.shouldScrollContents]); }, [props.shouldScrollContents]);
return ( return (
<StyledContainerComponent
{...props}
className={`${
props.shouldScrollContents ? getCanvasClassName() : ""
} ${generateClassName(props.widgetId)}`}
containerStyle={containerStyle}
// Before you remove: generateClassName is used for bounding the resizables within this canvas
// getCanvasClassName is used to add a scrollable parent.
ref={containerRef}
>
{props.children}
</StyledContainerComponent>
);
}
function ContainerComponent(props: ContainerComponentProps) {
useCanvasMinHeightUpdateHook(props.widgetId, props.minHeight);
return props.widgetId === MAIN_CONTAINER_WIDGET_ID ? (
<ContainerComponentWrapper {...props} />
) : (
<WidgetStyleContainer <WidgetStyleContainer
{...pick(props, [ {...pick(props, [
"widgetId", "widgetId",
@ -79,18 +99,7 @@ function ContainerComponent(props: ContainerComponentProps) {
"boxShadowColor", "boxShadowColor",
])} ])}
> >
<StyledContainerComponent <ContainerComponentWrapper {...props} />
{...props}
className={`${
props.shouldScrollContents ? getCanvasClassName() : ""
} ${generateClassName(props.widgetId)}`}
containerStyle={containerStyle}
// Before you remove: generateClassName is used for bounding the resizables within this canvas
// getCanvasClassName is used to add a scrollable parent.
ref={containerRef}
>
{props.children}
</StyledContainerComponent>
</WidgetStyleContainer> </WidgetStyleContainer>
); );
} }