diff --git a/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx b/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx index c5eed22ce57..f14084d7a03 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/dropdown/DropDownList.tsx @@ -18,6 +18,7 @@ import classNames from 'classnames'; import { isNil, lowerCase } from 'lodash'; import React, { FunctionComponent, useEffect, useState } from 'react'; +import { getCountBadge } from '../../utils/CommonUtils'; import { DropDownListItem, DropDownListProp } from './types'; const DropDownList: FunctionComponent = ({ @@ -28,9 +29,15 @@ const DropDownList: FunctionComponent = ({ showSearchBar = false, value, onSelect, + groupType = 'label', }: DropDownListProp) => { const [searchedList, setSearchedList] = useState(dropDownList); const [searchText, setSearchText] = useState(searchString); + const [activeTab, setActiveTab] = useState(1); + + const getTabClasses = (tab: number, activeTab: number) => { + return 'tw-gh-tabs' + (activeTab === tab ? ' active' : ''); + }; const handleListSearch = (text: string) => { setSearchText(text || ''); @@ -62,6 +69,17 @@ const DropDownList: FunctionComponent = ({ ); }; + const getActiveTab = () => { + let tab = 0; + listGroups.forEach((grp, i) => { + if (getSearchedListByGroup(grp).length === 0) { + tab = i + 1; + } + }); + + return tab; + }; + useEffect(() => { setSearchText(searchString); }, [searchString]); @@ -74,6 +92,10 @@ const DropDownList: FunctionComponent = ({ ); }, [searchText, dropDownList]); + useEffect(() => { + setActiveTab(getActiveTab() + 1); + }, [searchText]); + return ( <> {searchedList.length > 0 && ( @@ -108,28 +130,56 @@ const DropDownList: FunctionComponent = ({ )} + {groupType === 'tab' && ( +
+ {listGroups.map((grp, index) => { + return ( + + ); + })} +
+ )} +
{getSearchedListByGroup().map( (item: DropDownListItem, index: number) => getDropDownElement(item, index) )} - {listGroups.map((grp, index) => { - return ( -
- {getSearchedListByGroup(grp).length > 0 && ( - -
- {grp}{' '} -
-
- )} - {getSearchedListByGroup(grp).map( - (item: DropDownListItem, index: number) => - getDropDownElement(item, index) - )} -
- ); - })} + {groupType === 'label' ? ( + listGroups.map((grp, index) => { + return ( +
+ {getSearchedListByGroup(grp).length > 0 && ( + +
+ + {grp} + {' '} +
+
+ )} + {getSearchedListByGroup(grp).map( + (item: DropDownListItem, index: number) => + getDropDownElement(item, index) + )} +
+ ); + }) + ) : ( + <> + {getSearchedListByGroup(listGroups[activeTab - 1]).map( + (item: DropDownListItem, index: number) => + getDropDownElement(item, index) + )} + + )}
diff --git a/catalog-rest-service/src/main/resources/ui/src/components/dropdown/types.ts b/catalog-rest-service/src/main/resources/ui/src/components/dropdown/types.ts index 77921e5fdcf..4fe5e1d1a88 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/dropdown/types.ts +++ b/catalog-rest-service/src/main/resources/ui/src/components/dropdown/types.ts @@ -37,6 +37,7 @@ export type DropDownListItem = { string | number | boolean | undefined | Function | React.ReactElement >; +export type GroupType = 'label' | 'tab'; export type DropDownListProp = { dropDownList: Array; horzPosRight?: boolean; @@ -50,6 +51,7 @@ export type DropDownListProp = { value?: string ) => void; setIsOpen?: (value: boolean) => void; + groupType?: GroupType; }; export type DropDownProp = { diff --git a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/ManageTab.tsx b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/ManageTab.tsx index e37422a304c..195bd812a25 100644 --- a/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/ManageTab.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/components/my-data-details/ManageTab.tsx @@ -237,6 +237,7 @@ const ManageTab: FunctionComponent = ({ { }; export const pluralize = (count: number, noun: string, suffix = 's') => { - return `${count.toLocaleString()} ${noun}${ - count !== 1 && count !== 0 ? suffix : '' - }`; + const countString = count.toLocaleString(); + if (count !== 1 && count !== 0 && !noun.endsWith(suffix)) { + return `${countString} ${noun}${suffix}`; + } else { + if (noun.endsWith(suffix)) { + return `${countString} ${ + count > 1 ? noun : noun.slice(0, noun.length - 1) + }`; + } else { + return `${countString} ${noun}${count !== 1 ? suffix : ''}`; + } + } }; export const getUserTeams = (): Array => {