Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SQL Editor): names new query tabs correctly #18951

Merged

Conversation

cccs-Dustin
Copy link
Contributor

SUMMARY

The reason why the bug (view attached issue) occurred in the first place was because there was a local variable within the TabbedSqlEditors component called "queryCount". Whenever the component was reloaded/re-rendered, it caused this local variable to reset to it's default integer value of: '1'. Since this variable is reset to 1, the naming of the new query tabs would not work as intended.

To fix this issue, I decided to use a more dynamic method of naming the new query tabs:

  • If there are no currently open query tabs, create the new one with a name of: "Untitled Query 1"
  • If there are currently open query tabs, but none of them are named "Untitled Query #" (Where # is a valid integer value), the new query tab will be named: "Untitled Query 1"
  • If there are currently open query tabs and one or more of them are named "Untitled Query #" (Where # is a valid integer value), parse the untitled query names so that you are left with a list of all of the numbers. Select the highest number, and add one to it. The new query tab will have the name: "Untitled Query #" (Where # is a valid integer value, and is +1 of the previous largest untitled query number)

By using this more dynamic method of naming new query tabs, it allows us to avoid creating and maintaining unnecessary state. It also fixes the issue where there never used to be an "Untitled Query 1".

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
(the far right tab was created by selecting the "SQL query" button from the “+“ icon drop down on the top right of the web page beside the settings drop down)

After SQL query button

After:
(The query tabs were created using a combination of the two add query buttons, this image shows that the naming now works correctly regardless of which way you decide to create a new query tab)

After SQL query button - with fix

TESTING INSTRUCTIONS

  1. Go to the SQL Editor page by selecting it from the main menu under the "SQL Lab" drop down.
  2. Click on the "+" button next to the list of query tabs, it should properly increment the query tab names.
  3. Select the “+“ icon on the top right of the web page beside the settings drop down, and then click "SQL query".
  4. With the new code modifications, this second method of creating a query tab should also properly increment the query tab names.

ADDITIONAL INFORMATION

  • Has associated issue: The SQL Lab Add Query Buttons Do Not Name New Queries Properly #18949
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

…SQL Lab tab names. All that is left is to add tests to make sure that the function works correctly
…le only if the character after the string 'Untitled Query ' is a number. This prevents any issues when trying to get the maximum value in the list.
…ntreCanada/superset into bug/Fix_SQL_Lab_Add_Query_Button
@cccs-Dustin cccs-Dustin changed the title fix(SQL Editor): names new query tabs correctly fix(SQL Editor): WIP names new query tabs correctly Feb 25, 2022
@codecov
Copy link

codecov bot commented Feb 25, 2022

Codecov Report

Merging #18951 (784edb0) into master (79633ce) will increase coverage by 0.17%.
The diff coverage is 77.35%.

❗ Current head 784edb0 differs from pull request most recent head 7c6b70f. Consider uploading reports for the commit 7c6b70f to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18951      +/-   ##
==========================================
+ Coverage   66.38%   66.56%   +0.17%     
==========================================
  Files        1641     1641              
  Lines       63515    63500      -15     
  Branches     6418     6427       +9     
==========================================
+ Hits        42165    42268     +103     
+ Misses      19690    19550     -140     
- Partials     1660     1682      +22     
Flag Coverage Δ
javascript 51.37% <74.54%> (+0.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...perset-ui-chart-controls/src/sections/sections.tsx 100.00% <ø> (ø)
...et-ui-chart-controls/src/shared-controls/index.tsx 36.36% <ø> (+0.36%) ⬆️
...perset-ui-chart-controls/src/utils/D3Formatting.ts 100.00% <ø> (ø)
...ckages/superset-ui-core/src/query/extractExtras.ts 100.00% <ø> (ø)
.../superset-ui-core/src/query/types/QueryFormData.ts 100.00% <ø> (ø)
...reset-chart-deckgl/src/utilities/Shared_DeckGL.jsx 84.21% <ø> (ø)
...acy-preset-chart-deckgl/src/utilities/controls.jsx 11.11% <ø> (-8.89%) ⬇️
superset-frontend/src/SqlLab/fixtures.ts 100.00% <ø> (ø)
superset-frontend/src/SqlLab/reducers/sqlLab.js 33.15% <ø> (ø)
...perset-frontend/src/addSlice/AddSliceContainer.tsx 61.76% <ø> (ø)
... and 60 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 79633ce...7c6b70f. Read the comment docs.

@cccs-Dustin cccs-Dustin changed the title fix(SQL Editor): WIP names new query tabs correctly fix(SQL Editor): names new query tabs correctly Feb 28, 2022
Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking a look at this logic and fixing something that's been broken for years!!!

One other request: would you mind looking into writing a test case for this change? If it's not possible then no worries, but i'm a bit nervous about making changes to this large, untyped file.

…test to make sure that the newQueryEditor function in the TabbedSqlEditors component works as intended
Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for the iteration!

@cccs-Dustin cccs-Dustin closed this Mar 3, 2022
@cccs-Dustin cccs-Dustin reopened this Mar 3, 2022
@geido
Copy link
Member

geido commented Mar 3, 2022

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

@geido Ephemeral environment spinning up at http://54.190.58.79:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@geido geido merged commit 5a5ff99 into apache:master Mar 4, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

Ephemeral environment shutdown and build artifacts deleted.

@cccs-Dustin cccs-Dustin deleted the bug/Fix_SQL_Lab_Add_Query_Button branch March 15, 2022 12:15
villebro pushed a commit that referenced this pull request Apr 3, 2022
* Added in code changes that now properly increment the Untitled Query SQL Lab tab names. All that is left is to add tests to make sure that the function works correctly

* Updated the code so that it adds to the untitled_query_numbers variable only if the character after the string 'Untitled Query ' is a number. This prevents any issues when trying to get the maximum value in the list.

* Refactored part of the mapping code, to make it shorter and easier to read/understand

* Fixed issues in the code that were causing some of the CI tests to fail

* Made code changes based on comments within the PR. Also added a unit test to make sure that the newQueryEditor function in the TabbedSqlEditors component works as intended

* Fixed the failing cypress test in tabs.test.js

(cherry picked from commit 5a5ff99)
@mistercrunch mistercrunch added 🍒 1.5.2 🍒 1.5.3 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels lts-v1 size/M 🍒 1.5.0 🍒 1.5.1 🍒 1.5.2 🍒 1.5.3 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants