|
|
@@ -4,7 +4,9 @@ import React, {
|
|
|
|
|
|
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 Link from 'next/link';
|
|
|
import { useDrag, useDrop } from 'react-dnd';
|
|
|
@@ -19,7 +21,7 @@ import {
|
|
|
IPageHasId, IPageInfoAll, IPageToDeleteWithMeta,
|
|
|
} from '~/interfaces/page';
|
|
|
import { IPageForPageDuplicateModal } from '~/stores/modal';
|
|
|
-import { useSWRxPageChildren } from '~/stores/page-listing';
|
|
|
+import { mutatePageTree, useSWRxPageChildren } from '~/stores/page-listing';
|
|
|
import { usePageTreeDescCountMap } from '~/stores/ui';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
|
import { shouldRecoverPagePaths } from '~/utils/page-operation';
|
|
|
@@ -172,6 +174,10 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
|
|
|
|
|
|
const pageItemDropHandler = async(item: ItemNode) => {
|
|
|
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)) {
|
|
|
return;
|
|
|
@@ -192,6 +198,11 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
|
|
|
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();
|
|
|
|
|
|
if (onRenamed != null) {
|