jam411 3 лет назад
Родитель
Сommit
c010ab3508

+ 3 - 1
packages/app/src/components/PageAlert/OldRevisionAlert.tsx

@@ -16,10 +16,12 @@ export const OldRevisionAlert = (): JSX.Element => {
     return <></>;
   }
 
+  const path = page.path === '/' ? '/' : `/${page._id}`;
+
   return (
     <div className="alert alert-warning">
       <strong>{ t('Warning') }: </strong> { t('page_page.notice.version') }
-      <Link href={`/${page._id}`}>
+      <Link href={path}>
         <a><i className="icon-fw icon-arrow-right-circle"></i>{ t('Show latest') }</a>
       </Link>
     </div>

+ 5 - 2
packages/app/src/components/PageHistory.tsx

@@ -3,7 +3,7 @@ import React, { useState, useEffect } from 'react';
 import { IRevisionHasPageId } from '@growi/core';
 
 import { useCurrentPageId } from '~/stores/context';
-import { useSWRxPageRevisions } from '~/stores/page';
+import { useSWRxPageRevisions, useCurrentPagePath } from '~/stores/page';
 import loggerFactory from '~/utils/logger';
 
 import { PageRevisionTable } from './PageHistory/PageRevisionTable';
@@ -17,6 +17,7 @@ export const PageHistory: React.FC<{ onClose: () => void }> = ({ onClose }) => {
   const [activePage, setActivePage] = useState(1);
 
   const { data: currentPageId } = useCurrentPageId();
+  const { data: currentPagePath } = useCurrentPagePath();
 
   const { data: revisionsData, mutate: mutatePageRevisions } = useSWRxPageRevisions(activePage, 10, currentPageId);
 
@@ -36,7 +37,7 @@ export const PageHistory: React.FC<{ onClose: () => void }> = ({ onClose }) => {
 
   const pagingLimit = 10;
 
-  if (revisionsData == null || sourceRevision == null || targetRevision == null || currentPageId == null) {
+  if (revisionsData == null || sourceRevision == null || targetRevision == null || currentPageId == null || currentPagePath == null) {
     return (
       <div className="text-muted text-center">
         <i className="fa fa-2x fa-spinner fa-pulse mt-3"></i>
@@ -63,6 +64,8 @@ export const PageHistory: React.FC<{ onClose: () => void }> = ({ onClose }) => {
         pagingLimit={pagingLimit}
         sourceRevision={sourceRevision}
         targetRevision={targetRevision}
+        pageId={currentPageId}
+        pagePath={currentPagePath}
         onChangeSourceInvoked={setSourceRevision}
         onChangeTargetInvoked={setTargetRevision}
         onClose={onClose}

+ 6 - 1
packages/app/src/components/PageHistory/PageRevisionTable.tsx

@@ -12,6 +12,8 @@ type PageRevisionTAble = {
   pagingLimit: number,
   sourceRevision: IRevisionHasId,
   targetRevision: IRevisionHasId,
+  pageId: string,
+  pagePath: string,
   onChangeSourceInvoked: React.Dispatch<React.SetStateAction<IRevisionHasId | undefined>>,
   onChangeTargetInvoked: React.Dispatch<React.SetStateAction<IRevisionHasId | undefined>>,
   onClose: () => void,
@@ -21,7 +23,8 @@ export const PageRevisionTable = (props: PageRevisionTAble): JSX.Element => {
   const { t } = useTranslation();
 
   const {
-    revisions, pagingLimit, sourceRevision, targetRevision, onChangeSourceInvoked, onChangeTargetInvoked, onClose,
+    revisions, pagingLimit, sourceRevision, targetRevision, pageId, pagePath,
+    onChangeSourceInvoked, onChangeTargetInvoked, onClose,
   } = props;
 
   const revisionCount = revisions.length;
@@ -49,6 +52,8 @@ export const PageRevisionTable = (props: PageRevisionTAble): JSX.Element => {
           <div className="d-lg-flex">
             <Revision
               revision={revision}
+              pageId={pageId}
+              pagePath={pagePath}
               isLatestRevision={revision === latestRevision}
               hasDiff={hasDiff}
               key={`revision-history-rev-${revisionId}`}

+ 6 - 2
packages/app/src/components/PageHistory/Revision.tsx

@@ -12,6 +12,8 @@ import styles from './Revision.module.scss';
 
 type RevisionProps = {
   revision: IRevisionHasId,
+  pageId: string,
+  pagePath: string,
   isLatestRevision: boolean,
   hasDiff: boolean,
   onClose: () => void,
@@ -21,7 +23,7 @@ export const Revision = (props: RevisionProps): JSX.Element => {
   const { t } = useTranslation();
 
   const {
-    revision, isLatestRevision, hasDiff, onClose,
+    revision, pageId, pagePath, isLatestRevision, hasDiff, onClose,
   } = props;
 
   const renderSimplifiedNodiff = (revision: IRevisionHasId) => {
@@ -51,6 +53,8 @@ export const Revision = (props: RevisionProps): JSX.Element => {
 
     const pic = (typeof author === 'object') ? <UserPicture user={author} size="lg" /> : <></>;
 
+    const path = pagePath === '/' ? `/?revisionId=${revision._id}` : `/${pageId}?revisionId=${revision._id}`;
+
     return (
       <div className={`${styles['revision-history-main']} revision-history-main d-flex`}>
         <div className="picture-container">
@@ -64,7 +68,7 @@ export const Revision = (props: RevisionProps): JSX.Element => {
           <div className="mb-1">
             <UserDate dateTime={revision.createdAt} />
             <br className="d-xl-none d-block" />
-            <Link href={`?revisionId=${revision._id}`} prefetch={false}>
+            <Link href={path} prefetch={false}>
               <a className="ml-xl-3" onClick={onClose}>
                 <i className="icon-login"></i> {t('Go to this version')}
               </a>