mirror of
https://github.com/apache/superset.git
synced 2026-04-21 17:14:57 +00:00
@@ -51,7 +51,7 @@ const defaultQueryLimit = 100;
|
||||
const setup = (props?: Partial<QueryLimitSelectProps>, store?: Store) =>
|
||||
render(
|
||||
<QueryLimitSelect
|
||||
queryEditor={defaultQueryEditor}
|
||||
queryEditorId={defaultQueryEditor.id}
|
||||
maxRow={100000}
|
||||
defaultQueryLimit={defaultQueryLimit}
|
||||
{...props}
|
||||
@@ -67,12 +67,20 @@ describe('QueryLimitSelect', () => {
|
||||
const queryLimit = 10;
|
||||
const { getByText } = setup(
|
||||
{
|
||||
queryEditor: {
|
||||
...defaultQueryEditor,
|
||||
queryLimit,
|
||||
},
|
||||
queryEditorId: defaultQueryEditor.id,
|
||||
},
|
||||
mockStore(initialState),
|
||||
mockStore({
|
||||
...initialState,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
queryEditors: [
|
||||
{
|
||||
...defaultQueryEditor,
|
||||
queryLimit,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(getByText(queryLimit)).toBeInTheDocument();
|
||||
});
|
||||
@@ -129,7 +137,9 @@ describe('QueryLimitSelect', () => {
|
||||
{
|
||||
type: 'QUERY_EDITOR_SET_QUERY_LIMIT',
|
||||
queryLimit: LIMIT_DROPDOWN[expectedIndex],
|
||||
queryEditor: defaultQueryEditor,
|
||||
queryEditor: {
|
||||
id: defaultQueryEditor.id,
|
||||
},
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
* under the License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { styled, useTheme } from '@superset-ui/core';
|
||||
import { AntdDropdown } from 'src/components';
|
||||
import { Menu } from 'src/components/Menu';
|
||||
import Icons from 'src/components/Icons';
|
||||
import { SqlLabRootState, QueryEditor } from 'src/SqlLab/types';
|
||||
import { queryEditorSetQueryLimit } from 'src/SqlLab/actions/sqlLab';
|
||||
import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor';
|
||||
|
||||
export interface QueryLimitSelectProps {
|
||||
queryEditor: QueryEditor;
|
||||
queryEditorId: string;
|
||||
maxRow: number;
|
||||
defaultQueryLimit: number;
|
||||
}
|
||||
@@ -79,19 +79,12 @@ function renderQueryLimit(
|
||||
}
|
||||
|
||||
const QueryLimitSelect = ({
|
||||
queryEditor,
|
||||
queryEditorId,
|
||||
maxRow,
|
||||
defaultQueryLimit,
|
||||
}: QueryLimitSelectProps) => {
|
||||
const queryLimit = useSelector<SqlLabRootState, number>(
|
||||
({ sqlLab: { unsavedQueryEditor } }) => {
|
||||
const updatedQueryEditor = {
|
||||
...queryEditor,
|
||||
...(unsavedQueryEditor.id === queryEditor.id && unsavedQueryEditor),
|
||||
};
|
||||
return updatedQueryEditor.queryLimit || defaultQueryLimit;
|
||||
},
|
||||
);
|
||||
const queryEditor = useQueryEditor(queryEditorId, ['id', 'queryLimit']);
|
||||
const queryLimit = queryEditor.queryLimit || defaultQueryLimit;
|
||||
const dispatch = useDispatch();
|
||||
const setQueryLimit = (updatedQueryLimit: number) =>
|
||||
dispatch(queryEditorSetQueryLimit(queryEditor, updatedQueryLimit));
|
||||
|
||||
Reference in New Issue
Block a user