Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat/fileter_set
Browse files Browse the repository at this point in the history
* upstream/master:
  fix: create example DB if needed (apache#16451)
  fix(native-filters): add handle undefined control value gracefully (apache#16468)
  Revert "chore: Changes the DatabaseSelector to use the new Select component (apache#16334)" (apache#16478)
  fix(explore): JS error for creating new metrics from columns (apache#16477)
  fix: queryEditor bug (apache#16452)
  docs: make code snippet usable with required imports (apache#16473)
  perf(dashboard): decouple redux props from dashboard components (apache#16421)
  perf(dashboard): reduce number of rerenders of Charts (apache#16444)
  • Loading branch information
amitmiran137 committed Aug 29, 2021
2 parents 930863b + 62d8ab7 commit ee7c4e5
Show file tree
Hide file tree
Showing 34 changed files with 923 additions and 756 deletions.
6 changes: 5 additions & 1 deletion docs/src/pages/docs/installation/configuring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ CUSTOM_SECURITY_MANAGER = CustomSsoSecurityManager
the app object and can alter it in any way. For example, add `FLASK_APP_MUTATOR` into your
`superset_config.py` to setup session cookie expiration time to 24 hours:

```
```python
from flask import session
from flask import Flask


def make_session_permanent():
'''
Enable maxAge for the cookie 'session'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

import Chart from 'src/dashboard/containers/Chart';
import ChartHolder from 'src/dashboard/components/gridComponents/ChartHolder';
import ChartHolderConnected from 'src/dashboard/components/gridComponents/ChartHolder';
import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton';
import DragDroppable from 'src/dashboard/components/dnd/DragDroppable';
import HoverMenu from 'src/dashboard/components/menu/HoverMenu';
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('ChartHolder', () => {
const wrapper = mount(
<Provider store={mockStore}>
<DndProvider backend={HTML5Backend}>
<ChartHolder {...props} {...overrideProps} />
<ChartHolderConnected {...props} {...overrideProps} />
</DndProvider>
</Provider>,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { HTML5Backend } from 'react-dnd-html5-backend';

import { act } from 'react-dom/test-utils';
import { MarkdownEditor } from 'src/components/AsyncAceEditor';
import Markdown from 'src/dashboard/components/gridComponents/Markdown';
import MarkdownConnected from 'src/dashboard/components/gridComponents/Markdown';
import MarkdownModeDropdown from 'src/dashboard/components/menu/MarkdownModeDropdown';
import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('Markdown', () => {
const wrapper = mount(
<Provider store={mockStore}>
<DndProvider backend={HTML5Backend}>
<Markdown {...props} {...overrideProps} />
<MarkdownConnected {...props} {...overrideProps} />
</DndProvider>
</Provider>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ describe('Left Panel Expansion', () => {
</Provider>
</ThemeProvider>,
);
const dbSelect = screen.getByRole('combobox', {
name: 'Select a database',
});
const schemaSelect = screen.getByRole('combobox', {
name: 'Select a schema',
});
const dropdown = screen.getByText(/Select a table/i);
const dbSelect = screen.getByText(/select a database/i);
const schemaSelect = screen.getByText(/select a schema \(0\)/i);
const dropdown = screen.getByText(/Select table/i);
const abUser = screen.getByText(/ab_user/i);
expect(dbSelect).toBeInTheDocument();
expect(schemaSelect).toBeInTheDocument();
Expand Down
40 changes: 30 additions & 10 deletions superset-frontend/spec/javascripts/sqllab/actions/sqlLab_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ describe('async actions', () => {

let isFeatureEnabledMock;

beforeAll(() => {
beforeEach(() => {
isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(
feature => feature === 'SQLLAB_BACKEND_PERSISTENCE',
);
});

afterAll(() => {
afterEach(() => {
isFeatureEnabledMock.mockRestore();
});

Expand Down Expand Up @@ -612,9 +612,29 @@ describe('async actions', () => {
});

describe('queryEditorSetSql', () => {
describe('with backend persistence flag on', () => {
it('does not update the tab state in the backend', () => {
expect.assertions(2);

const sql = 'SELECT * ';
const store = mockStore({});

return store
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
.then(() => {
expect(store.getActions()).toHaveLength(0);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
});
});
});
});
describe('with backend persistence flag off', () => {
it('updates the tab state in the backend', () => {
expect.assertions(2);

const backendPersistenceOffMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
.mockImplementation(
feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
);
const sql = 'SELECT * ';
const store = mockStore({});
const expectedActions = [
Expand All @@ -624,12 +644,12 @@ describe('async actions', () => {
sql,
},
];
return store
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
.then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
});

store.dispatch(actions.queryEditorSetSql(queryEditor, sql));

expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
backendPersistenceOffMock.mockRestore();
});
});

Expand Down
17 changes: 7 additions & 10 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,16 +898,11 @@ export function updateSavedQuery(query) {

export function queryEditorSetSql(queryEditor, sql) {
return function (dispatch) {
const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
? SupersetClient.put({
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
postPayload: { sql, latest_query_id: queryEditor.latestQueryId },
})
: Promise.resolve();

return sync
.then(() => dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql }))
.catch(() =>
if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) {
return SupersetClient.put({
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
postPayload: { sql, latest_query_id: queryEditor.latestQueryId },
}).catch(() =>
dispatch(
addDangerToast(
t(
Expand All @@ -918,6 +913,8 @@ export function queryEditorSetSql(queryEditor, sql) {
),
),
);
}
return dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql });
};
}

Expand Down
9 changes: 5 additions & 4 deletions superset-frontend/src/components/CertifiedIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
*/
import React from 'react';
import { t, supersetTheme } from '@superset-ui/core';
import Icons, { IconType } from 'src/components/Icons';
import Icons from 'src/components/Icons';
import { Tooltip } from 'src/components/Tooltip';

export interface CertifiedIconProps {
certifiedBy?: string;
details?: string;
size?: IconType['iconSize'];
size?: number;
}

function CertifiedIcon({
certifiedBy,
details,
size = 'l',
size = 24,
}: CertifiedIconProps) {
return (
<Tooltip
Expand All @@ -48,7 +48,8 @@ function CertifiedIcon({
>
<Icons.Certified
iconColor={supersetTheme.colors.primary.base}
iconSize={size}
height={size}
width={size}
/>
</Tooltip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import DatabaseSelector from '.';
const SupersetClientGet = jest.spyOn(SupersetClient, 'get');

const createProps = () => ({
db: { id: 1, database_name: 'test', backend: 'postgresql' },
dbId: 1,
formMode: false,
isDatabaseSelectEnabled: true,
readOnly: false,
schema: undefined,
schema: 'public',
sqlLabMode: true,
getDbList: jest.fn(),
getTableList: jest.fn(),
Expand Down Expand Up @@ -129,7 +129,7 @@ beforeEach(() => {
changed_on: '2021-03-09T19:02:07.141095',
changed_on_delta_humanized: 'a day ago',
created_by: null,
database_name: 'test',
database_name: 'examples',
explore_database_id: 1,
expose_in_sqllab: true,
force_ctas_schema: null,
Expand All @@ -153,62 +153,50 @@ test('Refresh should work', async () => {

render(<DatabaseSelector {...props} />);

const select = screen.getByRole('combobox', {
name: 'Select a schema',
});

userEvent.click(select);

await waitFor(() => {
expect(SupersetClientGet).toBeCalledTimes(1);
expect(props.getDbList).toBeCalledTimes(0);
expect(SupersetClientGet).toBeCalledTimes(2);
expect(props.getDbList).toBeCalledTimes(1);
expect(props.getTableList).toBeCalledTimes(0);
expect(props.handleError).toBeCalledTimes(0);
expect(props.onDbChange).toBeCalledTimes(0);
expect(props.onSchemaChange).toBeCalledTimes(0);
expect(props.onSchemasLoad).toBeCalledTimes(0);
expect(props.onSchemasLoad).toBeCalledTimes(1);
expect(props.onUpdate).toBeCalledTimes(0);
});

userEvent.click(screen.getByRole('button', { name: 'refresh' }));
userEvent.click(screen.getByRole('button'));

await waitFor(() => {
expect(SupersetClientGet).toBeCalledTimes(2);
expect(props.getDbList).toBeCalledTimes(0);
expect(SupersetClientGet).toBeCalledTimes(3);
expect(props.getDbList).toBeCalledTimes(1);
expect(props.getTableList).toBeCalledTimes(0);
expect(props.handleError).toBeCalledTimes(0);
expect(props.onDbChange).toBeCalledTimes(0);
expect(props.onSchemaChange).toBeCalledTimes(0);
expect(props.onDbChange).toBeCalledTimes(1);
expect(props.onSchemaChange).toBeCalledTimes(1);
expect(props.onSchemasLoad).toBeCalledTimes(2);
expect(props.onUpdate).toBeCalledTimes(0);
expect(props.onUpdate).toBeCalledTimes(1);
});
});

test('Should database select display options', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
const select = screen.getByRole('combobox', {
name: 'Select a database',
});
expect(select).toBeInTheDocument();
userEvent.click(select);
expect(
await screen.findByRole('option', { name: 'postgresql: test' }),
).toBeInTheDocument();
const selector = await screen.findByText('Database:');
expect(selector).toBeInTheDocument();
expect(selector.parentElement).toHaveTextContent(
'Database:postgresql examples',
);
});

test('Should schema select display options', async () => {
const props = createProps();
render(<DatabaseSelector {...props} />);
const select = screen.getByRole('combobox', {
name: 'Select a schema',
});
expect(select).toBeInTheDocument();
userEvent.click(select);
expect(
await screen.findByRole('option', { name: 'public' }),
).toBeInTheDocument();
expect(
await screen.findByRole('option', { name: 'information_schema' }),
).toBeInTheDocument();

const selector = await screen.findByText('Schema:');
expect(selector).toBeInTheDocument();
expect(selector.parentElement).toHaveTextContent('Schema: public');

userEvent.click(screen.getByRole('button'));

expect(await screen.findByText('Select a schema (2)')).toBeInTheDocument();
});
Loading

0 comments on commit ee7c4e5

Please sign in to comment.