From 096a08ce5789eb252a08e7e80ebb8bffe8c902f0 Mon Sep 17 00:00:00 2001 From: Sachin Chaurasiya Date: Fri, 20 Oct 2023 20:02:30 +0530 Subject: [PATCH] chore(ui): add filter classifications option in tags container (#13668) --- .../TagsContainerV2.interface.ts | 1 + .../Tag/TagsContainerV2/TagsContainerV2.tsx | 8 +++-- .../resources/ui/src/constants/constants.ts | 2 ++ .../main/resources/ui/src/utils/TagsUtils.tsx | 34 +++++++++++++------ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.interface.ts b/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.interface.ts index c5fe002c7aa..a5fbfcc285f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.interface.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.interface.ts @@ -30,6 +30,7 @@ export type TagsContainerV2Props = { children?: ReactElement; displayType?: DisplayType; layoutType?: LayoutType; + filterClassifications?: string[]; onSelectionChange?: (selectedTags: EntityTags[]) => Promise; onThreadLinkSelect?: (value: string, threadType?: ThreadType) => void; }; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.tsx index 706fcc36ec6..cce2d62a136 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Tag/TagsContainerV2/TagsContainerV2.tsx @@ -22,7 +22,10 @@ import { ReactComponent as IconComments } from '../../../assets/svg/comment.svg' import { ReactComponent as EditIcon } from '../../../assets/svg/edit-new.svg'; import { ReactComponent as IconRequest } from '../../../assets/svg/request-icon.svg'; import { TableTagsProps } from '../../../components/TableTags/TableTags.interface'; -import { DE_ACTIVE_COLOR } from '../../../constants/constants'; +import { + DE_ACTIVE_COLOR, + KNOWLEDGE_CENTER_CLASSIFICATION, +} from '../../../constants/constants'; import { TAG_CONSTANT, TAG_START_WITH } from '../../../constants/Tag.constants'; import { SearchIndex } from '../../../enums/search.enum'; import { GlossaryTerm } from '../../../generated/entity/data/glossaryTerm'; @@ -63,6 +66,7 @@ const TagsContainerV2 = ({ onSelectionChange, onThreadLinkSelect, children, + filterClassifications = [KNOWLEDGE_CENTER_CLASSIFICATION], }: TagsContainerV2Props) => { const history = useHistory(); const [form] = Form.useForm(); @@ -131,7 +135,7 @@ const TagsContainerV2 = ({ const fetchAPI = useCallback( (searchValue: string, page: number) => { if (tagType === TagSource.Classification) { - return fetchTagsElasticSearch(searchValue, page); + return fetchTagsElasticSearch(searchValue, page, filterClassifications); } else { return fetchGlossaryList(searchValue, page); } diff --git a/openmetadata-ui/src/main/resources/ui/src/constants/constants.ts b/openmetadata-ui/src/main/resources/ui/src/constants/constants.ts index ac51042c7ad..49d2f6f8227 100644 --- a/openmetadata-ui/src/main/resources/ui/src/constants/constants.ts +++ b/openmetadata-ui/src/main/resources/ui/src/constants/constants.ts @@ -840,3 +840,5 @@ export const ICON_DIMENSION = { export const COMMON_ICON_STYLES: CSSProperties = { verticalAlign: 'middle', }; + +export const KNOWLEDGE_CENTER_CLASSIFICATION = 'KnowledgeCenter'; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/TagsUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/TagsUtils.tsx index 0c5fe2fedc4..f22051f371a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/TagsUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/TagsUtils.tsx @@ -295,15 +295,18 @@ export const tagRender = (customTagProps: CustomTagProps) => { ); }; +type ResultType = { + label: string; + value: string; + data: Tag; +}; + export const fetchTagsElasticSearch = async ( searchText: string, - page: number + page: number, + filterClassifications?: string[] ): Promise<{ - data: { - label: string; - value: string; - data: Tag; - }[]; + data: ResultType[]; paging: Paging; }> => { const res = await searchQuery({ @@ -316,11 +319,20 @@ export const fetchTagsElasticSearch = async ( }); return { - data: res.hits.hits.map(({ _source }) => ({ - label: _source.fullyQualifiedName ?? '', - value: _source.fullyQualifiedName ?? '', - data: _source, - })), + data: res.hits.hits.reduce((result: ResultType[], { _source }) => { + const classificationName = + _source.classification?.fullyQualifiedName ?? ''; + + if (!filterClassifications?.includes(classificationName)) { + result.push({ + label: _source.fullyQualifiedName ?? '', + value: _source.fullyQualifiedName ?? '', + data: _source, + }); + } + + return result; + }, []), paging: { total: res.hits.total.value, },