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

Merge pull request #4691 from weseek/feat/77525-81100-check-if-selected-pages-has-page

Feat/77525 81100 check if selected pages has page
Yuki Takei 4 лет назад
Родитель
Сommit
19bd23628d

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

@@ -33,7 +33,7 @@ class SearchPage extends React.Component {
       searchedPages: [],
       searchedPages: [],
       searchResultMeta: {},
       searchResultMeta: {},
       focusedPage: {},
       focusedPage: {},
-      selectedPages: new Set(),
+      selectedPagesIdList: new Set(),
       searchResultCount: 0,
       searchResultCount: 0,
       activePage: 1,
       activePage: 1,
       pagingLimit: 10, // change to an appropriate limit number
       pagingLimit: 10, // change to an appropriate limit number
@@ -185,14 +185,16 @@ class SearchPage extends React.Component {
     });
     });
   }
   }
 
 
-  toggleCheckBox = (page) => {
-    if (this.state.selectedPages.has(page)) {
-      this.state.selectedPages.delete(page);
+  toggleCheckBox = (pageId) => {
+    const { selectedPagesIdList } = this.state;
+
+    if (selectedPagesIdList.has(pageId)) {
+      selectedPagesIdList.delete(pageId);
     }
     }
     else {
     else {
-      this.state.selectedPages.add(page);
+      selectedPagesIdList.add(pageId);
     }
     }
-    switch (this.state.selectedPages.size) {
+    switch (selectedPagesIdList.size) {
       case 0:
       case 0:
         return this.setState({ selectAllCheckboxType: CheckboxType.NONE_CHECKED });
         return this.setState({ selectAllCheckboxType: CheckboxType.NONE_CHECKED });
       case this.state.searchedPages.length:
       case this.state.searchedPages.length:
@@ -203,15 +205,19 @@ class SearchPage extends React.Component {
   }
   }
 
 
   toggleAllCheckBox = (nextSelectAllCheckboxType) => {
   toggleAllCheckBox = (nextSelectAllCheckboxType) => {
+    const { selectedPagesIdList, searchedPages } = this.state;
     if (nextSelectAllCheckboxType === CheckboxType.NONE_CHECKED) {
     if (nextSelectAllCheckboxType === CheckboxType.NONE_CHECKED) {
-      this.state.selectedPages.clear();
+      selectedPagesIdList.clear();
     }
     }
     else {
     else {
-      this.state.searchedPages.forEach((page) => {
-        this.state.selectedPages.add(page);
+      searchedPages.forEach((page) => {
+        selectedPagesIdList.add(page._id);
       });
       });
     }
     }
-    this.setState({ selectAllCheckboxType: nextSelectAllCheckboxType });
+    this.setState({
+      selectedPagesIdList,
+      selectAllCheckboxType: nextSelectAllCheckboxType,
+    });
   };
   };
 
 
   renderSearchResultContent = () => {
   renderSearchResultContent = () => {
@@ -230,12 +236,12 @@ class SearchPage extends React.Component {
       <SearchResultList
       <SearchResultList
         pages={this.state.searchedPages || []}
         pages={this.state.searchedPages || []}
         focusedPage={this.state.focusedPage}
         focusedPage={this.state.focusedPage}
-        selectedPages={this.state.selectedPages || []}
+        selectedPagesIdList={this.state.selectedPagesIdList || []}
         searchResultCount={this.state.searchResultCount}
         searchResultCount={this.state.searchResultCount}
         activePage={this.state.activePage}
         activePage={this.state.activePage}
         pagingLimit={this.state.pagingLimit}
         pagingLimit={this.state.pagingLimit}
-        onClickInvoked={this.selectPage}
-        onChangedInvoked={this.toggleCheckBox}
+        onClickSearchResultItem={this.selectPage}
+        onClickCheckbox={this.toggleCheckBox}
         onPagingNumberChanged={this.onPagingNumberChanged}
         onPagingNumberChanged={this.onPagingNumberChanged}
       />
       />
     );
     );

+ 9 - 6
packages/app/src/components/SearchPage/SearchResultList.tsx

@@ -14,9 +14,9 @@ export type ISearchedPage = IPageHasId & {
 
 
 type Props = {
 type Props = {
   pages: ISearchedPage[],
   pages: ISearchedPage[],
-  selectedPages: ISearchedPage[],
-  onClickInvoked?: (pageId: string) => void,
-  onChangedInvoked?: (page: ISearchedPage) => void,
+  selectedPagesIdList: Set<string>
+  onClickSearchResultItem?: (pageId: string) => void,
+  onClickCheckbox?: (pageId: string) => void,
   searchResultCount?: number,
   searchResultCount?: number,
   activePage?: number,
   activePage?: number,
   pagingLimit?: number,
   pagingLimit?: number,
@@ -25,18 +25,21 @@ type Props = {
 }
 }
 
 
 const SearchResultList: FC<Props> = (props:Props) => {
 const SearchResultList: FC<Props> = (props:Props) => {
-  const { focusedPage } = props;
+  const { focusedPage, selectedPagesIdList } = props;
   const focusedPageId = focusedPage != null && focusedPage._id != null ? focusedPage._id : '';
   const focusedPageId = focusedPage != null && focusedPage._id != null ? focusedPage._id : '';
+
   return (
   return (
     <>
     <>
       {Array.isArray(props.pages) && props.pages.map((page) => {
       {Array.isArray(props.pages) && props.pages.map((page) => {
+        const isChecked = selectedPagesIdList.has(page._id);
         return (
         return (
           <SearchResultListItem
           <SearchResultListItem
             key={page._id}
             key={page._id}
             page={page}
             page={page}
-            onClickInvoked={props.onClickInvoked}
-            onClickCheckboxInvoked={props.onChangedInvoked}
+            onClickSearchResultItem={props.onClickSearchResultItem}
+            onClickCheckbox={props.onClickCheckbox}
             isSelected={page._id === focusedPageId || false}
             isSelected={page._id === focusedPageId || false}
+            isChecked={isChecked}
           />
           />
         );
         );
       })}
       })}

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

@@ -69,15 +69,15 @@ const PageItemControl: FC<PageItemControlProps> = (props: {page: ISearchedPage})
 type Props = {
 type Props = {
   page: ISearchedPage,
   page: ISearchedPage,
   isSelected: boolean,
   isSelected: boolean,
-  onClickCheckboxInvoked?: (page: ISearchedPage) => void,
-  // todo: fix name
-  // refs: https://redmine.weseek.co.jp/issues/81100
-  onClickInvoked?: (pageId: string) => void,
+  isChecked: boolean,
+  onClickCheckbox?: (pageId: string) => void,
+  onClickSearchResultItem?: (pageId: string) => void,
 }
 }
 
 
 const SearchResultListItem: FC<Props> = (props:Props) => {
 const SearchResultListItem: FC<Props> = (props:Props) => {
   const {
   const {
-    page, isSelected, onClickInvoked, onClickCheckboxInvoked,
+    // todo: refactoring variable name to clear what changed
+    page, isSelected, onClickSearchResultItem, onClickCheckbox, isChecked,
   } = 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.
   // Add prefix 'id_' in pageId, because scrollspy of bootstrap doesn't work when the first letter of id attr of target component is numeral.
@@ -92,8 +92,8 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
         className="d-block pt-3"
         className="d-block pt-3"
         href={pageId}
         href={pageId}
         onClick={() => {
         onClick={() => {
-          if (onClickInvoked != null) {
-            onClickInvoked(page._id);
+          if (onClickSearchResultItem != null) {
+            onClickSearchResultItem(page._id);
           }
           }
         }}
         }}
       >
       >
@@ -105,10 +105,11 @@ const SearchResultListItem: FC<Props> = (props:Props) => {
               type="checkbox"
               type="checkbox"
               id="flexCheckDefault"
               id="flexCheckDefault"
               onClick={() => {
               onClick={() => {
-                if (onClickCheckboxInvoked != null) {
-                  onClickCheckboxInvoked(page);
+                if (onClickCheckbox != null) {
+                  onClickCheckbox(page._id);
                 }
                 }
               }}
               }}
+              checked={isChecked}
             />
             />
           </div>
           </div>
           <div className="w-100">
           <div className="w-100">