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

Merge pull request #4837 from weseek/feat/82389-82533-new-branch-refactor-highlight-page-title

82533 add isHtmlInPath to esResult
Yuki Takei 4 лет назад
Родитель
Сommit
288d41c0f9

+ 10 - 5
packages/app/src/components/SearchPage/SearchResultListItem.tsx

@@ -3,7 +3,6 @@ import React, { FC } from 'react';
 import Clamp from 'react-multiline-clamp';
 
 import { UserPicture, PageListMeta, PagePathLabel } from '@growi/ui';
-import { DevidedPagePath } from '@growi/core';
 
 import { IPageSearchResultData } from '../../interfaces/search';
 import PageItemControl from '../Common/Dropdown/PageItemControl';
@@ -27,13 +26,19 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
   // Add prefix 'id_' in pageId, because scrollspy of bootstrap doesn't work when the first letter of id attr of target component is numeral.
   const pageId = `#${pageData._id}`;
 
-  const isPathIncludedHtml = pageMeta.elasticSearchResult?.highlightedPath != null || pageData.path != null;
-  const dPagePath = new DevidedPagePath(pageData.path, false, true);
+  const pageTitle = (
+    <PagePathLabel
+      path={pageMeta.elasticSearchResult?.highlightedPath || pageData.path}
+      isLatterOnly
+      isPathIncludedHtml={pageMeta.elasticSearchResult?.isHtmlInPath}
+    >
+    </PagePathLabel>
+  );
   const pagePathElem = (
     <PagePathLabel
       path={pageMeta.elasticSearchResult?.highlightedPath || pageData.path}
       isFormerOnly
-      isPathIncludedHtml={isPathIncludedHtml}
+      isPathIncludedHtml={pageMeta.elasticSearchResult?.isHtmlInPath}
     />
   );
 
@@ -69,7 +74,7 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
               {/* page title */}
               <h3 className="mb-0">
                 <UserPicture user={pageData.lastUpdateUser} />
-                <span className="mx-2">{dPagePath.latter}</span>
+                <span className="mx-2">{pageTitle}</span>
               </h3>
               {/* page meta */}
               <div className="d-flex mx-2">

+ 8 - 7
packages/app/src/interfaces/search.ts

@@ -7,12 +7,13 @@ export enum CheckboxType {
 }
 
 export type IPageSearchResultData = {
-  pageData: IPageHasId,
+  pageData: IPageHasId;
   pageMeta: {
-    bookmarkCount?: number,
+    bookmarkCount?: number;
     elasticSearchResult?: {
-      snippet: string,
-      highlightedPath: string,
-    },
-  },
-}
+      snippet: string;
+      highlightedPath: string;
+      isHtmlInPath: boolean;
+    };
+  };
+};

+ 2 - 0
packages/app/src/server/service/search.ts

@@ -416,10 +416,12 @@ class SearchService implements SearchQueryParser, SearchResolver {
         if (highlightData != null) {
           const snippet = highlightData['body.en'] || highlightData['body.ja'] || '';
           const pathMatch = highlightData['path.en'] || highlightData['path.ja'] || '';
+          const isHtmlInPath = highlightData['path.en'] != null || highlightData['path.ja'] != null;
 
           elasticSearchResult = {
             snippet: filterXss.process(snippet),
             highlightedPath: filterXss.process(pathMatch),
+            isHtmlInPath,
           };
         }