visuddhinanda 2 lat temu
rodzic
commit
dbb08488e0

+ 56 - 4
dashboard/src/components/discussion/DiscussionShow.tsx

@@ -5,6 +5,7 @@ import {
   Dropdown,
   Dropdown,
   message,
   message,
   Modal,
   Modal,
+  notification,
   Space,
   Space,
   Tag,
   Tag,
   Typography,
   Typography,
@@ -18,6 +19,7 @@ import {
   MessageOutlined,
   MessageOutlined,
   ExclamationCircleOutlined,
   ExclamationCircleOutlined,
   CloseOutlined,
   CloseOutlined,
+  SyncOutlined,
 } from "@ant-design/icons";
 } from "@ant-design/icons";
 import type { MenuProps } from "antd";
 import type { MenuProps } from "antd";
 
 
@@ -30,24 +32,29 @@ import { fullUrl } from "../../utils";
 import { ICommentRequest, ICommentResponse } from "../api/Comment";
 import { ICommentRequest, ICommentResponse } from "../api/Comment";
 import { useState } from "react";
 import { useState } from "react";
 import MdView from "../template/MdView";
 import MdView from "../template/MdView";
+import { TDiscussionType } from "./Discussion";
 
 
 const { Text } = Typography;
 const { Text } = Typography;
 
 
 interface IWidget {
 interface IWidget {
   data: IComment;
   data: IComment;
+  hideTitle?: boolean;
   onEdit?: Function;
   onEdit?: Function;
   onSelect?: Function;
   onSelect?: Function;
   onDelete?: Function;
   onDelete?: Function;
   onReply?: Function;
   onReply?: Function;
   onClose?: Function;
   onClose?: Function;
+  onConvert?: Function;
 }
 }
 const DiscussionShowWidget = ({
 const DiscussionShowWidget = ({
   data,
   data,
+  hideTitle = false,
   onEdit,
   onEdit,
   onSelect,
   onSelect,
   onDelete,
   onDelete,
   onReply,
   onReply,
   onClose,
   onClose,
+  onConvert,
 }: IWidget) => {
 }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
   const [closed, setClosed] = useState(data.status);
   const [closed, setClosed] = useState(data.status);
@@ -104,6 +111,23 @@ const DiscussionShowWidget = ({
     });
     });
   };
   };
 
 
+  const convert = (newType: TDiscussionType) => {
+    put<ICommentRequest, ICommentResponse>(`/v2/discussion/${data.id}`, {
+      title: data.title,
+      content: data.content,
+      status: data.status,
+      type: newType,
+    }).then((json) => {
+      console.log(json);
+      if (json.ok) {
+        notification.info({ message: "转换成功" });
+        if (typeof onConvert !== "undefined") {
+          onConvert(newType);
+        }
+      }
+    });
+  };
+
   const onClick: MenuProps["onClick"] = (e) => {
   const onClick: MenuProps["onClick"] = (e) => {
     console.log("click ", e);
     console.log("click ", e);
     switch (e.key) {
     switch (e.key) {
@@ -130,12 +154,18 @@ const DiscussionShowWidget = ({
         break;
         break;
       case "close":
       case "close":
         close(true);
         close(true);
-
         break;
         break;
-
       case "reopen":
       case "reopen":
         close(false);
         close(false);
-
+        break;
+      case "convert_qa":
+        convert("qa");
+        break;
+      case "convert_help":
+        convert("help");
+        break;
+      case "convert_discussion":
+        convert("discussion");
         break;
         break;
       case "delete":
       case "delete":
         if (data.id) {
         if (data.id) {
@@ -181,6 +211,28 @@ const DiscussionShowWidget = ({
       icon: <CheckOutlined />,
       icon: <CheckOutlined />,
       disabled: closed === "active",
       disabled: closed === "active",
     },
     },
+    {
+      type: "divider",
+    },
+    {
+      key: "convert",
+      label: intl.formatMessage({
+        id: "buttons.convert",
+      }),
+      icon: <SyncOutlined />,
+      children: [
+        { key: "convert_qa", label: "qa", disabled: data.type === "qa" },
+        { key: "convert_help", label: "help", disabled: data.type === "help" },
+        {
+          key: "convert_discussion",
+          label: "discussion",
+          disabled: data.type === "discussion",
+        },
+      ],
+    },
+    {
+      type: "divider",
+    },
     {
     {
       key: "delete",
       key: "delete",
       label: intl.formatMessage({
       label: intl.formatMessage({
@@ -196,7 +248,7 @@ const DiscussionShowWidget = ({
       size="small"
       size="small"
       title={
       title={
         <Space direction="vertical" size={"small"}>
         <Space direction="vertical" size={"small"}>
-          {data.title ? (
+          {data.title && !hideTitle ? (
             <Text
             <Text
               style={{ fontSize: 16 }}
               style={{ fontSize: 16 }}
               strong
               strong

+ 13 - 1
dashboard/src/components/discussion/DiscussionTopic.tsx

@@ -4,24 +4,29 @@ import DiscussionTopicInfo from "./DiscussionTopicInfo";
 import DiscussionTopicChildren from "./DiscussionTopicChildren";
 import DiscussionTopicChildren from "./DiscussionTopicChildren";
 import { IComment } from "./DiscussionItem";
 import { IComment } from "./DiscussionItem";
 import { TResType } from "./DiscussionListCard";
 import { TResType } from "./DiscussionListCard";
+import { TDiscussionType } from "./Discussion";
 
 
 interface IWidget {
 interface IWidget {
   resType?: TResType;
   resType?: TResType;
   topicId?: string;
   topicId?: string;
   topic?: IComment;
   topic?: IComment;
   focus?: string;
   focus?: string;
+  hideTitle?: boolean;
   onItemCountChange?: Function;
   onItemCountChange?: Function;
   onTopicReady?: Function;
   onTopicReady?: Function;
   onTopicDelete?: Function;
   onTopicDelete?: Function;
+  onConvert?: Function;
 }
 }
 const DiscussionTopicWidget = ({
 const DiscussionTopicWidget = ({
   resType,
   resType,
   topicId,
   topicId,
   topic,
   topic,
   focus,
   focus,
+  hideTitle = false,
   onTopicReady,
   onTopicReady,
   onItemCountChange,
   onItemCountChange,
   onTopicDelete,
   onTopicDelete,
+  onConvert,
 }: IWidget) => {
 }: IWidget) => {
   const [count, setCount] = useState<number>();
   const [count, setCount] = useState<number>();
   const [currResId, setCurrResId] = useState<string>();
   const [currResId, setCurrResId] = useState<string>();
@@ -30,16 +35,18 @@ const DiscussionTopicWidget = ({
   useEffect(() => {
   useEffect(() => {
     setCurrTopic(topic);
     setCurrTopic(topic);
   }, [topic]);
   }, [topic]);
+
   return (
   return (
     <>
     <>
       <DiscussionTopicInfo
       <DiscussionTopicInfo
         topicId={currTopicId}
         topicId={currTopicId}
         topic={currTopic}
         topic={currTopic}
+        hideTitle={hideTitle}
         childrenCount={count}
         childrenCount={count}
         onReady={(value: IComment) => {
         onReady={(value: IComment) => {
           setCurrResId(value.resId);
           setCurrResId(value.resId);
           setCurrTopic(value);
           setCurrTopic(value);
-          console.log("onReady", value);
+          console.log("discussion onReady", value);
           if (typeof onTopicReady !== "undefined") {
           if (typeof onTopicReady !== "undefined") {
             onTopicReady(value);
             onTopicReady(value);
           }
           }
@@ -49,6 +56,11 @@ const DiscussionTopicWidget = ({
             onTopicDelete();
             onTopicDelete();
           }
           }
         }}
         }}
+        onConvert={(value: TDiscussionType) => {
+          if (typeof onConvert !== "undefined") {
+            onConvert(value);
+          }
+        }}
       />
       />
       <DiscussionTopicChildren
       <DiscussionTopicChildren
         topic={currTopic}
         topic={currTopic}

+ 1 - 0
dashboard/src/components/discussion/DiscussionTopicChildren.tsx

@@ -159,6 +159,7 @@ const DiscussionTopicChildrenWidget = ({
               id: item.id,
               id: item.id,
               resId: item.res_id,
               resId: item.res_id,
               resType: item.res_type,
               resType: item.res_type,
+              type: item.type,
               user: item.editor,
               user: item.editor,
               parent: item.parent,
               parent: item.parent,
               title: item.title,
               title: item.title,

+ 14 - 2
dashboard/src/components/discussion/DiscussionTopicInfo.tsx

@@ -4,24 +4,29 @@ import { useEffect, useState } from "react";
 import { get } from "../../request";
 import { get } from "../../request";
 import { ICommentResponse } from "../api/Comment";
 import { ICommentResponse } from "../api/Comment";
 import DiscussionItem, { IComment } from "./DiscussionItem";
 import DiscussionItem, { IComment } from "./DiscussionItem";
+import { TDiscussionType } from "./Discussion";
 
 
 interface IWidget {
 interface IWidget {
   topicId?: string;
   topicId?: string;
   topic?: IComment;
   topic?: IComment;
   childrenCount?: number;
   childrenCount?: number;
+  hideTitle?: boolean;
   onDelete?: Function;
   onDelete?: Function;
   onReply?: Function;
   onReply?: Function;
   onClose?: Function;
   onClose?: Function;
   onReady?: Function;
   onReady?: Function;
+  onConvert?: Function;
 }
 }
 const DiscussionTopicInfoWidget = ({
 const DiscussionTopicInfoWidget = ({
   topicId,
   topicId,
   topic,
   topic,
   childrenCount,
   childrenCount,
+  hideTitle = false,
   onReady,
   onReady,
   onDelete,
   onDelete,
   onReply,
   onReply,
   onClose,
   onClose,
+  onConvert,
 }: IWidget) => {
 }: IWidget) => {
   const [data, setData] = useState<IComment | undefined>(topic);
   const [data, setData] = useState<IComment | undefined>(topic);
   useEffect(() => {
   useEffect(() => {
@@ -41,7 +46,7 @@ const DiscussionTopicInfoWidget = ({
       return;
       return;
     }
     }
     const url = `/v2/discussion/${topicId}`;
     const url = `/v2/discussion/${topicId}`;
-    console.log("url", url);
+    console.log("discussion url", url);
     get<ICommentResponse>(url)
     get<ICommentResponse>(url)
       .then((json) => {
       .then((json) => {
         if (json.ok) {
         if (json.ok) {
@@ -51,6 +56,7 @@ const DiscussionTopicInfoWidget = ({
             id: item.id,
             id: item.id,
             resId: item.res_id,
             resId: item.res_id,
             resType: item.res_type,
             resType: item.res_type,
+            type: item.type,
             parent: item.parent,
             parent: item.parent,
             user: item.editor,
             user: item.editor,
             title: item.title,
             title: item.title,
@@ -63,7 +69,7 @@ const DiscussionTopicInfoWidget = ({
           };
           };
           setData(discussion);
           setData(discussion);
           if (typeof onReady !== "undefined") {
           if (typeof onReady !== "undefined") {
-            console.log("on ready");
+            console.log("discussion on ready");
             onReady(discussion);
             onReady(discussion);
           }
           }
         } else {
         } else {
@@ -80,6 +86,7 @@ const DiscussionTopicInfoWidget = ({
       {data ? (
       {data ? (
         <DiscussionItem
         <DiscussionItem
           data={data}
           data={data}
+          hideTitle={hideTitle}
           onDelete={() => {
           onDelete={() => {
             if (typeof onDelete !== "undefined") {
             if (typeof onDelete !== "undefined") {
               onDelete(data.id);
               onDelete(data.id);
@@ -95,6 +102,11 @@ const DiscussionTopicInfoWidget = ({
               onClose(data);
               onClose(data);
             }
             }
           }}
           }}
+          onConvert={(value: TDiscussionType) => {
+            if (typeof onConvert !== "undefined") {
+              onConvert(value);
+            }
+          }}
         />
         />
       ) : (
       ) : (
         <></>
         <></>