Просмотр исходного кода

Merge pull request #5439 from weseek/imprv/88633-do-not-move-under-user-page

fix: 88633 movable user pages on pagetree
cao 4 лет назад
Родитель
Сommit
af4bafc08b

+ 13 - 4
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -62,7 +62,6 @@ const bookmarkMenuItemClickHandler = async(_pageId: string, _newValue: boolean):
   await bookmarkOperation(_pageId);
 };
 
-
 /**
  * Return new page path after the droppedPagePath is moved under the newParentPagePath
  * @param droppedPagePath
@@ -148,9 +147,13 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     }, 500);
   }, []);
 
-  const [{ isDragging }, drag] = useDrag(() => ({
+  const [, drag] = useDrag({
     type: 'PAGE_TREE',
     item: { page },
+    canDrag: () => {
+      const isDraggable = !pagePathUtils.isUserPage(page.path || '/');
+      return isDraggable;
+    },
     end: (item, monitor) => {
       // in order to set d-none to dropped Item
       const dropResult = monitor.getDropResult();
@@ -160,8 +163,9 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     },
     collect: monitor => ({
       isDragging: monitor.isDragging(),
+      canDrag: monitor.canDrag(),
     }),
-  }));
+  });
 
   const pageItemDropHandler = async(item: ItemNode) => {
     const { page: droppedPage } = item;
@@ -373,6 +377,7 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     return null;
   };
 
+
   useEffect(() => {
     if (!props.isScrolled && page.isTarget) {
       document.dispatchEvent(new CustomEvent('targetItemRendered'));
@@ -406,7 +411,11 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
   }, [data, isOpen, targetPathOrId]);
 
   return (
-    <div id={`pagetree-item-${page._id}`} className={`grw-pagetree-item-container ${isOver ? 'grw-pagetree-is-over' : ''} ${shouldHide ? 'd-none' : ''}`}>
+    <div
+      id={`pagetree-item-${page._id}`}
+      className={`grw-pagetree-item-container ${isOver ? 'grw-pagetree-is-over' : ''}
+    ${shouldHide ? 'd-none' : ''}`}
+    >
       <li
         ref={(c) => { drag(c); drop(c) }}
         className={`list-group-item list-group-item-action border-0 py-0 d-flex align-items-center ${page.isTarget ? 'grw-pagetree-is-target' : ''}`}

+ 13 - 0
packages/core/src/utils/page-path-utils.ts

@@ -47,6 +47,19 @@ export const isMovablePage = (path: string): boolean => {
   return !isTopPage(path) && !isUsersProtectedPages(path);
 };
 
+/**
+ * Whether path belongs to the user page
+ * @param path
+ */
+export const isUserPage = (path: string): boolean => {
+  // https://regex101.com/r/BSDdRr/1
+  if (path.match(/^\/user(\/.*)?$/)) {
+    return true;
+  }
+
+  return false;
+};
+
 /**
  * Whether path belongs to the trash page
  * @param path