Sfoglia il codice sorgente

refactor page path related classes

Yuki Takei 5 anni fa
parent
commit
8a153b1e98

+ 7 - 7
src/client/js/components/Navbar/GrowiSubNavigation.jsx

@@ -5,13 +5,13 @@ 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';
+
 import { createSubscribedElement } from '../UnstatedUtils';
 import AppContainer from '../../services/AppContainer';
 
-import PagePath from '../../models/PagePath';
-import LinkedPagePath from '../../models/LinkedPagePath';
-import PagePathHierarchicalLink from '../PageList/PagePathHierarchicalLink';
-
 import RevisionPath from '../Page/RevisionPath';
 import PageContainer from '../../services/PageContainer';
 import TagLabels from '../Page/TagLabels';
@@ -31,11 +31,11 @@ const GrowiSubNavigation = (props) => {
   const isPageNotFound = pageId == null;
   const isPageInTrash = isTrashPage(path);
 
-  const pagePathModel = new PagePath(pageContainer.state.path, false, true);
-  const linkedPagePathFormer = new LinkedPagePath(pagePathModel.former);
+  const dPagePath = new DevidedPagePath(pageContainer.state.path, false, true);
+  const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
   const renderFormerLink = () => (
     <>
-      { !pagePathModel.isRoot && <PagePathHierarchicalLink linkedPagePath={linkedPagePathFormer} /> }
+      { !dPagePath.isRoot && <PagePathHierarchicalLink linkedPagePath={linkedPagePathFormer} /> }
     </>
   );
 

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

@@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
 
 import { withTranslation } from 'react-i18next';
 
-import PagePath from '../../models/PagePath';
-import LinkedPagePath from '../../models/LinkedPagePath';
-import PagePathHierarchicalLink from '../PageList/PagePathHierarchicalLink';
+import DevidedPagePath from '@commons/models/devided-page-path';
+import LinkedPagePath from '@commons/models/linked-page-path';
+import PagePathHierarchicalLink from '@commons/components/PagePathHierarchicalLink';
 
 import CopyDropdown from './CopyDropdown';
 
@@ -20,13 +20,13 @@ const RevisionPath = (props) => {
     pageId, isPageInTrash, isPageForbidden,
   } = props;
 
-  const pagePathModel = new PagePath(props.pagePath, false, true);
-  const linkedPagePathLatter = new LinkedPagePath(pagePathModel.latter);
+  const dPagePath = new DevidedPagePath(props.pagePath, false, true);
+  const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
 
   return (
     <>
       <span className="d-flex align-items-center flex-wrap">
-        <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={pagePathModel.isRoot ? undefined : pagePathModel.former} />
+        <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={dPagePath.isRoot ? undefined : dPagePath.former} />
         <CopyDropdown pagePath={props.pagePath} pageId={pageId} buttonStyle={buttonStyle} />
         { !isPageInTrash && !isPageForbidden && (
           <a href="#edit" className="d-block d-edit-none text-muted btn btn-secondary bg-transparent btn-edit border-0" style={buttonStyle}>

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

@@ -1,22 +1,22 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 
-import PagePath from '../../models/PagePath';
+import DevidedPagePath from '@commons/models/devided-page-path';
 
 const PagePathLabel = (props) => {
 
-  const pagePath = new PagePath(props.page.path, false, true);
+  const dPagePath = new DevidedPagePath(props.page.path, false, true);
 
   let classNames = ['page-path'];
   classNames = classNames.concat(props.additionalClassNames);
 
   if (props.isLatterOnly) {
-    return <span className={classNames.join(' ')}>{pagePath.latter}</span>;
+    return <span className={classNames.join(' ')}>{dPagePath.latter}</span>;
   }
 
-  const textElem = (pagePath.former == null && pagePath.latter == null)
+  const textElem = (dPagePath.former == null && dPagePath.latter == null)
     ? <><strong>/</strong></>
-    : <>{pagePath.former}/<strong>{pagePath.latter}</strong></>;
+    : <>{dPagePath.former}/<strong>{dPagePath.latter}</strong></>;
 
   return <span className={classNames.join(' ')}>{textElem}</span>;
 };

+ 1 - 1
src/client/js/components/PageList/PagePathHierarchicalLink.jsx → src/lib/components/PagePathHierarchicalLink.jsx

@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
 
 import urljoin from 'url-join';
 
-import LinkedPagePath from '../../models/LinkedPagePath';
+import LinkedPagePath from '../models/linked-page-path';
 
 
 const PagePathHierarchicalLink = (props) => {

+ 1 - 1
src/client/js/models/PagePath.js → src/lib/models/devided-page-path.js

@@ -5,7 +5,7 @@ const PATTERN_INCLUDE_DATE = /^(.+\/[^/]+)\/(\d{4}|\d{4}\/\d{2}|\d{4}\/\d{2}\/\d
 // https://regex101.com/r/WVpPpY/1
 const PATTERN_DEFAULT = /^((.*)\/)?([^/]+)$/;
 
-export default class PagePath {
+export default class DevidedPagePath {
 
   constructor(path, skipNormalize = false, evalDatePath = false) {
 

+ 2 - 2
src/client/js/models/LinkedPagePath.js → src/lib/models/linked-page-path.js

@@ -1,6 +1,6 @@
 import { pathUtils } from 'growi-commons';
 
-import PagePath from './PagePath';
+import DevidedPagePath from './devided-page-path';
 
 /**
  * Linked Array Structured PagePath Model
@@ -9,7 +9,7 @@ export default class LinkedPagePath {
 
   constructor(path, skipNormalize = false) {
 
-    const pagePath = new PagePath(path, skipNormalize);
+    const pagePath = new DevidedPagePath(path, skipNormalize);
 
     this.pathName = pagePath.latter;
     this.isRoot = pagePath.isRoot;