Skip to content

Commit

Permalink
minor: remove suggestion api from UI (#17857)
Browse files Browse the repository at this point in the history
* minor: remove suggestion api from UI

* increase the page size to 10

* fix : unit test

* update playwright tests and getUserAndTeamSearch params

* added playwright for team search

* fix activity feed failure

---------

Co-authored-by: Ashish Gupta <ashish@getcollate.io>
  • Loading branch information
Sachin-chaurasiya and Ashish8689 authored Sep 16, 2024
1 parent 4fd2b24 commit eb7b1d5
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ test.describe('Incident Manager', () => {
await page.getByRole('menuitem', { name: 'Reassign' }).click();

const searchUserResponse = page.waitForResponse(
`/api/v1/search/suggest?q=*${user2.data.firstName}*${user2.data.lastName}*&index=user_search_index*`
`/api/v1/search/query?q=*${user2.data.firstName}*${user2.data.lastName}*&index=user_search_index*`
);

await page.getByTestId('select-assignee').locator('div').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ test('Classification Page', async ({ page }) => {

await page.click('[data-testid="select-assignee"]');
const assigneeResponse = page.waitForResponse(
'/api/v1/search/suggest?q=*&index=user_search_index*team_search_index*'
'/api/v1/search/query?q=*&index=user_search_index*team_search_index*'
);
await page.keyboard.type(assignee);
await page.click(`[data-testid="${assignee}"]`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import {
} from '../../utils/common';
import { addMultiOwner } from '../../utils/entity';
import { settingClick } from '../../utils/sidebar';
import { createTeam, hardDeleteTeam, softDeleteTeam } from '../../utils/team';
import {
createTeam,
hardDeleteTeam,
searchTeam,
softDeleteTeam,
} from '../../utils/team';

// use the admin user to login
test.use({ storageState: 'playwright/.auth/admin.json' });
Expand Down Expand Up @@ -406,4 +411,40 @@ test.describe('Teams Page', () => {
await hardDeleteTeam(page);
await afterAction();
});

test('Team search should work properly', async ({ page }) => {
const { apiContext, afterAction } = await getApiContext(page);
const id = uuid();
const team1 = new TeamClass();
const team2 = new TeamClass({
name: `pw team space-${id}`,
displayName: `pw team space ${id}`,
description: 'playwright team with space description',
teamType: 'Group',
});
const team3 = new TeamClass({
name: `pw.team.dot-${id}`,
displayName: `pw.team.dot ${id}`,
description: 'playwright team with dot description',
teamType: 'Group',
});

await team1.create(apiContext);
await team2.create(apiContext);
await team3.create(apiContext);

try {
await settingClick(page, GlobalSettingOptions.TEAMS);
await page.waitForLoadState('networkidle');

for (const team of [team1, team2, team3]) {
await searchTeam(page, team.responseData?.['displayName']);
}
} finally {
await team1.delete(apiContext);
await team2.delete(apiContext);
await team3.delete(apiContext);
await afterAction();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ export const createDescriptionTaskForGlossary = async (
await assigneeField.click();

const userSearchResponse = page.waitForResponse(
`/api/v1/search/suggest?q=${value.assignee}&index=user_search_index%2Cteam_search_index`
`/api/v1/search/query?q=${value.assignee}&index=user_search_index%2Cteam_search_index`
);
await assigneeField.fill(value.assignee);
await userSearchResponse;
Expand Down Expand Up @@ -922,7 +922,7 @@ export const createTagTaskForGlossary = async (
);
await assigneeField.click();
const userSearchResponse = page.waitForResponse(
`/api/v1/search/suggest?q=${value.assignee}&index=user_search_index%2Cteam_search_index`
`/api/v1/search/query?q=${value.assignee}&index=user_search_index%2Cteam_search_index`
);
await assigneeField.fill(value.assignee);
await userSearchResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const assignIncident = async (data: {
'#testCaseResolutionStatusDetails_assignee',
user.displayName
);
await page.waitForResponse('/api/v1/search/suggest?q=*');
await page.waitForResponse('/api/v1/search/query?q=*');
await page.click(`[data-testid="${user.name.toLocaleLowerCase()}"]`);
const updateIncident = page.waitForResponse(
'/api/v1/dataQuality/testCases/testCaseIncidentStatus'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ export const createDescriptionTask = async (
await assigneeField.click();

const userSearchResponse = page.waitForResponse(
`/api/v1/search/suggest?q=${value.assignee}&index=user_search_index%2Cteam_search_index`
`/api/v1/search/query?q=*${value.assignee}**&index=user_search_index%2Cteam_search_index`
);

await assigneeField.fill(value.assignee);
await userSearchResponse;

Expand Down Expand Up @@ -110,8 +111,9 @@ export const createTagTask = async (
'[data-testid="select-assignee"] > .ant-select-selector #assignees'
);
await assigneeField.click();

const userSearchResponse = page.waitForResponse(
`/api/v1/search/suggest?q=${value.assignee}&index=user_search_index%2Cteam_search_index`
`/api/v1/search/query?q=*${value.assignee}**&index=user_search_index%2Cteam_search_index`
);
await assigneeField.fill(value.assignee);
await userSearchResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,12 @@ export const removeOrganizationPolicyAndRole = async (
},
});
};

export const searchTeam = async (page: Page, teamName: string) => {
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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,27 @@ import {
EntityUrlMapType,
ENTITY_URL_MAP,
} from '../../../../constants/Feeds.constants';
import { getSearchedUsers, getUserSuggestions } from '../../../../rest/miscAPI';
import { getUserAndTeamSearch } from '../../../../rest/miscAPI';
import { buildMentionLink } from '../../../../utils/FeedUtils';
import { ExtensionRef } from '../../BlockEditor.interface';
import MentionList from './MentionList';

export const mentionSuggestion = () => ({
items: async ({ query }: { query: string }) => {
if (!query) {
const data = await getSearchedUsers('', 1, 5);
const hits = data.data.hits.hits;
const data = await getUserAndTeamSearch(query, false, 5);
const hits = data.data.hits.hits;

return hits.map((hit) => ({
id: hit._id,
name: hit._source.name,
label: hit._source.displayName ?? hit._source.name,
fqn: hit._source.fullyQualifiedName,
href: buildMentionLink(
ENTITY_URL_MAP[hit._source.entityType as EntityUrlMapType],
hit._source.name
),
type: hit._source.entityType,
}));
} else {
const data = await getUserSuggestions(query);
const hits = data.data.suggest['metadata-suggest'][0]['options'];

return hits.map((hit) => ({
id: hit._id,
name: hit._source.name,
label: hit._source.displayName ?? hit._source.name,
fqn: hit._source.fullyQualifiedName,
href: buildMentionLink(
ENTITY_URL_MAP[hit._source.entityType as EntityUrlMapType],
hit._source.name
),
type: hit._source.entityType,
}));
}
return hits.map((hit) => ({
id: hit._id,
name: hit._source.name,
label: hit._source.displayName ?? hit._source.name,
fqn: hit._source.fullyQualifiedName,
href: buildMentionLink(
ENTITY_URL_MAP[hit._source.entityType as EntityUrlMapType],
hit._source.name
),
type: hit._source.entityType,
}));
},

render: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ 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';
Expand All @@ -69,7 +68,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 { getSuggestions } from '../../../../rest/miscAPI';
import { getSearchedTeams } from '../../../../rest/miscAPI';
import { exportTeam, restoreTeam } from '../../../../rest/teamsAPI';
import { Transi18next } from '../../../../utils/CommonUtils';
import { getEntityName } from '../../../../utils/EntityUtils';
Expand Down Expand Up @@ -268,13 +267,8 @@ const TeamDetailsV1 = ({

const searchTeams = async (text: string) => {
try {
const res = await getSuggestions<SearchIndex.TEAM>(
text,
SearchIndex.TEAM
);
const data = res.data.suggest['metadata-suggest'][0].options.map(
(value) => value._source as Team
);
const res = await getSearchedTeams(text, 1, '');
const data = res.data.hits.hits.map((value) => value._source as Team);

setChildTeamList(data);
} catch (error) {
Expand Down
Loading

0 comments on commit eb7b1d5

Please sign in to comment.