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

Add parameter dialog doesn't work when query has selected text #4032

Merged
merged 2 commits into from
Aug 14, 2019

Conversation

rauchy
Copy link
Contributor

@rauchy rauchy commented Aug 13, 2019

Issue Summary

Adding a parameter through the Parameter settings dialog won't work when you have a selected text in the query (parameter is added without any settings):

add-param

This is definitively not critical, but I thought it was worth to report in any case.

Steps to Reproduce

  1. Open a query or create one
  2. Select part of the text
  3. Add a Parameter using Ctrl/Cmd+P
  4. Notice that the parameter will be created without any settings

Technical details:

  • Redash Version: Latest
  • Browser/OS: --
  • How did you install Redash:

@rauchy
Copy link
Contributor

rauchy commented Aug 11, 2019

Dug around this a bit. The issue originates when a selection is made and a parameter is added, and in that case the Ace editor's replace function signals two changes - one when removing the text, and one when adding the new parameter fragment. (When there is no selection made - the range passed to replace is of 0 length, so no remove is triggered).

Each of these signals is caught and subsequently causes updateParameters to be called, in which a call to parseQuery() is made. The first call to parseQuery(), caused by the signal induced by removing the text, tries to parse the incomplete query, so it resets the parameters to default settings, according to the logic in updateParameters.

For example, for this query:

SELECT * FROM users WHERE id=5

If you select the "5" and create an "id" number parameter using the dialog, Ace editor will signal 2 changes:

SELECT * FROM users WHERE id=

and

SELECT * FROM users WHERE id={{id}}

The first signal will blank the query parameters (due to parseQuery), and the second will use those blanked settings.

A simple workaround for this would be to simply insert the parameter fragment (instead of replacing the selection) when a selection is made.

@ranbena
Copy link
Contributor

ranbena commented Aug 11, 2019

Would debouncing parseQuery work?

@rauchy
Copy link
Contributor

rauchy commented Aug 13, 2019

We'd have to debounce a higher function, because parseQuery has return values, which updateParameters relies on, and so forth.

I actually tried this with the source view's updateQuery function and it didn't work, but going back I see that I actually used throttle instead of debounce (I always confuse the two) and got pissed that it didn't work :)

I'm a little concerned of edge cases so I'm going to submit this as a PR and would appreciate any thoughts on where this might fudge things up.

Copy link
Collaborator

@kravets-levko kravets-levko left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@gabrieldutra gabrieldutra left a comment

Choose a reason for hiding this comment

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

👌

@gabrieldutra gabrieldutra self-requested a review August 13, 2019 22:55
@gabrieldutra
Copy link
Member Author

I can't approve the PR 😅 (I guess it's because I initially created the issue and now the issue is a PR).

In any case, LGTM! :)

@rauchy rauchy merged commit f7c70c2 into master Aug 14, 2019
@rauchy rauchy deleted the replace-selected-text-with-parameter branch August 14, 2019 04:47
harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
…dash#4032)

* debounce updateQuery to prevent pasting parameters over selected texts failing parseQuery (see getredash#4032)

* drop defer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants