mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 18:48:35 +00:00 
			
		
		
		
	playwright improvement and remove usePaging hook from asynSelectListCompont (#23365)
(cherry picked from commit 131764db6b086bf804643c9d22745786e6539fd3)
This commit is contained in:
		
							parent
							
								
									c6f17ee84a
								
							
						
					
					
						commit
						d6a42b9698
					
				| @ -11,56 +11,12 @@ | |||||||
|  *  limitations under the License. |  *  limitations under the License. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import { expect, Page, test as base } from '@playwright/test'; | import { expect } from '@playwright/test'; | ||||||
| import { GlobalSettingOptions } from '../../constant/settings'; | import { GlobalSettingOptions } from '../../constant/settings'; | ||||||
| import { SidebarItem } from '../../constant/sidebar'; | import { SidebarItem } from '../../constant/sidebar'; | ||||||
| import { UserClass } from '../../support/user/UserClass'; |  | ||||||
| import { performAdminLogin } from '../../utils/admin'; |  | ||||||
| import { redirectToHomePage } from '../../utils/common'; | import { redirectToHomePage } from '../../utils/common'; | ||||||
| import { settingClick, sidebarClick } from '../../utils/sidebar'; | import { settingClick, sidebarClick } from '../../utils/sidebar'; | ||||||
| 
 | import { test } from '../fixtures/pages'; | ||||||
| const adminUser = new UserClass(); |  | ||||||
| const dataConsumerUser = new UserClass(); |  | ||||||
| 
 |  | ||||||
| const test = base.extend<{ |  | ||||||
|   page: Page; |  | ||||||
|   dataConsumerPage: Page; |  | ||||||
| }>({ |  | ||||||
|   page: async ({ browser }, use) => { |  | ||||||
|     const adminPage = await browser.newPage(); |  | ||||||
|     await adminUser.login(adminPage); |  | ||||||
|     await use(adminPage); |  | ||||||
|     await adminPage.close(); |  | ||||||
|   }, |  | ||||||
|   dataConsumerPage: async ({ browser }, use) => { |  | ||||||
|     const page = await browser.newPage(); |  | ||||||
|     await dataConsumerUser.login(page); |  | ||||||
|     await use(page); |  | ||||||
|     await page.close(); |  | ||||||
|   }, |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| base.beforeAll('Setup pre-requests', async ({ browser }) => { |  | ||||||
|   test.slow(true); |  | ||||||
| 
 |  | ||||||
|   const { apiContext, afterAction } = await performAdminLogin(browser); |  | ||||||
| 
 |  | ||||||
|   await adminUser.create(apiContext); |  | ||||||
|   await adminUser.setAdminRole(apiContext); |  | ||||||
|   await dataConsumerUser.create(apiContext); |  | ||||||
| 
 |  | ||||||
|   await afterAction(); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| base.afterAll('Cleanup', async ({ browser }) => { |  | ||||||
|   test.slow(true); |  | ||||||
| 
 |  | ||||||
|   const { apiContext, afterAction } = await performAdminLogin(browser); |  | ||||||
|   await adminUser.delete(apiContext); |  | ||||||
|   await dataConsumerUser.delete(apiContext); |  | ||||||
| 
 |  | ||||||
|   await afterAction(); |  | ||||||
| }); |  | ||||||
| 
 | 
 | ||||||
| test.describe('Online Users Feature', () => { | test.describe('Online Users Feature', () => { | ||||||
|   test.beforeEach(async ({ page }) => { |   test.beforeEach(async ({ page }) => { | ||||||
|  | |||||||
| @ -176,13 +176,4 @@ test.describe('User Profile Online Status', () => { | |||||||
|     await expect(onlineStatusBadge).toBeVisible(); |     await expect(onlineStatusBadge).toBeVisible(); | ||||||
|     await expect(onlineStatusBadge).toContainText(/Online now|Active recently/); |     await expect(onlineStatusBadge).toContainText(/Online now|Active recently/); | ||||||
|   }); |   }); | ||||||
| 
 |  | ||||||
|   test.afterAll('Cleanup', async ({ browser }) => { |  | ||||||
|     const { afterAction, apiContext } = await createNewPage(browser); |  | ||||||
| 
 |  | ||||||
|     // Delete test users
 |  | ||||||
|     await activeUser.delete(apiContext); |  | ||||||
|     await inactiveUser.delete(apiContext); |  | ||||||
|     await afterAction(); |  | ||||||
|   }); |  | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -14,10 +14,11 @@ import { Select, SelectProps, Space } from 'antd'; | |||||||
| import { AxiosError } from 'axios'; | import { AxiosError } from 'axios'; | ||||||
| import { debounce, isArray, isString } from 'lodash'; | import { debounce, isArray, isString } from 'lodash'; | ||||||
| import { FC, useCallback, useMemo, useRef, useState } from 'react'; | import { FC, useCallback, useMemo, useRef, useState } from 'react'; | ||||||
|  | import { PAGE_SIZE } from '../../../constants/constants'; | ||||||
| import { EntityType } from '../../../enums/entity.enum'; | import { EntityType } from '../../../enums/entity.enum'; | ||||||
| import { SearchIndex } from '../../../enums/search.enum'; | import { SearchIndex } from '../../../enums/search.enum'; | ||||||
| import { EntityReference } from '../../../generated/entity/type'; | import { EntityReference } from '../../../generated/entity/type'; | ||||||
| import { usePaging } from '../../../hooks/paging/usePaging'; | import { Paging } from '../../../generated/type/paging'; | ||||||
| import { searchQuery } from '../../../rest/searchAPI'; | import { searchQuery } from '../../../rest/searchAPI'; | ||||||
| import { | import { | ||||||
|   getEntityName, |   getEntityName, | ||||||
| @ -44,13 +45,8 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|   filterFqns = [], |   filterFqns = [], | ||||||
|   ...props |   ...props | ||||||
| }) => { | }) => { | ||||||
|   const { |   const [paging, setPaging] = useState<Paging>({} as Paging); | ||||||
|     currentPage, |   const [currentPage, setCurrentPage] = useState(1); | ||||||
|     handlePagingChange, |  | ||||||
|     handlePageChange, |  | ||||||
|     paging, |  | ||||||
|     pageSize, |  | ||||||
|   } = usePaging(); |  | ||||||
|   const [isLoading, setIsLoading] = useState(false); |   const [isLoading, setIsLoading] = useState(false); | ||||||
|   const [hasContentLoading, setHasContentLoading] = useState(false); |   const [hasContentLoading, setHasContentLoading] = useState(false); | ||||||
|   const [options, setOptions] = useState<DataAssetOption[]>( |   const [options, setOptions] = useState<DataAssetOption[]>( | ||||||
| @ -67,7 +63,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|       const dataAssetsResponse = await searchQuery({ |       const dataAssetsResponse = await searchQuery({ | ||||||
|         query: searchQueryParam ? `*${searchQueryParam}*` : '*', |         query: searchQueryParam ? `*${searchQueryParam}*` : '*', | ||||||
|         pageNumber: page, |         pageNumber: page, | ||||||
|         pageSize: pageSize, |         pageSize: PAGE_SIZE, | ||||||
|         searchIndex: searchIndex, |         searchIndex: searchIndex, | ||||||
|         // Filter out bots from user search
 |         // Filter out bots from user search
 | ||||||
|         queryFilter: { |         queryFilter: { | ||||||
| @ -103,7 +99,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|         }, |         }, | ||||||
|       }; |       }; | ||||||
|     }, |     }, | ||||||
|     [pageSize] |     [searchIndex] | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   const loadOptions = useCallback( |   const loadOptions = useCallback( | ||||||
| @ -113,16 +109,16 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|       try { |       try { | ||||||
|         const res = await fetchOptions(value, 1); |         const res = await fetchOptions(value, 1); | ||||||
|         setOptions(res.data); |         setOptions(res.data); | ||||||
|         handlePagingChange(res.paging); |  | ||||||
|         setSearchValue(value); |         setSearchValue(value); | ||||||
|         handlePageChange(1); |         setPaging(res.paging); | ||||||
|  |         setCurrentPage(1); | ||||||
|       } catch (error) { |       } catch (error) { | ||||||
|         showErrorToast(error as AxiosError); |         showErrorToast(error as AxiosError); | ||||||
|       } finally { |       } finally { | ||||||
|         setIsLoading(false); |         setIsLoading(false); | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     [fetchOptions, handlePagingChange, handlePageChange] |     [fetchOptions] | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   const optionList = useMemo(() => { |   const optionList = useMemo(() => { | ||||||
| @ -192,8 +188,8 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|           setHasContentLoading(true); |           setHasContentLoading(true); | ||||||
|           const res = await fetchOptions(searchValue, currentPage + 1); |           const res = await fetchOptions(searchValue, currentPage + 1); | ||||||
|           setOptions((prev) => [...prev, ...res.data]); |           setOptions((prev) => [...prev, ...res.data]); | ||||||
|           handlePagingChange(res.paging); |           setPaging(res.paging); | ||||||
|           handlePageChange((prev) => prev + 1); |           setCurrentPage((prev) => prev + 1); | ||||||
|         } catch (error) { |         } catch (error) { | ||||||
|           showErrorToast(error as AxiosError); |           showErrorToast(error as AxiosError); | ||||||
|         } finally { |         } finally { | ||||||
| @ -230,6 +226,16 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  |   const handleBlur = useCallback(() => { | ||||||
|  |     setCurrentPage(1); | ||||||
|  |     setSearchValue(''); | ||||||
|  |     setOptions([]); | ||||||
|  |   }, []); | ||||||
|  | 
 | ||||||
|  |   const handleFocus = useCallback(() => { | ||||||
|  |     loadOptions(''); | ||||||
|  |   }, []); | ||||||
|  | 
 | ||||||
|   const internalValue = useMemo(() => { |   const internalValue = useMemo(() => { | ||||||
|     if (isString(selectedValue) || isArray(selectedValue)) { |     if (isString(selectedValue) || isArray(selectedValue)) { | ||||||
|       return selectedValue as string | string[]; |       return selectedValue as string | string[]; | ||||||
| @ -253,13 +259,9 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|       options={optionList} |       options={optionList} | ||||||
|       style={{ width: '100%' }} |       style={{ width: '100%' }} | ||||||
|       value={internalValue} |       value={internalValue} | ||||||
|       onBlur={() => { |       onBlur={handleBlur} | ||||||
|         handlePageChange(1); |  | ||||||
|         setSearchValue(''); |  | ||||||
|         setOptions([]); |  | ||||||
|       }} |  | ||||||
|       onChange={handleChange} |       onChange={handleChange} | ||||||
|       onFocus={() => loadOptions('')} |       onFocus={handleFocus} | ||||||
|       onPopupScroll={onScroll} |       onPopupScroll={onScroll} | ||||||
|       onSearch={debounceFetcher} |       onSearch={debounceFetcher} | ||||||
|       {...props} |       {...props} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ashish Gupta
						Ashish Gupta