Skip to content

run auto-layout on pod resize #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions ui/src/components/nodes/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,32 @@ export const CodeNode = memo<NodeProps>(function ({
state.pods[id]?.stderr
);
const nodesMap = useStore(store, (state) => state.ydoc.getMap<Node>("pods"));
const autoForceGlobal = useStore(store, (state) => state.autoForceGlobal);

const onResize = useCallback(
const onResizeStop = useCallback(
(e, data) => {
const { size } = data;
const node = nodesMap.get(id);
if (node) {
node.style = { ...node.style, width: size.width };
nodesMap.set(id, node);
// new width
nodesMap.set(id, { ...node, width: size.width });
setPodGeo(
id,
{
parent: node.parentNode ? node.parentNode : "ROOT",
x: node.position.x,
y: node.position.y,
// new width
width: size.width!,
height: node.height!,
},
true
);
updateView();
autoForceGlobal();
}
},
[id, nodesMap, setPodGeo, updateView]
[id, nodesMap, setPodGeo, updateView, autoForceGlobal]
);

const [showToolbar, setShowToolbar] = useState(false);
Expand Down Expand Up @@ -510,7 +513,7 @@ export const CodeNode = memo<NodeProps>(function ({
}}
>
<ResizableBox
onResizeStop={onResize}
onResizeStop={onResizeStop}
height={pod.height || 100}
width={pod.width || 0}
axis={"x"}
Expand Down Expand Up @@ -669,7 +672,7 @@ export const CodeNode = memo<NodeProps>(function ({
right: 0,
transform: "translate(0, -100%)",
background: "white",
zIndex: 250,
zIndex: 10,
justifyContent: "center",
}}
>
Expand Down
15 changes: 9 additions & 6 deletions ui/src/components/nodes/Rich.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -682,29 +682,32 @@ export const RichNode = memo<Props>(function ({
const reactFlowInstance = useReactFlow();

const [showToolbar, setShowToolbar] = useState(false);
const autoForceGlobal = useStore(store, (state) => state.autoForceGlobal);

const onResize = useCallback(
const onResizeStop = useCallback(
(e, data) => {
const { size } = data;
const node = nodesMap.get(id);
if (node) {
node.style = { ...node.style, width: size.width };
nodesMap.set(id, node);
// new width
nodesMap.set(id, { ...node, width: size.width });
setPodGeo(
id,
{
parent: node.parentNode ? node.parentNode : "ROOT",
x: node.position.x,
y: node.position.y,
// new width
width: size.width!,
height: node.height!,
},
true
);
updateView();
autoForceGlobal();
}
},
[id, nodesMap, setPodGeo, updateView]
[id, nodesMap, setPodGeo, updateView, autoForceGlobal]
);

useEffect(() => {
Expand Down Expand Up @@ -789,7 +792,7 @@ export const RichNode = memo<Props>(function ({
}}
>
<ResizableBox
onResizeStop={onResize}
onResizeStop={onResizeStop}
height={pod.height || 100}
width={pod.width || 0}
axis={"x"}
Expand Down Expand Up @@ -930,7 +933,7 @@ export const RichNode = memo<Props>(function ({
right: "25px",
top: "-15px",
background: "white",
zIndex: 250,
zIndex: 10,
justifyContent: "center",
alignItems: "center",
}}
Expand Down