Skip to content

Commit 84d786b

Browse files
guan404mingxvega
authored andcommitted
Remove react-resizable dependency from UI (#62226)
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
1 parent 37d3f67 commit 84d786b

4 files changed

Lines changed: 46 additions & 135 deletions

File tree

airflow-core/src/airflow/ui/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"react-innertext": "^1.1.5",
6363
"react-json-view": "^1.21.3",
6464
"react-markdown": "^9.1.0",
65-
"react-resizable": "^3.0.5",
6665
"react-resizable-panels": "^3.0.6",
6766
"react-router-dom": "^7.12.0",
6867
"react-syntax-highlighter": "^15.6.1",
@@ -85,7 +84,6 @@
8584
"@types/node": "^24.10.1",
8685
"@types/react": "^19.2.7",
8786
"@types/react-dom": "^19.2.3",
88-
"@types/react-resizable": "^3.0.8",
8987
"@types/react-syntax-highlighter": "^15.5.13",
9088
"@typescript-eslint/eslint-plugin": "^8.49.0",
9189
"@typescript-eslint/parser": "^8.49.0",

airflow-core/src/airflow/ui/pnpm-lock.yaml

Lines changed: 0 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airflow-core/src/airflow/ui/src/components/ui/ResizableWrapper.tsx

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,9 @@
1717
* under the License.
1818
*/
1919
import { Box } from "@chakra-ui/react";
20-
import { forwardRef } from "react";
2120
import type { PropsWithChildren } from "react";
22-
import { ResizableBox } from "react-resizable";
23-
import "react-resizable/css/styles.css";
24-
25-
import { usePersistentResizableState } from "src/utils/usePersistentResizableState";
26-
27-
const ResizeHandle = forwardRef<HTMLDivElement>((props, ref) => (
28-
<Box
29-
background="linear-gradient(-45deg, transparent 6px, #ccc 6px, #ccc 8px, transparent 8px, transparent 12px, #ccc 12px, #ccc 14px, transparent 14px)"
30-
bottom={0}
31-
cursor="se-resize"
32-
height={5}
33-
position="absolute"
34-
ref={ref}
35-
right={0}
36-
width={5}
37-
{...props}
38-
/>
39-
));
21+
import { useEffect, useRef } from "react";
22+
import { useLocalStorage } from "usehooks-ts";
4023

4124
type ResizableWrapperProps = {
4225
readonly defaultSize?: { height: number; width: number };
@@ -55,28 +38,56 @@ export const ResizableWrapper = ({
5538
maxConstraints = MAX_SIZE,
5639
storageKey,
5740
}: ResizableWrapperProps) => {
58-
const { handleResize, handleResizeStop, size } = usePersistentResizableState(storageKey, defaultSize);
41+
const ref = useRef<HTMLDivElement>(null);
42+
const [storedSize, setStoredSize] = useLocalStorage(storageKey, defaultSize);
43+
44+
useEffect(() => {
45+
const el = ref.current;
46+
47+
if (!el) {
48+
return undefined;
49+
}
50+
51+
let timeoutId: ReturnType<typeof setTimeout>;
52+
53+
const observer = new ResizeObserver((entries) => {
54+
for (const entry of entries) {
55+
const { height, width } = entry.contentRect;
56+
57+
if (width > 0 && height > 0) {
58+
clearTimeout(timeoutId);
59+
timeoutId = setTimeout(() => {
60+
setStoredSize({ height: Math.round(height), width: Math.round(width) });
61+
}, 300);
62+
}
63+
}
64+
});
65+
66+
observer.observe(el);
67+
68+
return () => {
69+
observer.disconnect();
70+
clearTimeout(timeoutId);
71+
};
72+
}, [setStoredSize]);
5973

6074
return (
61-
<ResizableBox
62-
handle={<ResizeHandle />}
63-
height={size.height}
64-
maxConstraints={maxConstraints}
65-
minConstraints={[DEFAULT_SIZE.width, DEFAULT_SIZE.height]}
66-
onResize={handleResize}
67-
onResizeStop={handleResizeStop}
68-
resizeHandles={["se"]}
69-
style={{
70-
backgroundColor: "inherit",
71-
borderRadius: "inherit",
75+
<Box
76+
css={{
7277
display: "flex",
7378
flexDirection: "column",
7479
overflow: "hidden",
75-
position: "relative",
80+
resize: "both",
7681
}}
77-
width={size.width}
82+
height={`${storedSize.height}px`}
83+
maxHeight={`${maxConstraints[1]}px`}
84+
maxWidth={`${maxConstraints[0]}px`}
85+
minHeight={`${DEFAULT_SIZE.height}px`}
86+
minWidth={`${DEFAULT_SIZE.width}px`}
87+
ref={ref}
88+
width={`${storedSize.width}px`}
7889
>
79-
<div>{children}</div>
80-
</ResizableBox>
90+
{children}
91+
</Box>
8192
);
8293
};

airflow-core/src/airflow/ui/src/utils/usePersistentResizableState.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)