Skip to content

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: delete content can recover

shuai7cdc4c8c6268
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index 16a5fb48..b9cbec70 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -56,6 +56,7 @@ export interface TagInfo extends TagBase {
updated_at?;
main_tag_slug_name?: string;
excerpt?;
+ status: string;
}
export interface QuestionParams extends ImgCodeReq {
title: string;
diff --git a/ui/src/components/Operate/index.tsx b/ui/src/components/Operate/index.tsx
index 5b83cb40..f93b6926 100644
--- a/ui/src/components/Operate/index.tsx
+++ b/ui/src/components/Operate/index.tsx
@@ -13,8 +13,8 @@ import {
editCheck,
reopenQuestion,
questionOpetation,
- changeQuestionStatus,
- changeAnswerStatus,
+ unDeleteAnswer,
+ unDeleteQuestion,
} from '@/services';
import { tryNormalLogged } from '@/utils/guard';
import { floppyNavigation } from '@/utils';
@@ -151,13 +151,13 @@ const Index: FC<IProps> = ({
confirmText: t('undelete', { keyPrefix: 'btns' }),
onConfirm: () => {
if (type === 'question') {
- changeQuestionStatus(qid, 'available').then(() => {
- callback?.('all');
+ unDeleteQuestion(qid).then(() => {
+ callback?.('default');
});
}
if (type === 'answer') {
- changeAnswerStatus(aid, 'available').then(() => {
+ unDeleteAnswer(aid).then(() => {
callback?.('all');
});
}
diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsx
index 2cde7d04..6b5bc723 100644
--- a/ui/src/pages/Tags/Detail/index.tsx
+++ b/ui/src/pages/Tags/Detail/index.tsx
@@ -47,7 +47,7 @@ const Index: FC = () => {
const { data: tagResp, isLoading } = useTagInfo({ name: curTagName });
const { data: listData, isLoading: listLoading } = useQuestionList(reqParams);
const { data: followResp } = useFollow(tagFollow);
- const { data: synonymsRes } = useQuerySynonymsTags(tagInfo?.tag_id);
+ const { data: synonymsRes } = useQuerySynonymsTags(tagInfo?.tag_id, '');
const toggleFollow = () => {
if (!guard.tryNormalLogged(true)) {
return;
diff --git a/ui/src/pages/Tags/Info/index.tsx b/ui/src/pages/Tags/Info/index.tsx
index c56b29e1..13eca786 100644
--- a/ui/src/pages/Tags/Info/index.tsx
+++ b/ui/src/pages/Tags/Info/index.tsx
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
-import { Row, Col, Button, Card } from 'react-bootstrap';
+import { Alert, Row, Col, Button, Card } from 'react-bootstrap';
import { useParams, useNavigate, Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
@@ -13,6 +13,7 @@ import {
saveSynonymsTags,
deleteTag,
editCheck,
+ unDeleteTag,
} from '@/services';
import { pathFactory } from '@/router/pathFactory';
import { loggedUserInfoStore, toastStore } from '@/stores';
@@ -23,10 +24,15 @@ const TagIntroduction = () => {
const isLogged = Boolean(userInfo?.access_token);
const [isEdit, setEditState] = useState(false);
const { tagName } = useParams();
- const { data: tagInfo } = useTagInfo({ name: tagName });
+ const { data: tagInfo, mutate: refreshTagInfo } = useTagInfo({
+ name: tagName,
+ });
const { t } = useTranslation('translation', { keyPrefix: 'tag_info' });
const navigate = useNavigate();
- const { data: synonymsData, mutate } = useQuerySynonymsTags(tagInfo?.tag_id);
+ const { data: synonymsData, mutate } = useQuerySynonymsTags(
+ tagInfo?.tag_id,
+ tagInfo?.status,
+ );
let pageTitle = '';
if (tagInfo) {
pageTitle = `'${tagInfo.display_name}' ${t('tag_wiki', {
@@ -118,7 +124,7 @@ const TagIntroduction = () => {
confirmBtnVariant: 'danger',
onConfirm: () => {
deleteTag(tagInfo.tag_id).then(() => {
- navigate('/tags', { replace: true });
+ // navigate('/tags', { replace: true });
});
},
});
@@ -126,14 +132,35 @@ const TagIntroduction = () => {
const onAction = (params) => {
if (params.action === 'edit') {
handleEditTag();
- } else if (params.action === 'delete') {
+ }
+ if (params.action === 'delete') {
handleDeleteTag();
}
+ if (params.action === 'undelete') {
+ Modal.confirm({
+ title: t('undelete_title', { keyPrefix: 'delete' }),
+ content: t('undelete_desc', { keyPrefix: 'delete' }),
+ cancelBtnVariant: 'link',
+ confirmBtnVariant: 'danger',
+ confirmText: t('undelete', { keyPrefix: 'btns' }),
+ onConfirm: () => {
+ unDeleteTag(tagInfo.tag_id).then(() => {
+ // undo
+ refreshTagInfo();
+ });
+ },
+ });
+ }
};
return (
<Row className="pt-4 mb-5">
<Col className="page-main flex-auto">
+ {tagInfo?.status === 'deleted' && (
+ <Alert variant="danger" className="mb-4">
+ {t('post_deleted', { keyPrefix: 'messages' })}
+ </Alert>
+ )}
<h3 className="mb-3">
<Link
to={pathFactory.tagLanding(tagInfo.slug_name)}
diff --git a/ui/src/services/client/question.ts b/ui/src/services/client/question.ts
index 92cc5504..57485ebc 100644
--- a/ui/src/services/client/question.ts
+++ b/ui/src/services/client/question.ts
@@ -73,3 +73,15 @@ export const putInviteUser = (
...imgCode,
});
};
+
+export const unDeleteAnswer = (id) => {
+ return request.post('/answer/api/v1/answer/recover', {
+ answer_id: id,
+ });
+};
+
+export const unDeleteQuestion = (qid) => {
+ return request.post('/answer/api/v1/question/recover', {
+ question_id: qid,
+ });
+};
diff --git a/ui/src/services/client/tag.ts b/ui/src/services/client/tag.ts
index 1296e888..8511e1bc 100644
--- a/ui/src/services/client/tag.ts
+++ b/ui/src/services/client/tag.ts
@@ -13,8 +13,13 @@ export const modifyTag = (params) => {
return request.put('/answer/api/v1/tag', params);
};
-export const useQuerySynonymsTags = (tagId) => {
- const apiUrl = tagId ? `/answer/api/v1/tag/synonyms?tag_id=${tagId}` : '';
+export const useQuerySynonymsTags = (tagId, status) => {
+ const apiUrl =
+ status === 'deleted'
+ ? ''
+ : tagId
+ ? `/answer/api/v1/tag/synonyms?tag_id=${tagId}`
+ : '';
return useSWR<{
synonyms: Type.SynonymsTag[];
member_actions?: Type.MemberActionItem[];
@@ -47,10 +52,11 @@ export const useTagInfo = ({ id = '', name = '' }) => {
name = encodeURIComponent(name);
apiUrl = `/answer/api/v1/tag?name=${name}`;
}
- const { data, error } = useSWR<Type.TagInfo>(apiUrl, (url) =>
+ const { data, error, mutate } = useSWR<Type.TagInfo>(apiUrl, (url) =>
request.get(url, { allow404: true }),
);
return {
+ mutate,
data,
isLoading: !data && !error,
error,
@@ -70,3 +76,9 @@ export const createTag = (params: Type.TagBase) => {
const apiUrl = '/answer/api/v1/tag';
return request.post<Type.TagInfo>(apiUrl, params);
};
+
+export const unDeleteTag = (id) => {
+ return request.post('/answer/api/v1/tag/recover', {
+ tag_id: id,
+ });
+};