Просмотр исходного кода

134432 add null guard in CodeMirrorEditor

soumaeda 2 лет назад
Родитель
Сommit
b3436b9f90

+ 1 - 1
apps/app/src/components/PageEditor/PageEditor.tsx

@@ -189,7 +189,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   const openTableModalHandler = useCallback(() => {
     const editor = codeMirrorEditor?.view;
     const markdownTable = mtu.getMarkdownTable(editor);
-    if (openHandsontableModal == null) {
+    if (markdownTable == null) {
       return;
     }
     openHandsontableModal(markdownTable, editor);

+ 1 - 1
apps/app/src/stores/modal.tsx

@@ -516,7 +516,7 @@ type HandsontableModalStatus = {
 
 type HandsontableModalStatusUtils = {
   open(
-    table: MarkdownTable | null,
+    table: MarkdownTable,
     editor?: any,
     autoFormatMarkdownTable?: boolean,
     onSave?: HandsonTableModalSaveHandler

+ 6 - 2
packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx

@@ -26,7 +26,7 @@ type Props = {
   onChange?: (value: string) => void,
   onUpload?: (files: File[]) => void,
   indentSize?: number,
-  onClickTableBtn: () => void,
+  onClickTableBtn?: () => void,
 }
 
 export const CodeMirrorEditor = (props: Props): JSX.Element => {
@@ -141,7 +141,11 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
     }
 
     return '';
-  }, [isUploading, isDragAccept, isDragReject, acceptedFileType]);
+  }, [isUploading, acceptedFileType, isDragAccept, isDragReject]);
+
+  if (onClickTableBtn == null) {
+    return <></>;
+  }
 
   return (
     <div className={`${style['codemirror-editor']} flex-expand-vert`}>

+ 1 - 1
packages/editor/src/components/CodeMirrorEditorComment.tsx

@@ -18,7 +18,7 @@ type Props = {
   onChange?: (value: string) => void,
   onComment?: () => void,
   acceptedFileType?: AcceptedUploadFileType,
-  onClickTableBtn: () => void,
+  onClickTableBtn?: () => void,
 }
 
 export const CodeMirrorEditorComment = (props: Props): JSX.Element => {

+ 1 - 1
packages/editor/src/components/CodeMirrorEditorMain.tsx

@@ -19,7 +19,7 @@ type Props = {
   onUpload?: (files: File[]) => void,
   acceptedFileType?: AcceptedUploadFileType,
   indentSize?: number,
-  onClickTableBtn: () => void,
+  onClickTableBtn?: () => void,
 }
 
 export const CodeMirrorEditorMain = (props: Props): JSX.Element => {