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

Enable "Run Query in New Tab" in SQL Lab #1343

Merged
merged 6 commits into from
Oct 18, 2016
Merged

Enable "Run Query in New Tab" in SQL Lab #1343

merged 6 commits into from
Oct 18, 2016

Conversation

nickbarnwell
Copy link

Fixes #1147 – saw this was on the roadmap but it's important for the workflow I personally use so worst case I'll abandon this patch if there's already a fix in mainline.

Commit 7d33c8f shows the first approach I took, before reading a bit more about Redux; I can rebase it away and add tests if the approach in f3326a3 looks good.

n.b. This was my first time working with React/Redux, apologies in advance if this isn't idiomatic; I tried my best to base it on the rest of the codebase.

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

One minor nit, but otherwise LGTM. I'm glad to see that people out there are already using SQL Lab. Thank you for the PR.

dbId: (action.query.dbId) ? action.query.dbId : null,
schema: (action.query.schema) ? action.query.schema : null,
autorun: true,
sql: `${action.query.sql}`,
Copy link
Member

Choose a reason for hiding this comment

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

same as sql: action.query.sql,

@nickbarnwell
Copy link
Author

Thanks for the quick feedback! Definitely should've caught that nit, cargo-culted a little too hard there.

Will add tests tonight; since I was already in there I added a few for other reducer actions around QueryEditors - would you prefer those be separated out into another PR?

Nick Barnwell added 5 commits October 14, 2016 17:29
Method #1; doesn't feel very clean.

Going to attempt to reimplement using an action and changing state directly
through the reducer rather than creating a new QueryEditor object directly from
the QueryTable
Bug => Attempting to clone anything other than the most recent Query for a given
TabbedQueryEditor would throw an exception, because we depended on lastQueryId
to find the title of the QueryEditor to clone. Since you can only activate a
clone from the currently active tab, we can instead fetch the ID of the Editor
to copy the Title of from the tip of tabHistory.
Copy link
Author

@nickbarnwell nickbarnwell left a comment

Choose a reason for hiding this comment

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

There are a few places where I wasn't sure how you prefer things to be tested and/or implemented. Called them out to save you some work when reviewing.

sql: action.query.sql,
};

return sqlLabReducer(state, actions.addQueryEditor(qe));
Copy link
Author

Choose a reason for hiding this comment

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

Wasn't super DRY essentially copying addQueryEditor into this action. This seems better, but not terribly clean either…suggestions for improvement welcome!

import { describe, it } from 'mocha';
import { expect } from 'chai';

describe('sqlLabReducer', () => {
Copy link
Author

Choose a reason for hiding this comment

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

Couldn't find anything to model these tests off of, let me know how you'd prefer them to be structured.

});

it('should prefix the new tab title with "Copy of"', () => {
expect(newState.queryEditors[1].title).to.include("Copy of");
Copy link
Author

Choose a reason for hiding this comment

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

Assuming that our new queryEditor will always be the last element is all well and good, but seems terribly hacky to me. Any suggestions or are you fine with it?


it('should have at most one more tab', () => {
expect(newState.queryEditors).have.length(2);
//expect(newState.queryEditors.filter((qe) => qe.sql == testQuery.SQL).length).to.equal(2)
Copy link
Author

Choose a reason for hiding this comment

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

Woops. Will remove this when I clean up any other nits from code review.

@mistercrunch
Copy link
Member

Thanks for the PR, this looks good to me as is, I'll do a blitz soon to get some test coverage on SQL Lab, but for now this is good!

@mistercrunch mistercrunch merged commit 2edce5b into apache:master Oct 18, 2016
@nickbarnwell nickbarnwell deleted the nickbarnwell/fix-1147-sqlab-run-query-in-new-tab branch October 18, 2016 23:04
neevany pushed a commit to Kieraya/caravel that referenced this pull request Oct 24, 2016
* Enable "Clone to New Tab" btn in QueryHistoryTable

Method apache#1; doesn't feel very clean.

Going to attempt to reimplement using an action and changing state directly
through the reducer rather than creating a new QueryEditor object directly from
the QueryTable

* Move Clone Logic to Action

* Implement PR feedback

* Clean up reducer action; fix bug

Bug => Attempting to clone anything other than the most recent Query for a given
TabbedQueryEditor would throw an exception, because we depended on lastQueryId
to find the title of the QueryEditor to clone. Since you can only activate a
clone from the currently active tab, we can instead fetch the ID of the Editor
to copy the Title of from the tip of tabHistory.

* Tests for Reducer Action

* Fix CodeClimate feedback
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.12.0 labels Feb 19, 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 🚢 0.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run query in new tab on SQL Lab / Query History doesn't work
2 participants