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;
|
id?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
value?: DataAssetOption | DataAssetOption[] | string | string[];
|
||||||
debounceTimeout?: number;
|
debounceTimeout?: number;
|
||||||
defaultValue?: string[];
|
defaultValue?: string[];
|
||||||
initialOptions?: DataAssetOption[];
|
initialOptions?: DataAssetOption[];
|
||||||
|
@ -214,6 +214,30 @@ describe('DataAssetAsyncSelectList', () => {
|
|||||||
expect(screen.getByText(placeholder)).toBeInTheDocument();
|
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 () => {
|
it("should render the default value when there's a value and initial option", async () => {
|
||||||
const defaultValue = ['1'];
|
const defaultValue = ['1'];
|
||||||
const initialOptions: DataAssetOption[] = [
|
const initialOptions: DataAssetOption[] = [
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
import { Select, SelectProps, Space } from 'antd';
|
import { Select, SelectProps, Space } from 'antd';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { debounce } from 'lodash';
|
import { debounce, isArray, isString } from 'lodash';
|
||||||
import React, { FC, useCallback, useMemo, useRef, useState } from 'react';
|
import React, { FC, useCallback, useMemo, useRef, useState } from 'react';
|
||||||
import { PAGE_SIZE } from '../../../constants/constants';
|
import { PAGE_SIZE } from '../../../constants/constants';
|
||||||
import { EntityType } from '../../../enums/entity.enum';
|
import { EntityType } from '../../../enums/entity.enum';
|
||||||
@ -40,6 +40,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({
|
|||||||
debounceTimeout = 800,
|
debounceTimeout = 800,
|
||||||
initialOptions,
|
initialOptions,
|
||||||
searchIndex = SearchIndex.ALL,
|
searchIndex = SearchIndex.ALL,
|
||||||
|
value: selectedValue,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
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 (
|
return (
|
||||||
<Select
|
<Select
|
||||||
|
allowClear
|
||||||
autoFocus
|
autoFocus
|
||||||
showSearch
|
showSearch
|
||||||
data-testid="asset-select-list"
|
data-testid="asset-select-list"
|
||||||
@ -228,6 +239,7 @@ const DataAssetAsyncSelectList: FC<DataAssetAsyncSelectListProps> = ({
|
|||||||
optionLabelProp="displayName"
|
optionLabelProp="displayName"
|
||||||
options={optionList}
|
options={optionList}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
|
value={internalValue}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
handlePageChange(1);
|
handlePageChange(1);
|
||||||
setSearchValue('');
|
setSearchValue('');
|
||||||
|
@ -738,7 +738,9 @@ export const PropertyValue: FC<PropertyValueProps> = ({
|
|||||||
<Button
|
<Button
|
||||||
className="entity-button flex-center p-0 m--ml-1"
|
className="entity-button flex-center p-0 m--ml-1"
|
||||||
icon={
|
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) ? (
|
{['user', 'team'].includes(item.type) ? (
|
||||||
<ProfilePicture
|
<ProfilePicture
|
||||||
className="d-flex"
|
className="d-flex"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user