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

refactor PagePath, LinkedPagePath

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

+ 3 - 4
src/client/js/components/PageList/PagePathHierarchicalLink.jsx

@@ -7,7 +7,7 @@ import LinkedPagePath from '../../models/LinkedPagePath';
 const PagePathHierarchicalLink = (props) => {
   const { linkedPagePath } = props;
 
-  const RootLink = () => {
+  if (linkedPagePath.isRoot) {
     return props.isPageInTrash
       ? (
         <>
@@ -27,10 +27,10 @@ const PagePathHierarchicalLink = (props) => {
           </span>
         </>
       );
-  };
+  }
 
   const isParentExists = linkedPagePath.parent != null;
-  const isParentRoot = isParentExists && linkedPagePath.parent.parent == null;
+  const isParentRoot = isParentExists && linkedPagePath.parent.isRoot;
   return (
     <>
       { isParentExists && (
@@ -41,7 +41,6 @@ const PagePathHierarchicalLink = (props) => {
           ) }
         </>
       ) }
-      { !isParentExists && <RootLink /> }
 
       <a className="page-segment" href={encodeURI(linkedPagePath.href)}>{linkedPagePath.pathName}</a>
     </>

+ 1 - 1
src/client/js/components/PageList/PagePathLabel.jsx

@@ -5,7 +5,7 @@ import PagePath from '../../models/PagePath';
 
 const PagePathLabel = (props) => {
 
-  const pagePath = new PagePath(props.page.path, true);
+  const pagePath = new PagePath(props.page.path, false, true);
 
   let classNames = ['page-path'];
   classNames = classNames.concat(props.additionalClassNames);

+ 7 - 6
src/client/js/models/LinkedPagePath.js

@@ -9,18 +9,19 @@ export default class LinkedPagePath {
 
   constructor(path, skipNormalize = false) {
 
-    const pagePath = new PagePath(path, false, skipNormalize);
+    const pagePath = new PagePath(path, skipNormalize);
 
     this.pathName = pagePath.latter;
-    this.parent = pagePath.former != null
-      ? new LinkedPagePath(pagePath.former, true)
-      : null;
+    this.isRoot = pagePath.isRoot;
+    this.parent = pagePath.isRoot
+      ? null
+      : new LinkedPagePath(pagePath.former, true);
 
   }
 
   get href() {
-    if (this.parent == null) {
-      return '/';
+    if (this.isRoot) {
+      return '';
     }
 
     return pathUtils.normalizePath(`${this.parent.href}/${this.pathName}`);

+ 9 - 5
src/client/js/models/PagePath.js

@@ -7,18 +7,22 @@ const PATTERN_DEFAULT = /^((.*)\/)?([^/]+)$/;
 
 export default class PagePath {
 
-  constructor(path, evalDatePath = false, skipNormalize = false) {
-
-    const pagePath = skipNormalize ? path : pathUtils.normalizePath(path);
+  constructor(path, skipNormalize = false, evalDatePath = false) {
 
+    this.isRoot = false;
     this.former = null;
-    this.latter = pagePath;
+    this.latter = null;
 
     // root
-    if (pagePath === '/') {
+    if (path == null || path === '' || path === '/') {
+      this.isRoot = true;
+      this.latter = '/';
       return;
     }
 
+    const pagePath = skipNormalize ? path : pathUtils.normalizePath(path);
+    this.latter = pagePath;
+
     // evaluate date path
     if (evalDatePath) {
       const matchDate = pagePath.match(PATTERN_INCLUDE_DATE);