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

fix(sqllab): flaky json explore modal due to over-rendering #26156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface QueryAutoRefreshProps {

// returns true if the Query.state matches one of the specifc values indicating the query is still processing on server
export const isQueryRunning = (q: Query): boolean =>
runningQueryStateList.includes(q?.state);
runningQueryStateList.includes(q?.state) && !q?.resultsKey;

// returns true if at least one query is running and within the max age to poll timeframe
export const shouldCheckForQueries = (queryList: QueryDictionary): boolean => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import QueryHistory from 'src/SqlLab/components/QueryHistory';
import { initialState } from 'src/SqlLab/fixtures';

const mockedProps = {
queries: [],
queryEditorId: 123,
displayLimit: 1000,
latestQueryId: 'yhMUZCGb',
};
Expand All @@ -32,7 +33,7 @@ const setup = (overrides = {}) => (

describe('QueryHistory', () => {
it('Renders an empty state for query history', () => {
render(setup());
render(setup(), { useRedux: true, initialState });

const emptyStateText = screen.getByText(
/run a query to display query history/i,
Expand Down
29 changes: 22 additions & 7 deletions superset-frontend/src/SqlLab/components/QueryHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import React, { useMemo } from 'react';
import { shallowEqual, useSelector } from 'react-redux';
import { EmptyStateMedium } from 'src/components/EmptyState';
import { t, styled, QueryResponse } from '@superset-ui/core';
import { t, styled } from '@superset-ui/core';
import QueryTable from 'src/SqlLab/components/QueryTable';
import { SqlLabRootState } from 'src/SqlLab/types';

interface QueryHistoryProps {
queries: QueryResponse[];
queryEditorId: string | number;
displayLimit: number;
latestQueryId: string | undefined;
}
Expand All @@ -39,11 +41,23 @@
`;

const QueryHistory = ({
queries,
queryEditorId,
displayLimit,
latestQueryId,
}: QueryHistoryProps) =>
queries.length > 0 ? (
}: QueryHistoryProps) => {
const queries = useSelector(
({ sqlLab: { queries } }: SqlLabRootState) => queries,
shallowEqual,
);
const editorQueries = useMemo(
() =>
Object.values(queries).filter(
({ sqlEditorId }) => String(sqlEditorId) === String(queryEditorId),

Check warning on line 55 in superset-frontend/src/SqlLab/components/QueryHistory/index.tsx

View check run for this annotation

Codecov / codecov/patch

superset-frontend/src/SqlLab/components/QueryHistory/index.tsx#L55

Added line #L55 was not covered by tests
),
[queries, queryEditorId],
);

return editorQueries.length > 0 ? (
<QueryTable
columns={[
'state',
Expand All @@ -55,7 +69,7 @@
'results',
'actions',
]}
queries={queries}
queries={editorQueries}
displayLimit={displayLimit}
latestQueryId={latestQueryId}
/>
Expand All @@ -67,5 +81,6 @@
/>
</StyledEmptyStateWrapper>
);
};

export default QueryHistory;
3 changes: 1 addition & 2 deletions superset-frontend/src/SqlLab/components/QueryTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ const QueryTable = ({
modalBody={
<ResultSet
showSql
user={user}
query={query}
queryId={query.id}
height={400}
displayLimit={displayLimit}
defaultQueryLimit={1000}
Expand Down
Loading
Loading