From d8a7a623fd4a21aedc554bd522939f31f8886f00 Mon Sep 17 00:00:00 2001 From: Abhishek-kumar-samsung Date: Tue, 22 Apr 2025 16:34:06 +0530 Subject: [PATCH 1/6] added logic for custom limit in sql lab --- .../src/SqlLab/components/QueryLimitSelect/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx index 9e2e89aad03c..4de88a3efbc2 100644 --- a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx +++ b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx @@ -20,6 +20,7 @@ import { useDispatch } from 'react-redux'; import { t } from '@superset-ui/core'; import { Dropdown } from 'src/components/Dropdown'; import { Menu } from 'src/components/Menu'; +import { Input } from 'src/components/Input'; import { Icons } from 'src/components/Icons'; import { queryEditorSetQueryLimit } from 'src/SqlLab/actions/sqlLab'; import useQueryEditor from 'src/SqlLab/hooks/useQueryEditor'; @@ -55,6 +56,17 @@ function renderQueryLimit( {convertToNumWithSpaces(limit)}{' '} ))} + { + if (event.key === 'Enter') { + const limit = parseInt(event.target.value, 10); + setQueryLimit(limit); + convertToNumWithSpaces(limit); + } + }} + /> ); } From ebb6864647a0bcaaff0fad9d2d9b1ccd196e0547 Mon Sep 17 00:00:00 2001 From: Abhishek-kumar-samsung Date: Tue, 22 Apr 2025 17:03:40 +0530 Subject: [PATCH 2/6] linting resolved --- .../src/SqlLab/components/QueryLimitSelect/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx index 4de88a3efbc2..8c4accd6d304 100644 --- a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx +++ b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx @@ -61,7 +61,8 @@ function renderQueryLimit( placeholder="custom limit" onKeyDown={event => { if (event.key === 'Enter') { - const limit = parseInt(event.target.value, 10); + const val = (event.target as HTMLInputElement).value; + const limit = parseInt(val, 10); setQueryLimit(limit); convertToNumWithSpaces(limit); } From e49d03b3ee3bc0ca77625cf69a64fd8d3a207b25 Mon Sep 17 00:00:00 2001 From: Abhishek-kumar-samsung Date: Wed, 23 Apr 2025 10:25:17 +0530 Subject: [PATCH 3/6] Moved input to Menu.Item --- .../components/QueryLimitSelect/index.tsx | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx index 8c4accd6d304..7c311487f026 100644 --- a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx +++ b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx @@ -56,18 +56,21 @@ function renderQueryLimit( {convertToNumWithSpaces(limit)}{' '} ))} - { - if (event.key === 'Enter') { - const val = (event.target as HTMLInputElement).value; - const limit = parseInt(val, 10); - setQueryLimit(limit); - convertToNumWithSpaces(limit); - } - }} - /> + + e.stopPropagation()} + onKeyDown={event => { + if (event.key === 'Enter') { + const val = (event.target as HTMLInputElement).value; + const limit = parseInt(val, 10); + setQueryLimit(limit); + convertToNumWithSpaces(limit); + } + }} + /> + ); } From ae2a0b5efb3c86f3a36aed01f84207cc50457086 Mon Sep 17 00:00:00 2001 From: Abhishek-kumar-samsung Date: Wed, 23 Apr 2025 11:02:40 +0530 Subject: [PATCH 4/6] Added logic to handle negative limit issue --- .../src/SqlLab/components/QueryLimitSelect/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx index 7c311487f026..bdc837eee091 100644 --- a/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx +++ b/superset-frontend/src/SqlLab/components/QueryLimitSelect/index.tsx @@ -60,11 +60,13 @@ function renderQueryLimit( e.stopPropagation()} onKeyDown={event => { if (event.key === 'Enter') { const val = (event.target as HTMLInputElement).value; - const limit = parseInt(val, 10); + let limit = parseInt(val, 10); + if (limit < 1) limit = 1; setQueryLimit(limit); convertToNumWithSpaces(limit); } From 5ac44fbf947e8e07b4a5584a501d16108a48a218 Mon Sep 17 00:00:00 2001 From: Abhishek-kumar-samsung Date: Wed, 23 Apr 2025 11:05:26 +0530 Subject: [PATCH 5/6] modified test file --- .../components/QueryLimitSelect/QueryLimitSelect.test.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx b/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx index 8d421f92c92e..68aaf27ab0b0 100644 --- a/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx +++ b/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx @@ -143,7 +143,9 @@ describe('QueryLimitSelect', () => { elem.textContent?.trim(), ); - expect(actualLabels).toEqual(expectedLabels); + expect(actualLabels.slice(0, actualLabels.length - 1)).toEqual( + expectedLabels, + ); }); it('renders dropdown select correctly when maxRow is a multiple of 10', async () => { @@ -165,7 +167,9 @@ describe('QueryLimitSelect', () => { elem.textContent?.trim(), ); - expect(actualLabels).toEqual(expectedLabels); + expect(actualLabels.slice(0, actualLabels.length - 1)).toEqual( + expectedLabels, + ); }); it('dispatches QUERY_EDITOR_SET_QUERY_LIMIT action on dropdown menu click', async () => { From 1f6f68695da34c7b58a12a273c27b39edfe72a2e Mon Sep 17 00:00:00 2001 From: Abhishek-kumar-samsung Date: Wed, 23 Apr 2025 11:17:45 +0530 Subject: [PATCH 6/6] Update QueryLimitSelect.test.tsx --- .../components/QueryLimitSelect/QueryLimitSelect.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx b/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx index 68aaf27ab0b0..3b992a6dd752 100644 --- a/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx +++ b/superset-frontend/src/SqlLab/components/QueryLimitSelect/QueryLimitSelect.test.tsx @@ -123,7 +123,9 @@ describe('QueryLimitSelect', () => { elem.textContent?.trim(), ); - expect(actualLabels).toEqual(expectedLabels); + expect(actualLabels.slice(0, actualLabels.length - 1)).toEqual( + expectedLabels, + ); }); it('renders dropdown select correctly when maxRow is less than 10', async () => {