Sfoglia il codice sorgente

Merge pull request #4692 from weseek/fix/81794-81812-search-result-data-changed

Fix/81794 81812 search result data changed
Yuki Takei 4 anni fa
parent
commit
9c2373bf8e

+ 13 - 13
packages/app/src/components/SearchPage.jsx

@@ -28,9 +28,9 @@ class SearchPage extends React.Component {
     this.state = {
     this.state = {
       searchingKeyword: decodeURI(this.props.query.q) || '',
       searchingKeyword: decodeURI(this.props.query.q) || '',
       searchedKeyword: '',
       searchedKeyword: '',
-      searchedPages: [],
+      searchResults: [],
       searchResultMeta: {},
       searchResultMeta: {},
-      focusedPage: {},
+      focusedSearchResultData: {},
       selectedPages: new Set(),
       selectedPages: new Set(),
       searchResultCount: 0,
       searchResultCount: 0,
       activePage: 1,
       activePage: 1,
@@ -125,7 +125,7 @@ class SearchPage extends React.Component {
       this.setState({
       this.setState({
         searchingKeyword: '',
         searchingKeyword: '',
         searchedKeyword: '',
         searchedKeyword: '',
-        searchedPages: [],
+        searchResults: [],
         searchResultMeta: {},
         searchResultMeta: {},
         searchResultCount: 0,
         searchResultCount: 0,
         activePage: 1,
         activePage: 1,
@@ -149,10 +149,10 @@ class SearchPage extends React.Component {
       if (res.data.length > 0) {
       if (res.data.length > 0) {
         this.setState({
         this.setState({
           searchedKeyword: keyword,
           searchedKeyword: keyword,
-          searchedPages: res.data,
+          searchResults: res.data,
           searchResultMeta: res.meta,
           searchResultMeta: res.meta,
           searchResultCount: res.meta.total,
           searchResultCount: res.meta.total,
-          focusedPage: res.data[0],
+          focusedSearchResultData: res.data[0],
           // reset active page if keyword changes, otherwise set the current state
           // reset active page if keyword changes, otherwise set the current state
           activePage: this.state.searchedKeyword === keyword ? this.state.activePage : 1,
           activePage: this.state.searchedKeyword === keyword ? this.state.activePage : 1,
         });
         });
@@ -160,10 +160,10 @@ class SearchPage extends React.Component {
       else {
       else {
         this.setState({
         this.setState({
           searchedKeyword: keyword,
           searchedKeyword: keyword,
-          searchedPages: [],
+          searchResults: [],
           searchResultMeta: {},
           searchResultMeta: {},
           searchResultCount: 0,
           searchResultCount: 0,
-          focusedPage: {},
+          focusedSearchResultData: {},
           activePage: 1,
           activePage: 1,
         });
         });
       }
       }
@@ -174,11 +174,11 @@ class SearchPage extends React.Component {
   }
   }
 
 
   selectPage= (pageId) => {
   selectPage= (pageId) => {
-    const index = this.state.searchedPages.findIndex((page) => {
-      return page._id === pageId;
+    const index = this.state.searchResults.findIndex(({ pageData }) => {
+      return pageData._id === pageId;
     });
     });
     this.setState({
     this.setState({
-      focusedPage: this.state.searchedPages[index],
+      focusedSearchResultData: this.state.searchResults[index],
     });
     });
   }
   }
 
 
@@ -196,7 +196,7 @@ class SearchPage extends React.Component {
       <SearchResultContent
       <SearchResultContent
         appContainer={this.props.appContainer}
         appContainer={this.props.appContainer}
         searchingKeyword={this.state.searchingKeyword}
         searchingKeyword={this.state.searchingKeyword}
-        focusedPage={this.state.focusedPage}
+        focusedSearchResultData={this.state.focusedSearchResultData}
       >
       >
       </SearchResultContent>
       </SearchResultContent>
     );
     );
@@ -205,8 +205,8 @@ class SearchPage extends React.Component {
   renderSearchResultList = () => {
   renderSearchResultList = () => {
     return (
     return (
       <SearchResultList
       <SearchResultList
-        pages={this.state.searchedPages || []}
-        focusedPage={this.state.focusedPage}
+        pages={this.state.searchResults || []}
+        focusedSearchResultData={this.state.focusedSearchResultData}
         selectedPages={this.state.selectedPages || []}
         selectedPages={this.state.selectedPages || []}
         searchResultCount={this.state.searchResultCount}
         searchResultCount={this.state.searchResultCount}
         activePage={this.state.activePage}
         activePage={this.state.activePage}

+ 6 - 3
packages/app/src/components/SearchPage/SearchResultContent.tsx

@@ -1,5 +1,7 @@
 import React, { FC } from 'react';
 import React, { FC } from 'react';
 
 
+import { IPageSearchResultData } from '../../interfaces/search';
+
 import RevisionLoader from '../Page/RevisionLoader';
 import RevisionLoader from '../Page/RevisionLoader';
 import AppContainer from '../../client/services/AppContainer';
 import AppContainer from '../../client/services/AppContainer';
 
 
@@ -7,13 +9,14 @@ import AppContainer from '../../client/services/AppContainer';
 type Props ={
 type Props ={
   appContainer: AppContainer,
   appContainer: AppContainer,
   searchingKeyword:string,
   searchingKeyword:string,
-  focusedPage : any,
+  focusedSearchResultData : IPageSearchResultData,
 }
 }
 const SearchResultContent: FC<Props> = (props: Props) => {
 const SearchResultContent: FC<Props> = (props: Props) => {
   // Temporaly workaround for lint error
   // Temporaly workaround for lint error
   // later needs to be fixed: RevisoinRender to typescriptcomponet
   // later needs to be fixed: RevisoinRender to typescriptcomponet
   const RevisionRenderTypeAny: any = RevisionLoader;
   const RevisionRenderTypeAny: any = RevisionLoader;
-  const renderPage = (page) => {
+  const renderPage = (searchResultData) => {
+    const page = searchResultData?.pageData || {};
     const growiRenderer = props.appContainer.getRenderer('searchresult');
     const growiRenderer = props.appContainer.getRenderer('searchresult');
     let showTags = false;
     let showTags = false;
     if (page.tags != null && page.tags.length > 0) { showTags = true }
     if (page.tags != null && page.tags.length > 0) { showTags = true }
@@ -39,7 +42,7 @@ const SearchResultContent: FC<Props> = (props: Props) => {
       </div>
       </div>
     );
     );
   };
   };
-  const content = renderPage(props.focusedPage);
+  const content = renderPage(props.focusedSearchResultData);
   return (
   return (
 
 
     <div>{content}</div>
     <div>{content}</div>

+ 3 - 3
packages/app/src/components/SearchPage/SearchResultList.tsx

@@ -12,12 +12,12 @@ type Props = {
   activePage?: number,
   activePage?: number,
   pagingLimit?: number,
   pagingLimit?: number,
   onPagingNumberChanged?: (activePage: number) => void,
   onPagingNumberChanged?: (activePage: number) => void,
-  focusedPage?: IPageSearchResultData,
+  focusedSearchResultData?: IPageSearchResultData,
 }
 }
 
 
 const SearchResultList: FC<Props> = (props:Props) => {
 const SearchResultList: FC<Props> = (props:Props) => {
-  const { focusedPage } = props;
-  const focusedPageId = (focusedPage !== undefined && focusedPage.pageData !== undefined) ? focusedPage.pageData._id : '';
+  const { focusedSearchResultData } = props;
+  const focusedPageId = (focusedSearchResultData != null && focusedSearchResultData.pageData != null) ? focusedSearchResultData.pageData._id : '';
   return (
   return (
     <>
     <>
       {props.pages.map((page) => {
       {props.pages.map((page) => {