mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-30 18:17:53 +00:00 
			
		
		
		
	pass entity reference in autocomplete widget (#14423)
This commit is contained in:
		
							parent
							
								
									78bd8f98b5
								
							
						
					
					
						commit
						d3a75652cf
					
				| @ -21,6 +21,13 @@ jest.mock('../../rest/searchAPI'); | |||||||
| jest.mock('../../utils/TableUtils'); | jest.mock('../../utils/TableUtils'); | ||||||
| jest.mock('../../utils/EntityUtils', () => ({ | jest.mock('../../utils/EntityUtils', () => ({ | ||||||
|   getEntityName: jest.fn().mockReturnValue('Test'), |   getEntityName: jest.fn().mockReturnValue('Test'), | ||||||
|  |   getEntityReferenceFromEntity: jest | ||||||
|  |     .fn() | ||||||
|  |     .mockImplementation((entity, type) => ({ | ||||||
|  |       ...entity, | ||||||
|  |       entityType: undefined, | ||||||
|  |       type: type, | ||||||
|  |     })), | ||||||
| })); | })); | ||||||
| jest.mock('../common/ProfilePicture/ProfilePicture', () => { | jest.mock('../common/ProfilePicture/ProfilePicture', () => { | ||||||
|   return jest |   return jest | ||||||
| @ -68,6 +75,9 @@ const mockSearchAPIResponse = { | |||||||
|             name: 'test 1', |             name: 'test 1', | ||||||
|             fullyQualifiedName: 'test-1', |             fullyQualifiedName: 'test-1', | ||||||
|             entityType: 'table', |             entityType: 'table', | ||||||
|  |             href: '', | ||||||
|  |             description: '', | ||||||
|  |             deleted: false, | ||||||
|           }, |           }, | ||||||
|         }, |         }, | ||||||
|         { |         { | ||||||
| @ -76,6 +86,9 @@ const mockSearchAPIResponse = { | |||||||
|             name: 'test 2', |             name: 'test 2', | ||||||
|             fullyQualifiedName: 'test-2', |             fullyQualifiedName: 'test-2', | ||||||
|             entityType: 'table', |             entityType: 'table', | ||||||
|  |             href: '', | ||||||
|  |             description: '', | ||||||
|  |             deleted: false, | ||||||
|           }, |           }, | ||||||
|         }, |         }, | ||||||
|       ], |       ], | ||||||
| @ -135,7 +148,10 @@ describe('DataAssetAsyncSelectList', () => { | |||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const { container } = render( |     const { container } = render( | ||||||
|       <DataAssetAsyncSelectList searchIndex={SearchIndex.USER} /> |       <DataAssetAsyncSelectList | ||||||
|  |         mode="multiple" | ||||||
|  |         searchIndex={SearchIndex.USER} | ||||||
|  |       /> | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     await act(async () => { |     await act(async () => { | ||||||
| @ -153,8 +169,16 @@ describe('DataAssetAsyncSelectList', () => { | |||||||
|       { |       { | ||||||
|         displayName: 'Test', |         displayName: 'Test', | ||||||
|         label: 'Test', |         label: 'Test', | ||||||
|         reference: { id: '1', type: 'table' }, |         reference: { | ||||||
|         value: '1', |           id: '1', | ||||||
|  |           type: 'table', | ||||||
|  |           name: 'test 1', | ||||||
|  |           deleted: false, | ||||||
|  |           description: '', | ||||||
|  |           fullyQualifiedName: 'test-1', | ||||||
|  |           href: '', | ||||||
|  |         }, | ||||||
|  |         value: 'test-1', | ||||||
|       }, |       }, | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
| @ -180,7 +204,7 @@ describe('DataAssetAsyncSelectList', () => { | |||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const option = screen.getByTestId('option-1'); |     const option = screen.getByTestId('option-test-1'); | ||||||
| 
 | 
 | ||||||
|     await act(async () => { |     await act(async () => { | ||||||
|       fireEvent.click(option); |       fireEvent.click(option); | ||||||
|  | |||||||
| @ -16,10 +16,15 @@ import { debounce } from 'lodash'; | |||||||
| import React, { FC, useCallback, useMemo, useRef, useState } from 'react'; | import React, { FC, useCallback, useMemo, useRef, useState } from 'react'; | ||||||
| import Loader from '../../components/Loader/Loader'; | import Loader from '../../components/Loader/Loader'; | ||||||
| import { PAGE_SIZE } from '../../constants/constants'; | import { PAGE_SIZE } from '../../constants/constants'; | ||||||
|  | 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 { usePaging } from '../../hooks/paging/usePaging'; | import { usePaging } from '../../hooks/paging/usePaging'; | ||||||
| import { searchQuery } from '../../rest/searchAPI'; | import { searchQuery } from '../../rest/searchAPI'; | ||||||
| import { getEntityName } from '../../utils/EntityUtils'; | import { | ||||||
|  |   getEntityName, | ||||||
|  |   getEntityReferenceFromEntity, | ||||||
|  | } from '../../utils/EntityUtils'; | ||||||
| import { getEntityIcon } from '../../utils/TableUtils'; | import { getEntityIcon } from '../../utils/TableUtils'; | ||||||
| import { showErrorToast } from '../../utils/ToastUtils'; | import { showErrorToast } from '../../utils/ToastUtils'; | ||||||
| import ProfilePicture from '../common/ProfilePicture/ProfilePicture'; | import ProfilePicture from '../common/ProfilePicture/ProfilePicture'; | ||||||
| @ -70,13 +75,16 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
| 
 | 
 | ||||||
|       const dataAssets = hits.map(({ _source }) => { |       const dataAssets = hits.map(({ _source }) => { | ||||||
|         const entityName = getEntityName(_source); |         const entityName = getEntityName(_source); | ||||||
|  |         const entityRef = getEntityReferenceFromEntity( | ||||||
|  |           _source as EntityReference, | ||||||
|  |           _source.entityType as EntityType | ||||||
|  |         ); | ||||||
| 
 | 
 | ||||||
|         return { |         return { | ||||||
|           label: entityName, |           label: entityName, | ||||||
|           value: _source.id, |           value: _source.fullyQualifiedName, | ||||||
|           reference: { |           reference: { | ||||||
|             id: _source.id ?? '', |             ...entityRef, | ||||||
|             type: _source.entityType, |  | ||||||
|           }, |           }, | ||||||
|           displayName: entityName, |           displayName: entityName, | ||||||
|           name: _source.name, |           name: _source.name, | ||||||
| @ -184,6 +192,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   const handleChange: SelectProps['onChange'] = (values: string[], options) => { |   const handleChange: SelectProps['onChange'] = (values: string[], options) => { | ||||||
|  |     if (mode) { | ||||||
|       const selectedOptions = (options as DataAssetOption[]).reduce( |       const selectedOptions = (options as DataAssetOption[]).reduce( | ||||||
|         (acc, option) => { |         (acc, option) => { | ||||||
|           if (values.includes(option.value as string)) { |           if (values.includes(option.value as string)) { | ||||||
| @ -197,6 +206,9 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({ | |||||||
| 
 | 
 | ||||||
|       selectedDataAssetsRef.current = selectedOptions; |       selectedDataAssetsRef.current = selectedOptions; | ||||||
|       onChange?.(selectedOptions); |       onChange?.(selectedOptions); | ||||||
|  |     } else { | ||||||
|  |       onChange?.(options as DataAssetOption); | ||||||
|  |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|  | |||||||
| @ -16,16 +16,20 @@ import { SearchIndex } from '../../enums/search.enum'; | |||||||
| import DataAssetAsyncSelectList from '../DataAssetAsyncSelectList/DataAssetAsyncSelectList'; | import DataAssetAsyncSelectList from '../DataAssetAsyncSelectList/DataAssetAsyncSelectList'; | ||||||
| import { DataAssetOption } from '../DataAssetAsyncSelectList/DataAssetAsyncSelectList.interface'; | import { DataAssetOption } from '../DataAssetAsyncSelectList/DataAssetAsyncSelectList.interface'; | ||||||
| 
 | 
 | ||||||
| const AsyncSelectWidget = ({ onChange, schema }: WidgetProps) => { | const AsyncSelectWidget = ({ onChange, schema, ...props }: WidgetProps) => { | ||||||
|   const handleChange = (value: DataAssetOption | DataAssetOption[]) => { |   const handleChange = (value: DataAssetOption | DataAssetOption[]) => { | ||||||
|  |     if (Array.isArray(value)) { | ||||||
|       const data = value.map((item: DataAssetOption) => item.reference); |       const data = value.map((item: DataAssetOption) => item.reference); | ||||||
|       onChange(data); |       onChange(data); | ||||||
|  |     } else { | ||||||
|  |       const data = value.reference; | ||||||
|  |       onChange(data); | ||||||
|  |     } | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   return ( |   return ( | ||||||
|     <DataAssetAsyncSelectList |     <DataAssetAsyncSelectList | ||||||
|       defaultValue={schema.value} |       defaultValue={props.value.fullyQualifiedName ?? ''} | ||||||
|       mode="multiple" |  | ||||||
|       placeholder={schema.placeholder ?? ''} |       placeholder={schema.placeholder ?? ''} | ||||||
|       searchIndex={schema?.autoCompleteType ?? SearchIndex.TABLE} |       searchIndex={schema?.autoCompleteType ?? SearchIndex.TABLE} | ||||||
|       onChange={handleChange} |       onChange={handleChange} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 karanh37
						karanh37