mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 09:51:26 +00:00
fix: metadata contextmenu position (#6643)
Co-authored-by: 杨国璇 <ygx@Hello-word.local>
This commit is contained in:
@@ -34,6 +34,8 @@ const DirViews = ({ userPerm, repoID, currentPath, currentRepoInfo }) => {
|
|||||||
updateEnableMetadata(value);
|
updateEnableMetadata(value);
|
||||||
}, [updateEnableMetadata]);
|
}, [updateEnableMetadata]);
|
||||||
|
|
||||||
|
if (!enableMetadataManagement) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TreeSection
|
<TreeSection
|
||||||
|
@@ -2,4 +2,5 @@
|
|||||||
display: block;
|
display: block;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
box-shadow: 0 0 5px #ccc;
|
box-shadow: 0 0 5px #ccc;
|
||||||
|
position: fixed;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,8 @@ const ContextMenu = ({
|
|||||||
onClearSelected,
|
onClearSelected,
|
||||||
onCopySelected,
|
onCopySelected,
|
||||||
updateRecords,
|
updateRecords,
|
||||||
|
getTableContentRect,
|
||||||
|
getTableCanvasContainerRect,
|
||||||
}) => {
|
}) => {
|
||||||
const menuRef = useRef(null);
|
const menuRef = useRef(null);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
@@ -220,41 +222,33 @@ const ContextMenu = ({
|
|||||||
setVisible(false);
|
setVisible(false);
|
||||||
}, [onOpenFileInNewTab, onOpenParentFolder, onCopySelected, onClearSelected, generateSummary]);
|
}, [onOpenFileInNewTab, onOpenParentFolder, onCopySelected, onClearSelected, generateSummary]);
|
||||||
|
|
||||||
const getMenuPosition = (x = 0, y = 0) => {
|
const getMenuPosition = useCallback((x = 0, y = 0) => {
|
||||||
let menuStyles = {
|
let menuStyles = {
|
||||||
top: y,
|
top: y,
|
||||||
left: x
|
left: x
|
||||||
};
|
};
|
||||||
if (!menuRef.current) return menuStyles;
|
if (!menuRef.current) return menuStyles;
|
||||||
|
|
||||||
const { innerWidth, innerHeight } = window;
|
|
||||||
const rect = menuRef.current.getBoundingClientRect();
|
const rect = menuRef.current.getBoundingClientRect();
|
||||||
|
const tableCanvasContainerRect = getTableCanvasContainerRect();
|
||||||
|
const tableContentRect = getTableContentRect();
|
||||||
|
const { right: innerWidth, bottom: innerHeight } = tableContentRect;
|
||||||
|
menuStyles.top = menuStyles.top - tableCanvasContainerRect.top;
|
||||||
|
menuStyles.left = menuStyles.left - tableCanvasContainerRect.left;
|
||||||
|
|
||||||
// Calculate the offset of the parent components
|
if (y + rect.height > innerHeight - 10) {
|
||||||
const parentRect = menuRef.current.parentElement.getBoundingClientRect();
|
|
||||||
const offsetX = parentRect.left;
|
|
||||||
const offsetY = parentRect.top;
|
|
||||||
|
|
||||||
// Adjust the position based on the offset
|
|
||||||
menuStyles.top = y - offsetY;
|
|
||||||
menuStyles.left = x - offsetX;
|
|
||||||
|
|
||||||
const metadataResultFooterHeight = 32;
|
|
||||||
const contentHeight = innerHeight - metadataResultFooterHeight;
|
|
||||||
if (y + rect.height > contentHeight) {
|
|
||||||
menuStyles.top -= rect.height;
|
menuStyles.top -= rect.height;
|
||||||
}
|
}
|
||||||
if (x + rect.width > innerWidth) {
|
if (x + rect.width > innerWidth) {
|
||||||
menuStyles.left -= rect.width;
|
menuStyles.left -= rect.width;
|
||||||
}
|
}
|
||||||
if (menuStyles.top < 0) {
|
if (menuStyles.top < 0) {
|
||||||
menuStyles.top = rect.height < contentHeight ? (contentHeight - rect.height) / 2 : 0;
|
menuStyles.top = rect.bottom > innerHeight ? (innerHeight - 10 - rect.height) / 2 : 0;
|
||||||
}
|
}
|
||||||
if (menuStyles.left < 0) {
|
if (menuStyles.left < 0) {
|
||||||
menuStyles.left = rect.width < innerWidth ? (innerWidth - rect.width) / 2 : 0;
|
menuStyles.left = rect.width < innerWidth ? (innerWidth - rect.width) / 2 : 0;
|
||||||
}
|
}
|
||||||
return menuStyles;
|
return menuStyles;
|
||||||
};
|
}, [getTableContentRect, getTableCanvasContainerRect]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleShow = (event) => {
|
const handleShow = (event) => {
|
||||||
@@ -272,6 +266,7 @@ const ContextMenu = ({
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('contextmenu', handleShow);
|
document.removeEventListener('contextmenu', handleShow);
|
||||||
};
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -313,6 +308,7 @@ ContextMenu.propTypes = {
|
|||||||
selectedRange: PropTypes.object,
|
selectedRange: PropTypes.object,
|
||||||
selectedPosition: PropTypes.object,
|
selectedPosition: PropTypes.object,
|
||||||
recordMetrics: PropTypes.object,
|
recordMetrics: PropTypes.object,
|
||||||
|
getTableContentRect: PropTypes.func,
|
||||||
recordGetterByIndex: PropTypes.func,
|
recordGetterByIndex: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -542,6 +542,7 @@ class RecordsBody extends Component {
|
|||||||
gridUtils={this.props.gridUtils}
|
gridUtils={this.props.gridUtils}
|
||||||
getCopiedRecordsAndColumnsFromRange={this.props.getCopiedRecordsAndColumnsFromRange}
|
getCopiedRecordsAndColumnsFromRange={this.props.getCopiedRecordsAndColumnsFromRange}
|
||||||
modifyColumnData={this.props.modifyColumnData}
|
modifyColumnData={this.props.modifyColumnData}
|
||||||
|
getTableCanvasContainerRect={this.props.getTableCanvasContainerRect}
|
||||||
/>
|
/>
|
||||||
<div className="sf-metadata-result-table" style={{ width: this.props.totalWidth + SEQUENCE_COLUMN_WIDTH }} ref={this.setResultRef}>
|
<div className="sf-metadata-result-table" style={{ width: this.props.totalWidth + SEQUENCE_COLUMN_WIDTH }} ref={this.setResultRef}>
|
||||||
{this.renderRecords()}
|
{this.renderRecords()}
|
||||||
@@ -608,6 +609,7 @@ RecordsBody.propTypes = {
|
|||||||
openDownloadFilesDialog: PropTypes.func,
|
openDownloadFilesDialog: PropTypes.func,
|
||||||
cacheDownloadFilesProps: PropTypes.func,
|
cacheDownloadFilesProps: PropTypes.func,
|
||||||
onCellContextMenu: PropTypes.func,
|
onCellContextMenu: PropTypes.func,
|
||||||
|
getTableCanvasContainerRect: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default RecordsBody;
|
export default RecordsBody;
|
||||||
|
@@ -904,6 +904,7 @@ class GroupBody extends Component {
|
|||||||
gridUtils={this.props.gridUtils}
|
gridUtils={this.props.gridUtils}
|
||||||
getCopiedRecordsAndColumnsFromRange={this.props.getCopiedRecordsAndColumnsFromRange}
|
getCopiedRecordsAndColumnsFromRange={this.props.getCopiedRecordsAndColumnsFromRange}
|
||||||
modifyColumnData={this.props.modifyColumnData}
|
modifyColumnData={this.props.modifyColumnData}
|
||||||
|
getTableCanvasContainerRect={this.props.getTableCanvasContainerRect}
|
||||||
/>
|
/>
|
||||||
<div className="sf-metadata-result-table" ref={this.setResultRef}>
|
<div className="sf-metadata-result-table" ref={this.setResultRef}>
|
||||||
{this.renderGroups()}
|
{this.renderGroups()}
|
||||||
@@ -972,6 +973,7 @@ GroupBody.propTypes = {
|
|||||||
openDownloadFilesDialog: PropTypes.func,
|
openDownloadFilesDialog: PropTypes.func,
|
||||||
cacheDownloadFilesProps: PropTypes.func,
|
cacheDownloadFilesProps: PropTypes.func,
|
||||||
onCellContextMenu: PropTypes.func,
|
onCellContextMenu: PropTypes.func,
|
||||||
|
getTableCanvasContainerRect: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default GroupBody;
|
export default GroupBody;
|
||||||
|
@@ -609,6 +609,10 @@ class Records extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getTableCanvasContainerRect = () => {
|
||||||
|
return this.resultContainerRef.getBoundingClientRect();
|
||||||
|
};
|
||||||
|
|
||||||
renderRecordsBody = ({ containerWidth }) => {
|
renderRecordsBody = ({ containerWidth }) => {
|
||||||
const { isGroupView, recordGetterByIndex, updateRecords } = this.props;
|
const { isGroupView, recordGetterByIndex, updateRecords } = this.props;
|
||||||
const { recordMetrics, columnMetrics, colOverScanStartIdx, colOverScanEndIdx } = this.state;
|
const { recordMetrics, columnMetrics, colOverScanStartIdx, colOverScanEndIdx } = this.state;
|
||||||
@@ -629,6 +633,7 @@ class Records extends Component {
|
|||||||
hasSelectedCell: this.hasSelectedCell,
|
hasSelectedCell: this.hasSelectedCell,
|
||||||
cacheScrollTop: this.storeScrollTop,
|
cacheScrollTop: this.storeScrollTop,
|
||||||
onCellContextMenu: this.onCellContextMenu,
|
onCellContextMenu: this.onCellContextMenu,
|
||||||
|
getTableCanvasContainerRect: this.getTableCanvasContainerRect,
|
||||||
};
|
};
|
||||||
if (this.props.isGroupView) {
|
if (this.props.isGroupView) {
|
||||||
return (
|
return (
|
||||||
|
@@ -1124,6 +1124,8 @@ class InteractionMasks extends React.Component {
|
|||||||
selectedRange: !isSelectedSingleCell ? selectedRange : null,
|
selectedRange: !isSelectedSingleCell ? selectedRange : null,
|
||||||
onClearSelected: this.handleSelectCellsDelete,
|
onClearSelected: this.handleSelectCellsDelete,
|
||||||
onCopySelected: this.onCopySelected,
|
onCopySelected: this.onCopySelected,
|
||||||
|
getTableContentRect: this.props.getTableContentRect,
|
||||||
|
getTableCanvasContainerRect: this.props.getTableCanvasContainerRect
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -1178,6 +1180,7 @@ InteractionMasks.propTypes = {
|
|||||||
gridUtils: PropTypes.object,
|
gridUtils: PropTypes.object,
|
||||||
getCopiedRecordsAndColumnsFromRange: PropTypes.func,
|
getCopiedRecordsAndColumnsFromRange: PropTypes.func,
|
||||||
onCommit: PropTypes.func,
|
onCommit: PropTypes.func,
|
||||||
|
getTableCanvasContainerRect: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default InteractionMasks;
|
export default InteractionMasks;
|
||||||
|
Reference in New Issue
Block a user