A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: support list and unlist in admin contents page for questions (#780)
Han Gaod4af6f5e86f1
diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex e155edff..2d595775 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -1103,6 +1103,14 @@ ui:confirm_btn: Reopentitle: Reopen this postcontent: Are you sure you want to reopen?+ list:+ confirm_btn: List+ title: List this post+ content: Are you sure you want to list?+ unlist:+ confirm_btn: Unlist+ title: Unlist this post+ content: Are you sure you want to unlist?pin:title: Pin this postcontent: Are you sure you wish to pinned globally? This post will appear at the top of all post lists.@@ -1130,6 +1138,8 @@ ui:save: Savedelete: Deleteundelete: Undelete+ list: List+ unlist: Unlistlogin: Log insignup: Sign uplogout: Log out@@ -1538,6 +1548,7 @@ ui:normal: Normalclosed: Closeddeleted: Deleted+ unlisted: Unlistedpost: Postvotes: Votesanswers: Answers@@ -1846,3 +1857,5 @@ ui:post_hide_list: This post has been hidden from list.post_show_list: This post has been shown to list.post_reopen: This post has been reopened.+ post_list: This post has been listed.+ post_unlist: This post has been unlisted.diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yamlindex 81ca99f4..a0b84535 100644--- a/i18n/zh_CN.yaml+++ b/i18n/zh_CN.yaml@@ -1073,6 +1073,14 @@ ui:confirm_btn: 重新打开title: 重新打开这个帖子content: 确定要重新打开吗?+ list:+ confirm_btn: 列表显示+ title: 列表中显示这个帖子+ content: 确定要列表中显示这个帖子吗?+ unlist:+ confirm_btn: 列表隐藏+ title: 从列表中隐藏这个帖子+ content: 确定要从列表中隐藏这个帖子吗?pin:title: 置顶该帖子content: 你确定要全局置顶吗?这个帖子将出现在所有帖子列表的顶部。@@ -1094,6 +1102,8 @@ ui:save: 保存delete: 删除undelete: 撤消删除+ list: 列表显示+ unlist: 列表隐藏login: 登录signup: 注册logout: 退出@@ -1494,6 +1504,7 @@ ui:closed: 已关闭deleted: 已删除post: 标题+ unlisted: 已隐藏votes: 得票数answers: 回答数created: 创建于@@ -1802,3 +1813,5 @@ ui:post_hide_list: 此帖子已经从列表中隐藏。post_show_list: 该帖子已显示到列表中。post_reopen: 这个帖子已被重新打开.+ post_list: 这个帖子已经被显示+ post_unlist: 这个帖子已经被隐藏diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.goindex 5b583993..a7c305dd 100644--- a/internal/schema/question_schema.go+++ b/internal/schema/question_schema.go@@ -265,6 +265,8 @@ type AdminQuestionInfo struct {ID string `json:"id"`Title string `json:"title"`VoteCount int `json:"vote_count"`+ Show int `json:"show"`+ Pin int `json:"pin"`AnswerCount int `json:"answer_count"`AcceptedAnswerID string `json:"accepted_answer_id"`CreateTime int64 `json:"create_time"`diff --git a/ui/src/common/constants.ts b/ui/src/common/constants.tsindex 373e41d2..8868c9a0 100644--- a/ui/src/common/constants.ts+++ b/ui/src/common/constants.ts@@ -66,6 +66,10 @@ export const ADMIN_LIST_STATUS = {variant: 'text-bg-danger',name: 'deleted',},+ unlisted: {+ variant: 'text-bg-secondary',+ name: 'unlisted',+ },};export const ADMIN_NAV_MENUS = [diff --git a/ui/src/pages/Admin/Questions/components/Action/index.tsx b/ui/src/pages/Admin/Questions/components/Action/index.tsxindex 3861a839..a1f7e2a2 100644--- a/ui/src/pages/Admin/Questions/components/Action/index.tsx+++ b/ui/src/pages/Admin/Questions/components/Action/index.tsx@@ -21,10 +21,14 @@ import { Dropdown } from 'react-bootstrap';import { useTranslation } from 'react-i18next';import { Icon, Modal } from '@/components';-import { changeQuestionStatus, reopenQuestion } from '@/services';+import {+ changeQuestionStatus,+ questionOperation,+ reopenQuestion,+} from '@/services';import { useReportModal, useToast } from '@/hooks';-const AnswerActions = ({ itemData, refreshList, curFilter }) => {+const AnswerActions = ({ itemData, refreshList, curFilter, show, pin }) => {const { t } = useTranslation('translation', { keyPrefix: 'delete' });const closeModal = useReportModal(refreshList);const toast = useToast();@@ -90,6 +94,29 @@ const AnswerActions = ({ itemData, refreshList, curFilter }) => {},});}++ if (type === 'list' || type === 'unlist') {+ const keyPrefix =+ type === 'list' ? 'question_detail.list' : 'question_detail.unlist';+ Modal.confirm({+ title: t('title', { keyPrefix }),+ content: t('content', { keyPrefix }),+ cancelBtnVariant: 'link',+ confirmText: t('confirm_btn', { keyPrefix }),+ onConfirm: () => {+ questionOperation({+ id: itemData.id,+ operation: type === 'list' ? 'show' : 'hide',+ }).then(() => {+ toast.onShow({+ msg: t(`post_${type}`, { keyPrefix: 'messages' }),+ variant: 'success',+ });+ refreshList();+ });+ },+ });+ }};return (@@ -120,6 +147,17 @@ const AnswerActions = ({ itemData, refreshList, curFilter }) => {{t('undelete', { keyPrefix: 'btns' })}</Dropdown.Item>)}+ {show === 2 ? (+ <Dropdown.Item onClick={() => handleAction('list')}>+ {t('list', { keyPrefix: 'btns' })}+ </Dropdown.Item>+ ) : (+ pin !== 2 && (+ <Dropdown.Item onClick={() => handleAction('unlist')}>+ {t('unlist', { keyPrefix: 'btns' })}+ </Dropdown.Item>+ )+ )}</Dropdown.Menu></Dropdown>);diff --git a/ui/src/pages/Admin/Questions/index.tsx b/ui/src/pages/Admin/Questions/index.tsxindex 89ff51cb..27565fa6 100644--- a/ui/src/pages/Admin/Questions/index.tsx+++ b/ui/src/pages/Admin/Questions/index.tsx@@ -96,8 +96,8 @@ const Questions: FC = () => {<th>{t('post')}</th><th style={{ width: '8%' }}>{t('votes')}</th><th style={{ width: '8%' }}>{t('answers')}</th>- <th style={{ width: '20%' }}>{t('created')}</th>- <th style={{ width: '9%' }}>{t('status')}</th>+ <th style={{ width: '15%' }}>{t('created')}</th>+ <th style={{ width: '14%' }}>{t('status')}</th><th style={{ width: '10%' }} className="text-end">{t('action')}</th>@@ -143,10 +143,21 @@ const Questions: FC = () => {<spanclassName={classNames('badge',+ 'me-1',+ 'mb-1',ADMIN_LIST_STATUS[curFilter]?.variant,)}>{t(ADMIN_LIST_STATUS[curFilter]?.name)}</span>+ {li.show === 2 && (+ <span+ className={classNames(+ 'badge',+ ADMIN_LIST_STATUS.unlisted.variant,+ )}>+ {t(ADMIN_LIST_STATUS.unlisted.name)}+ </span>+ )}</td><td className="text-end">@@ -154,6 +165,8 @@ const Questions: FC = () => {itemData={{ id: li.id, answer_count: li.answer_count }}refreshList={refreshList}curFilter={curFilter}+ show={li.show}+ pin={li.pin}/></td></tr>