korbit-ai[bot] commented on code in PR #32335:
URL: https://github.com/apache/superset/pull/32335#discussion_r1964252859


##########
superset-frontend/src/dashboard/components/gridComponents/Markdown.jsx:
##########
@@ -215,17 +216,32 @@ class Markdown extends PureComponent {
   }
 
   handleChangeFocus(nextFocus) {
+    if(this.state.isEditing){
     const nextFocused = !!nextFocus;
     const nextEditMode = nextFocused ? 'edit' : 'preview';
     this.setState(() => ({ isFocused: nextFocused }));
-    this.handleChangeEditorMode(nextEditMode);
+    this.handleChangeEditorMode(nextEditMode);}
   }
 
   handleChangeEditorMode(mode) {
-    const nextState = {
+    let nextState = {
       ...this.state,
       editorMode: mode,
+      isEditing: mode === 'edit',
     };
+
+    if(mode == 'edit') {
+      nextState = {
+        ...this.state,
+        editorMode: 'edit',
+        isEditing: true,
+      };
+      console.log('here');
+    }

Review Comment:
   ### Redundant Edit Mode State Logic <sub>![category 
Design](https://img.shields.io/badge/Design-0d9488)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   Redundant state setting logic in handleChangeEditorMode with duplicate code 
paths for edit mode.
   
   ###### Why this matters
   The duplicate state setting can lead to inconsistent behavior and makes the 
code harder to maintain.
   
   ###### Suggested change ∙ *Feature Preview*
   Simplify the state setting logic:
   ```javascript
   handleChangeEditorMode(mode) {
       const nextState = {
           ...this.state,
           editorMode: mode,
           isEditing: mode === 'edit',
           hasError: mode === 'preview' ? false : this.state.hasError
       };
       
       if (mode === 'preview') {
           this.updateMarkdownContent();
       }
   
       this.setState(nextState);
   }
   ```
   
   
   </details>
   
   <sub>
   
   [![Report a problem with this 
comment](https://img.shields.io/badge/Report%20a%20problem%20with%20this%20comment-gray.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmNWVjMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS10cmlhbmdsZS1hbGVydCI+PHBhdGggZD0ibTIxLjczIDE4LTgtMTRhMiAyIDAgMCAwLTMuNDggMGwtOCAxNEEyIDIgMCAwIDAgNCAyMWgxNmEyIDIgMCAwIDAgMS43My0zIi8+PHBhdGggZD0iTTEyIDl2NCIvPjxwYXRoIGQ9Ik0xMiAxN2guMDEiLz48L3N2Zz4=)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/3ca1c3b6-6d74-4f6d-bef2-2d8e20f23f1d?suggestedFixEnabled=true)
   
   💬 Chat with Korbit by mentioning @korbit-ai.
   </sub>
   
   <!--- korbi internal id:aba6e73f-729d-409c-8227-6305c7f8865f -->
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to