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

refs #82628: fix search keyword result sorting
- Replace get nextSort and nextOrder logic
- Add comments

NEEDLEMAN3\tatsu 4 лет назад
Родитель
Сommit
dae34c85dc

+ 1 - 14
packages/app/src/components/SearchPage.jsx

@@ -79,20 +79,7 @@ class SearchPage extends React.Component {
     this.setState({ excludeTrash: !this.state.excludeTrash });
   }
 
-  getNextSort(sort) {
-    switch (sort) {
-      case '_score':
-        return 'updated_at';
-      case 'updated_at':
-        return 'created_at';
-      default:
-        return '_score';
-    }
-  }
-
-  onChangeSortInvoked() {
-    const nextSort = this.state.order === 'desc' ? this.state.sort : this.getNextSort(this.state.sort);
-    const nextOrder = nextSort === this.state.sort ? 'asc' : 'desc';
+  onChangeSortInvoked(nextSort, nextOrder) {
     this.setState({
       sort: nextSort,
       order: nextOrder,

+ 21 - 2
packages/app/src/components/SearchPage/SearchControl.tsx

@@ -13,7 +13,7 @@ type Props = {
   onSearchInvoked: (data : any[]) => boolean,
   onExcludeUsersHome?: () => void,
   onExcludeTrash?: () => void,
-  onChangeSortInvoked?: () => void,
+  onChangeSortInvoked?: (nextSort: string, nextOrder: string) => void,
 }
 
 const SearchControl: FC <Props> = (props: Props) => {
@@ -34,9 +34,24 @@ const SearchControl: FC <Props> = (props: Props) => {
     }
   };
 
+  // TODO: imprement sort dropdown
+  // refs: https://redmine.weseek.co.jp/issues/82513
   const onClickChangeSort = () => {
     if (props.onChangeSortInvoked != null) {
-      props.onChangeSortInvoked();
+      const getNextSort = (sort) => {
+        switch (sort) {
+          case '_score':
+            return 'updated_at';
+          case 'updated_at':
+            return 'created_at';
+          case 'created_at':
+          default:
+            return '_score';
+        }
+      };
+      const nextSort = props.order === 'desc' ? props.sort : getNextSort(props.sort);
+      const nextOrder = nextSort === props.sort ? 'asc' : 'desc';
+      props.onChangeSortInvoked(nextSort, nextOrder);
     }
   };
 
@@ -66,6 +81,10 @@ const SearchControl: FC <Props> = (props: Props) => {
           />
         </div>
         <div className="mr-4 d-flex">
+          {/*
+            TODO: imprement sort dropdown
+            refs: https://redmine.weseek.co.jp/issues/82513
+          */}
           <button type="button" onClick={onClickChangeSort}>change sort</button>
           <p>sort:{props.sort}, order: {props.order}</p>
         </div>