From 5b49db2c07f0991f9944b74e38b994d0c2d22ff4 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Mon, 28 Oct 2024 21:01:56 +0530 Subject: [PATCH] MINOR: fix organization data show in teams data after search (#18427) * fix organization data show in teams data after search * remove unsued code --- .../ui/playwright/e2e/Pages/Teams.spec.ts | 23 +++++----- .../resources/ui/playwright/utils/team.ts | 12 ++++- .../Team/TeamDetails/TeamDetailsV1.tsx | 39 +++++++++++++--- .../src/main/resources/ui/src/rest/miscAPI.ts | 25 ----------- .../resources/ui/src/utils/UserDataUtils.ts | 45 ------------------- 5 files changed, 57 insertions(+), 87 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts index 1d43dd213b4..23ef97fe4ac 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Teams.spec.ts @@ -16,20 +16,20 @@ import { EntityTypeEndpoint } from '../../support/entity/Entity.interface'; import { TeamClass } from '../../support/team/TeamClass'; import { UserClass } from '../../support/user/UserClass'; import { - createNewPage, - descriptionBox, - getApiContext, - redirectToHomePage, - toastNotification, - uuid, + createNewPage, + descriptionBox, + getApiContext, + redirectToHomePage, + toastNotification, + uuid } from '../../utils/common'; import { addMultiOwner } from '../../utils/entity'; import { settingClick } from '../../utils/sidebar'; import { - createTeam, - hardDeleteTeam, - searchTeam, - softDeleteTeam, + createTeam, + hardDeleteTeam, + searchTeam, + softDeleteTeam } from '../../utils/team'; // use the admin user to login @@ -440,6 +440,9 @@ test.describe('Teams Page', () => { for (const team of [team1, team2, team3]) { await searchTeam(page, team.responseData?.['displayName']); } + + // Should not find the organization team and show errorPlaceholder + await searchTeam(page, 'Organization', true); } finally { await team1.delete(apiContext); await team2.delete(apiContext); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/team.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/team.ts index 4ffa5541332..2de12ad1fe3 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/team.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/team.ts @@ -251,11 +251,19 @@ export const removeOrganizationPolicyAndRole = async ( }); }; -export const searchTeam = async (page: Page, teamName: string) => { +export const searchTeam = async ( + page: Page, + teamName: string, + searchWillBeEmpty?: boolean +) => { const searchResponse = page.waitForResponse('/api/v1/search/query?q=**'); await page.fill('[data-testid="searchbar"]', teamName); await searchResponse; - await expect(page.locator('table')).toContainText(teamName); + if (searchWillBeEmpty) { + await expect(page.getByTestId('search-error-placeholder')).toBeVisible(); + } else { + await expect(page.locator('table')).toContainText(teamName); + } }; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx index 44ec2338af5..8f75580baee 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Settings/Team/TeamDetails/TeamDetailsV1.tsx @@ -41,7 +41,7 @@ import { ReactComponent as ImportIcon } from '../../../../assets/svg/ic-import.s import { ReactComponent as IconRestore } from '../../../../assets/svg/ic-restore.svg'; import { ReactComponent as IconOpenLock } from '../../../../assets/svg/open-lock.svg'; import { ReactComponent as IconTeams } from '../../../../assets/svg/teams.svg'; -import { ROUTES } from '../../../../constants/constants'; +import { PAGE_SIZE, ROUTES } from '../../../../constants/constants'; import { GLOSSARIES_DOCS, ROLE_DOCS, @@ -55,6 +55,7 @@ import { usePermissionProvider } from '../../../../context/PermissionProvider/Pe import { ResourceEntity } from '../../../../context/PermissionProvider/PermissionProvider.interface'; import { ERROR_PLACEHOLDER_TYPE } from '../../../../enums/common.enum'; import { EntityAction, EntityType } from '../../../../enums/entity.enum'; +import { SearchIndex } from '../../../../enums/search.enum'; import { OwnerType } from '../../../../enums/user.enum'; import { Operation } from '../../../../generated/entity/policies/policy'; import { Team, TeamType } from '../../../../generated/entity/teams/team'; @@ -68,7 +69,7 @@ import { useApplicationStore } from '../../../../hooks/useApplicationStore'; import useCustomLocation from '../../../../hooks/useCustomLocation/useCustomLocation'; import AddAttributeModal from '../../../../pages/RolesPage/AddAttributeModal/AddAttributeModal'; import { ImportType } from '../../../../pages/TeamsPage/ImportTeamsPage/ImportTeamsPage.interface'; -import { getSearchedTeams } from '../../../../rest/miscAPI'; +import { searchQuery } from '../../../../rest/searchAPI'; import { exportTeam, restoreTeam } from '../../../../rest/teamsAPI'; import { Transi18next } from '../../../../utils/CommonUtils'; import { getEntityName } from '../../../../utils/EntityUtils'; @@ -267,10 +268,38 @@ const TeamDetailsV1 = ({ const searchTeams = async (text: string) => { try { - const res = await getSearchedTeams(text, 1, ''); - const data = res.data.hits.hits.map((value) => value._source as Team); + const res = await searchQuery({ + query: `*${text}*`, + pageNumber: 1, + pageSize: PAGE_SIZE, + queryFilter: { + query: { + bool: { + must_not: [ + { + term: { + 'name.keyword': 'Organization', + }, + }, + ], + }, + }, + }, + searchIndex: SearchIndex.TEAM, + }); - setChildTeamList(data); + const data = res.hits.hits.map((value) => value._source as Team); + + setChildTeamList( + data.map((team) => { + return { + ...team, + // search data will contain children empty array, so we need to remove it + // to avoid expand handler to show in ui + children: isEmpty(team.children) ? undefined : team.children, + }; + }) + ); } catch (error) { setChildTeamList([]); } diff --git a/openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.ts b/openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.ts index 601ce4294e9..82b3a8826f5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.ts @@ -132,31 +132,6 @@ export const getTeamsByQuery = async (params: { return response.data; }; -export const getSearchedUsers = ( - queryString: string, - from: number, - size = 10 -) => { - return searchData(queryString, from, size, '', '', '', SearchIndex.USER); -}; - -export const getSearchedTeams = ( - queryString: string, - from: number, - filter?: string, - size = 10 -) => { - return searchData( - queryString, - from, - size, - filter ?? '', - '', - '', - SearchIndex.TEAM - ); -}; - export const getUserAndTeamSearch = ( term: string, userOnly = false, diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/UserDataUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/UserDataUtils.ts index bf23ac3ed2c..dc80270c6a2 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/UserDataUtils.ts +++ b/openmetadata-ui/src/main/resources/ui/src/utils/UserDataUtils.ts @@ -15,14 +15,8 @@ import { AxiosError } from 'axios'; import { compare } from 'fast-json-patch'; import { isEqual } from 'lodash'; import { OidcUser } from '../components/Auth/AuthProviders/AuthProvider.interface'; -import { WILD_CARD_CHAR } from '../constants/char.constants'; -import { SettledStatus } from '../enums/Axios.enum'; -import { SearchIndex } from '../enums/search.enum'; -import { SearchResponse } from '../interface/search.interface'; -import { getSearchedTeams, getSearchedUsers } from '../rest/miscAPI'; import { updateUserDetail } from '../rest/userAPI'; import { User } from './../generated/entity/teams/user'; -import { formatTeamsResponse, formatUsersResponse } from './APIUtils'; import { getImages } from './CommonUtils'; import i18n from './i18next/LocalUtil'; import { @@ -70,45 +64,6 @@ export const matchUserDetails = ( return isMatch; }; -export const searchFormattedUsersAndTeams = async ( - searchQuery = WILD_CARD_CHAR, - from = 1 -) => { - try { - const promises = [ - getSearchedUsers(searchQuery, from), - getSearchedTeams(searchQuery, from, 'teamType:Group'), - ]; - - const [resUsers, resTeams] = await Promise.allSettled(promises); - - const users = - resUsers.status === SettledStatus.FULFILLED - ? formatUsersResponse( - (resUsers.value.data as SearchResponse).hits.hits - ) - : []; - const teams = - resTeams.status === SettledStatus.FULFILLED - ? formatTeamsResponse( - (resTeams.value.data as SearchResponse).hits.hits - ) - : []; - const usersTotal = - resUsers.status === SettledStatus.FULFILLED - ? resUsers.value.data.hits.total.value - : 0; - const teamsTotal = - resTeams.status === SettledStatus.FULFILLED - ? resTeams.value.data.hits.total.value - : 0; - - return { users, teams, usersTotal, teamsTotal }; - } catch (error) { - return { users: [], teams: [], usersTotal: 0, teamsTotal: 0 }; - } -}; - export const getUserWithImage = (user: User) => { const profile = getImageWithResolutionAndFallback(