Skip to content

Commit

Permalink
feat: Better return messages in SQL Editor (apache#14381)
Browse files Browse the repository at this point in the history
* Sqllab limit

* Add migration script

* Set default values

* initial push

* revisions

* moving migration to separate PR

* revisions

* Fix apply_limit_to_sql

* all but tests

* added unit tests

* result set

* first draft

* revisions

* made user required prop, added it to all places ResultSet is imported

* changed QueryTable test to allow for useSelector

* Query Table working

* working with heights

* fixed scrolling

* got rid of animated

* fixed tests, revisions

* revisions

* revisions

* heights

* fun with heights

* alert state

* aaron helped me fix this

* better alert messages

* fixed result set test

Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
  • Loading branch information
2 people authored and cccs-RyanS committed Dec 17, 2021
1 parent ca3b5b7 commit dbc3c92
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { fireEvent, render, screen, act } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import userEvent from '@testing-library/user-event';
import { user } from './fixtures';

const mockStore = configureStore([thunk]);
const store = mockStore({});
const store = mockStore({
sqlLab: user,
});

const SEARCH_ENDPOINT = 'glob:*/superset/search_queries?*';
const USER_ENDPOINT = 'glob:*/api/v1/query/related/user';
Expand Down
25 changes: 17 additions & 8 deletions superset-frontend/spec/javascripts/sqllab/QueryTable_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
* under the License.
*/
import React from 'react';
import { shallow } from 'enzyme';
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import { styledMount as mount } from 'spec/helpers/theming';
import QueryTable from 'src/SqlLab/components/QueryTable';
import TableView from 'src/components/TableView';
import { TableCollection } from 'src/components/dataViewCommon';
import { queries } from './fixtures';
import { Provider } from 'react-redux';
import { queries, user } from './fixtures';

describe('QueryTable', () => {
const mockedProps = {
Expand All @@ -35,12 +38,18 @@ describe('QueryTable', () => {
expect(React.isValidElement(<QueryTable {...mockedProps} />)).toBe(true);
});
it('renders a proper table', () => {
const wrapper = shallow(<QueryTable {...mockedProps} />);
const tableWrapper = wrapper
.find(TableView)
.shallow()
.find(TableCollection)
.shallow();
const mockStore = configureStore([thunk]);
const store = mockStore({
sqlLab: user,
});

const wrapper = mount(
<Provider store={store}>
<QueryTable {...mockedProps} />
</Provider>,
);
const tableWrapper = wrapper.find(TableView).find(TableCollection);

expect(wrapper.find(TableView)).toExist();
expect(tableWrapper.find('table')).toExist();
expect(tableWrapper.find('table').find('thead').find('tr')).toHaveLength(1);
Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
runningQuery,
stoppedQuery,
initialState,
user,
} from './fixtures';

const mockStore = configureStore([thunk]);
Expand All @@ -54,8 +55,10 @@ describe('ResultSet', () => {
},
cache: true,
query: queries[0],
height: 0,
height: 140,
database: { allows_virtual_table_explore: true },
user,
defaultQueryLimit: 1000,
};
const stoppedQueryProps = { ...mockedProps, query: stoppedQuery };
const runningQueryProps = { ...mockedProps, query: runningQuery };
Expand Down
14 changes: 14 additions & 0 deletions superset-frontend/spec/javascripts/sqllab/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const queries = [
executedSql: null,
changed_on: '2016-10-19T20:56:06',
rows: 42,
queryLimit: 100,
endDttm: 1476910566798,
limit_reached: false,
schema: 'test_schema',
Expand Down Expand Up @@ -461,6 +462,18 @@ export const runningQuery = {
};
export const cachedQuery = { ...queries[0], cached: true };

export const user = {
createdOn: '2021-04-27T18:12:38.952304',
email: 'admin',
firstName: 'admin',
isActive: true,
lastName: 'admin',
permissions: {},
roles: { Admin: Array(173) },
userId: 1,
username: 'admin',
};

export const initialState = {
sqlLab: {
offline: false,
Expand All @@ -473,6 +486,7 @@ export const initialState = {
workspaceQueries: [],
queriesLastUpdate: 0,
activeSouthPaneTab: 'Results',
user: { user },
},
messageToasts: [],
common: {
Expand Down
13 changes: 10 additions & 3 deletions superset-frontend/src/SqlLab/components/QueryTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import moment from 'moment';
import Card from 'src/components/Card';
import ProgressBar from 'src/components/ProgressBar';
import Label from 'src/components/Label';
import { t } from '@superset-ui/core';

import { t, css } from '@superset-ui/core';
import { useSelector } from 'react-redux';
import TableView from 'src/components/TableView';
import Button from 'src/components/Button';
import { fDuration } from 'src/modules/dates';
Expand Down Expand Up @@ -53,6 +53,10 @@ const openQuery = id => {
window.open(url);
};

const StaticPosition = css`
position: static;
`;

const QueryTable = props => {
const columns = useMemo(
() =>
Expand All @@ -64,6 +68,8 @@ const QueryTable = props => {
[props.columns],
);

const user = useSelector(({ sqlLab: { user } }) => user);

const data = useMemo(() => {
const restoreSql = query => {
props.actions.queryEditorSetSql({ id: query.sqlEditorId }, query.sql);
Expand Down Expand Up @@ -129,7 +135,7 @@ const QueryTable = props => {
</Button>
);
q.sql = (
<Card>
<Card css={[StaticPosition]}>
<HighlightedSql
sql={q.sql}
rawSql={q.executedSql}
Expand All @@ -153,6 +159,7 @@ const QueryTable = props => {
modalBody={
<ResultSet
showSql
user={user}
query={query}
actions={props.actions}
height={400}
Expand Down

0 comments on commit dbc3c92

Please sign in to comment.