Skip to content

Commit

Permalink
update (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleLittleCloud authored Dec 19, 2024
1 parent c77a8a4 commit d06d330
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 65 deletions.
70 changes: 8 additions & 62 deletions stepwise-studio/components/step-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,42 +337,22 @@ const StepNode: React.FC<NodeProps<StepNodeProps>> = (prop) => {

useEffect(() => {
if (stepNodeRef.current) {
// this usually means that the content of this node has changed
// so we want to automatically adjust the weight to present the content in a nicer way
// by setting the width to undefined, the prop.data.onResize will be invoked
// and the new width will be re-calculated when the node is re-rendered
// if (
// height !== stepNodeRef.current.offsetHeight &&
// width === stepNodeRef.current.offsetWidth &&
// width !== undefined
// ) {
// console.log("Setting width to undefined");
// prop.data.onResize(
// undefined,
// undefined,
// );

// return;
// }

if (
height !== stepNodeRef.current.offsetHeight ||
width !== stepNodeRef.current.offsetWidth
) {
if (width === undefined && stepNodeRef.current.offsetWidth) {
setWidth(stepNodeRef.current.offsetWidth);
setHeight(stepNodeRef.current.offsetHeight);
} else {
prop.data.onResize(
stepNodeRef.current.offsetHeight ?? height,
width ?? stepNodeRef.current.offsetWidth,
stepNodeRef.current.offsetHeight,
stepNodeRef.current.offsetWidth,
);

return;
}
}
}, [
width,
height,
stepNodeRef.current,
stepNodeRef.current?.offsetHeight,
stepNodeRef.current?.offsetWidth,
width,
height,
]);

return (
Expand Down Expand Up @@ -786,38 +766,4 @@ const StepNode: React.FC<NodeProps<StepNodeProps>> = (prop) => {
);
};

const ResizableStepNode = React.forwardRef<
HTMLDivElement,
NodeProps<StepNodeProps>
>((props, ref) => {
const [width, setWidth] = useState<number | undefined>(props.data.width);
const [height, setHeight] = useState<number | undefined>(props.data.height);

useEffect(() => {
if (props.data.width && props.data.height) {
console.log(
"Setting width and height: ",
props.data.width,
props.data.height,
);
setWidth(props.data.width);
setHeight(props.data.height);
}
}, [props.data.width, props.data.height]);

return height && width ? (
<div
ref={ref}
style={{
width: `${width}px`,
height: `${height}px`,
}}
>
<StepNode {...props} />
</div>
) : (
<StepNode {...props} />
);
});

export { StepNode };
2 changes: 1 addition & 1 deletion stepwise-studio/components/step-run-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const StepRunSidebar: React.FC<StepRunSidebarProps> = () => {
const { selectedStepRunHistory } = useStepRunHistoryStore();
const page = useChatSideBarStore((state) => state.page);
return (
<div className="flex flex-col border-2 h-screen h-max-screen p-4 shadow-xl gap-2 bg-sidebar rounded-lg">
<div className="flex flex-col h-screen h-max-screen p-4 shadow-xl gap-2 bg-sidebar">
<ChatNavigationTopBar />
{page === "chat" && (
<div className="flex flex-col grow overflow-y-auto">
Expand Down
5 changes: 3 additions & 2 deletions stepwise-studio/components/workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const WorkflowInner: React.FC<WorkflowProps> = (props) => {
var position = workflow.stepPositions[stepNodeID];
var size = workflow.stepSizes[stepNodeID];
return {
id: `${workflow.name}-${step.name}`,
id: stepNodeID,
type: "stepNode",
position: position,
...(size ?? { width: 200, height: 100 }), // if size is not defined, use default size
Expand Down Expand Up @@ -150,11 +150,12 @@ const WorkflowInner: React.FC<WorkflowProps> = (props) => {
},
onResize: (height, width) => {
if (!selectedWorkflow) return selectedWorkflow;
const stepNodeID = `${workflow.name}-${step.name}`;
setSelectedWorkflow({
...selectedWorkflow,
stepSizes: {
...selectedWorkflow.stepSizes,
[step.name]:
[stepNodeID]:
height && width
? { height, width }
: undefined,
Expand Down

0 comments on commit d06d330

Please sign in to comment.