mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
Put back preview icon for fetching preview data
This commit is contained in:
parent
56f5b736dd
commit
b6f5dcfe64
@ -38,7 +38,7 @@ export function resetState() {
|
|||||||
return { type: RESET_STATE };
|
return { type: RESET_STATE };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startQuery(query) {
|
export function startQuery(query, table) {
|
||||||
Object.assign(query, {
|
Object.assign(query, {
|
||||||
id: shortid.generate(),
|
id: shortid.generate(),
|
||||||
progress: 0,
|
progress: 0,
|
||||||
@ -46,7 +46,7 @@ export function startQuery(query) {
|
|||||||
state: (query.runAsync) ? 'pending' : 'running',
|
state: (query.runAsync) ? 'pending' : 'running',
|
||||||
cached: false,
|
cached: false,
|
||||||
});
|
});
|
||||||
return { type: START_QUERY, query };
|
return { type: START_QUERY, query, table };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function querySuccess(query, results) {
|
export function querySuccess(query, results) {
|
||||||
@ -91,9 +91,9 @@ export function fetchQueryResults(query) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runQuery(query) {
|
export function runQuery(query, table) {
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
dispatch(startQuery(query));
|
dispatch(startQuery(query, table));
|
||||||
const sqlJsonUrl = '/caravel/sql_json/';
|
const sqlJsonUrl = '/caravel/sql_json/';
|
||||||
const sqlJsonRequest = {
|
const sqlJsonRequest = {
|
||||||
client_id: query.id,
|
client_id: query.id,
|
||||||
@ -204,33 +204,21 @@ export function queryEditorSetSelectedText(queryEditor, sql) {
|
|||||||
return { type: QUERY_EDITOR_SET_SELECTED_TEXT, queryEditor, sql };
|
return { type: QUERY_EDITOR_SET_SELECTED_TEXT, queryEditor, sql };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mergeTable(table, query) {
|
export function mergeTable(table) {
|
||||||
return { type: MERGE_TABLE, table, query };
|
return { type: MERGE_TABLE, table };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addTable(query, tableName) {
|
export function addTable(query, tableName) {
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
let url = `/caravel/table/${query.dbId}/${tableName}/${query.schema}/`;
|
let url = `/caravel/table/${query.dbId}/${tableName}/${query.schema}/`;
|
||||||
$.get(url, (data) => {
|
$.get(url, (data) => {
|
||||||
const dataPreviewQuery = {
|
dispatch(
|
||||||
dbId: query.dbId,
|
mergeTable(Object.assign(data, {
|
||||||
sql: data.selectStar,
|
|
||||||
tableName,
|
|
||||||
sqlEditorId: null,
|
|
||||||
tab: '',
|
|
||||||
runAsync: false,
|
|
||||||
ctas: false,
|
|
||||||
};
|
|
||||||
// Run query to get preview data for table
|
|
||||||
dispatch(runQuery(dataPreviewQuery));
|
|
||||||
// Merge table to tables in state
|
|
||||||
dispatch(mergeTable(
|
|
||||||
Object.assign(data, {
|
|
||||||
dbId: query.dbId,
|
dbId: query.dbId,
|
||||||
queryEditorId: query.id,
|
queryEditorId: query.id,
|
||||||
schema: query.schema,
|
schema: query.schema,
|
||||||
expanded: true,
|
expanded: true,
|
||||||
}), dataPreviewQuery)
|
}))
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.fail(() => {
|
.fail(() => {
|
||||||
|
@ -14,6 +14,7 @@ const propTypes = {
|
|||||||
searchText: React.PropTypes.string,
|
searchText: React.PropTypes.string,
|
||||||
showSql: React.PropTypes.bool,
|
showSql: React.PropTypes.bool,
|
||||||
visualize: React.PropTypes.bool,
|
visualize: React.PropTypes.bool,
|
||||||
|
cache: React.PropTypes.bool,
|
||||||
};
|
};
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
search: true,
|
search: true,
|
||||||
@ -22,6 +23,7 @@ const defaultProps = {
|
|||||||
csv: true,
|
csv: true,
|
||||||
searchText: '',
|
searchText: '',
|
||||||
actions: {},
|
actions: {},
|
||||||
|
cache: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +38,8 @@ class ResultSet extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
// when new results comes in, save them locally and clear in store
|
// when new results comes in, save them locally and clear in store
|
||||||
if ((!nextProps.query.cached)
|
if (this.props.cache && (!nextProps.query.cached)
|
||||||
&& nextProps.query.results
|
&& nextProps.query.results && nextProps.query.results.data.length > 0) {
|
||||||
&& nextProps.query.results.data.length > 0) {
|
|
||||||
this.setState(
|
this.setState(
|
||||||
{ results: nextProps.query.results },
|
{ results: nextProps.query.results },
|
||||||
this.clearQueryResults(nextProps.query)
|
this.clearQueryResults(nextProps.query)
|
||||||
@ -122,9 +123,9 @@ class ResultSet extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
const query = this.props.query;
|
const query = this.props.query;
|
||||||
const results = (this.props.query.cached) ? this.state.results : query.results;
|
const results =
|
||||||
|
(this.props.cache && this.props.query.cached) ? this.state.results : query.results;
|
||||||
let sql;
|
let sql;
|
||||||
|
|
||||||
if (this.props.showSql) {
|
if (this.props.showSql) {
|
||||||
sql = <HighlightedSql sql={query.sql} />;
|
sql = <HighlightedSql sql={query.sql} />;
|
||||||
}
|
}
|
||||||
@ -197,7 +198,9 @@ class ResultSet extends React.PureComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (<Alert bsStyle="warning">The query returned no data</Alert>);
|
const alertMessage = query.cached ?
|
||||||
|
'click on preview in left bar to fetch table data' : 'The query returned no data';
|
||||||
|
return (<Alert bsStyle="warning">{alertMessage}</Alert>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResultSet.propTypes = propTypes;
|
ResultSet.propTypes = propTypes;
|
||||||
|
@ -54,7 +54,13 @@ class SouthPane extends React.PureComponent {
|
|||||||
eventKey={query.id}
|
eventKey={query.id}
|
||||||
key={query.id}
|
key={query.id}
|
||||||
>
|
>
|
||||||
<ResultSet query={query} visualize={false} csv={false} actions={props.actions} />
|
<ResultSet
|
||||||
|
query={query}
|
||||||
|
visualize={false}
|
||||||
|
csv={false}
|
||||||
|
actions={props.actions}
|
||||||
|
cache
|
||||||
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -53,6 +53,18 @@ class TableElement extends React.PureComponent {
|
|||||||
this.setState({ expanded: false });
|
this.setState({ expanded: false });
|
||||||
this.props.actions.removeDataPreview(this.props.table);
|
this.props.actions.removeDataPreview(this.props.table);
|
||||||
}
|
}
|
||||||
|
previewData() {
|
||||||
|
const query = {
|
||||||
|
dbId: this.props.table.dbId,
|
||||||
|
sql: this.props.table.selectStar,
|
||||||
|
tableName: this.props.table.name,
|
||||||
|
sqlEditorId: null,
|
||||||
|
tab: '',
|
||||||
|
runAsync: false,
|
||||||
|
ctas: false,
|
||||||
|
};
|
||||||
|
this.props.actions.runQuery(query, this.props.table);
|
||||||
|
}
|
||||||
toggleSortColumns() {
|
toggleSortColumns() {
|
||||||
this.setState({ sortColumns: !this.state.sortColumns });
|
this.setState({ sortColumns: !this.state.sortColumns });
|
||||||
}
|
}
|
||||||
@ -181,6 +193,12 @@ class TableElement extends React.PureComponent {
|
|||||||
'Original table column order'}
|
'Original table column order'}
|
||||||
href="#"
|
href="#"
|
||||||
/>
|
/>
|
||||||
|
<Link
|
||||||
|
className="fa fa-search-plus pull-left m-l-2"
|
||||||
|
onClick={this.previewData.bind(this)}
|
||||||
|
tooltip="Data preview"
|
||||||
|
href="#"
|
||||||
|
/>
|
||||||
{table.selectStar &&
|
{table.selectStar &&
|
||||||
<CopyToClipboard
|
<CopyToClipboard
|
||||||
copyNode={
|
copyNode={
|
||||||
|
@ -85,19 +85,11 @@ export const sqlLabReducer = function (state, action) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (existingTable) {
|
if (existingTable) {
|
||||||
if (action.query) {
|
|
||||||
at.dataPreviewQueryId = action.query.id;
|
|
||||||
}
|
|
||||||
return alterInArr(state, 'tables', existingTable, at);
|
return alterInArr(state, 'tables', existingTable, at);
|
||||||
}
|
}
|
||||||
at.id = shortid.generate();
|
at.id = shortid.generate();
|
||||||
// for new table, associate Id of query for data preview
|
|
||||||
at.dataPreviewQueryId = null;
|
at.dataPreviewQueryId = null;
|
||||||
let newState = addToArr(state, 'tables', at);
|
return addToArr(state, 'tables', at);
|
||||||
if (action.query) {
|
|
||||||
newState = alterInArr(newState, 'tables', at, { dataPreviewQueryId: action.query.id });
|
|
||||||
}
|
|
||||||
return newState;
|
|
||||||
},
|
},
|
||||||
[actions.EXPAND_TABLE]() {
|
[actions.EXPAND_TABLE]() {
|
||||||
return alterInArr(state, 'tables', action.table, { expanded: true });
|
return alterInArr(state, 'tables', action.table, { expanded: true });
|
||||||
@ -126,6 +118,8 @@ export const sqlLabReducer = function (state, action) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newState.activeSouthPaneTab = action.query.id;
|
newState.activeSouthPaneTab = action.query.id;
|
||||||
|
newState = alterInArr(
|
||||||
|
newState, 'tables', action.table, { dataPreviewQueryId: action.query.id });
|
||||||
}
|
}
|
||||||
newState = addToObject(newState, 'queries', action.query);
|
newState = addToObject(newState, 'queries', action.query);
|
||||||
const sqlEditor = { id: action.query.sqlEditorId };
|
const sqlEditor = { id: action.query.sqlEditorId };
|
||||||
|
@ -24,9 +24,9 @@ describe('TableElement', () => {
|
|||||||
React.isValidElement(<TableElement {...mockedProps} />)
|
React.isValidElement(<TableElement {...mockedProps} />)
|
||||||
).to.equal(true);
|
).to.equal(true);
|
||||||
});
|
});
|
||||||
it('has 2 Link elements', () => {
|
it('has 3 Link elements', () => {
|
||||||
const wrapper = shallow(<TableElement {...mockedProps} />);
|
const wrapper = shallow(<TableElement {...mockedProps} />);
|
||||||
expect(wrapper.find(Link)).to.have.length(2);
|
expect(wrapper.find(Link)).to.have.length(3);
|
||||||
});
|
});
|
||||||
it('has 14 columns', () => {
|
it('has 14 columns', () => {
|
||||||
const wrapper = shallow(<TableElement {...mockedProps} />);
|
const wrapper = shallow(<TableElement {...mockedProps} />);
|
||||||
|
Loading…
Reference in New Issue
Block a user