Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert QueryAutoRefresh to TypeScript functional React component [sc-48362] #20179

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
dc45703
git commit -m 'Convert QueryAutoRefresh to functional component [sc-4…
eric-briscoe May 24, 2022
42a7c73
addressing PR comments [sc-48362]
eric-briscoe May 25, 2022
9888daa
Merge branch 'master' into ericbriscoe/sc-48362/convert-queryautorefr…
eric-briscoe May 25, 2022
79a30aa
Address PR comment to use enum for QueryState [sc-48362]
eric-briscoe May 25, 2022
c4f1c15
Merge branch 'master' into ericbriscoe/sc-48362/convert-queryautorefr…
eric-briscoe May 25, 2022
fe6a853
Address PR comments for object type validation [sc-48362]
eric-briscoe May 25, 2022
eecc6a4
Merge branch 'master' into ericbriscoe/sc-48362/convert-queryautorefr…
eric-briscoe May 25, 2022
d4a58aa
Addresses PR comment to add QueryState.SCHEDULED to runningQueryState…
eric-briscoe May 25, 2022
44a9956
Fix prettier lint error [sc-48362]
eric-briscoe May 26, 2022
4424516
Adjust unit tests for props update hoisting callbacks out of actions …
eric-briscoe May 31, 2022
27f5d7a
Merge branch 'master' into ericbriscoe/sc-48362/convert-queryautorefr…
eric-briscoe May 31, 2022
9265175
Merge branch 'master' into ericbriscoe/sc-48362/convert-queryautorefr…
eric-briscoe Jun 14, 2022
0d3153f
Update with changes from master [sc-48362]
eric-briscoe Jun 14, 2022
00767ed
Merge branch 'master' into ericbriscoe/sc-48362/convert-queryautorefr…
eric-briscoe Jun 22, 2022
ff39bc2
Removes logic setting user offline and relying on results panel error…
eric-briscoe Jun 22, 2022
81376fb
Fixes bad import after some TypeScript definitions were relocated to …
eric-briscoe Jun 22, 2022
6aa313e
Fixes TypeScript errors [sc-48362]
eric-briscoe Jun 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions superset-frontend/src/SqlLab/components/App/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from 'src/SqlLab/constants';
import * as Actions from 'src/SqlLab/actions/sqlLab';
import TabbedSqlEditors from '../TabbedSqlEditors';
import QueryAutoRefresh from '../QueryAutoRefresh';
import QueryAutoRefreshContainer from '../QueryAutoRefresh/QueryAutoRefreshContainer';

class App extends React.PureComponent {
constructor(props) {
Expand Down Expand Up @@ -99,7 +99,7 @@ class App extends React.PureComponent {
}
return (
<div className="App SqlLab">
<QueryAutoRefresh />
<QueryAutoRefreshContainer />
<TabbedSqlEditors />
<ToastContainer />
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { render } from '@testing-library/react';
import QueryAutoRefresh, {
isQueryRunning,
shouldCheckForQueries,
} from 'src/SqlLab/components/QueryAutoRefresh';
import { successfulQuery, runningQuery } from 'src/SqlLab/fixtures';

// NOTE: The uses of @ts-ignore in this file is to enable testing of bad inputs to verify the
// function / component handles bad data elegantly
describe('QueryAutoRefresh', () => {
const offline = false;
const queries = [runningQuery];
const actions = {
setUserOffline: jest.fn(),
refreshQueries: jest.fn(),
};
const queriesLastUpdate = Date.now();

it('isQueryRunning returns true for valid running query', () => {
const running = isQueryRunning(runningQuery);
expect(running).toBe(true);
});

it('isQueryRunning returns false for valid not-running query', () => {
const running = isQueryRunning(successfulQuery);
expect(running).toBe(false);
});

it('isQueryRunning returns false for invalid query', () => {
// @ts-ignore
let running = isQueryRunning(null);
expect(running).toBe(false);
// @ts-ignore
running = isQueryRunning(undefined);
expect(running).toBe(false);
// @ts-ignore
running = isQueryRunning('I Should Be An Object');
expect(running).toBe(false);
// @ts-ignore
running = isQueryRunning({ state: { badFormat: true } });
expect(running).toBe(false);
});

it('shouldCheckForQueries is true for valid running query', () => {
expect(shouldCheckForQueries([runningQuery])).toBe(true);
});

it('shouldCheckForQueries is false for valid completed query', () => {
expect(shouldCheckForQueries([successfulQuery])).toBe(false);
});

it('shouldCheckForQueries is false for invalid inputs', () => {
// @ts-ignore
expect(shouldCheckForQueries(null)).toBe(false);
// @ts-ignore
expect(shouldCheckForQueries(undefined)).toBe(false);
expect(
// @ts-ignore
shouldCheckForQueries([null, 'hello world', [], undefined, 23]),
).toBe(false);
});

it('Attempts to refresh when given pending query', () => {
render(
<QueryAutoRefresh
queries={queries}
offline={offline}
actions={actions}
queriesLastUpdate={queriesLastUpdate}
/>,
);
setTimeout(() => {
expect(actions.refreshQueries).toHaveBeenCalled();
expect(actions.setUserOffline).not.toHaveBeenCalled();
}, 1000);
});

it('Does not fail and attempts to refresh when given pending query and invlaid query', () => {
render(
<QueryAutoRefresh
// @ts-ignore
queries={[runningQuery, null]}
offline={offline}
actions={actions}
queriesLastUpdate={queriesLastUpdate}
/>,
);
setTimeout(() => {
expect(actions.refreshQueries).toHaveBeenCalled();
expect(actions.setUserOffline).not.toHaveBeenCalled();
}, 1000);
});

it('Does NOT Attempt to refresh when given only completed queries', () => {
render(
<QueryAutoRefresh
queries={[successfulQuery]}
offline={offline}
actions={actions}
queriesLastUpdate={queriesLastUpdate}
/>,
);
setTimeout(() => {
expect(actions.refreshQueries).not.toHaveBeenCalled();
expect(actions.setUserOffline).not.toHaveBeenCalled();
}, 1000);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import { Dispatch, bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import * as Actions from 'src/SqlLab/actions/sqlLab';
import { RootState } from 'src/SqlLab/types';
import QueryAutoRefresh, { QueryAutoRefreshProps } from '.';

function QueryAutoRefreshConnector({
offline,
queries,
actions,
queriesLastUpdate,
}: QueryAutoRefreshProps) {
return (
<QueryAutoRefresh
offline={offline}
queries={queries}
actions={actions}
queriesLastUpdate={queriesLastUpdate}
/>
);
}

function mapStateToProps({ sqlLab }: RootState) {
return {
offline: sqlLab.offline,
queries: sqlLab.queries,
queriesLastUpdate: sqlLab.queriesLastUpdate,
};
}

function mapDispatchToProps(dispatch: Dispatch) {
return {
actions: bindActionCreators<any, any>(Actions, dispatch),
};
}

export default connect<any>(
mapStateToProps,
mapDispatchToProps,
)(QueryAutoRefreshConnector);
124 changes: 0 additions & 124 deletions superset-frontend/src/SqlLab/components/QueryAutoRefresh/index.jsx

This file was deleted.

Loading