mirror of
https://github.com/apache/superset.git
synced 2026-04-22 09:35:23 +00:00
Enable "Run Query in New Tab" in SQL Lab (#1343)
* Enable "Clone to New Tab" btn in QueryHistoryTable 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 * 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
This commit is contained in:
committed by
Maxime Beauchemin
parent
8f299448ea
commit
2edce5bf8a
@@ -34,6 +34,20 @@ export const sqlLabReducer = function (state, action) {
|
||||
const newState = Object.assign({}, state, { tabHistory });
|
||||
return addToArr(newState, 'queryEditors', action.queryEditor);
|
||||
},
|
||||
[actions.CLONE_QUERY_TO_NEW_TAB]() {
|
||||
const progenitor = state.queryEditors.find((qe) =>
|
||||
qe.id === state.tabHistory[state.tabHistory.length - 1]);
|
||||
const qe = {
|
||||
id: shortid.generate(),
|
||||
title: `Copy of ${progenitor.title}`,
|
||||
dbId: (action.query.dbId) ? action.query.dbId : null,
|
||||
schema: (action.query.schema) ? action.query.schema : null,
|
||||
autorun: true,
|
||||
sql: action.query.sql,
|
||||
};
|
||||
|
||||
return sqlLabReducer(state, actions.addQueryEditor(qe));
|
||||
},
|
||||
[actions.REMOVE_QUERY_EDITOR]() {
|
||||
let newState = removeFromArr(state, 'queryEditors', action.queryEditor);
|
||||
// List of remaining queryEditor ids
|
||||
|
||||
Reference in New Issue
Block a user