mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-27 10:26:09 +00:00
minor: add value prop in data asset async select list (#16169)
* minor: add value prop in data asset async select list * fix: icon
This commit is contained in:
parent
5002527c19
commit
5ab97b23e3
@ -30,6 +30,7 @@ export interface DataAssetAsyncSelectListProps {
|
||||
id?: string;
|
||||
className?: string;
|
||||
placeholder?: string;
|
||||
value?: DataAssetOption | DataAssetOption[] | string | string[];
|
||||
debounceTimeout?: number;
|
||||
defaultValue?: string[];
|
||||
initialOptions?: DataAssetOption[];
|
||||
|
@ -214,6 +214,30 @@ describe('DataAssetAsyncSelectList', () => {
|
||||
expect(screen.getByText(placeholder)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should render the default value when there's a default value and initial option", async () => {
|
||||
const defaultValue = ['1'];
|
||||
const initialOptions: DataAssetOption[] = [
|
||||
{
|
||||
displayName: 'Test',
|
||||
label: 'Test',
|
||||
reference: { id: '1', type: 'table' },
|
||||
value: '1',
|
||||
},
|
||||
];
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<DataAssetAsyncSelectList
|
||||
defaultValue={defaultValue}
|
||||
initialOptions={initialOptions}
|
||||
mode="multiple"
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
expect(screen.getByText('Test')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should render the default value when there's a value and initial option", async () => {
|
||||
const defaultValue = ['1'];
|
||||
const initialOptions: DataAssetOption[] = [
|
||||
|
@ -12,7 +12,7 @@
|
||||
*/
|
||||
import { Select, SelectProps, Space } from 'antd';
|
||||
import { AxiosError } from 'axios';
|
||||
import { debounce } from 'lodash';
|
||||
import { debounce, isArray, isString } from 'lodash';
|
||||
import React, { FC, useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { PAGE_SIZE } from '../../../constants/constants';
|
||||
import { EntityType } from '../../../enums/entity.enum';
|
||||
@ -40,6 +40,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({
|
||||
debounceTimeout = 800,
|
||||
initialOptions,
|
||||
searchIndex = SearchIndex.ALL,
|
||||
value: selectedValue,
|
||||
...props
|
||||
}) => {
|
||||
const {
|
||||
@ -216,8 +217,18 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const internalValue = useMemo(() => {
|
||||
if (isString(selectedValue) || isArray(selectedValue)) {
|
||||
return selectedValue as string | string[];
|
||||
}
|
||||
const selectedOption = selectedValue as DataAssetOption;
|
||||
|
||||
return selectedOption?.value as string;
|
||||
}, [mode, selectedValue]);
|
||||
|
||||
return (
|
||||
<Select
|
||||
allowClear
|
||||
autoFocus
|
||||
showSearch
|
||||
data-testid="asset-select-list"
|
||||
@ -228,6 +239,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({
|
||||
optionLabelProp="displayName"
|
||||
options={optionList}
|
||||
style={{ width: '100%' }}
|
||||
value={internalValue}
|
||||
onBlur={() => {
|
||||
handlePageChange(1);
|
||||
setSearchValue('');
|
||||
|
@ -738,7 +738,9 @@ export const PropertyValue: FC<PropertyValueProps> = ({
|
||||
<Button
|
||||
className="entity-button flex-center p-0 m--ml-1"
|
||||
icon={
|
||||
<div className="entity-button-icon m-r-xs">
|
||||
<div
|
||||
className="entity-button-icon m-r-xs"
|
||||
style={{ width: '18px', display: 'flex' }}>
|
||||
{['user', 'team'].includes(item.type) ? (
|
||||
<ProfilePicture
|
||||
className="d-flex"
|
||||
|
Loading…
x
Reference in New Issue
Block a user