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