mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-21 15:11:08 +08:00
### What problem does this PR solve? Hi team, @ZhenhangTung @KevinHuSh @cike8899 About #10384 , I've completed the UI optimization adjustments for the Agent page according to our previous discussions and the design draft sketches provided by @Naomi. The main modifications include: 1. Adjusted the style and content of placeholder-node. 2. Adjusted the location of the dropdown (to the right of the placeholder-node) . 3. Adjusted the tooltip position spacing when the mouse hovers in the dropdown menu. 4. Hides the thick scroll bar on the dropdown component. 5. Highlight the connection line when dragging to generate a placeholder-node <img width="1323" height="509" alt="Image" src="https://github.com/user-attachments/assets/0d366f7f-477d-4c00-bb58-d5d58b3a745f" /> Please review the related code modifications when you have time. Let me know if further adjustments are needed! Thanks! ### Type of change - [x] Other (please describe): UI Enhancement --------- Co-authored-by: leonlai <leonlai@futurefab.ai>
111 lines
3.0 KiB
TypeScript
111 lines
3.0 KiB
TypeScript
import { useCallback } from 'react';
|
|
import {
|
|
DROPDOWN_HORIZONTAL_OFFSET,
|
|
DROPDOWN_VERTICAL_OFFSET,
|
|
HALF_PLACEHOLDER_NODE_WIDTH,
|
|
} from '../constant';
|
|
|
|
/**
|
|
* Dropdown position calculation Hook
|
|
* Responsible for calculating dropdown menu position relative to placeholder node
|
|
*/
|
|
export const useDropdownPosition = (reactFlowInstance: any) => {
|
|
/**
|
|
* Calculate dropdown menu position
|
|
* @param clientX Mouse click screen X coordinate
|
|
* @param clientY Mouse click screen Y coordinate
|
|
* @returns Dropdown menu screen coordinates
|
|
*/
|
|
const calculateDropdownPosition = useCallback(
|
|
(clientX: number, clientY: number) => {
|
|
if (!reactFlowInstance) {
|
|
return { x: clientX, y: clientY };
|
|
}
|
|
|
|
// Convert screen coordinates to flow coordinates
|
|
const placeholderNodePosition = reactFlowInstance.screenToFlowPosition({
|
|
x: clientX,
|
|
y: clientY,
|
|
});
|
|
|
|
// Calculate dropdown position in flow coordinate system
|
|
const dropdownFlowPosition = {
|
|
x:
|
|
placeholderNodePosition.x +
|
|
HALF_PLACEHOLDER_NODE_WIDTH +
|
|
DROPDOWN_HORIZONTAL_OFFSET,
|
|
y: placeholderNodePosition.y - DROPDOWN_VERTICAL_OFFSET,
|
|
};
|
|
|
|
// Convert flow coordinates back to screen coordinates
|
|
const dropdownScreenPosition =
|
|
reactFlowInstance.flowToScreenPosition(dropdownFlowPosition);
|
|
|
|
return {
|
|
x: dropdownScreenPosition.x,
|
|
y: dropdownScreenPosition.y,
|
|
};
|
|
},
|
|
[reactFlowInstance],
|
|
);
|
|
|
|
/**
|
|
* Calculate placeholder node flow coordinate position
|
|
* @param clientX Mouse click screen X coordinate
|
|
* @param clientY Mouse click screen Y coordinate
|
|
* @returns Placeholder node flow coordinates
|
|
*/
|
|
const getPlaceholderNodePosition = useCallback(
|
|
(clientX: number, clientY: number) => {
|
|
if (!reactFlowInstance) {
|
|
return { x: clientX, y: clientY };
|
|
}
|
|
|
|
return reactFlowInstance.screenToFlowPosition({
|
|
x: clientX,
|
|
y: clientY,
|
|
});
|
|
},
|
|
[reactFlowInstance],
|
|
);
|
|
|
|
/**
|
|
* Convert flow coordinates to screen coordinates
|
|
* @param flowPosition Flow coordinates
|
|
* @returns Screen coordinates
|
|
*/
|
|
const flowToScreenPosition = useCallback(
|
|
(flowPosition: { x: number; y: number }) => {
|
|
if (!reactFlowInstance) {
|
|
return flowPosition;
|
|
}
|
|
|
|
return reactFlowInstance.flowToScreenPosition(flowPosition);
|
|
},
|
|
[reactFlowInstance],
|
|
);
|
|
|
|
/**
|
|
* Convert screen coordinates to flow coordinates
|
|
* @param screenPosition Screen coordinates
|
|
* @returns Flow coordinates
|
|
*/
|
|
const screenToFlowPosition = useCallback(
|
|
(screenPosition: { x: number; y: number }) => {
|
|
if (!reactFlowInstance) {
|
|
return screenPosition;
|
|
}
|
|
|
|
return reactFlowInstance.screenToFlowPosition(screenPosition);
|
|
},
|
|
[reactFlowInstance],
|
|
);
|
|
|
|
return {
|
|
calculateDropdownPosition,
|
|
getPlaceholderNodePosition,
|
|
flowToScreenPosition,
|
|
screenToFlowPosition,
|
|
};
|
|
};
|