Skip to content

Commit

Permalink
Moved ajax call for fetching table metadata from SqlEditorLeftBar to …
Browse files Browse the repository at this point in the history
…actions (#1494)
  • Loading branch information
vera-liu authored Nov 1, 2016
1 parent 2fd2526 commit 5238053
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
36 changes: 36 additions & 0 deletions caravel/assets/javascripts/SqlLab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,42 @@ export function mergeTable(table) {
return { type: MERGE_TABLE, table };
}

export function addTable(query, tableName) {
return function (dispatch) {
let url = `/caravel/table/${query.dbId}/${tableName}/${query.schema}/`;
$.get(url, (data) => {
dispatch(
mergeTable(Object.assign(data, {
dbId: query.dbId,
queryEditorId: query.id,
schema: query.schema,
expanded: true,
}))
);
})
.fail(() => {
dispatch(
addAlert({
msg: 'Error occurred while fetching metadata',
bsStyle: 'danger',
})
);
});

url = `/caravel/extra_table_metadata/${query.dbId}/${tableName}/${query.schema}/`;
$.get(url, (data) => {
const table = {
dbId: query.dbId,
queryEditorId: query.id,
schema: query.schema,
name: tableName,
};
Object.assign(table, data);
dispatch(mergeTable(table));
});
};
}

export function expandTable(table) {
return { type: EXPAND_TABLE, table };
}
Expand Down
31 changes: 2 additions & 29 deletions caravel/assets/javascripts/SqlLab/components/SqlEditorLeftBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,10 @@ class SqlEditorLeftBar extends React.PureComponent {
changeTable(tableOpt) {
const tableName = tableOpt.value;
const qe = this.props.queryEditor;
let url = `/caravel/table/${qe.dbId}/${tableName}/${qe.schema}/`;

this.setState({ tableLoading: true });
$.get(url, (data) => {
this.props.actions.mergeTable(Object.assign(data, {
dbId: qe.dbId,
queryEditorId: qe.id,
schema: qe.schema,
expanded: true,
}));
this.setState({ tableLoading: false });
})
.fail(() => {
this.props.actions.addAlert({
msg: 'Error occurred while fetching metadata',
bsStyle: 'danger',
});
this.setState({ tableLoading: false });
});

url = `/caravel/extra_table_metadata/${qe.dbId}/${tableName}/${qe.schema}/`;
$.get(url, (data) => {
const table = {
dbId: this.props.queryEditor.dbId,
queryEditorId: this.props.queryEditor.id,
schema: qe.schema,
name: tableName,
};
Object.assign(table, data);
this.props.actions.mergeTable(table);
});
this.props.actions.addTable(qe, tableName);
this.setState({ tableLoading: false });
}
render() {
let networkAlert = null;
Expand Down

0 comments on commit 5238053

Please sign in to comment.