Przeglądaj źródła

Merge pull request #1374 from visuddhinanda/agile

有discussion 的 按钮变成兰色
visuddhinanda 2 lat temu
rodzic
commit
bfc2797618

+ 10 - 10
dashboard/src/components/api/Dict.ts

@@ -5,11 +5,11 @@ import { ICaseListData } from "../dict/CaseList";
 export interface IDictRequest {
   id?: number;
   word: string;
-  type?: string;
-  grammar?: string;
+  type?: string | null;
+  grammar?: string | null;
   mean?: string | null;
   parent?: string | null;
-  note?: string;
+  note?: string | null;
   factors?: string | null;
   factormean?: string | null;
   confidence: number;
@@ -38,13 +38,13 @@ export interface IDictInfo {
 export interface IApiResponseDictData {
   id: string;
   word: string;
-  type: string;
-  grammar: string;
-  mean: string;
-  parent: string;
-  note: string;
-  factors: string;
-  factormean: string;
+  type?: string | null;
+  grammar?: string | null;
+  mean?: string | null;
+  parent?: string | null;
+  note?: string | null;
+  factors?: string | null;
+  factormean?: string | null;
   language: string;
   dict?: IDictInfo;
   dict_id: string;

+ 10 - 3
dashboard/src/components/article/ToolButtonDiscussion.tsx

@@ -43,6 +43,7 @@ interface DataNode {
   title: string;
   key: string;
   isLeaf?: boolean;
+  childrenCount?: number;
   children?: DataNode[];
 }
 
@@ -75,8 +76,12 @@ const ToolButtonDiscussionWidget = ({ type, articleId }: IWidget) => {
       console.log("discussion tree", json);
       if (json.ok) {
         const newTree: DataNode[] = json.data.rows.map((item) => {
-          const children = item.pr.map((pr) => {
-            return { title: pr.title, key: pr.title };
+          const children: DataNode[] = item.pr.map((pr) => {
+            return {
+              title: pr.title,
+              key: pr.title,
+              childrenCount: pr.children_count,
+            };
           });
           return {
             title: item.sentence.content,
@@ -109,7 +114,9 @@ const ToolButtonDiscussionWidget = ({ type, articleId }: IWidget) => {
             treeData={treeData}
             titleRender={(node) => {
               const ele = document.getElementById(node.key);
-              const count = node.children?.length;
+              const count = node.childrenCount
+                ? node.childrenCount
+                : node.children?.length;
               return (
                 <div
                   onClick={() => {

+ 8 - 6
dashboard/src/components/dict/Community.tsx

@@ -57,18 +57,20 @@ const CommunityWidget = ({ word }: IWidget) => {
             const currScore = Math.floor(
               (it.exp / 3600) * (it.confidence / 100)
             );
-
-            score = meaning.get(it.mean);
-            meaning.set(it.mean, score ? score + currScore : currScore);
+            if (it.mean) {
+              score = meaning.get(it.mean);
+              meaning.set(it.mean, score ? score + currScore : currScore);
+            }
 
             if (it.type || it.grammar) {
               const strCase = it.type + "$" + it.grammar;
               score = grammar.get(strCase);
               grammar.set(strCase, score ? score + currScore : currScore);
             }
-
-            score = parent.get(it.parent);
-            parent.set(it.parent, score ? score + currScore : currScore);
+            if (it.parent) {
+              score = parent.get(it.parent);
+              parent.set(it.parent, score ? score + currScore : currScore);
+            }
 
             if (it.editor) {
               score = editorId.get(it.editor.id);

+ 9 - 3
dashboard/src/components/dict/Compound.tsx

@@ -61,9 +61,15 @@ const CompoundWidget = ({ word, add, split, onSearch }: IWidget) => {
     const url = `/v2/userdict?view=compound&word=${word}&order=confidence`;
     get<IApiResponseDictList>(url).then((json) => {
       if (json.ok) {
-        const data = json.data.rows.map((item) => {
-          return { value: item.factors, label: item.factors };
-        });
+        const data = json.data.rows
+          .filter((value) => typeof value.factors === "string")
+          .map((item) => {
+            if (item.factors) {
+              return { value: item.factors, label: item.factors };
+            } else {
+              return { value: "", label: "" };
+            }
+          });
         setCompound(data);
       }
     });

+ 7 - 7
dashboard/src/components/dict/DictCreate.tsx

@@ -7,13 +7,13 @@ import DictEditInner from "./DictEditInner";
 export interface IDictFormData {
   id: number;
   word: string;
-  type: string;
-  grammar: string;
-  parent: string;
-  meaning: string;
-  note: string;
-  factors: string;
-  factormeaning: string;
+  type?: string | null;
+  grammar?: string | null;
+  parent?: string | null;
+  meaning?: string | null;
+  note?: string | null;
+  factors?: string | null;
+  factormeaning?: string | null;
   lang: string;
   confidence: number;
 }

+ 6 - 6
dashboard/src/components/dict/UserDictList.tsx

@@ -35,12 +35,12 @@ export interface IWord {
   sn: number;
   wordId: string;
   word: string;
-  type: string;
-  grammar: string;
-  parent: string;
-  meaning: string;
-  note: string;
-  factors: string;
+  type?: string | null;
+  grammar?: string | null;
+  parent?: string | null;
+  meaning?: string | null;
+  note?: string | null;
+  factors?: string | null;
   dict?: IDictInfo;
   updated_at?: string;
   created_at?: string;

+ 9 - 12
dashboard/src/components/template/SentEdit/SentCell.tsx

@@ -41,8 +41,6 @@ const SentCellWidget = ({
   const acceptPr = useAppSelector(sentence);
   const [prOpen, setPrOpen] = useState(false);
 
-  console.log("load", initValue, value);
-
   useEffect(() => {
     if (value) {
       setSentData(value);
@@ -209,16 +207,15 @@ const SentCellWidget = ({
                 wordWidget={wordWidget}
               />
             )}
-            {sentData.id ? (
-              <SuggestionToolbar
-                style={{ marginLeft: "2em" }}
-                compact={compact}
-                data={sentData}
-                isPr={isPr}
-                prOpen={prOpen}
-                onPrClose={() => setPrOpen(false)}
-              />
-            ) : undefined}
+
+            <SuggestionToolbar
+              style={{ marginLeft: "2em" }}
+              compact={compact}
+              data={sentData}
+              isPr={isPr}
+              prOpen={prOpen}
+              onPrClose={() => setPrOpen(false)}
+            />
           </div>
         ) : undefined}
       </SentEditMenu>

+ 7 - 1
dashboard/src/components/template/SentEdit/SuggestionBox.tsx

@@ -114,7 +114,13 @@ const SuggestionBoxWidget = ({
 
   return (
     <>
-      <Space onClick={showDrawer}>
+      <Space
+        onClick={showDrawer}
+        style={{
+          cursor: "pointer",
+          color: prNumber && prNumber > 0 ? "#1890ff" : "unset",
+        }}
+      >
         {trigger}
         {prNumber}
       </Space>

+ 63 - 51
dashboard/src/components/template/SentEdit/SuggestionToolbar.tsx

@@ -30,59 +30,71 @@ const SuggestionToolbarWidget = ({
   const [CommentCount, setCommentCount] = useState<number | undefined>(
     data.suggestionCount?.discussion
   );
-  const prButton = (
-    <Space>
-      <LikeOutlined />
-      <Divider type="vertical" />
-      <PrAcceptButton
-        data={data}
-        onAccept={(value: ISentence) => {
-          if (typeof onAccept !== "undefined") {
-            onAccept(value);
-          }
-        }}
-      />
-    </Space>
-  );
-  const normalButton = (
-    <Space size={"small"}>
-      <SuggestionBox
-        open={prOpen}
-        onClose={() => {
-          if (typeof onPrClose !== "undefined") {
-            onPrClose();
-          }
-        }}
-        data={data}
-        trigger={
-          <Tooltip title="修改建议">
-            <HandOutlinedIcon style={{ cursor: "pointer" }} />
-          </Tooltip>
-        }
-      />
-      {compact ? undefined : <Divider type="vertical" />}
-      <CommentBox
-        resId={data.id}
-        resType="sentence"
-        trigger={
-          <Tooltip title="讨论">
-            <CommentOutlined style={{ cursor: "pointer" }} />
-          </Tooltip>
-        }
-        onCommentCountChange={(count: number) => {
-          setCommentCount(count);
-        }}
-      />
-      {CommentCount}
-      {compact ? undefined : <Divider type="vertical" />}
-      {compact ? undefined : (
-        <Text copyable={{ text: data.content ? data.content : "" }}></Text>
-      )}
-    </Space>
-  );
+
   return (
     <Paragraph type="secondary" style={style}>
-      {isPr ? prButton : normalButton}
+      {isPr ? (
+        <Space>
+          <LikeOutlined />
+          <Divider type="vertical" />
+          <PrAcceptButton
+            data={data}
+            onAccept={(value: ISentence) => {
+              if (typeof onAccept !== "undefined") {
+                onAccept(value);
+              }
+            }}
+          />
+        </Space>
+      ) : (
+        <Space size={"small"}>
+          <SuggestionBox
+            open={prOpen}
+            onClose={() => {
+              if (typeof onPrClose !== "undefined") {
+                onPrClose();
+              }
+            }}
+            data={data}
+            trigger={
+              <Tooltip title="修改建议">
+                <HandOutlinedIcon />
+              </Tooltip>
+            }
+          />
+          {compact ? undefined : <Divider type="vertical" />}
+          <CommentBox
+            resId={data.id}
+            resType="sentence"
+            trigger={
+              <Tooltip title="讨论">
+                <Space
+                  size={"small"}
+                  style={{
+                    cursor: "pointer",
+                    color:
+                      data.suggestionCount?.discussion &&
+                      data.suggestionCount?.discussion > 0
+                        ? "#1890ff"
+                        : "unset",
+                  }}
+                >
+                  <CommentOutlined />
+                  {CommentCount}
+                </Space>
+              </Tooltip>
+            }
+            onCommentCountChange={(count: number) => {
+              setCommentCount(count);
+            }}
+          />
+
+          {compact ? undefined : <Divider type="vertical" />}
+          {compact ? undefined : (
+            <Text copyable={{ text: data.content ? data.content : "" }}></Text>
+          )}
+        </Space>
+      )}
     </Paragraph>
   );
 };

+ 1 - 1
dashboard/src/components/template/Wbw/CaseFormula.tsx

@@ -44,7 +44,7 @@ const CaseFormulaWidget = ({ data, onChange, onCaseChange }: IWidget) => {
       );
     }
     let strFormula: string;
-    if (result.length > 0) {
+    if (result.length > 0 && result[0].mean) {
       strFormula = result[0].mean;
     } else {
       strFormula = "{无}";

+ 3 - 1
dashboard/src/components/template/Wbw/WbwDetailBasic.tsx

@@ -42,7 +42,9 @@ export const getParentInDict = (
     let myMap = new Map<string, number>();
     let parent: string[] = [];
     for (const iterator of result) {
-      myMap.set(iterator.parent, 1);
+      if (iterator.parent) {
+        myMap.set(iterator.parent, 1);
+      }
     }
     myMap.forEach((value, key, map) => {
       parent.push(key);

+ 3 - 1
dashboard/src/components/template/Wbw/WbwDetailParent2.tsx

@@ -33,7 +33,9 @@ const WbwParent2Widget = ({ data, onChange }: IWidget) => {
       let myMap = new Map<string, number>();
       let parent: string[] = [];
       for (const iterator of result) {
-        myMap.set(iterator.parent, 1);
+        if (iterator.parent) {
+          myMap.set(iterator.parent, 1);
+        }
       }
       myMap.forEach((value, key, map) => {
         parent.push(key);

+ 3 - 1
dashboard/src/components/template/Wbw/WbwFactorMeaning.tsx

@@ -48,7 +48,9 @@ const WbwFactorMeaningWidget = ({
       let myMap = new Map<string, number>();
       let factors: string[] = [];
       for (const iterator of result) {
-        myMap.set(iterator.factormean, 1);
+        if (iterator.factormean) {
+          myMap.set(iterator.factormean, 1);
+        }
       }
       myMap.forEach((value, key, map) => {
         factors.push(key);

+ 6 - 2
dashboard/src/components/template/Wbw/WbwFactors.tsx

@@ -23,7 +23,9 @@ export const getFactorsInDict = (
     let myMap = new Map<string, number>();
     let factors: string[] = [];
     for (const iterator of result) {
-      myMap.set(iterator.factors, 1);
+      if (iterator.factors) {
+        myMap.set(iterator.factors, 1);
+      }
     }
     myMap.forEach((value, key, map) => {
       factors.push(key);
@@ -69,7 +71,9 @@ const WbwFactorsWidget = ({ data, display, onChange }: IWidget) => {
       let myMap = new Map<string, number>();
       let factors: string[] = [];
       for (const iterator of result) {
-        myMap.set(iterator.factors, 1);
+        if (iterator.factors) {
+          myMap.set(iterator.factors, 1);
+        }
       }
       myMap.forEach((value, key, map) => {
         factors.push(key);

+ 1 - 0
dashboard/src/components/template/Wbw/WbwMeaningSelect.tsx

@@ -75,6 +75,7 @@ const WbwMeaningSelectWidget = ({ data, onSelect }: IWidget) => {
         const indexParent = mParent.findIndex((item) => item.word === word1);
         result1.forEach((value, index, array) => {
           if (
+            value.parent &&
             value.parent !== "" &&
             !baseRemind.includes(value.parent) &&
             !baseDone.includes(value.parent)