Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
app: fix initial preview query (#371)
Browse files Browse the repository at this point in the history
* Fix invocation of `PREVIEW_QUERY` from `Settings.react.js` and
  `Preview.react.js`. This fixes the initial preview query that depend
  on the database name (e.g. MSSql).

Fixes #356
  • Loading branch information
n-riesco authored Feb 13, 2018
1 parent 399c591 commit e7474da
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/actions/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ export function getApacheDrillS3Keys(connectionId) {
);
}

export function previewTable (connectionId, dialect, table, database) {
export function previewTable(connectionId, connectionObject, table, elasticsearchIndex) {
const body = {
query: PREVIEW_QUERY(dialect, table, database)
query: PREVIEW_QUERY(connectionObject, table, elasticsearchIndex)
};
return apiThunk(
`connections/${connectionId}/query`,
Expand Down
2 changes: 1 addition & 1 deletion app/components/Settings/Preview/Preview.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Preview extends Component {

const dialect = connectionObject.dialect;
const showEditor = propOr(true, 'showEditor')(preview);
const code = propOr(PREVIEW_QUERY(dialect, selectedTable), 'code')(preview);
const code = propOr(PREVIEW_QUERY(connectionObject, selectedTable), 'code')(preview);
propOr('', 'error')(preview);

// Surpressing ESLint cause restricting line length would harm JSX readability
Expand Down
6 changes: 3 additions & 3 deletions app/components/Settings/Settings.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ function mapStateToProps(state) {
const preview = previews[selectedConnectionId] || {};
const connection = connections[selectedTab];
if (connection && !hasIn('code', preview)) {
preview.code = PREVIEW_QUERY(connection.dialect, selectedTable);
preview.code = PREVIEW_QUERY(connection, selectedTable);
}

return {
Expand Down Expand Up @@ -604,9 +604,9 @@ function mergeProps(stateProps, dispatchProps, ownProps) {
function boundPreviewTables() {
return dispatch(Actions.previewTable(
selectedConnectionId,
connectionObject.dialect,
connectionObject,
selectedTable,
connectionObject.database || selectedIndex
selectedIndex
));
}
function boundUpdatePreview(previewUpdateObject) {
Expand Down
9 changes: 4 additions & 5 deletions app/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ export const LOGOS = {
[DIALECTS.DATA_WORLD]: 'images/dataworld-logo.png'
};

export function PREVIEW_QUERY (dialect, table, database = '') {
switch (dialect) {
export function PREVIEW_QUERY(connection, table, elasticsearchIndex) {
switch (connection.dialect) {
case DIALECTS.IBM_DB2:
return `SELECT * FROM ${table} FETCH FIRST 1000 ROWS ONLY`;
case DIALECTS.APACHE_IMPALA:
Expand All @@ -228,11 +228,10 @@ export function PREVIEW_QUERY (dialect, table, database = '') {
case DIALECTS.REDSHIFT:
return `SELECT * FROM ${table} LIMIT 1000`;
case DIALECTS.MSSQL:
return 'SELECT TOP 1000 * FROM ' +
`${database}.dbo.${table}`;
return `SELECT TOP 1000 * FROM ${connection.database}.dbo.${table}`;
case DIALECTS.ELASTICSEARCH:
return JSON.stringify({
index: database || '_all',
index: elasticsearchIndex || '_all',
type: table || '_all',
body: {
query: { 'match_all': {} },
Expand Down

0 comments on commit e7474da

Please sign in to comment.