You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by sh...@apache.org on 2024/03/13 03:22:58 UTC

(incubator-answer) 02/02: feat: admin qeustions and answers add pending list

This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch feat/1.3.0/ui
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 724dc022b70ce230baba1950ad57b5fbd6d6e6e7
Author: shuai <li...@sifou.com>
AuthorDate: Wed Mar 13 11:22:44 2024 +0800

    feat: admin qeustions and answers add pending list
---
 i18n/en_US.yaml                                      |  9 ++++-----
 i18n/zh_CN.yaml                                      |  9 +++++++++
 ui/src/common/constants.ts                           |  4 ++++
 ui/src/common/interface.ts                           |  8 ++++++--
 .../pages/Admin/Answers/components/Action/index.tsx  | 12 ++++++++++++
 ui/src/pages/Admin/Answers/index.tsx                 | 12 +++++++++---
 .../Admin/Dashboard/components/Statistics/index.tsx  |  2 +-
 .../Admin/Questions/components/Action/index.tsx      | 12 ++++++++++++
 ui/src/pages/Admin/Questions/index.tsx               | 11 ++++++++---
 ui/src/pages/Review/components/FlagContent/index.tsx |  2 +-
 .../pages/Review/components/QueuedContent/index.tsx  | 20 +++++++++++++-------
 .../pages/Review/components/SuggestContent/index.tsx |  9 +--------
 ui/src/pages/Review/index.tsx                        | 10 +++++-----
 ui/src/services/client/review.ts                     |  4 ++--
 14 files changed, 87 insertions(+), 37 deletions(-)

diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 8dd7f55c..7236e700 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -1174,6 +1174,10 @@ ui:
     filter: Filter
     ignore: Ignore
     submit: Submit
+    normal: Normal
+    closed: Closed
+    deleted: Deleted
+    pending: Pending
   search:
     title: Search Results
     keywords: Keywords
@@ -1552,9 +1556,6 @@ ui:
         content: A suspended user can't log in.
     questions:
       page_title: Questions
-      normal: Normal
-      closed: Closed
-      deleted: Deleted
       unlisted: Unlisted
       post: Post
       votes: Votes
@@ -1568,8 +1569,6 @@ ui:
         placeholder: "Filter by title, question:id"
     answers:
       page_title: Answers
-      normal: Normal
-      deleted: Deleted
       post: Post
       votes: Votes
       created: Created
diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml
index 1151de96..1b964c4d 100644
--- a/i18n/zh_CN.yaml
+++ b/i18n/zh_CN.yaml
@@ -1133,6 +1133,15 @@ ui:
     system_setting: System setting
     default: Default
     reset: Reset
+    tag: Tag
+    post_lowercase: 帖子
+    filter: Filter
+    ignore: 忽略
+    submit: 提交
+    normal: 正常
+    closed: 已关闭
+    deleted: 已删除
+    pending: Pending
   search:
     title: 搜索结果
     keywords: 关键词
diff --git a/ui/src/common/constants.ts b/ui/src/common/constants.ts
index 7b5a6803..59f28c91 100644
--- a/ui/src/common/constants.ts
+++ b/ui/src/common/constants.ts
@@ -71,6 +71,10 @@ export const ADMIN_LIST_STATUS = {
     variant: 'text-bg-danger',
     name: 'deleted',
   },
+  pending: {
+    variant: 'text-bg-warning',
+    name: 'pending',
+  },
   unlist: {
     variant: 'text-bg-secondary',
     name: 'unlist',
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index 7c4c5e71..2bc8876c 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -300,9 +300,13 @@ export interface QueryQuestionsReq extends Paging {
   in_days?: number;
 }
 
-export type AdminQuestionStatus = 'available' | 'closed' | 'deleted';
+export type AdminQuestionStatus =
+  | 'available'
+  | 'pending'
+  | 'closed'
+  | 'deleted';
 
-export type AdminContentsFilterBy = 'normal' | 'closed' | 'deleted';
+export type AdminContentsFilterBy = 'normal' | 'pending' | 'closed' | 'deleted';
 
 export interface AdminContentsReq extends Paging {
   status: AdminContentsFilterBy;
diff --git a/ui/src/pages/Admin/Answers/components/Action/index.tsx b/ui/src/pages/Admin/Answers/components/Action/index.tsx
index 7f34f219..c4308cd2 100644
--- a/ui/src/pages/Admin/Answers/components/Action/index.tsx
+++ b/ui/src/pages/Admin/Answers/components/Action/index.tsx
@@ -19,6 +19,7 @@
 
 import { Dropdown } from 'react-bootstrap';
 import { useTranslation } from 'react-i18next';
+import { Link } from 'react-router-dom';
 
 import { Icon, Modal } from '@/components';
 import { changeAnswerStatus } from '@/services';
@@ -58,6 +59,17 @@ const AnswerActions = ({ itemData, curFilter, refreshList }) => {
     }
   };
 
+  if (curFilter === 'pending') {
+    return (
+      <Link
+        to={`/review?type=queued_post&objectId=${itemData.id}`}
+        className="btn btn-link p-0"
+        title={t('review', { keyPrefix: 'header.nav' })}>
+        <Icon name="three-dots-vertical" />
+      </Link>
+    );
+  }
+
   return (
     <Dropdown>
       <Dropdown.Toggle variant="link" className="no-toggle p-0">
diff --git a/ui/src/pages/Admin/Answers/index.tsx b/ui/src/pages/Admin/Answers/index.tsx
index febc8e81..a653f7f5 100644
--- a/ui/src/pages/Admin/Answers/index.tsx
+++ b/ui/src/pages/Admin/Answers/index.tsx
@@ -40,7 +40,11 @@ import { pathFactory } from '@/router/pathFactory';
 
 import AnswerAction from './components/Action';
 
-const answerFilterItems: Type.AdminContentsFilterBy[] = ['normal', 'deleted'];
+const answerFilterItems: Type.AdminContentsFilterBy[] = [
+  'normal',
+  'pending',
+  'deleted',
+];
 
 const Answers: FC = () => {
   const [urlSearchParams, setUrlSearchParams] = useSearchParams();
@@ -77,7 +81,7 @@ const Answers: FC = () => {
           data={answerFilterItems}
           currentSort={curFilter}
           sortKey="status"
-          i18nKeyPrefix="admin.answers"
+          i18nKeyPrefix="btns"
         />
 
         <Form.Control
@@ -150,7 +154,9 @@ const Answers: FC = () => {
                       'badge',
                       ADMIN_LIST_STATUS[curFilter]?.variant,
                     )}>
-                    {t(ADMIN_LIST_STATUS[curFilter]?.name)}
+                    {t(ADMIN_LIST_STATUS[curFilter]?.name, {
+                      keyPrefix: 'btns',
+                    })}
                   </span>
                 </td>
                 <td className="text-end">
diff --git a/ui/src/pages/Admin/Dashboard/components/Statistics/index.tsx b/ui/src/pages/Admin/Dashboard/components/Statistics/index.tsx
index 6555c8cc..d0f5f410 100644
--- a/ui/src/pages/Admin/Dashboard/components/Statistics/index.tsx
+++ b/ui/src/pages/Admin/Dashboard/components/Statistics/index.tsx
@@ -58,7 +58,7 @@ const Statistics: FC<IProps> = ({ data }) => {
           <Col xs={6}>
             <span className="text-secondary me-1">{t('flags')}</span>
             <strong>
-              <Link to="/review?type=flagged" className="ms-2">
+              <Link to="/review?type=flagged_post" className="ms-2">
                 {data.report_count}
               </Link>
             </strong>
diff --git a/ui/src/pages/Admin/Questions/components/Action/index.tsx b/ui/src/pages/Admin/Questions/components/Action/index.tsx
index a1f7e2a2..f5d2b41f 100644
--- a/ui/src/pages/Admin/Questions/components/Action/index.tsx
+++ b/ui/src/pages/Admin/Questions/components/Action/index.tsx
@@ -19,6 +19,7 @@
 
 import { Dropdown } from 'react-bootstrap';
 import { useTranslation } from 'react-i18next';
+import { Link } from 'react-router-dom';
 
 import { Icon, Modal } from '@/components';
 import {
@@ -119,6 +120,17 @@ const AnswerActions = ({ itemData, refreshList, curFilter, show, pin }) => {
     }
   };
 
+  if (curFilter === 'pending') {
+    return (
+      <Link
+        to={`/review?type=queued_post&objectId=${itemData.id}`}
+        className="btn btn-link p-0"
+        title={t('review', { keyPrefix: 'header.nav' })}>
+        <Icon name="three-dots-vertical" />
+      </Link>
+    );
+  }
+
   return (
     <Dropdown>
       <Dropdown.Toggle variant="link" className="no-toggle p-0">
diff --git a/ui/src/pages/Admin/Questions/index.tsx b/ui/src/pages/Admin/Questions/index.tsx
index 7a7b7be9..0488a08b 100644
--- a/ui/src/pages/Admin/Questions/index.tsx
+++ b/ui/src/pages/Admin/Questions/index.tsx
@@ -41,6 +41,7 @@ import Action from './components/Action';
 
 const questionFilterItems: Type.AdminContentsFilterBy[] = [
   'normal',
+  'pending',
   'closed',
   'deleted',
 ];
@@ -78,7 +79,7 @@ const Questions: FC = () => {
           data={questionFilterItems}
           currentSort={curFilter}
           sortKey="status"
-          i18nKeyPrefix="admin.questions"
+          i18nKeyPrefix="btns"
         />
 
         <Form.Control
@@ -147,7 +148,9 @@ const Questions: FC = () => {
                       'mb-1',
                       ADMIN_LIST_STATUS[curFilter]?.variant,
                     )}>
-                    {t(ADMIN_LIST_STATUS[curFilter]?.name)}
+                    {t(ADMIN_LIST_STATUS[curFilter]?.name, {
+                      keyPrefix: 'btns',
+                    })}
                   </span>
                   {li.show === 2 && (
                     <span
@@ -155,7 +158,9 @@ const Questions: FC = () => {
                         'badge',
                         ADMIN_LIST_STATUS.unlist.variant,
                       )}>
-                      {t(ADMIN_LIST_STATUS.unlist.name)}
+                      {t(ADMIN_LIST_STATUS.unlist.name, {
+                        keyPrefix: 'btns',
+                      })}
                     </span>
                   )}
                 </td>
diff --git a/ui/src/pages/Review/components/FlagContent/index.tsx b/ui/src/pages/Review/components/FlagContent/index.tsx
index 6a8556ad..11056c89 100644
--- a/ui/src/pages/Review/components/FlagContent/index.tsx
+++ b/ui/src/pages/Review/components/FlagContent/index.tsx
@@ -161,7 +161,7 @@ const Index: FC<IProps> = ({ refreshCount }) => {
                   ADMIN_LIST_STATUS[object_status]?.variant,
                 )}>
                 {t(ADMIN_LIST_STATUS[object_status]?.name, {
-                  keyPrefix: 'admin.questions',
+                  keyPrefix: 'btns',
                 })}
               </span>
               {flagItemData?.object_show_status === 2 && (
diff --git a/ui/src/pages/Review/components/QueuedContent/index.tsx b/ui/src/pages/Review/components/QueuedContent/index.tsx
index b490bb22..3d3b579d 100644
--- a/ui/src/pages/Review/components/QueuedContent/index.tsx
+++ b/ui/src/pages/Review/components/QueuedContent/index.tsx
@@ -1,7 +1,7 @@
 import { FC, useEffect, useState } from 'react';
 import { Card, Alert, Stack, Button } from 'react-bootstrap';
 import { useTranslation } from 'react-i18next';
-import { Link } from 'react-router-dom';
+import { Link, useSearchParams } from 'react-router-dom';
 
 import classNames from 'classnames';
 
@@ -17,6 +17,8 @@ interface IProps {
 }
 
 const Index: FC<IProps> = ({ refreshCount }) => {
+  const [urlSearch, setUrlSearchParams] = useSearchParams();
+  const objectId = urlSearch.get('objectId') || '';
   const { t } = useTranslation('translation', { keyPrefix: 'page_review' });
   const [noTasks, setNoTasks] = useState(false);
   const [isLoading, setIsLoading] = useState(false);
@@ -33,7 +35,7 @@ const Index: FC<IProps> = ({ refreshCount }) => {
       pageNumber = 1;
       setPage(pageNumber);
       // eslint-disable-next-line @typescript-eslint/no-use-before-define
-      queryNextOne(pageNumber);
+      queryNextOne(pageNumber, '');
       return;
     }
     if (pageNumber !== page) {
@@ -48,14 +50,14 @@ const Index: FC<IProps> = ({ refreshCount }) => {
     }, 150);
   };
 
-  const queryNextOne = (pageNumber) => {
-    getPendingReviewPostList(pageNumber).then((resp) => {
+  const queryNextOne = (pageNumber, id) => {
+    getPendingReviewPostList(pageNumber, id).then((resp) => {
       resolveNextOne(resp, pageNumber);
     });
   };
 
   useEffect(() => {
-    queryNextOne(page);
+    queryNextOne(page, objectId);
   }, []);
 
   const handleAction = (type: 'approve' | 'reject') => {
@@ -69,7 +71,11 @@ const Index: FC<IProps> = ({ refreshCount }) => {
     })
       .then(() => {
         refreshCount();
-        queryNextOne(page + 1);
+        queryNextOne(page, '');
+        if (objectId) {
+          urlSearch.delete('objectId');
+          setUrlSearchParams(urlSearch);
+        }
       })
       .finally(() => {
         setIsLoading(false);
@@ -144,7 +150,7 @@ const Index: FC<IProps> = ({ refreshCount }) => {
                   ADMIN_LIST_STATUS[object_status]?.variant,
                 )}>
                 {t(ADMIN_LIST_STATUS[object_status]?.name, {
-                  keyPrefix: 'admin.questions',
+                  keyPrefix: 'btns',
                 })}
               </span>
               {flagItemData?.object_show_status === 2 && (
diff --git a/ui/src/pages/Review/components/SuggestContent/index.tsx b/ui/src/pages/Review/components/SuggestContent/index.tsx
index dde42796..8b618a91 100644
--- a/ui/src/pages/Review/components/SuggestContent/index.tsx
+++ b/ui/src/pages/Review/components/SuggestContent/index.tsx
@@ -177,14 +177,7 @@ const Index: FC<IProps> = ({ refreshCount }) => {
 
   return (
     <Card>
-      <Card.Header>
-        {t('suggest_type_edit', {
-          type:
-            type === 'question' || type === 'answer'
-              ? t('post_lowercase', { keyPrefix: 'btns' })
-              : type,
-        })}
-      </Card.Header>
+      <Card.Header>{t('suggest_edits')}</Card.Header>
       <Card.Body className="p-0">
         <Alert variant="info" className="border-0 rounded-0 mb-0">
           <Stack
diff --git a/ui/src/pages/Review/index.tsx b/ui/src/pages/Review/index.tsx
index 0fc84b06..a0590e7e 100644
--- a/ui/src/pages/Review/index.tsx
+++ b/ui/src/pages/Review/index.tsx
@@ -46,11 +46,11 @@ const Index: FC = () => {
     getReviewType()
       .then((resp) => {
         if (searchType) {
-          const filterData = resp.filter((item) =>
-            item.name.includes(searchType),
-          );
-          if (filterData.length > 0) {
-            setCurrentReviewType(filterData[0].name);
+          const filterData = resp.find((item) => item.name === searchType);
+          if (Number(filterData?.todo_amount) > 0) {
+            setCurrentReviewType(filterData?.name || '');
+          } else {
+            setIsEmpty(true);
           }
         } else {
           const filterData = resp.filter((item) => item.todo_amount > 0);
diff --git a/ui/src/services/client/review.ts b/ui/src/services/client/review.ts
index 22d95ecd..c1ff0079 100644
--- a/ui/src/services/client/review.ts
+++ b/ui/src/services/client/review.ts
@@ -39,8 +39,8 @@ export const putFlagReviewAction = (params: Type.PutFlagReviewParams) => {
   return request.put('/answer/api/v1/report/review', params);
 };
 
-export const getPendingReviewPostList = (page: number) => {
-  const apiUrl = `/answer/api/v1/review/pending/post/page?page=${page}`;
+export const getPendingReviewPostList = (page: number, objectId?: string) => {
+  const apiUrl = `/answer/api/v1/review/pending/post/page?page=${page}&object_id=${objectId}`;
   return request.get<Type.QueuedReviewResp>(apiUrl);
 };