Yuki Takei 6 лет назад
Родитель
Сommit
95e46b6265

+ 5 - 5
src/client/js/components/Page/RevisionPath.jsx

@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
 
 import { withTranslation } from 'react-i18next';
 
+import { isTrashPage } from '@commons/util/path-utils';
 import DevidedPagePath from '@commons/models/devided-page-path';
 import LinkedPagePath from '@commons/models/linked-page-path';
 import PagePathHierarchicalLink from '@commons/components/PagePathHierarchicalLink';
@@ -17,18 +18,19 @@ const RevisionPath = (props) => {
   };
 
   const {
-    pageId, isPageInTrash, isPageForbidden,
+    pagePath, pageId, isPageForbidden,
   } = props;
 
-  const dPagePath = new DevidedPagePath(props.pagePath, false, true);
+  const dPagePath = new DevidedPagePath(pagePath, false, true);
   const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
+  const isInTrash = isTrashPage(pagePath);
 
   return (
     <>
       <span className="d-flex align-items-center flex-wrap">
         <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={dPagePath.isRoot ? undefined : dPagePath.former} />
         <CopyDropdown pagePath={props.pagePath} pageId={pageId} buttonStyle={buttonStyle} />
-        { !isPageInTrash && !isPageForbidden && (
+        { !isInTrash && !isPageForbidden && (
           <a href="#edit" className="d-block d-edit-none text-muted btn btn-secondary bg-transparent btn-edit border-0" style={buttonStyle}>
             <i className="icon-note" />
           </a>
@@ -44,12 +46,10 @@ RevisionPath.propTypes = {
   pagePath: PropTypes.string.isRequired,
   pageId: PropTypes.string,
   isPageForbidden: PropTypes.bool,
-  isPageInTrash: PropTypes.bool,
 };
 
 RevisionPath.defaultProps = {
   isPageForbidden: false,
-  isPageInTrash: false,
 };
 
 export default withTranslation()(RevisionPath);

+ 10 - 6
src/lib/components/PagePathHierarchicalLink.jsx

@@ -7,7 +7,7 @@ import LinkedPagePath from '../models/linked-page-path';
 
 
 const PagePathHierarchicalLink = (props) => {
-  const { linkedPagePath, basePath } = props;
+  const { linkedPagePath, basePath, isInTrash } = props;
 
   // render root element
   if (linkedPagePath.isRoot) {
@@ -15,7 +15,7 @@ const PagePathHierarchicalLink = (props) => {
       return null;
     }
 
-    return props.isPageInTrash
+    return isInTrash
       ? (
         <>
           <span className="path-segment">
@@ -37,15 +37,20 @@ const PagePathHierarchicalLink = (props) => {
   }
 
   const isParentExists = linkedPagePath.parent != null;
-  const isParentRoot = isParentExists && linkedPagePath.parent.isRoot;
+  const isParentRoot = linkedPagePath.parent?.isRoot;
   const isSeparatorRequired = isParentExists && !isParentRoot;
+  const isParentInTrash = isInTrash || linkedPagePath.isInTrash;
 
   const href = encodeURI(urljoin(basePath || '/', linkedPagePath.href));
 
   return (
     <>
       { isParentExists && (
-        <PagePathHierarchicalLink linkedPagePath={linkedPagePath.parent} basePath={basePath} />
+        <PagePathHierarchicalLink
+          linkedPagePath={linkedPagePath.parent}
+          basePath={basePath}
+          isInTrash={isParentInTrash}
+        />
       ) }
       { isSeparatorRequired && (
         <span className="separator">/</span>
@@ -59,8 +64,7 @@ const PagePathHierarchicalLink = (props) => {
 PagePathHierarchicalLink.propTypes = {
   linkedPagePath: PropTypes.instanceOf(LinkedPagePath).isRequired,
   basePath: PropTypes.string,
-
-  isPageInTrash: PropTypes.bool, // TODO: omit
+  isInTrash: PropTypes.bool,
 };
 
 export default PagePathHierarchicalLink;

+ 6 - 0
src/lib/models/linked-page-path.js

@@ -1,4 +1,5 @@
 import { pathUtils } from 'growi-commons';
+import { isTrashPage } from '@commons/util/path-utils';
 
 import DevidedPagePath from './devided-page-path';
 
@@ -11,6 +12,7 @@ export default class LinkedPagePath {
 
     const pagePath = new DevidedPagePath(path, skipNormalize);
 
+    this.path = path;
     this.pathName = pagePath.latter;
     this.isRoot = pagePath.isRoot;
     this.parent = pagePath.isRoot
@@ -27,4 +29,8 @@ export default class LinkedPagePath {
     return pathUtils.normalizePath(`${this.parent.href}/${this.pathName}`);
   }
 
+  get isInTrash() {
+    return isTrashPage(this.path);
+  }
+
 }