Skip to content
Snippets Groups Projects
Unverified Commit 4806e787 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Fix notebook being unable to resize (#40136)

* Use Mantine instead of styled components

* Fix notebook being unable to resize

Fixes #33982

* Address review commments
parent 53e220cb
No related branches found
No related tags found
No related merge requests found
import cx from "classnames";
import PropTypes from "prop-types";
import { forwardRef } from "react";
import { ResizableBox } from "react-resizable";
import CS from "metabase/css/core/index.css";
import { darken } from "metabase/lib/colors";
import Notebook from "metabase/query_builder/components/notebook/Notebook";
import { NotebookContainer, Handle } from "./ResizableNotebook.styled";
import { Flex, Box } from "metabase/ui";
const propTypes = {
isResizing: PropTypes.bool.isRequired,
......@@ -13,6 +14,42 @@ const propTypes = {
onResizeStop: PropTypes.func.isRequired,
};
/**
* Prevents automatic scroll effect on queries with lots of steps.
* When overflow is 'scroll' and the notebook is being resized,
* its height changes and it scrolls automatically.
* Setting the overflow to "hidden" while resizing fixes that behavior.
* @link Demo: https://github.com/metabase/metabase/pull/19103#issuecomment-981935878
*/
const getOverflow = isResizing => (isResizing ? "hidden" : "scroll");
const Handle = forwardRef(function Handle(props, ref) {
return (
<Flex
align="center"
justify="center"
w="100%"
h="sm"
pos="absolute"
bottom="-0.25rem"
style={{
cursor: "row-resize",
}}
ref={ref}
{...props}
>
<Box
w="6.25rem"
h="xs"
bg={darken("border", 0.03)}
style={{
borderRadius: "xs",
}}
></Box>
</Flex>
);
});
function ResizableNotebook({
isResizing,
onResizeStop,
......@@ -30,9 +67,9 @@ function ResizableNotebook({
onResizeStop(...args);
}}
>
<NotebookContainer isResizing={isResizing}>
<Box w="100%" style={{ overflowY: getOverflow(isResizing) }}>
<Notebook {...notebookProps} hasVisualizeButton={false} />
</NotebookContainer>
</Box>
</ResizableBox>
);
}
......
import styled from "@emotion/styled";
import type { ComponentProps } from "react";
import { color, darken } from "metabase/lib/colors";
export const NotebookContainer = styled.div<{ isResizing: boolean }>`
width: 100%;
overflow-y: ${props => {
// Prevents automatic scroll effect on queries with lots of steps.
// When overflow is 'scroll' and the notebook is being resized,
// it's height changes and it scrolls automatically.
// Setting the overflow to "hidden" while resizing fixes that behavior
// Demo: https://github.com/metabase/metabase/pull/19103#issuecomment-981935878
return props.isResizing ? "hidden" : "scroll";
}};
`;
const HandleContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 8px;
width: 100%;
position: absolute;
bottom: -4px;
cursor: row-resize;
`;
const HandleContent = styled.div`
width: 100px;
height: 5px;
border-radius: 4px;
background-color: ${darken(color("border"), 0.03)};
`;
export function Handle(props: ComponentProps<typeof HandleContainer>) {
return (
<HandleContainer {...props}>
<HandleContent />
</HandleContainer>
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment