Browse Source

Merge pull request #1271 from visuddhinanda/agile

relation 箭头右支持拼写过滤
visuddhinanda 2 years ago
parent
commit
594a2752c1

+ 3 - 1
dashboard/src/components/admin/relation/GrammarSelect.tsx

@@ -3,12 +3,14 @@ import { ProFormSelect } from "@ant-design/pro-components";
 import { useIntl } from "react-intl";
 
 interface IWidget {
+  name: string;
   trigger?: JSX.Element;
   id?: string;
   hidden?: boolean;
   onSuccess?: Function;
 }
 const GrammarSelectWidget = ({
+  name,
   trigger = <>{"trigger"}</>,
   id,
   hidden = false,
@@ -76,7 +78,7 @@ const GrammarSelectWidget = ({
         mode: "tags",
       }}
       width="md"
-      name="fromCase"
+      name={name}
       allowClear={false}
       label={intl.formatMessage({ id: "forms.fields.case.label" })}
     />

+ 1 - 1
dashboard/src/components/admin/relation/NissayaEndingEdit.tsx

@@ -107,7 +107,7 @@ const NissayaEndingWidget = ({
         <LangSelect width="md" />
       </ProForm.Group>
       <ProForm.Group>
-        <GrammarSelect />
+        <GrammarSelect name="fromCase" />
         <ProFormText
           width="md"
           name="fromSpell"

+ 13 - 23
dashboard/src/components/admin/relation/RelationEdit.tsx

@@ -1,7 +1,6 @@
 import {
   ModalForm,
   ProForm,
-  ProFormDependency,
   ProFormInstance,
   ProFormSelect,
   ProFormText,
@@ -78,14 +77,6 @@ const RelationEditWidget = ({
   const formRef = useRef<ProFormInstance>();
   const intl = useIntl();
 
-  const verbOptions = _verb.map((item) => {
-    return {
-      value: item,
-      label: intl.formatMessage({
-        id: `dict.fields.type.${item}.label`,
-      }),
-    };
-  });
   return (
     <ModalForm<IRelation>
       title={title}
@@ -101,6 +92,7 @@ const RelationEditWidget = ({
       onFinish={async (values) => {
         let data = values;
         data.from = { spell: values.fromSpell, case: values.fromCase };
+        data.to = { spell: values.toSpell, case: values.toCase };
         let res: IRelationResponse;
         if (typeof id === "undefined") {
           res = await post<IRelationRequest, IRelationResponse>(
@@ -131,7 +123,7 @@ const RelationEditWidget = ({
               const res = await get<IRelationResponse>(`/v2/relation/${id}`);
               console.log("relation get", res);
               if (res.ok) {
-                setTitle(res.data.name);
+                setTitle(res.data.name + "dd");
 
                 return {
                   id: id,
@@ -141,6 +133,8 @@ const RelationEditWidget = ({
                   fromCase: res.data.from?.case,
                   fromSpell: res.data.from?.spell,
                   to: res.data.to,
+                  toCase: res.data.to?.case,
+                  toSpell: res.data.to?.spell,
                   match: res.data.match ? res.data.match : undefined,
                   category: res.data.category,
                 };
@@ -161,25 +155,23 @@ const RelationEditWidget = ({
           label={intl.formatMessage({ id: "forms.fields.name.label" })}
         />
       </ProForm.Group>
-      <ProForm.Group title="from">
-        <GrammarSelect />
+      <ProForm.Group title="">
+        <GrammarSelect name="fromCase" />
         <ProFormText
           width="md"
           name="fromSpell"
           label={intl.formatMessage({ id: "buttons.spell" })}
         />
       </ProForm.Group>
-      <ProForm.Group>
-        <ProFormSelect
-          options={verbOptions}
-          fieldProps={{
-            mode: "tags",
-          }}
+      <ProForm.Group title="连接到">
+        <GrammarSelect name="toCase" />
+        <ProFormText
           width="md"
-          name="to"
-          allowClear={false}
-          label={intl.formatMessage({ id: "forms.fields.to.label" })}
+          name="toSpell"
+          label={intl.formatMessage({ id: "buttons.spell" })}
         />
+      </ProForm.Group>
+      <ProForm.Group>
         <ProFormSelect
           options={["gender", "number", "case"].map((item) => {
             return {
@@ -195,8 +187,6 @@ const RelationEditWidget = ({
           allowClear={false}
           label={intl.formatMessage({ id: "forms.fields.match.label" })}
         />
-      </ProForm.Group>
-      <ProForm.Group>
         <ProFormText
           width="md"
           name="category"

+ 7 - 37
dashboard/src/components/channel/ChapterInChannelList.tsx

@@ -2,7 +2,6 @@ import { useIntl } from "react-intl";
 import { Progress, Typography } from "antd";
 import { ProTable } from "@ant-design/pro-components";
 import { Link } from "react-router-dom";
-import { Space, Table } from "antd";
 import { Button, Dropdown } from "antd";
 import { DeleteOutlined } from "@ant-design/icons";
 
@@ -129,6 +128,8 @@ const ChpaterInChannelListWidget = ({ channelId, onSelect }: IWidget) => {
           width: 120,
           valueType: "option",
           render: (text, row, index, action) => {
+            let editLink = `/article/chapter/${row.book}-${row.paragraph}?mode=edit`;
+            editLink += channelId ? `&channel=${channelId}` : "";
             return [
               <Dropdown.Button
                 key={index}
@@ -155,47 +156,16 @@ const ChpaterInChannelListWidget = ({ channelId, onSelect }: IWidget) => {
                   },
                 }}
               >
-                <></>
+                <Link to={editLink}>
+                  {intl.formatMessage({
+                    id: "buttons.translate",
+                  })}
+                </Link>
               </Dropdown.Button>,
             ];
           },
         },
       ]}
-      rowSelection={{
-        // 自定义选择项参考: https://ant.design/components/table-cn/#components-table-demo-row-selection-custom
-        // 注释该行则默认不显示下拉选项
-        selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
-      }}
-      tableAlertRender={({
-        selectedRowKeys,
-        selectedRows,
-        onCleanSelected,
-      }) => (
-        <Space size={24}>
-          <span>
-            {intl.formatMessage({ id: "buttons.selected" })}
-            {selectedRowKeys.length}
-            <Button
-              type="link"
-              style={{ marginInlineStart: 8 }}
-              onClick={onCleanSelected}
-            >
-              {intl.formatMessage({ id: "buttons.unselect" })}
-            </Button>
-          </span>
-        </Space>
-      )}
-      tableAlertOptionRender={() => {
-        return (
-          <Space size={16}>
-            <Button type="link">
-              {intl.formatMessage({
-                id: "buttons.delete.all",
-              })}
-            </Button>
-          </Space>
-        );
-      }}
       request={async (params = {}, sorter, filter) => {
         // TODO
         console.log(params, sorter, filter);

+ 21 - 19
dashboard/src/components/general/NissayaCardTable.tsx

@@ -1,25 +1,28 @@
-import { Button, Table, Tag } from "antd";
+import { recordKeyToString } from "@ant-design/pro-components";
+import { Button, Space, Table, Tag } from "antd";
 import { useEffect, useState } from "react";
 
 interface ICaseItem {
   label: string;
   link: string;
 }
-interface DataType {
-  key: React.ReactNode;
+interface IRelationNode {
   case?: ICaseItem[];
   spell?: string;
+}
+interface DataType {
+  key: React.ReactNode;
   relation: string;
   localRelation?: string;
-  to?: ICaseItem[];
+  to?: IRelationNode;
+  from?: IRelationNode;
   category?: { name: string; note: string; meaning: string };
   translation?: string;
   children?: DataType[];
 }
 export interface INissayaRelation {
-  case?: ICaseItem[];
-  spell?: string;
-  to?: ICaseItem[];
+  from?: IRelationNode;
+  to?: IRelationNode;
   category?: { name: string; note: string; meaning: string };
   local_ending: string;
   relation: string;
@@ -52,9 +55,8 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
             .map((item, index) => {
               return {
                 key: `c_${index}`,
-                case: item.case,
-                spell: item.spell,
                 relation: item.relation,
+                from: item.from,
                 to: item.to,
                 category: item.category,
                 translation: item.local_ending,
@@ -62,10 +64,9 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
             });
           newData.push({
             key: id,
-            case: item.case,
-            spell: item.spell,
             relation: item.relation,
             to: item.to,
+            from: item.from,
             category: item.category,
             translation: item.local_ending,
             children: children,
@@ -74,9 +75,8 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
       } else {
         newData.push({
           key: id,
-          case: item.case,
-          spell: item.spell,
           relation: item.relation,
+          from: item.to,
           to: item.to,
           category: item.category,
           translation: item.local_ending,
@@ -95,8 +95,8 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
           key: "from",
           render: (value, record, index) => {
             return (
-              <>
-                {record.case?.map((item, id) => {
+              <Space>
+                {record.from?.case?.map((item, id) => {
                   return (
                     <Button
                       key={id}
@@ -108,7 +108,8 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
                     </Button>
                   );
                 })}
-              </>
+                {record.from?.spell}
+              </Space>
             );
           },
         },
@@ -130,8 +131,8 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
               return <>{record.category?.meaning}</>;
             } else {
               return (
-                <>
-                  {record.to?.map((item, id) => {
+                <Space>
+                  {record.to?.case?.map((item, id) => {
                     return (
                       <Button
                         key={id}
@@ -143,7 +144,8 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
                       </Button>
                     );
                   })}
-                </>
+                  {record.to?.spell}
+                </Space>
               );
             }
           },

+ 13 - 5
dashboard/src/pages/admin/relation/list.tsx

@@ -19,8 +19,6 @@ import { useRef } from "react";
 import { IUser } from "../../../reducers/current-user";
 import RelationEdit from "../../../components/admin/relation/RelationEdit";
 import DataImport from "../../../components/admin/relation/DataImport";
-import { useAppSelector } from "../../../hooks";
-import { getTerm } from "../../../reducers/term-vocabulary";
 import { SortOrder } from "antd/lib/table/interface";
 import TimeShow from "../../../components/general/TimeShow";
 import { ITerm } from "../../../components/term/TermEdit";
@@ -49,7 +47,7 @@ export interface IRelationRequest {
   name_term?: ITerm;
   case?: string | null;
   from?: IFrom | null;
-  to?: string[];
+  to?: IFrom | null;
   match?: string[];
   category?: string;
   category_channel?: string;
@@ -85,7 +83,9 @@ export interface IRelation {
   from?: IFrom | null;
   fromCase?: string[];
   fromSpell?: string;
-  to?: string[];
+  to?: IFrom | null;
+  toCase?: string[];
+  toSpell?: string;
   match?: string[];
   category?: string;
   category_channel?: string;
@@ -244,7 +244,8 @@ const Widget = () => {
             dataIndex: "to",
             key: "to",
             render: (text, row, index, action) => {
-              return row.to?.map((item, id) => (
+              const spell = row.to?.spell;
+              const toCase = row.to?.case?.map((item, id) => (
                 <Tooltip title={item} key={id}>
                   <Tag key={id}>
                     {intl.formatMessage({
@@ -253,6 +254,12 @@ const Widget = () => {
                   </Tag>
                 </Tooltip>
               ));
+              return (
+                <>
+                  {spell}
+                  {toCase}
+                </>
+              );
             },
           },
           {
@@ -398,6 +405,7 @@ const Widget = () => {
 
           console.log("url", url);
           const res = await get<IRelationListResponse>(url);
+          console.log("data", res.data);
           const items: IRelation[] = res.data.rows.map((item, id) => {
             return {
               sn: offset + id + 1,