ソースを参照

IWbw 中的参数value有可能为null

visuddhinanda 2 年 前
コミット
839b3adeae

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

@@ -17,7 +17,7 @@ const RelaGraphicWidget = ({ wbwData }: IWidget) => {
     const relationWords = data
       ?.filter((value) => value.relation)
       .map((item) => {
-        if (item.relation) {
+        if (item.relation && item.relation.value) {
           const json: IRelation[] = JSON.parse(item.relation.value);
           const graphic = json.map((relation) => {
             const localName = terms?.find(

+ 5 - 5
dashboard/src/components/template/Wbw/WbwDetailBasic.tsx

@@ -73,11 +73,11 @@ const WbwDetailBasicWidget = ({
     data.factors?.value?.split("+")
   );
   const [openCreate, setOpenCreate] = useState(false);
-  const [_meaning, setMeaning] = useState<string | undefined>(
-    data.meaning?.value
-  );
+  const [_meaning, setMeaning] = useState<string | undefined>();
   useEffect(() => {
-    setMeaning(data.meaning?.value);
+    if (typeof data.meaning?.value === "string") {
+      setMeaning(data.meaning?.value);
+    }
   }, [data.meaning]);
   const onMeaningChange = (value: string) => {
     console.log(`Selected: ${value}`);
@@ -101,7 +101,7 @@ const WbwDetailBasicWidget = ({
     setParentOptions(parentOptions);
   }, [inlineDict, data]);
 
-  const relationCount = data.relation
+  const relationCount = data.relation?.value
     ? JSON.parse(data.relation.value).length
     : 0;
 

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

@@ -60,7 +60,9 @@ const WbwDetailBookMarkWidget = ({ data, onChange }: IWidget) => {
         value={value}
       />
       <TextArea
-        defaultValue={data.bookMarkText?.value}
+        defaultValue={
+          data.bookMarkText?.value ? data.bookMarkText?.value : undefined
+        }
         showCount
         maxLength={512}
         autoSize={{ minRows: 6, maxRows: 8 }}

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

@@ -20,7 +20,7 @@ const WbwDetailNoteWidget = ({ data, onChange }: IWidget) => {
   return (
     <>
       <TextArea
-        defaultValue={data.note?.value}
+        defaultValue={data.note?.value ? data.note?.value : undefined}
         showCount
         maxLength={512}
         autoSize={{ minRows: 8, maxRows: 10 }}

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

@@ -45,7 +45,7 @@ const WbwParent2Widget = ({ data, onChange }: IWidget) => {
   };
 
   useEffect(() => {
-    if (typeof data.parent === "undefined") {
+    if (typeof data.parent?.value !== "string") {
       return;
     }
     const parent = getParentInDict(

+ 4 - 2
dashboard/src/components/template/Wbw/WbwDetailRelation.tsx

@@ -55,12 +55,14 @@ const WbwDetailRelationWidget = ({ data, onChange, onAdd }: IWidget) => {
     if (typeof data.relation === "undefined") {
       return;
     }
-    const arrRelation: IRelation[] = JSON.parse(data.relation?.value);
+    const arrRelation: IRelation[] = JSON.parse(
+      data.relation?.value ? data.relation?.value : "[]"
+    );
     setRelation(arrRelation);
   }, [data.relation]);
 
   useEffect(() => {
-    const caseEnd = data.case?.value.split("$");
+    const caseEnd = data.case?.value?.split("$");
     if (typeof caseEnd === "undefined") {
       return;
     }

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

@@ -102,7 +102,7 @@ const WbwPaliWidget = ({ data, display, onSave }: IWidget) => {
   ) : (
     <></>
   );
-  const color = data.bookMarkColor
+  const color = data.bookMarkColor?.value
     ? bookMarkColor[data.bookMarkColor.value]
     : "white";
 

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

@@ -14,7 +14,7 @@ const WbwParent2Widget = ({ data }: IWidget) => {
           {intl.formatMessage({
             id:
               "dict.fields.type." +
-              data.grammar2.value.replaceAll(".", "") +
+              data.grammar2.value?.replaceAll(".", "") +
               ".short.label",
           })}
         </Tag>

+ 15 - 15
dashboard/src/components/template/Wbw/WbwWord.tsx

@@ -60,20 +60,20 @@ export interface IWbw {
   sn: number[];
   word: WbwElement<string>;
   real: WbwElement<string>;
-  meaning?: WbwElement<string>;
-  type?: WbwElement<string>;
-  grammar?: WbwElement<string>;
-  style?: WbwElement<string>;
-  case?: WbwElement<string>;
-  parent?: WbwElement<string>;
-  parent2?: WbwElement<string>;
-  grammar2?: WbwElement<string>;
-  factors?: WbwElement<string>;
-  factorMeaning?: WbwElement<string>;
-  relation?: WbwElement<string>;
-  note?: WbwElement<string>;
-  bookMarkColor?: WbwElement<number>;
-  bookMarkText?: WbwElement<string>;
+  meaning?: WbwElement<string | null>;
+  type?: WbwElement<string | null>;
+  grammar?: WbwElement<string | null>;
+  style?: WbwElement<string | null>;
+  case?: WbwElement<string | null>;
+  parent?: WbwElement<string | null>;
+  parent2?: WbwElement<string | null>;
+  grammar2?: WbwElement<string | null>;
+  factors?: WbwElement<string | null>;
+  factorMeaning?: WbwElement<string | null>;
+  relation?: WbwElement<string | null>;
+  note?: WbwElement<string | null>;
+  bookMarkColor?: WbwElement<number | null>;
+  bookMarkText?: WbwElement<string | null>;
   locked?: boolean;
   confidence: number;
   attachments?: UploadFile[];
@@ -114,7 +114,7 @@ const WbwWordWidget = ({
     setWordData(data);
   }, [data]);
 
-  const color = wordData.bookMarkColor
+  const color = wordData.bookMarkColor?.value
     ? bookMarkColor[wordData.bookMarkColor.value]
     : "unset";
   const wbwCtl = wordData.type?.value === ".ctl." ? "wbw_ctl" : "";

+ 34 - 31
dashboard/src/components/template/WbwSent.tsx

@@ -25,19 +25,19 @@ interface IWbwXml {
   id: string;
   pali: WbwElement<string>;
   real?: WbwElement<string>;
-  type?: WbwElement<string>;
-  gramma?: WbwElement<string>;
-  mean?: WbwElement<string>;
-  org?: WbwElement<string>;
-  om?: WbwElement<string>;
-  case?: WbwElement<string>;
-  parent?: WbwElement<string>;
-  pg?: WbwElement<string>;
-  parent2?: WbwElement<string>;
-  rela?: WbwElement<string>;
+  type?: WbwElement<string | null>;
+  gramma?: WbwElement<string | null>;
+  mean?: WbwElement<string | null>;
+  org?: WbwElement<string | null>;
+  om?: WbwElement<string | null>;
+  case?: WbwElement<string | null>;
+  parent?: WbwElement<string | null>;
+  pg?: WbwElement<string | null>;
+  parent2?: WbwElement<string | null>;
+  rela?: WbwElement<string | null>;
   lock?: boolean;
-  bmt?: WbwElement<string>;
-  bmc?: WbwElement<number>;
+  bmt?: WbwElement<string | null>;
+  bmc?: WbwElement<number | null>;
   cf: number;
 }
 interface IWbwUpdateResponse {
@@ -210,25 +210,28 @@ export const WbwSentCtl = ({
             }}
             onSplit={(isSplit: boolean) => {
               if (isSplit) {
-                //拆分
-                const newData: IWbw[] = JSON.parse(JSON.stringify(wordData));
-                const children: IWbw[] | undefined = wordData[id].factors?.value
-                  .split("+")
-                  .map((item, index) => {
-                    return {
-                      word: { value: item, status: 5 },
-                      real: { value: item, status: 5 },
-                      book: wordData[id].book,
-                      para: wordData[id].para,
-                      sn: [...wordData[id].sn, index],
-                      confidence: 1,
-                    };
-                  });
-                if (typeof children !== "undefined") {
-                  console.log("children", children);
-                  newData.splice(id + 1, 0, ...children);
-                  console.log("new-data", newData);
-                  setWordData(newData);
+                //拆开
+                const factors = wordData[id]?.factors?.value;
+                if (typeof factors === "string") {
+                  const newData: IWbw[] = JSON.parse(JSON.stringify(wordData));
+                  const children: IWbw[] | undefined = factors
+                    .split("+")
+                    .map((item, index) => {
+                      return {
+                        word: { value: item, status: 5 },
+                        real: { value: item, status: 5 },
+                        book: wordData[id].book,
+                        para: wordData[id].para,
+                        sn: [...wordData[id].sn, index],
+                        confidence: 1,
+                      };
+                    });
+                  if (typeof children !== "undefined") {
+                    console.log("children", children);
+                    newData.splice(id + 1, 0, ...children);
+                    console.log("new-data", newData);
+                    setWordData(newData);
+                  }
                 }
               } else {
                 //合并