Przeglądaj źródła

Merge pull request #1541 from visuddhinanda/agile

修改建议支持文本比对
visuddhinanda 2 lat temu
rodzic
commit
b6f2a390ac

+ 15 - 4
dashboard/src/components/fts/FullTextSearchResult.tsx

@@ -38,6 +38,8 @@ interface IFtsItem {
   content?: string;
   path?: ITocPathNode[];
 }
+
+export type ISearchView = "pali" | "title";
 interface IWidget {
   keyWord?: string;
   tags?: string[];
@@ -47,7 +49,7 @@ interface IWidget {
   orderBy?: string | null;
   match?: string | null;
   keyWord2?: string;
-  view?: string;
+  view?: ISearchView;
   pageType?: string;
 }
 const FullTxtSearchResultWidget = ({
@@ -138,6 +140,17 @@ const FullTxtSearchResultWidget = ({
         } else {
           paragraph = [item.paragraph - 1, item.paragraph, item.paragraph + 1];
         }
+        let link: string = "";
+        switch (view) {
+          case "pali":
+            link = `/article/para/${item.book}-${item.paragraph}?book=${item.book}&par=${paragraph}&focus=${item.paragraph}`;
+            break;
+          case "title":
+            link = `/article/chapter/${item.book}-${item.paragraph}`;
+            break;
+          default:
+            break;
+        }
         return (
           <List.Item>
             {loading ? (
@@ -160,9 +173,7 @@ const FullTxtSearchResultWidget = ({
                   </Space>
                 </div>
                 <Title level={4} style={{ fontWeight: 500 }}>
-                  <Link
-                    to={`/article/para/${item.book}-${item.paragraph}?book=${item.book}&par=${paragraph}&focus=${item.paragraph}`}
-                  >
+                  <Link to={link} target="_blank">
                     {item.title}
                   </Link>
                 </Title>

+ 36 - 0
dashboard/src/components/general/TextDiff.tsx

@@ -0,0 +1,36 @@
+import { Tooltip, Typography } from "antd";
+import { Change, diffChars } from "diff";
+
+const { Text } = Typography;
+
+interface IWidget {
+  content?: string | null;
+  oldContent?: string | null;
+}
+const TextDiffWidget = ({ content, oldContent }: IWidget) => {
+  if (content) {
+    if (oldContent) {
+      const diff: Change[] = diffChars(oldContent, content);
+      const diffResult = diff.map((item, id) => {
+        return (
+          <Text
+            key={id}
+            type={
+              item.added ? "success" : item.removed ? "danger" : "secondary"
+            }
+            delete={item.removed ? true : undefined}
+          >
+            {item.value}
+          </Text>
+        );
+      });
+      return <Tooltip title={content}>{diffResult}</Tooltip>;
+    } else {
+      return <Text>{content}</Text>;
+    }
+  } else {
+    return <></>;
+  }
+};
+
+export default TextDiffWidget;

+ 7 - 0
dashboard/src/components/template/SentEdit/SentCell.tsx

@@ -16,6 +16,7 @@ import SentWbwEdit, { sentSave } from "./SentWbwEdit";
 import { getEnding } from "../../../reducers/nissaya-ending-vocabulary";
 import { nissayaBase } from "../Nissaya/NissayaMeaning";
 import { anchor, message } from "../../../reducers/discussion";
+import TextDiff from "../../general/TextDiff";
 
 interface IWidget {
   initValue?: ISentence;
@@ -24,6 +25,8 @@ interface IWidget {
   isPr?: boolean;
   editMode?: boolean;
   compact?: boolean;
+  showDiff?: boolean;
+  diffText?: string | null;
   onChange?: Function;
 }
 const SentCellWidget = ({
@@ -33,6 +36,8 @@ const SentCellWidget = ({
   isPr = false,
   editMode = false,
   compact = false,
+  showDiff = false,
+  diffText,
   onChange,
 }: IWidget) => {
   const intl = useIntl();
@@ -222,6 +227,8 @@ const SentCellWidget = ({
                   }}
                 />
               )
+            ) : showDiff ? (
+              <TextDiff content={sentData.content} oldContent={diffText} />
             ) : (
               <MdView
                 style={{

+ 21 - 2
dashboard/src/components/template/SentEdit/SuggestionList.tsx

@@ -1,4 +1,4 @@
-import { message, Skeleton } from "antd";
+import { message, Skeleton, Switch } from "antd";
 import { useEffect, useState } from "react";
 
 import { get } from "../../../request";
@@ -11,6 +11,7 @@ interface IWidget {
   para: number;
   wordStart: number;
   wordEnd: number;
+  content?: string | null;
   channel: IChannel;
   enable?: boolean;
   reload?: boolean;
@@ -23,6 +24,7 @@ const SuggestionListWidget = ({
   wordStart,
   wordEnd,
   channel,
+  content,
   reload = false,
   enable = true,
   onReload,
@@ -30,6 +32,7 @@ const SuggestionListWidget = ({
 }: IWidget) => {
   const [sentData, setSentData] = useState<ISentence[]>([]);
   const [loading, setLoading] = useState(false);
+  const [showDiff, setShowDiff] = useState(true);
   const load = () => {
     if (!enable) {
       return;
@@ -83,9 +86,25 @@ const SuggestionListWidget = ({
         <Skeleton />
       ) : (
         <>
+          <div style={{ textAlign: "right" }}>
+            {"文本比对"}
+            <Switch
+              size="small"
+              defaultChecked
+              onChange={(checked) => setShowDiff(checked)}
+            />
+          </div>
           {sentData.length > 0
             ? sentData.map((item, id) => {
-                return <SentCell value={item} key={id} isPr={true} />;
+                return (
+                  <SentCell
+                    value={item}
+                    key={id}
+                    isPr={true}
+                    showDiff={showDiff}
+                    diffText={content}
+                  />
+                );
               })
             : "没有修改建议"}
         </>

+ 4 - 2
dashboard/src/pages/library/search/search.tsx

@@ -3,7 +3,9 @@ import { useEffect, useState } from "react";
 import { Row, Col, Breadcrumb, Space, Tabs } from "antd";
 import FullSearchInput from "../../../components/fts/FullSearchInput";
 import BookTree from "../../../components/corpus/BookTree";
-import FullTextSearchResult from "../../../components/fts/FullTextSearchResult";
+import FullTextSearchResult, {
+  ISearchView,
+} from "../../../components/fts/FullTextSearchResult";
 import FtsBookList from "../../../components/fts/FtsBookList";
 import FtsSetting from "../../../components/fts/FtsSetting";
 import CaseList from "../../../components/dict/CaseList";
@@ -123,7 +125,7 @@ const Widget = () => {
                   ]}
                 />
                 <FullTextSearchResult
-                  view={view}
+                  view={view as ISearchView}
                   pageType={pageType}
                   keyWord={key}
                   tags={searchParams.get("tags")?.split(",")}