Sfoglia il codice sorgente

Fix dnd same item multiple time disappear from page tree

https://youtrack.weseek.co.jp/issue/GW-7932
Mudana-Grune 3 anni fa
parent
commit
6cffbd5e46
1 ha cambiato i file con 13 aggiunte e 2 eliminazioni
  1. 13 2
      packages/app/src/components/Sidebar/PageTree/Item.tsx

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

@@ -4,7 +4,9 @@ import React, {
 
 
 import nodePath from 'path';
 import nodePath from 'path';
 
 
-import { pathUtils, pagePathUtils, Nullable } from '@growi/core';
+import {
+  pathUtils, pagePathUtils, Nullable, DevidedPagePath,
+} from '@growi/core';
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import Link from 'next/link';
 import Link from 'next/link';
 import { useDrag, useDrop } from 'react-dnd';
 import { useDrag, useDrop } from 'react-dnd';
@@ -19,7 +21,7 @@ import {
   IPageHasId, IPageInfoAll, IPageToDeleteWithMeta,
   IPageHasId, IPageInfoAll, IPageToDeleteWithMeta,
 } from '~/interfaces/page';
 } from '~/interfaces/page';
 import { IPageForPageDuplicateModal } from '~/stores/modal';
 import { IPageForPageDuplicateModal } from '~/stores/modal';
-import { useSWRxPageChildren } from '~/stores/page-listing';
+import { mutatePageTree, useSWRxPageChildren } from '~/stores/page-listing';
 import { usePageTreeDescCountMap } from '~/stores/ui';
 import { usePageTreeDescCountMap } from '~/stores/ui';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 import { shouldRecoverPagePaths } from '~/utils/page-operation';
 import { shouldRecoverPagePaths } from '~/utils/page-operation';
@@ -172,6 +174,10 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
 
 
   const pageItemDropHandler = async(item: ItemNode) => {
   const pageItemDropHandler = async(item: ItemNode) => {
     const { page: droppedPage } = item;
     const { page: droppedPage } = item;
+    const dpagePath = new DevidedPagePath(droppedPage.path, false, true);
+
+    // Check if droppedPage is direct descendant of root
+    const isDirectDescendantOfRoot = dpagePath.isFormerRoot;
 
 
     if (!isDroppable(droppedPage, page, true)) {
     if (!isDroppable(droppedPage, page, true)) {
       return;
       return;
@@ -192,6 +198,11 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
         updateMetadata: true,
         updateMetadata: true,
       });
       });
 
 
+      // Mutate page tree if target is root or dropped item is direct descendant of root
+      if (page.parent === null || isDirectDescendantOfRoot) {
+        await mutatePageTree();
+      }
+
       await mutateChildren();
       await mutateChildren();
 
 
       if (onRenamed != null) {
       if (onRenamed != null) {