Skip to content

Commit

Permalink
Merge pull request #9365 from weseek/imprv/open-page-tree-item-in-new…
Browse files Browse the repository at this point in the history
…-tab

imprv: Open the link of PageTreeItem in a new tab when the user middle click
  • Loading branch information
mergify[bot] authored Nov 6, 2024
2 parents d2883d1 + 53bc001 commit 9206dc0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export const PageTreeItem: FC<TreeItemProps> = (props) => {
router.push(link);
}, [router]);

const itemSelectedByWheelClickHandler = useCallback((page: IPageForItem) => {
if (page.path == null || page._id == null) {
return;
}

const url = pathUtils.returnPathForURL(page.path, page._id);

window.open(url, '_blank');
}, []);

const [, drag] = useDrag({
type: 'PAGE_TREE',
item: { page },
Expand Down Expand Up @@ -186,6 +196,7 @@ export const PageTreeItem: FC<TreeItemProps> = (props) => {
onClick={itemSelectedHandler}
onClickDuplicateMenuItem={props.onClickDuplicateMenuItem}
onClickDeleteMenuItem={props.onClickDeleteMenuItem}
onWheelClick={itemSelectedByWheelClickHandler}
onRenamed={props.onRenamed}
itemRef={itemRef}
itemClass={PageTreeItem}
Expand Down
17 changes: 16 additions & 1 deletion apps/app/src/client/components/TreeItem/TreeItemLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const TreeItemLayout: FC<TreeItemLayoutProps> = (props) => {
indentSize = 10,
itemLevel: baseItemLevel = 1,
itemNode, targetPathOrId, isOpen: _isOpen = false,
onRenamed, onClick, onClickDuplicateMenuItem, onClickDeleteMenuItem, isEnableActions, isReadOnlyUser, isWipPageShown = true,
onRenamed, onClick, onClickDuplicateMenuItem, onClickDeleteMenuItem, onWheelClick,
isEnableActions, isReadOnlyUser, isWipPageShown = true,
itemRef, itemClass,
showAlternativeContent,
} = props;
Expand All @@ -51,6 +52,19 @@ export const TreeItemLayout: FC<TreeItemLayoutProps> = (props) => {

}, [onClick, page]);

const itemMouseupHandler = useCallback((e: MouseEvent) => {
// DO NOT handle the event when e.currentTarget and e.target is different
if (e.target !== e.currentTarget) {
return;
}

if (e.button === 1) {
e.preventDefault();
onWheelClick?.(page);
}

}, [onWheelClick, page]);


// descendantCount
const { getDescCount } = usePageTreeDescCountMap();
Expand Down Expand Up @@ -141,6 +155,7 @@ export const TreeItemLayout: FC<TreeItemLayoutProps> = (props) => {
border-0 py-0 ps-0 d-flex align-items-center rounded-1`}
id={`grw-pagetree-list-${page._id}`}
onClick={itemClickHandler}
onMouseUp={itemMouseupHandler}
aria-current={isSelected ? true : undefined}
>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export type TreeItemProps = TreeItemBaseProps & {
showAlternativeContent?: boolean,
customAlternativeComponents?: Array<React.FunctionComponent<TreeItemToolProps>>,
onClick?(page: IPageForItem): void,
onWheelClick?(page: IPageForItem): void,
};

0 comments on commit 9206dc0

Please sign in to comment.