Skip to content

Commit

Permalink
chore(ui): add initialOptions prop in tag suggestion component (#14085
Browse files Browse the repository at this point in the history
)

* chore(ui): add initialData prop in tag suggestion component

* address comment
  • Loading branch information
Sachin-chaurasiya authored Nov 23, 2023
1 parent c95de19 commit 631145d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface AsyncSelectListProps {
placeholder?: string;
debounceTimeout?: number;
defaultValue?: string[];
initialData?: SelectOption[];
initialOptions?: SelectOption[];
onChange?: (option: DefaultOptionType | DefaultOptionType[]) => void;
fetchOptions: (
search: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AsyncSelectList: FC<AsyncSelectListProps> = ({
onChange,
fetchOptions,
debounceTimeout = 800,
initialData,
initialOptions,
className,
...props
}) => {
Expand All @@ -52,7 +52,7 @@ const AsyncSelectList: FC<AsyncSelectListProps> = ({
const [searchValue, setSearchValue] = useState<string>('');
const [paging, setPaging] = useState<Paging>({} as Paging);
const [currentPage, setCurrentPage] = useState(1);
const selectedTagsRef = useRef<SelectOption[]>(initialData ?? []);
const selectedTagsRef = useRef<SelectOption[]>(initialOptions ?? []);

const loadOptions = useCallback(
async (value: string) => {
Expand Down Expand Up @@ -204,7 +204,7 @@ const AsyncSelectList: FC<AsyncSelectListProps> = ({
data ?? {
value,
label: value,
data: initialData?.find((item) => item.value === value)?.data,
data: initialOptions?.find((item) => item.value === value)?.data,
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const TagSelectForm = ({
<AsyncSelectList
className="tag-select-box"
fetchOptions={fetchApi}
initialData={tagData}
initialOptions={tagData}
mode="multiple"
placeholder={placeholder}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { isArray, isEmpty } from 'lodash';
import { EntityTags } from 'Models';
import React, { useMemo } from 'react';
import AsyncSelectList from '../../../components/AsyncSelectList/AsyncSelectList';
import { SelectOption } from '../../../components/AsyncSelectList/AsyncSelectList.interface';
import { TagSource } from '../../../generated/entity/data/container';
import { TagLabel } from '../../../generated/type/tagLabel';
import {
Expand All @@ -28,13 +29,15 @@ export interface TagSuggestionProps {
placeholder?: string;
tagType?: TagSource;
value?: TagLabel[];
initialOptions?: SelectOption[];
onChange?: (newTags: TagLabel[]) => void;
}

const TagSuggestion: React.FC<TagSuggestionProps> = ({
onChange,
value,
placeholder,
initialOptions,
tagType = TagSource.Classification,
}) => {
const isGlossaryType = useMemo(
Expand Down Expand Up @@ -82,6 +85,7 @@ const TagSuggestion: React.FC<TagSuggestionProps> = ({
<AsyncSelectList
defaultValue={value?.map((item) => item.tagFQN) || []}
fetchOptions={isGlossaryType ? fetchGlossaryList : fetchTagsElasticSearch}
initialOptions={initialOptions}
mode="multiple"
placeholder={
placeholder ??
Expand Down

0 comments on commit 631145d

Please sign in to comment.