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></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>
[](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]