mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-03 14:13:06 +00:00
fix(ui): owner search issue and show total count on load (#5932)
This commit is contained in:
parent
44fa4712d7
commit
27467a618a
@ -180,13 +180,11 @@ const ManageTab: FunctionComponent<ManageProps> = ({
|
|||||||
const getOwnerSuggestion = useCallback(
|
const getOwnerSuggestion = useCallback(
|
||||||
(qSearchText = '') => {
|
(qSearchText = '') => {
|
||||||
setIsUserLoading(true);
|
setIsUserLoading(true);
|
||||||
|
setListOwners([]);
|
||||||
suggestFormattedUsersAndTeams(qSearchText)
|
suggestFormattedUsersAndTeams(qSearchText)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const { users, teams } = res;
|
const { users, teams } = res;
|
||||||
setListOwners(getOwnerList(users, teams));
|
setListOwners(getOwnerList(users, teams, true));
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setListOwners([]);
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setIsUserLoading(false);
|
setIsUserLoading(false);
|
||||||
|
@ -12,15 +12,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { isUndefined, lowerCase } from 'lodash';
|
import { isUndefined, lowerCase } from 'lodash';
|
||||||
import React, { Fragment } from 'react';
|
import React, { Fragment, useEffect, useState } from 'react';
|
||||||
|
import { getTeams } from '../../../axiosAPIs/teamsAPI';
|
||||||
|
import { getUsers } from '../../../axiosAPIs/userAPI';
|
||||||
import { ADMIN_ONLY_ACCESSIBLE_SECTION } from '../../../enums/common.enum';
|
import { ADMIN_ONLY_ACCESSIBLE_SECTION } from '../../../enums/common.enum';
|
||||||
import { Operation } from '../../../generated/entity/policies/policy';
|
import { Operation } from '../../../generated/entity/policies/policy';
|
||||||
import { EntityReference } from '../../../generated/type/entityReference';
|
import { EntityReference } from '../../../generated/type/entityReference';
|
||||||
import { useAuth } from '../../../hooks/authHooks';
|
import { useAuth } from '../../../hooks/authHooks';
|
||||||
|
import jsonData from '../../../jsons/en';
|
||||||
import { hasEditAccess } from '../../../utils/CommonUtils';
|
import { hasEditAccess } from '../../../utils/CommonUtils';
|
||||||
import { getTitleCase } from '../../../utils/EntityUtils';
|
import { getTitleCase } from '../../../utils/EntityUtils';
|
||||||
|
import { showErrorToast } from '../../../utils/ToastUtils';
|
||||||
import { isCurrentUserAdmin } from '../../../utils/UserDataUtils';
|
import { isCurrentUserAdmin } from '../../../utils/UserDataUtils';
|
||||||
import { Button } from '../../buttons/Button/Button';
|
import { Button } from '../../buttons/Button/Button';
|
||||||
import DropDownList from '../../dropdown/DropDownList';
|
import DropDownList from '../../dropdown/DropDownList';
|
||||||
@ -78,11 +83,50 @@ const OwnerWidget = ({
|
|||||||
handleSearchOwnerDropdown,
|
handleSearchOwnerDropdown,
|
||||||
}: OwnerWidgetProps) => {
|
}: OwnerWidgetProps) => {
|
||||||
const { userPermissions, isAdminUser } = useAuth();
|
const { userPermissions, isAdminUser } = useAuth();
|
||||||
|
const [totalUsersCount, setTotalUsersCount] = useState<number>(0);
|
||||||
|
const [totalTeamsCount, setTotalTeamsCount] = useState<number>(0);
|
||||||
const getOwnerGroup = () => {
|
const getOwnerGroup = () => {
|
||||||
return allowTeamOwner ? ['Teams', 'Users'] : ['Users'];
|
return allowTeamOwner ? ['Teams', 'Users'] : ['Users'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchTeamsAndUsersCount = () => {
|
||||||
|
getUsers('', 0)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.data) {
|
||||||
|
setTotalUsersCount(res.data.paging.total);
|
||||||
|
} else {
|
||||||
|
throw jsonData['api-error-messages']['unexpected-server-response'];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: AxiosError) => {
|
||||||
|
showErrorToast(
|
||||||
|
err,
|
||||||
|
jsonData['api-error-messages']['unexpected-server-response']
|
||||||
|
);
|
||||||
|
setTotalTeamsCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
getTeams('', 0)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.data) {
|
||||||
|
setTotalTeamsCount(res.data.paging.total);
|
||||||
|
} else {
|
||||||
|
throw jsonData['api-error-messages']['unexpected-server-response'];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: AxiosError) => {
|
||||||
|
showErrorToast(
|
||||||
|
err,
|
||||||
|
jsonData['api-error-messages']['unexpected-server-response']
|
||||||
|
);
|
||||||
|
setTotalTeamsCount(0);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchTeamsAndUsersCount();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const getOwnerUpdateLoader = () => {
|
const getOwnerUpdateLoader = () => {
|
||||||
switch (statusOwner) {
|
switch (statusOwner) {
|
||||||
case 'waiting':
|
case 'waiting':
|
||||||
@ -128,6 +172,16 @@ const OwnerWidget = ({
|
|||||||
? 'The owner of the team can manage the team by adding or removing users. Add or update Team ownership here'
|
? 'The owner of the team can manage the team by adding or removing users. Add or update Team ownership here'
|
||||||
: `Add or update ${getTitleCase(entityType)} ownership here`;
|
: `Add or update ${getTitleCase(entityType)} ownership here`;
|
||||||
|
|
||||||
|
const handleTotalCountForGroup = (groupName: string) => {
|
||||||
|
if (lowerCase(groupName) === 'users') {
|
||||||
|
return totalUsersCount;
|
||||||
|
} else if (lowerCase(groupName) === 'teams') {
|
||||||
|
return totalTeamsCount;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div className="tw-mt-1 tw-bg-white">
|
<div className="tw-mt-1 tw-bg-white">
|
||||||
@ -177,6 +231,7 @@ const OwnerWidget = ({
|
|||||||
showEmptyList
|
showEmptyList
|
||||||
controlledSearchStr={ownerSearchText}
|
controlledSearchStr={ownerSearchText}
|
||||||
dropDownList={listOwners}
|
dropDownList={listOwners}
|
||||||
|
getTotalCountForGroup={handleTotalCountForGroup}
|
||||||
groupType="tab"
|
groupType="tab"
|
||||||
isLoading={isListLoading}
|
isLoading={isListLoading}
|
||||||
listGroups={getOwnerGroup()}
|
listGroups={getOwnerGroup()}
|
||||||
|
@ -36,6 +36,7 @@ const DropDownList: FunctionComponent<DropDownListProp> = ({
|
|||||||
domPosition,
|
domPosition,
|
||||||
className = '',
|
className = '',
|
||||||
widthClass = 'tw-w-52',
|
widthClass = 'tw-w-52',
|
||||||
|
getTotalCountForGroup,
|
||||||
}: DropDownListProp) => {
|
}: DropDownListProp) => {
|
||||||
const { height: windowHeight } = useWindowDimensions();
|
const { height: windowHeight } = useWindowDimensions();
|
||||||
const isMounted = useRef<boolean>(false);
|
const isMounted = useRef<boolean>(false);
|
||||||
@ -89,6 +90,17 @@ const DropDownList: FunctionComponent<DropDownListProp> = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getGroupCount = (groupName?: string): number => {
|
||||||
|
let count = 0;
|
||||||
|
if (controlledSearchStr === '' && getTotalCountForGroup && groupName) {
|
||||||
|
count = getTotalCountForGroup(groupName);
|
||||||
|
} else {
|
||||||
|
count = getSearchedListByGroup(groupName)?.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
|
||||||
const getDropDownElement = (item: DropDownListItem, index: number) => {
|
const getDropDownElement = (item: DropDownListItem, index: number) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -278,7 +290,7 @@ const DropDownList: FunctionComponent<DropDownListProp> = ({
|
|||||||
onClick={() => setActiveTab(index + 1)}>
|
onClick={() => setActiveTab(index + 1)}>
|
||||||
{grp}
|
{grp}
|
||||||
{getCountBadge(
|
{getCountBadge(
|
||||||
getSearchedListByGroup(grp).length,
|
getGroupCount(grp),
|
||||||
'',
|
'',
|
||||||
activeTab === index + 1
|
activeTab === index + 1
|
||||||
)}
|
)}
|
||||||
|
@ -59,6 +59,7 @@ export type DropDownListProp = {
|
|||||||
domPosition?: DOMRect;
|
domPosition?: DOMRect;
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
widthClass?: string;
|
widthClass?: string;
|
||||||
|
getTotalCountForGroup?: (groupName: string) => number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DropDownProp = {
|
export type DropDownProp = {
|
||||||
|
@ -16,9 +16,16 @@ import AppState from '../AppState';
|
|||||||
import { EntityReference } from '../generated/type/entityUsage';
|
import { EntityReference } from '../generated/type/entityUsage';
|
||||||
import { getEntityName } from './CommonUtils';
|
import { getEntityName } from './CommonUtils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param listUsers - List of users
|
||||||
|
* @param listTeams - List of teams
|
||||||
|
* @param excludeCurrentUser - Wether to exclude current user to be on list. Needed when calls from searching
|
||||||
|
* @returns List of user or team
|
||||||
|
*/
|
||||||
export const getOwnerList = (
|
export const getOwnerList = (
|
||||||
listUsers?: FormattedUsersData[],
|
listUsers?: FormattedUsersData[],
|
||||||
listTeams?: FormattedTeamsData[]
|
listTeams?: FormattedTeamsData[],
|
||||||
|
excludeCurrentUser?: boolean
|
||||||
) => {
|
) => {
|
||||||
const userDetails = AppState.getCurrentUserDetails();
|
const userDetails = AppState.getCurrentUserDetails();
|
||||||
|
|
||||||
@ -47,17 +54,21 @@ export const getOwnerList = (
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
...(!excludeCurrentUser
|
||||||
name: getEntityName(userDetails as unknown as EntityReference),
|
? [
|
||||||
value: userDetails.id,
|
{
|
||||||
group: 'Users',
|
name: getEntityName(userDetails as unknown as EntityReference),
|
||||||
type: 'user',
|
value: userDetails.id,
|
||||||
},
|
group: 'Users',
|
||||||
|
type: 'user',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
...users,
|
...users,
|
||||||
...teams,
|
...teams,
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return userDetails
|
return userDetails && !excludeCurrentUser
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
name: getEntityName(userDetails as unknown as EntityReference),
|
name: getEntityName(userDetails as unknown as EntityReference),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user