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

redairect to new page after page duplication

kaori 4 лет назад
Родитель
Сommit
b014b5b271

+ 5 - 2
packages/app/src/components/Navbar/GrowiContextualSubNavigation.tsx

@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
 
 
 import { DropdownItem } from 'reactstrap';
 import { DropdownItem } from 'reactstrap';
 
 
-import { OnRenamedFunction, OnDeletedFunction } from '~/interfaces/ui';
+import { OnDuplicatedFunction, OnRenamedFunction, OnDeletedFunction } from '~/interfaces/ui';
 import { IPageHasId } from '~/interfaces/page';
 import { IPageHasId } from '~/interfaces/page';
 
 
 import { withUnstatedContainers } from '../UnstatedUtils';
 import { withUnstatedContainers } from '../UnstatedUtils';
@@ -184,7 +184,10 @@ const GrowiContextualSubNavigation = (props) => {
   }, [pageId]);
   }, [pageId]);
 
 
   const duplicateItemClickedHandler = useCallback(async(page: IPageForPageDuplicateModal) => {
   const duplicateItemClickedHandler = useCallback(async(page: IPageForPageDuplicateModal) => {
-    openDuplicateModal(page);
+    const duplicatedHandler: OnDuplicatedFunction = (path, pageId) => {
+      window.location.href = pageId;
+    };
+    openDuplicateModal(page, { onDuplicated: duplicatedHandler });
   }, [openDuplicateModal]);
   }, [openDuplicateModal]);
 
 
   const renameItemClickedHandler = useCallback(async(page: IPageForPageRenameModal) => {
   const renameItemClickedHandler = useCallback(async(page: IPageForPageRenameModal) => {

+ 2 - 2
packages/app/src/components/PageDuplicateModal.jsx

@@ -112,10 +112,10 @@ const PageDuplicateModal = (props) => {
     setErrs(null);
     setErrs(null);
 
 
     try {
     try {
-      await appContainer.apiv3Post('/pages/duplicate', { pageId, pageNameInput, isRecursively: isDuplicateRecursively });
+      const { data } = await appContainer.apiv3Post('/pages/duplicate', { pageId, pageNameInput, isRecursively: isDuplicateRecursively });
       const onDuplicated = duplicateModalData.opts?.onDuplicated;
       const onDuplicated = duplicateModalData.opts?.onDuplicated;
       if (onDuplicated != null) {
       if (onDuplicated != null) {
-        onDuplicated(path);
+        onDuplicated(path, data.page._id);
       }
       }
       closeDuplicateModal();
       closeDuplicateModal();
     }
     }

+ 2 - 1
packages/app/src/components/SearchPage/SearchResultContent.tsx

@@ -120,7 +120,8 @@ export const SearchResultContent: FC<Props> = (props: Props) => {
 
 
 
 
   const duplicateItemClickedHandler = useCallback(async(pageToDuplicate) => {
   const duplicateItemClickedHandler = useCallback(async(pageToDuplicate) => {
-    const duplicatedHandler: OnDuplicatedFunction = (path) => {
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    const duplicatedHandler: OnDuplicatedFunction = (path, pageId) => {
       toastSuccess(t('duplicated_pages', { path }));
       toastSuccess(t('duplicated_pages', { path }));
 
 
       advancePt();
       advancePt();

+ 2 - 1
packages/app/src/components/Sidebar/PageTree/ItemsTree.tsx

@@ -143,7 +143,8 @@ const ItemsTree: FC<ItemsTreeProps> = (props: ItemsTreeProps) => {
   }, []);
   }, []);
 
 
   const onClickDuplicateMenuItem = (pageToDuplicate: IPageForPageDuplicateModal) => {
   const onClickDuplicateMenuItem = (pageToDuplicate: IPageForPageDuplicateModal) => {
-    const duplicatedHandler: OnDuplicatedFunction = (path) => {
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    const duplicatedHandler: OnDuplicatedFunction = (path, pageId) => {
       toastSuccess(t('duplicated_pages', { path }));
       toastSuccess(t('duplicated_pages', { path }));
 
 
       advancePt();
       advancePt();

+ 1 - 1
packages/app/src/interfaces/ui.ts

@@ -23,4 +23,4 @@ export type ICustomNavTabMappings = { [key: string]: ICustomTabContent };
 
 
 export type OnDeletedFunction = (idOrPaths: string | string[], isRecursively: Nullable<true>, isCompletely: Nullable<true>) => void;
 export type OnDeletedFunction = (idOrPaths: string | string[], isRecursively: Nullable<true>, isCompletely: Nullable<true>) => void;
 export type OnRenamedFunction = (path: string) => void;
 export type OnRenamedFunction = (path: string) => void;
-export type OnDuplicatedFunction = (path: string) => void;
+export type OnDuplicatedFunction = (path: string, pageId: string) => void;