Skip to content

Commit

Permalink
fix variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace committed Mar 25, 2020
1 parent a64aaf9 commit bd3b854
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ if (sqlLabMenu) {

const Application = () => (
<Provider store={store}>
<App formData={bootstrapData.form_data} />
<App />
</Provider>
);

Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class App extends React.PureComponent {
content = (
<>
<QueryAutoRefresh />
<TabbedSqlEditors formData={this.props.formData} />
<TabbedSqlEditors />
</>
);
}
Expand Down
7 changes: 5 additions & 2 deletions superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const propTypes = {
databases: PropTypes.object.isRequired,
queries: PropTypes.object.isRequired,
queryEditors: PropTypes.array,
requestedQuery: PropTypes.object,
tabHistory: PropTypes.array.isRequired,
tables: PropTypes.array.isRequired,
offline: PropTypes.bool,
Expand All @@ -48,6 +49,7 @@ const propTypes = {
const defaultProps = {
queryEditors: [],
offline: false,
requestedQuery: null,
saveQueryWarning: null,
scheduleQueryWarning: null,
};
Expand Down Expand Up @@ -101,7 +103,7 @@ class TabbedSqlEditors extends React.PureComponent {

// merge post form data with GET search params
const query = {
...this.props.formData,
...this.props.requestedQuery,
...URI(window.location).search(true),
};

Expand Down Expand Up @@ -379,7 +381,7 @@ class TabbedSqlEditors extends React.PureComponent {
TabbedSqlEditors.propTypes = propTypes;
TabbedSqlEditors.defaultProps = defaultProps;

function mapStateToProps({ sqlLab, common }) {
function mapStateToProps({ sqlLab, common, requestedQuery }) {
return {
databases: sqlLab.databases,
queryEditors: sqlLab.queryEditors,
Expand All @@ -393,6 +395,7 @@ function mapStateToProps({ sqlLab, common }) {
maxRow: common.conf.SQL_MAX_ROW,
saveQueryWarning: common.conf.SQLLAB_SAVE_WARNING_MESSAGE,
scheduleQueryWarning: common.conf.SQLLAB_SCHEDULE_WARNING_MESSAGE,
requestedQuery,
};
}
function mapDispatchToProps(dispatch) {
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/SqlLab/reducers/getInitialState.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function getInitialState({
tab_state_ids: tabStateIds = [],
databases,
queries: queries_,
requested_query: requestedQuery,
}) {
/**
* Before YYYY-MM-DD, the state for SQL Lab was stored exclusively in the
Expand Down Expand Up @@ -180,6 +181,7 @@ export default function getInitialState({
tables,
queriesLastUpdate: Date.now(),
},
requestedQuery,
messageToasts: getToastsFromPyFlashMessages(
(common || {}).flash_messages || [],
),
Expand Down
26 changes: 16 additions & 10 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ def profile(self, username):
)

@staticmethod
def _get_sqllab_payload(user_id: int) -> Dict[str, Any]:
def _get_sqllab_tabs(user_id: int) -> Dict[str, Any]:
# send list of tab state ids
tabs_state = (
db.session.query(TabState.id, TabState.label)
Expand Down Expand Up @@ -2743,8 +2743,6 @@ def _get_sqllab_payload(user_id: int) -> Dict[str, Any]:
}

return {
"defaultDbId": config["SQLLAB_DEFAULT_DBID"],
"common": common_bootstrap_payload(),
"tab_state_ids": tabs_state,
"active_tab": active_tab.to_dict() if active_tab else None,
"databases": databases,
Expand All @@ -2755,14 +2753,22 @@ def _get_sqllab_payload(user_id: int) -> Dict[str, Any]:
@expose("/sqllab", methods=["GET", "POST"])
def sqllab(self):
"""SQL Editor"""
payload = self._get_sqllab_payload(g.user.get_id())
form_data = request.form.get('form_data')
try:
payload['form_data'] = json.loads(form_data)
except:
pass
payload = {
"defaultDbId": config["SQLLAB_DEFAULT_DBID"],
"common": common_bootstrap_payload(),
}

tabs_data = self._get_sqllab_tabs(g.user.get_id())
payload.update(tabs_data)

form_data = request.form.get("form_data")
if form_data:
try:
payload["requested_query"] = json.loads(form_data)
except json.JSONDecodeError:
pass
bootstrap_data = json.dumps(
payload, default=utils.pessimistic_json_iso_dttm_ser,
payload, default=utils.pessimistic_json_iso_dttm_ser
)

return self.render_template(
Expand Down
2 changes: 1 addition & 1 deletion tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ def test_sqllab_backend_persistence_payload(self):

# we should have only 1 query returned, since the second one is not
# associated with any tabs
payload = views.Superset._get_sqllab_payload(user_id=user_id)
payload = views.Superset._get_sqllab_tabs(user_id=user_id)
self.assertEqual(len(payload["queries"]), 1)


Expand Down

0 comments on commit bd3b854

Please sign in to comment.