SULLEY\ryo-h 4 лет назад
Родитель
Сommit
251a4260c3

+ 1 - 1
packages/app/src/components/PageList/Page.jsx

@@ -11,7 +11,7 @@ export default class Page extends React.Component {
       page, noLink,
     } = this.props;
 
-    let pagePathElem = <PagePathLabel page={page} additionalClassNames={['mx-1']} />;
+    let pagePathElem = <PagePathLabel path={page.path} additionalClassNames={['mx-1']} />;
     if (!noLink) {
       pagePathElem = <a className="text-break" href={page.path}>{pagePathElem}</a>;
     }

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

@@ -15,6 +15,7 @@ type Props ={
     lastUpdateUser: any
     elasticSearchResult: {
       snippet: string,
+      highlightedPath: string,
     }
   },
   onClickInvoked: (data: string) => void,
@@ -28,7 +29,7 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
   const pageId = `#${page._id}`;
 
   const dPagePath = new DevidedPagePath(page.path, false, true);
-  const pagePathElem = <PagePathLabel page={page} isFormerOnly />;
+  const pagePathElem = <PagePathLabel path={props.page.elasticSearchResult.highlightedPath} isFormerOnly />;
 
   // TODO : send cetain  length of body (revisionBody) from elastisearch by adding some settings to the query and
   //         when keyword is not in page content, display revisionBody.

+ 1 - 1
packages/app/src/components/SearchTypeahead.jsx

@@ -180,7 +180,7 @@ class SearchTypeahead extends React.Component {
     return (
       <span>
         <UserPicture user={page.lastUpdateUser} size="sm" noLink />
-        <span className="ml-1 text-break text-wrap"><PagePathLabel page={page} /></span>
+        <span className="ml-1 text-break text-wrap"><PagePathLabel path={page.path} /></span>
         <PageListMeta page={page} />
       </span>
     );

+ 3 - 5
packages/core/src/models/devided-page-path.js

@@ -2,10 +2,8 @@ import * as pathUtils from '../utils/path-utils';
 
 // https://regex101.com/r/BahpKX/2
 const PATTERN_INCLUDE_DATE = /^(.+\/[^/]+)\/(\d{4}|\d{4}\/\d{2}|\d{4}\/\d{2}\/\d{2})$/;
-// https://regex101.com/r/WVpPpY/1
-const PATTERN_DEFAULT = /^((.*)\/)?([^/]+)$/;
-// https://regex101.com/r/uCC4aX/1
-const PATTERN_PATH_HIGHLIGHTED = /^((.*)(?<!<)\/)(.*)$/;
+// https://regex101.com/r/HJNvMW/1
+const PATTERN_DEFAULT = /^((.*)(?<!<)\/)?(.+)$/gm;
 // https://regex101.com/r/4J4JuR/1
 const PATTERN_PATH_WITH_ANY_HTML_TAGS = /<("[^"]*"|'[^']*'|[^'">])*>/g;
 
@@ -42,7 +40,7 @@ export class DevidedPagePath {
     const regex = new RegExp(PATTERN_PATH_WITH_ANY_HTML_TAGS);
     // testing whether the html tags exists in the path or not
     if (regex.test(pagePath)) {
-      const matchDefault = pagePath.match(PATTERN_PATH_HIGHLIGHTED);
+      const matchDefault = pagePath.match(PATTERN_DEFAULT);
       this.isFormerRoot = matchDefault[1] === '/';
       this.former = matchDefault[2];
       this.latter = matchDefault[3];

+ 1 - 1
packages/plugin-lsx/src/client/js/components/LsxPageList/PagePathWrapper.jsx

@@ -13,7 +13,7 @@ export class PagePathWrapper extends React.Component {
     }
 
     return (
-      <PagePathLabel page={{ path: this.props.pagePath }} isLatterOnly additionalClassNames={classNames} />
+      <PagePathLabel path={this.props.pagePath} isLatterOnly additionalClassNames={classNames} />
     );
   }
 

+ 3 - 4
packages/ui/src/components/PagePath/PagePathLabel.jsx

@@ -4,8 +4,7 @@ import PropTypes from 'prop-types';
 import { DevidedPagePath } from '@growi/core';
 
 export const PagePathLabel = (props) => {
-  const highlightedPath = props.page.elasticSearchResult.highlightedPath;
-  const dPagePath = new DevidedPagePath(highlightedPath, false, true);
+  const dPagePath = new DevidedPagePath(props.path, false, true);
 
   let classNames = [''];
   classNames = classNames.concat(props.additionalClassNames);
@@ -21,7 +20,7 @@ export const PagePathLabel = (props) => {
 
   if (props.isFormerOnly) {
     const textElem = dPagePath.isFormerRoot
-      ? <></>
+      ? <>/</>
       : <>{dPagePath.former}</>;
     return displayPath(textElem);
   }
@@ -34,10 +33,10 @@ export const PagePathLabel = (props) => {
 };
 
 PagePathLabel.propTypes = {
-  page: PropTypes.object.isRequired,
   isLatterOnly: PropTypes.bool,
   isFormerOnly: PropTypes.bool,
   additionalClassNames: PropTypes.arrayOf(PropTypes.string),
+  path: PropTypes.string.isRequired,
 };
 
 PagePathLabel.defaultProps = {