浏览代码

Merge pull request #1423 from visuddhinanda/agile

timeline 加人名
visuddhinanda 2 年之前
父节点
当前提交
48a4f9000a

+ 3 - 0
dashboard/src/components/api/webhook.ts

@@ -1,5 +1,6 @@
 import { IUser } from "../auth/User";
 import { TResType } from "../discussion/DiscussionListCard";
+import { IWebhookEvent } from "../webhook/WebhookTpl";
 
 export type TReceiverType = "wechat" | "dingtalk";
 
@@ -9,6 +10,7 @@ export interface IWebhookRequest {
   url: string;
   receiver: TReceiverType;
   event?: string[] | null;
+  event2?: IWebhookEvent[] | null;
   status?: string;
 }
 
@@ -19,6 +21,7 @@ export interface IWebhookApiData {
   url: string;
   receiver: TReceiverType;
   event: string[] | null;
+  event2?: IWebhookEvent[] | null;
   fail: number;
   success: number;
   status: string;

+ 7 - 1
dashboard/src/components/auth/User.tsx

@@ -5,6 +5,12 @@ export interface IUser {
   nickName: string;
   userName: string;
   avatar?: string;
+}
+interface IWidget {
+  id?: string;
+  nickName?: string;
+  userName?: string;
+  avatar?: string;
   showAvatar?: boolean;
   showName?: boolean;
 }
@@ -14,7 +20,7 @@ const UserWidget = ({
   avatar,
   showAvatar = true,
   showName = true,
-}: IUser) => {
+}: IWidget) => {
   return (
     <Space>
       {showAvatar ? (

+ 7 - 1
dashboard/src/components/auth/UserName.tsx

@@ -2,9 +2,15 @@ export interface IUser {
   id?: string;
   nickName?: string;
   realName?: string;
+}
+interface IWidget {
+  id?: string;
+  nickName?: string;
+  realName?: string;
   onClick?: Function;
 }
-const UserNameWidget = ({ id, nickName, realName, onClick }: IUser) => {
+
+const UserNameWidget = ({ id, nickName, realName, onClick }: IWidget) => {
   return (
     <span
       onClick={(e) => {

+ 11 - 6
dashboard/src/components/corpus/SentHistory.tsx

@@ -1,15 +1,17 @@
 import { ProList } from "@ant-design/pro-components";
-import { Typography } from "antd";
+import { Space } from "antd";
 
 import { get } from "../../request";
+import User from "../auth/User";
 import { IUser } from "../auth/UserName";
 import TimeShow from "../general/TimeShow";
 
-const { Text } = Typography;
-
 interface ISentHistoryData {
+  id: string;
+  sent_uid: string;
   content: string;
   editor: IUser;
+  landmark: string;
   created_at: string;
 }
 
@@ -31,8 +33,6 @@ const SentHistoryWidget = ({ sentId }: IWidget) => {
   return (
     <ProList<ISentHistory>
       rowKey="id"
-      headerTitle={"time line"}
-      showActions="hover"
       request={async (params = {}, sorter, filter) => {
         if (typeof sentId === "undefined") {
           return {
@@ -91,7 +91,12 @@ const SentHistoryWidget = ({ sentId }: IWidget) => {
         },
         description: {
           render: (text, row, index, action) => {
-            return <TimeShow type="secondary" createdAt={row.createdAt} />;
+            return (
+              <Space style={{ fontSize: "80%" }}>
+                <User {...row.editor} />
+                <TimeShow type="secondary" createdAt={row.createdAt} />
+              </Space>
+            );
           },
         },
         actions: {

+ 6 - 1
dashboard/src/components/corpus/SentHistoryModal.tsx

@@ -1,5 +1,7 @@
 import React, { useEffect, useState } from "react";
 import { Modal } from "antd";
+import { useIntl } from "react-intl";
+
 import SentHistory from "./SentHistory";
 
 interface IWidget {
@@ -15,6 +17,7 @@ const SentHistoryModalWidget = ({
   onClose,
 }: IWidget) => {
   const [isModalOpen, setIsModalOpen] = useState(open);
+  const intl = useIntl();
 
   useEffect(() => setIsModalOpen(open), [open]);
 
@@ -41,7 +44,9 @@ const SentHistoryModalWidget = ({
       <span onClick={showModal}>{trigger}</span>
       <Modal
         width={"80%"}
-        title="加入文集"
+        title={intl.formatMessage({
+          id: "buttons.timeline",
+        })}
         open={isModalOpen}
         onOk={handleOk}
         onCancel={handleCancel}

+ 3 - 1
dashboard/src/components/template/SentEdit/SentEditMenu.tsx

@@ -58,7 +58,9 @@ const SentEditMenuWidget = ({
   const items: MenuProps["items"] = [
     {
       key: "timeline",
-      label: "时间线",
+      label: intl.formatMessage({
+        id: "buttons.timeline",
+      }),
       icon: <FieldTimeOutlined />,
     },
     {

+ 7 - 1
dashboard/src/components/webhook/WebhookEdit.tsx

@@ -5,13 +5,14 @@ import {
   ProFormText,
 } from "@ant-design/pro-components";
 import { message, Space, Typography } from "antd";
-import { useRef } from "react";
+import { useRef, useState } from "react";
 import { useIntl } from "react-intl";
 import { Link } from "react-router-dom";
 
 import { get, post, put } from "../../request";
 import { IWebhookRequest, IWebhookResponse } from "../api/webhook";
 import { TResType } from "../discussion/DiscussionListCard";
+import WebhookTpl, { IWebhookEvent } from "./WebhookTpl";
 
 const { Title } = Typography;
 
@@ -32,6 +33,7 @@ const WebhookEditWidget = ({
   onSuccess,
 }: IWidget) => {
   const formRef = useRef<ProFormInstance>();
+  const [event, setEvent] = useState<IWebhookEvent[]>([]);
   const intl = useIntl();
 
   return (
@@ -52,6 +54,7 @@ const WebhookEditWidget = ({
           let data: IWebhookRequest = values;
           data.res_id = res_id;
           data.res_type = res_type;
+          data.event2 = event;
           let res: IWebhookResponse;
           if (typeof id === "undefined") {
             res = await post<IWebhookRequest, IWebhookResponse>(
@@ -152,6 +155,9 @@ const WebhookEditWidget = ({
             label={intl.formatMessage({ id: "forms.fields.status.label" })}
           />
         </ProForm.Group>
+        <ProForm.Group>
+          <WebhookTpl onChange={(value: IWebhookEvent[]) => setEvent(value)} />
+        </ProForm.Group>
       </ProForm>
     </Space>
   );

+ 163 - 0
dashboard/src/components/webhook/WebhookTpl.tsx

@@ -0,0 +1,163 @@
+import { Button, Space, Tag, Tree } from "antd";
+import { useEffect, useState } from "react";
+import { useAppSelector } from "../../hooks";
+import { currentUser } from "../../reducers/current-user";
+import ArticleListModal from "../article/ArticleListModal";
+
+export interface IWebhookEvent {
+  key: string;
+  tpl?: string;
+  tplTitle?: string;
+}
+
+interface DataNode {
+  title: string;
+  key: string;
+  isLeaf?: boolean;
+  children?: DataNode[];
+}
+
+interface IWidget {
+  value?: IWebhookEvent[];
+  onChange?: Function;
+}
+const WebhookTplWidget = ({ value = [], onChange }: IWidget) => {
+  const [event, setEvent] = useState(value);
+  const user = useAppSelector(currentUser);
+
+  useEffect(() => {
+    if (typeof onChange !== "undefined") {
+      onChange(event);
+    }
+  }, [event]);
+
+  const treeData: DataNode[] = [
+    {
+      title: "事件",
+      key: "event",
+      children: [
+        {
+          title: "discussion",
+          key: "discussion",
+          children: [
+            {
+              title: "create",
+              key: "discussion-create",
+              isLeaf: true,
+            },
+            {
+              title: "replay",
+              key: "discussion-replay",
+              isLeaf: true,
+            },
+            {
+              title: "edit",
+              key: "discussion-edit",
+              isLeaf: true,
+            },
+          ],
+        },
+        {
+          title: "pr",
+          key: "pr",
+          children: [
+            {
+              title: "create",
+              key: "pr-create",
+              isLeaf: true,
+            },
+            {
+              title: "edit",
+              key: "pr-edit",
+              isLeaf: true,
+            },
+          ],
+        },
+        {
+          title: "content",
+          key: "content",
+          children: [
+            {
+              title: "create",
+              key: "content-create",
+              isLeaf: true,
+            },
+            {
+              title: "edit",
+              key: "content-edit",
+              isLeaf: true,
+            },
+          ],
+        },
+      ],
+    },
+  ];
+
+  return (
+    <Tree
+      treeData={treeData}
+      checkable
+      titleRender={(node) => {
+        const tpl = event?.find((value) => value.key === node.key);
+        return (
+          <Space>
+            {node.title}
+            {node.key === "event" ? `自定义模版${event.length}` : ""}
+            {node.isLeaf ? (
+              <ArticleListModal
+                studioName={user?.realName}
+                trigger={
+                  <Button type="text">
+                    {tpl ? (
+                      <Tag
+                        closable
+                        onClose={() => {
+                          setEvent((origin) => {
+                            const index = origin.findIndex(
+                              (value) => value.key === node.key
+                            );
+                            if (index >= 0) {
+                              origin.splice(index, 1);
+                              console.log("origin", origin);
+                            }
+                            return origin;
+                          });
+                        }}
+                      >
+                        {tpl.tplTitle}
+                      </Tag>
+                    ) : (
+                      "默认模版"
+                    )}
+                  </Button>
+                }
+                multiple={false}
+                onSelect={(id: string, title: string) => {
+                  setEvent((origin) => {
+                    const index = origin.findIndex(
+                      (value) => value.key === node.key
+                    );
+                    if (index >= 0) {
+                      origin[index].tpl = id;
+                      origin[index].tplTitle = title;
+                      return origin;
+                    } else {
+                      return [
+                        ...origin,
+                        { key: node.key, tpl: id, tplTitle: title },
+                      ];
+                    }
+                  });
+                }}
+              />
+            ) : (
+              ""
+            )}
+          </Space>
+        );
+      }}
+    />
+  );
+};
+
+export default WebhookTplWidget;

+ 1 - 0
dashboard/src/locales/zh-Hans/buttons.ts

@@ -68,6 +68,7 @@ const items = {
   "buttons.channel.collaborator": "协作",
   "buttons.channel.public": "公开",
   "buttons.refresh": "刷新",
+  "buttons.timeline": "时间线",
 };
 
 export default items;