MINOR: fix organization data show in teams data after search (#18427)

* fix organization data show in teams data after search

* remove unsued code
This commit is contained in:
Ashish Gupta 2024-10-28 21:01:56 +05:30 committed by GitHub
parent ed9b66c5c5
commit 5b49db2c07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 57 additions and 87 deletions

View File

@ -21,7 +21,7 @@ import {
getApiContext,
redirectToHomePage,
toastNotification,
uuid,
uuid
} from '../../utils/common';
import { addMultiOwner } from '../../utils/entity';
import { settingClick } from '../../utils/sidebar';
@ -29,7 +29,7 @@ import {
createTeam,
hardDeleteTeam,
searchTeam,
softDeleteTeam,
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);

View File

@ -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;
if (searchWillBeEmpty) {
await expect(page.getByTestId('search-error-placeholder')).toBeVisible();
} else {
await expect(page.locator('table')).toContainText(teamName);
}
};

View File

@ -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([]);
}

View File

@ -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,

View File

@ -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<SearchIndex.USER>).hits.hits
)
: [];
const teams =
resTeams.status === SettledStatus.FULFILLED
? formatTeamsResponse(
(resTeams.value.data as SearchResponse<SearchIndex.TEAM>).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(