You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "puridach-w (via GitHub)" <gi...@apache.org> on 2024/01/23 06:36:38 UTC

[PR] feat: Stop editor scrolling to top [superset]

puridach-w opened a new pull request, #26754:
URL: https://github.com/apache/superset/pull/26754

   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   This contribution introduces a vital usability upgrade to the SQL Editor within Apache Superset. The enhancement consists of a coding modification that embeds the cursor position into the Redux state.
   
   Traditionally, every time users switch between SQL Lab tabs, the SQL editor viewport resets, forcing them to scroll from the top to locate their last worked-on position. This scenario presents an inconvenience that disrupts workflow and decreases editing efficiency.
   
   This update directly addresses the issue. Upon rendering the SQL editor, it now auto-focuses on the saved cursor position from the Redux state, aligning the screen with the user's last point of work. Users can now effortlessly switch tabs, and upon their return, find the SQL Editor positioned exactly where they left off.
   
   ### BEFORE SCREENSHOTS OR ANIMATED GIF
   https://github.com/apache/superset/assets/76474644/6dfaac9e-4d96-4a8c-b641-c962bf903f58
   
   ### AFTER SCREENSHOTS OR ANIMATED GIF
   https://github.com/apache/superset/assets/76474644/f4430d28-9b98-4806-b85f-bab7cc70d6ab
   
   ### TESTING INSTRUCTIONS
   - Navigate to the SQLLab page
   - Write some query statement
   - Switch to other SQL editor tab
   - Switch back to the original SQL editor tab
   - Verify that cursor focus on exact location where it was placed before you switched tabs
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "justinpark (via GitHub)" <gi...@apache.org>.
justinpark commented on code in PR #26754:
URL: https://github.com/apache/superset/pull/26754#discussion_r1463746516


##########
superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx:
##########
@@ -143,6 +151,16 @@ const AceEditorWrapper = ({
 
       currentSelectionCache.current = selectedText;
     });
+    editor.selection.on('changeCursor', () => {
+      const cursor = editor.getCursorPosition();
+      onCursorPositionChange(cursor);
+    });
+
+    const { row, column } = cursorPosition;
+    editor.moveCursorToPosition({ row, column });
+    editor.focus();
+    editor.renderer.updateFontSize();

Review Comment:
   This operation(updateFontSize) seems redundant.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "justinpark (via GitHub)" <gi...@apache.org>.
justinpark commented on code in PR #26754:
URL: https://github.com/apache/superset/pull/26754#discussion_r1465381657


##########
superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:
##########
@@ -759,6 +760,10 @@ const SqlEditor: React.FC<Props> = ({
     );
   };
 
+  const handleCursorPositionChange = (newPosition: any) => {

Review Comment:
   Since you already added[ type for the cursor position,](https://github.com/apache/superset/pull/26754/files#diff-98bfde8ed111b1aa1a94f5da25ed87585b19908a628063fd133958e9576c239aR38) please use `CursorPosition` instead of any type
   
   ```suggestion
     const handleCursorPositionChange = (newPosition: CursorPosition) => {
   ```
   
   



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "justinpark (via GitHub)" <gi...@apache.org>.
justinpark commented on code in PR #26754:
URL: https://github.com/apache/superset/pull/26754#discussion_r1465384806


##########
superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx:
##########
@@ -35,11 +35,17 @@ type HotKey = {
   func: (aceEditor: IAceEditor) => void;
 };
 
+type CursorPosition = {
+  row: number;
+  column: number;
+};
+

Review Comment:
   Let's reuse the CursorPosition type you already defined in SqlLab/types.
   
   ```suggestion
   import type { CursorPosition } from 'src/SqlLab/types';
   ```



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #26754:
URL: https://github.com/apache/superset/pull/26754


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "puridach-w (via GitHub)" <gi...@apache.org>.
puridach-w commented on code in PR #26754:
URL: https://github.com/apache/superset/pull/26754#discussion_r1464245657


##########
superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx:
##########
@@ -143,6 +151,16 @@ const AceEditorWrapper = ({
 
       currentSelectionCache.current = selectedText;
     });
+    editor.selection.on('changeCursor', () => {
+      const cursor = editor.getCursorPosition();
+      onCursorPositionChange(cursor);
+    });
+
+    const { row, column } = cursorPosition;
+    editor.moveCursorToPosition({ row, column });
+    editor.focus();
+    editor.renderer.updateFontSize();

Review Comment:
   You're right. I already modify the code to remove that line of code.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #26754:
URL: https://github.com/apache/superset/pull/26754#issuecomment-1908683247

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/26754?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: `1 lines` in your changes are missing coverage. Please review.
   > Comparison is base [(`04445a3`)](https://app.codecov.io/gh/apache/superset/commit/04445a34872267a55ec0ef526cdc061ee0ad3dd4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 69.48% compared to head [(`6056bbd`)](https://app.codecov.io/gh/apache/superset/pull/26754?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 69.49%.
   > Report is 25 commits behind head on master.
   
   | [Files](https://app.codecov.io/gh/apache/superset/pull/26754?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset-frontend/src/SqlLab/reducers/sqlLab.js](https://app.codecov.io/gh/apache/superset/pull/26754?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL1NxbExhYi9yZWR1Y2Vycy9zcWxMYWIuanM=) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/26754?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@           Coverage Diff           @@
   ##           master   #26754   +/-   ##
   =======================================
     Coverage   69.48%   69.49%           
   =======================================
     Files        1894     1894           
     Lines       74151    74165   +14     
     Branches     8243     8245    +2     
   =======================================
   + Hits        51527    51540   +13     
   - Misses      20555    20556    +1     
     Partials     2069     2069           
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/26754/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [javascript](https://app.codecov.io/gh/apache/superset/pull/26754/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.88% <92.85%> (+0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/26754?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] feat: Stop editor scrolling to top [superset]

Posted by "justinpark (via GitHub)" <gi...@apache.org>.
justinpark commented on code in PR #26754:
URL: https://github.com/apache/superset/pull/26754#discussion_r1465378130


##########
superset-frontend/src/hooks/apiResources/sqlLab.ts:
##########
@@ -51,6 +56,7 @@ export type InitialState = {
     hide_left_bar?: boolean;
     saved_query: { id: number } | null;
     extra_json?: Record<string, any>;
+    cursor_position?: CursorPosition;

Review Comment:
   Since `cursor_position` will not be persisted, this should be excluded here.
   
   ```suggestion
   ```



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org