瀏覽代碼

Merge pull request #1521 from visuddhinanda/agile

Agile #1517
visuddhinanda 2 年之前
父節點
當前提交
2f6a3a1ec5

+ 36 - 0
dashboard/src/assets/icon/index.tsx

@@ -422,6 +422,38 @@ const AnthologyOutLined = () => (
   </svg>
 );
 
+const SearchOutLined = () => (
+  <svg
+    viewBox="0 0 1024 1024"
+    version="1.1"
+    xmlns="http://www.w3.org/2000/svg"
+    p-id="7586"
+    width="1em"
+    height="1em"
+  >
+    <path
+      d="M1011.2 705.9456c0 62.2592-39.7824 112.5376-88.8832 112.5376H101.632c-49.0496 0-88.8832-50.2784-88.8832-112.5376V318.0544c0-62.2592 39.8336-112.5376 88.8832-112.5376h820.7872c49.152 0 88.8832 50.2784 88.8832 112.4352v387.9936h-0.1024z"
+      fill="currentColor"
+      p-id="7587"
+    ></path>
+    <path
+      d="M979.2512 313.1392c0-44.9536-36.5056-81.4592-81.4592-81.4592H126.3104c-44.9536 0-81.4592 36.5056-81.4592 81.4592v397.6704c0 45.056 36.5056 81.4592 81.4592 81.4592h771.4816a81.408 81.408 0 0 0 81.4592-81.4592V313.1392z"
+      fill="currentColor"
+      p-id="7588"
+    ></path>
+    <path
+      d="M720.9984 632.9856a157.9008 157.9008 0 0 1-145.1008-96.2048 156.8256 156.8256 0 0 1-12.3904-61.2864 157.9008 157.9008 0 0 1 96.2048-145.1008c19.4048-8.192 40.0384-12.3904 61.2864-12.3904a157.9008 157.9008 0 0 1 145.1008 96.2048c8.192 19.4048 12.3904 40.0384 12.3904 61.2864a157.1328 157.1328 0 0 1-96.2048 145.0496 155.9552 155.9552 0 0 1-61.2864 12.4416z m0-291.9936c-74.1888 0-134.5024 60.3648-134.5024 134.5024s60.3648 134.5024 134.5024 134.5024c74.1888 0 134.5024-60.3648 134.5024-134.5024S795.1872 340.992 720.9984 340.992zM907.1616 697.4464a35.584 35.584 0 0 1-25.2416-10.3936l-67.8912-65.8432 15.9744-16.4864 68.096 65.9968a12.8 12.8 0 0 0 9.1136 3.7376 12.7488 12.7488 0 0 0 12.8-12.8512 12.7488 12.7488 0 0 0-3.7376-9.0624l-0.1536-0.1536-65.8944-67.9424 16.4864-15.9744 65.8432 67.8912a35.6352 35.6352 0 0 1-25.3952 61.0816z"
+      fill="currentColor"
+      p-id="7589"
+    ></path>
+    <path
+      d="M652.7488 543.7952a96 96 0 0 1-28.3136-68.352c0-25.8048 10.0352-50.0736 28.3136-68.3008l16.2304 16.2304a73.728 73.728 0 0 0 0 104.192l-16.2304 16.2304z"
+      fill="currentColor"
+      p-id="7590"
+    ></path>
+  </svg>
+);
+
 export const DictIcon = (props: Partial<CustomIconComponentProps>) => (
   <Icon component={DictSvg} {...props} />
 );
@@ -507,3 +539,7 @@ export const CourseOutLinedIcon = (
 export const AnthologyOutLinedIcon = (
   props: Partial<CustomIconComponentProps>
 ) => <Icon component={AnthologyOutLined} {...props} />;
+
+export const SearchOutLinedIcon = (
+  props: Partial<CustomIconComponentProps>
+) => <Icon component={SearchOutLined} {...props} />;

+ 4 - 7
dashboard/src/components/api/Auth.ts

@@ -1,3 +1,5 @@
+import { IUser } from "../auth/User";
+
 export type TRole =
   | "owner"
   | "manager"
@@ -14,17 +16,12 @@ export interface IUserRequest {
   nickName?: string;
   avatar?: string;
 }
-export interface IUserApiData {
-  id: string;
-  userName: string;
-  nickName: string;
-  avatar?: string;
-}
+
 export interface IUserListResponse {
   ok: boolean;
   message: string;
   data: {
-    rows: IUserApiData[];
+    rows: IUser[];
     count: number;
   };
 }

+ 3 - 3
dashboard/src/components/api/Comment.ts

@@ -1,6 +1,6 @@
+import { IUser } from "../auth/User";
 import { TContentType } from "../discussion/DiscussionCreate";
 import { TResType } from "../discussion/DiscussionListCard";
-import { IUserApiData } from "./Auth";
 
 export interface ICommentRequest {
   id?: string;
@@ -12,7 +12,7 @@ export interface ICommentRequest {
   parent?: string;
   tpl_id?: string;
   status?: "active" | "close";
-  editor?: IUserApiData;
+  editor?: IUser;
   created_at?: string;
   updated_at?: string;
 }
@@ -29,7 +29,7 @@ export interface ICommentApiData {
   tpl_id?: string;
   status?: "active" | "close";
   children_count?: number;
-  editor: IUserApiData;
+  editor: IUser;
   created_at?: string;
   updated_at?: string;
 }

+ 5 - 3
dashboard/src/components/corpus/BookTree.tsx

@@ -114,9 +114,11 @@ const BookTreeWidget = ({
         </Button>
         {multiSelectable ? (
           <Space>
-            {intl.formatMessage({
-              id: "buttons.multiple.select",
-            })}
+            <Text>
+              {intl.formatMessage({
+                id: "buttons.multiple.select",
+              })}
+            </Text>
             <Switch
               size="small"
               defaultChecked={multiSelect}

+ 47 - 42
dashboard/src/components/discussion/DiscussionCreate.tsx

@@ -11,10 +11,14 @@ import "react-quill/dist/quill.snow.css";
 
 import { IComment } from "./DiscussionItem";
 import { post } from "../../request";
-import { ICommentRequest, ICommentResponse } from "../api/Comment";
+import {
+  ICommentApiData,
+  ICommentRequest,
+  ICommentResponse,
+} from "../api/Comment";
 import { useAppSelector } from "../../hooks";
 import { currentUser as _currentUser } from "../../reducers/current-user";
-import { useRef } from "react";
+import { useRef, useState } from "react";
 import MDEditor from "@uiw/react-md-editor";
 
 export type TContentType = "text" | "markdown" | "html" | "json";
@@ -24,8 +28,9 @@ interface IWidget {
   resType?: string;
   parent?: string;
   topic?: IComment;
-  onCreated?: Function;
   contentType?: TContentType;
+  onCreated?: Function;
+  onTopicCreated?: Function;
 }
 const DiscussionCreateWidget = ({
   resId,
@@ -34,10 +39,27 @@ const DiscussionCreateWidget = ({
   parent,
   topic,
   onCreated,
+  onTopicCreated,
 }: IWidget) => {
   const intl = useIntl();
   const formRef = useRef<ProFormInstance>();
   const _currUser = useAppSelector(_currentUser);
+  const [currParent, setCurrParent] = useState(parent);
+
+  const toIComment = (value: ICommentApiData): IComment => {
+    return {
+      id: value.id,
+      resId: value.res_id,
+      resType: value.res_type,
+      user: value.editor,
+      title: value.title,
+      parent: value.parent,
+      tplId: value.tpl_id,
+      content: value.content,
+      createdAt: value.created_at,
+      updatedAt: value.updated_at,
+    };
+  };
 
   if (typeof _currUser === "undefined") {
     return <></>;
@@ -50,34 +72,38 @@ const DiscussionCreateWidget = ({
             formRef={formRef}
             onFinish={async (values) => {
               //新建
-              console.log("create", resId, resType, parent);
+              console.log("create", resId, resType, currParent, topic);
               console.log("value", values);
-              if (typeof parent === "undefined") {
+              let newParent: string | undefined;
+              if (typeof currParent === "undefined") {
                 if (typeof topic !== "undefined" && topic.tplId) {
-                  const newTopic = await post<
-                    ICommentRequest,
-                    ICommentResponse
-                  >(`/v2/discussion`, {
+                  const topicData: ICommentRequest = {
                     res_id: resId,
                     res_type: resType,
                     title: topic.title,
                     tpl_id: topic.tplId,
                     content: topic.content,
                     content_type: "markdown",
-                  });
+                  };
+                  console.log("create topic", topicData);
+                  const newTopic = await post<
+                    ICommentRequest,
+                    ICommentResponse
+                  >(`/v2/discussion`, topicData);
                   if (newTopic.ok) {
-                    parent = newTopic.data.id;
+                    setCurrParent(newTopic.data.id);
+                    newParent = newTopic.data.id;
                   } else {
                     console.error("no parent id");
                     return;
                   }
                 }
               }
-              console.log("parent", parent);
+              console.log("parent", currParent);
               post<ICommentRequest, ICommentResponse>(`/v2/discussion`, {
                 res_id: resId,
                 res_type: resType,
-                parent: parent,
+                parent: newParent ? newParent : currParent,
                 title: values.title,
                 content: values.content,
                 content_type: contentType,
@@ -87,30 +113,7 @@ const DiscussionCreateWidget = ({
                   if (json.ok) {
                     formRef.current?.resetFields();
                     if (typeof onCreated !== "undefined") {
-                      onCreated({
-                        id: json.data.id,
-                        resId: json.data.res_id,
-                        resType: json.data.res_type,
-                        user: {
-                          id: json.data.editor?.id
-                            ? json.data.editor.id
-                            : "null",
-                          nickName: json.data.editor?.nickName
-                            ? json.data.editor.nickName
-                            : "null",
-                          realName: json.data.editor?.userName
-                            ? json.data.editor.userName
-                            : "null",
-                          avatar: json.data.editor?.avatar
-                            ? json.data.editor.avatar
-                            : "null",
-                        },
-                        title: json.data.title,
-                        parent: json.data.parent,
-                        content: json.data.content,
-                        createdAt: json.data.created_at,
-                        updatedAt: json.data.updated_at,
-                      });
+                      onCreated(toIComment(json.data));
                     }
                   } else {
                     message.error(json.message);
@@ -127,7 +130,7 @@ const DiscussionCreateWidget = ({
                 name="title"
                 width={"lg"}
                 hidden={
-                  typeof parent !== "undefined" ||
+                  typeof currParent !== "undefined" ||
                   typeof topic?.tplId !== "undefined"
                 }
                 label={intl.formatMessage({ id: "forms.fields.title.label" })}
@@ -135,7 +138,9 @@ const DiscussionCreateWidget = ({
                 placeholder={intl.formatMessage({
                   id: "forms.message.question.required",
                 })}
-                rules={[{ required: parent || topic?.tplId ? false : true }]}
+                rules={[
+                  { required: currParent || topic?.tplId ? false : true },
+                ]}
               />
             </ProForm.Group>
             <ProForm.Group>
@@ -183,12 +188,12 @@ const DiscussionCreateWidget = ({
                   rules={[
                     {
                       required:
-                        typeof parent !== "undefined" ||
+                        typeof currParent !== "undefined" ||
                         typeof topic?.tplId !== "undefined",
                     },
                   ]}
                   label={
-                    typeof parent === "undefined" &&
+                    typeof currParent === "undefined" &&
                     typeof topic?.tplId === "undefined"
                       ? intl.formatMessage({
                           id: "forms.message.question.description.option",
@@ -201,7 +206,7 @@ const DiscussionCreateWidget = ({
                   <MDEditor
                     placeholder={
                       "问题的详细描述" +
-                      (typeof parent !== "undefined" &&
+                      (typeof currParent !== "undefined" &&
                       typeof topic?.tplId !== "undefined"
                         ? ""
                         : "(选填)")

+ 5 - 3
dashboard/src/components/discussion/DiscussionTopicChildren.tsx

@@ -43,6 +43,8 @@ const DiscussionTopicChildrenWidget = ({
   const [loading, setLoading] = useState(false);
   const [history, setHistory] = useState<ISentHistoryData[]>([]);
   const [items, setItems] = useState<IItem[]>();
+  const [currTopic, setCurrTopic] = useState(topic);
+
   console.log("topicId", topicId);
   useEffect(() => {
     if (loading === false) {
@@ -65,7 +67,7 @@ const DiscussionTopicChildrenWidget = ({
       };
     });
     const topicTime = new Date(
-      topic?.createdAt ? topic?.createdAt : ""
+      currTopic?.createdAt ? currTopic?.createdAt : ""
     ).getTime();
     let firstHis = history.findIndex(
       (value) =>
@@ -124,7 +126,7 @@ const DiscussionTopicChildrenWidget = ({
       });
     }
     setItems(newMixItems);
-  }, [data, history, topic?.createdAt]);
+  }, [data, history, currTopic?.createdAt]);
 
   useEffect(() => {
     if (resType === "sentence" && resId) {
@@ -224,7 +226,7 @@ const DiscussionTopicChildrenWidget = ({
         resType={resType}
         contentType="markdown"
         parent={topicId}
-        topic={topic}
+        topic={currTopic}
         onCreated={(e: IComment) => {
           const newData = JSON.parse(JSON.stringify(e));
           setData([...data, newData]);

+ 6 - 5
dashboard/src/components/fts/FullTextSearchResult.tsx

@@ -132,11 +132,12 @@ const FullTxtSearchResultWidget = ({
         },
       }}
       renderItem={(item) => {
-        const paragraph = [
-          item.paragraph - 1,
-          item.paragraph,
-          item.paragraph + 1,
-        ];
+        let paragraph: number[];
+        if (view === "title") {
+          paragraph = [item.paragraph, item.paragraph + 1, item.paragraph + 2];
+        } else {
+          paragraph = [item.paragraph - 1, item.paragraph, item.paragraph + 1];
+        }
         return (
           <List.Item>
             {loading ? (