diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/IncidentManager.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/IncidentManager.spec.ts index 12914ee56ee..120cfd0a7e9 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/IncidentManager.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/IncidentManager.spec.ts @@ -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(); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tags.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tags.spec.ts index d108e2a3b32..cbb3cbea016 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tags.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Tags.spec.ts @@ -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}"]`); 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 f7b8c7883eb..393eb932817 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 @@ -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' }); @@ -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(); + } + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/glossary.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/glossary.ts index 83d78bd4301..541551fa3aa 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/glossary.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/glossary.ts @@ -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; @@ -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; diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/incidentManager.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/incidentManager.ts index 1ba8153c1e8..81893c9b554 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/incidentManager.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/incidentManager.ts @@ -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' diff --git a/openmetadata-ui/src/main/resources/ui/playwright/utils/task.ts b/openmetadata-ui/src/main/resources/ui/playwright/utils/task.ts index a0886947207..dfccbd0cefd 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/task.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/task.ts @@ -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; @@ -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; 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 c91867ebf72..4ffa5541332 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/utils/team.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/utils/team.ts @@ -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); +}; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/BlockEditor/Extensions/mention/mentionSuggestions.ts b/openmetadata-ui/src/main/resources/ui/src/components/BlockEditor/Extensions/mention/mentionSuggestions.ts index 62a1b97cb4e..1b1a471b5c3 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/BlockEditor/Extensions/mention/mentionSuggestions.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/BlockEditor/Extensions/mention/mentionSuggestions.ts @@ -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: () => { 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 eaa18b03774..de4450acd76 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 @@ -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'; @@ -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'; @@ -268,13 +267,8 @@ const TeamDetailsV1 = ({ const searchTeams = async (text: string) => { try { - const res = await getSuggestions( - 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) { diff --git a/openmetadata-ui/src/main/resources/ui/src/mocks/Task.mock.ts b/openmetadata-ui/src/main/resources/ui/src/mocks/Task.mock.ts index 3ab8cb5fe77..66258c20aff 100644 --- a/openmetadata-ui/src/main/resources/ui/src/mocks/Task.mock.ts +++ b/openmetadata-ui/src/main/resources/ui/src/mocks/Task.mock.ts @@ -102,177 +102,172 @@ export const TASK_COLUMNS: Column[] = [ ]; export const MOCK_ASSIGNEE_DATA = { - suggest: { - 'metadata-suggest': [ - { - text: 'ash', - offset: 0, - length: 3, - options: [ - { - text: 'Ashish Gupta', - _index: 'user_search_index', - _type: '_doc', - _id: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4', - _score: 30, - _ignored: ['description.keyword'], - _source: { - id: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4', - name: 'ashish', - fullyQualifiedName: 'ashish', - description: - 'this is test description. this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!', - displayName: 'Ashish Gupta', - version: 0.8, - updatedAt: 1699428544440, - updatedBy: 'ashish', - email: 'ashish@getcollate.io', - isBot: false, - isAdmin: true, - profile: { - images: { - image: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s96-c', - image24: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s24-c', - image32: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s32-c', - image48: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s48-c', - image72: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s72-c', - image192: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s192-c', - image512: - 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s512-c', - }, + data: { + hits: { + hits: [ + { + text: 'Ashish Gupta', + _index: 'user_search_index', + _type: '_doc', + _id: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4', + _score: 30, + _ignored: ['description.keyword'], + _source: { + id: '18ca6cd1-d696-4a22-813f-c7a42fc09dc4', + name: 'ashish', + fullyQualifiedName: 'ashish', + description: + 'this is test description. this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!this is test description!', + displayName: 'Ashish Gupta', + version: 0.8, + updatedAt: 1699428544440, + updatedBy: 'ashish', + email: 'ashish@getcollate.io', + isBot: false, + isAdmin: true, + profile: { + images: { + image: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s96-c', + image24: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s24-c', + image32: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s32-c', + image48: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s48-c', + image72: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s72-c', + image192: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s192-c', + image512: + 'https://lh3.googleusercontent.com/a/ACg8ocJghhvg6uUMNVzzmA1YEtgSvHKmDmo0RSIeydHuqzM1=s512-c', }, - teams: [ - { - id: '9efbccd7-3d0b-485d-89c4-ac0f8fc80da5', - type: 'team', - name: 'Organization', - fullyQualifiedName: 'Organization', - description: - 'Organization under which all the other team hierarchy is created', - displayName: 'Organization', - deleted: false, - href: 'http://sandbox-beta.open-metadata.org/api/v1/teams/9efbccd7-3d0b-485d-89c4-ac0f8fc80da5', - }, - ], - personas: [], - deleted: false, - roles: [], - inheritedRoles: [ - { - id: 'f8239edf-4f55-43a4-8d6e-a34e4fadee25', - type: 'role', - name: 'DataConsumer', - fullyQualifiedName: 'DataConsumer', - description: - 'Users with Data Consumer role use different data assets for their day to day work.', - displayName: 'Data Consumer', - deleted: false, - }, - ], - isEmailVerified: true, - domain: { - id: '9545569e-9b4e-4be0-8142-ce5d502fbab7', - type: 'domain', - name: 'Product', - fullyQualifiedName: 'Product', + }, + teams: [ + { + id: '9efbccd7-3d0b-485d-89c4-ac0f8fc80da5', + type: 'team', + name: 'Organization', + fullyQualifiedName: 'Organization', description: - 'A Domain producing and serving Product Master Data.', - displayName: 'Product Name', - inherited: true, + 'Organization under which all the other team hierarchy is created', + displayName: 'Organization', + deleted: false, + href: 'http://sandbox-beta.open-metadata.org/api/v1/teams/9efbccd7-3d0b-485d-89c4-ac0f8fc80da5', }, - fqnParts: ['ashish', 'Ashish Gupta'], - suggest: [ - { - input: 'ashish', - weight: 5, - }, - { - input: 'Ashish Gupta', - weight: 10, - }, - ], - entityType: 'user', - }, - contexts: { - deleted: ['false'], - }, - }, - { - text: 'Ashley King', - _index: 'user_search_index', - _type: '_doc', - _id: '0c83a592-7ced-4156-b235-01726259a0e7', - _score: 30, - _source: { - id: '0c83a592-7ced-4156-b235-01726259a0e7', - name: 'ashley_king5', - fullyQualifiedName: 'ashley_king5', - displayName: 'Ashley King', - version: 0.2, - updatedAt: 1702647808915, - updatedBy: 'ingestion-bot', - email: 'ashley_king5@gmail.com', - isAdmin: false, - teams: [ - { - id: 'dfa05a46-eb4f-4c68-8cd6-140b0d330b8d', - type: 'team', - name: 'Compute', - fullyQualifiedName: 'Compute', - deleted: false, - }, - ], - personas: [], - deleted: false, - roles: [], - inheritedRoles: [ - { - id: 'f8239edf-4f55-43a4-8d6e-a34e4fadee25', - type: 'role', - name: 'DataConsumer', - fullyQualifiedName: 'DataConsumer', - description: - 'Users with Data Consumer role use different data assets for their day to day work.', - displayName: 'Data Consumer', - deleted: false, - }, - ], - domain: { - id: '52fc9c67-78b7-42bf-8147-69278853c230', - type: 'domain', - name: 'Design', - fullyQualifiedName: 'Design', - description: "Here' the description for Product Design", - displayName: 'Product Design ', - inherited: true, + ], + personas: [], + deleted: false, + roles: [], + inheritedRoles: [ + { + id: 'f8239edf-4f55-43a4-8d6e-a34e4fadee25', + type: 'role', + name: 'DataConsumer', + fullyQualifiedName: 'DataConsumer', + description: + 'Users with Data Consumer role use different data assets for their day to day work.', + displayName: 'Data Consumer', + deleted: false, }, - fqnParts: ['ashley_king5', 'Ashley King'], - suggest: [ - { - input: 'ashley_king5', - weight: 5, - }, - { - input: 'Ashley King', - weight: 10, - }, - ], - entityType: 'user', - isBot: false, - }, - contexts: { - deleted: ['false'], + ], + isEmailVerified: true, + domain: { + id: '9545569e-9b4e-4be0-8142-ce5d502fbab7', + type: 'domain', + name: 'Product', + fullyQualifiedName: 'Product', + description: + 'A Domain producing and serving Product Master Data.', + displayName: 'Product Name', + inherited: true, }, + fqnParts: ['ashish', 'Ashish Gupta'], + suggest: [ + { + input: 'ashish', + weight: 5, + }, + { + input: 'Ashish Gupta', + weight: 10, + }, + ], + entityType: 'user', }, - ], - }, - ], + contexts: { + deleted: ['false'], + }, + }, + { + text: 'Ashley King', + _index: 'user_search_index', + _type: '_doc', + _id: '0c83a592-7ced-4156-b235-01726259a0e7', + _score: 30, + _source: { + id: '0c83a592-7ced-4156-b235-01726259a0e7', + name: 'ashley_king5', + fullyQualifiedName: 'ashley_king5', + displayName: 'Ashley King', + version: 0.2, + updatedAt: 1702647808915, + updatedBy: 'ingestion-bot', + email: 'ashley_king5@gmail.com', + isAdmin: false, + teams: [ + { + id: 'dfa05a46-eb4f-4c68-8cd6-140b0d330b8d', + type: 'team', + name: 'Compute', + fullyQualifiedName: 'Compute', + deleted: false, + }, + ], + personas: [], + deleted: false, + roles: [], + inheritedRoles: [ + { + id: 'f8239edf-4f55-43a4-8d6e-a34e4fadee25', + type: 'role', + name: 'DataConsumer', + fullyQualifiedName: 'DataConsumer', + description: + 'Users with Data Consumer role use different data assets for their day to day work.', + displayName: 'Data Consumer', + deleted: false, + }, + ], + domain: { + id: '52fc9c67-78b7-42bf-8147-69278853c230', + type: 'domain', + name: 'Design', + fullyQualifiedName: 'Design', + description: "Here' the description for Product Design", + displayName: 'Product Design ', + inherited: true, + }, + fqnParts: ['ashley_king5', 'Ashley King'], + suggest: [ + { + input: 'ashley_king5', + weight: 5, + }, + { + input: 'Ashley King', + weight: 10, + }, + ], + entityType: 'user', + isBot: false, + }, + contexts: { + deleted: ['false'], + }, + }, + ], + }, }, }; diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerPage.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerPage.tsx index 55106225b68..b187ffe272f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerPage.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/IncidentManager/IncidentManagerPage.tsx @@ -61,7 +61,7 @@ import { TestCaseIncidentStatusParams, updateTestCaseIncidentById, } from '../../rest/incidentManagerAPI'; -import { getUserSuggestions } from '../../rest/miscAPI'; +import { getUserAndTeamSearch } from '../../rest/miscAPI'; import { searchQuery } from '../../rest/searchAPI'; import { getUsers } from '../../rest/userAPI'; import { @@ -225,11 +225,11 @@ const IncidentManagerPage = () => { return; } try { - const res = await getUserSuggestions(query, true); - const hits = res.data.suggest['metadata-suggest'][0]['options']; + const res = await getUserAndTeamSearch(query, true); + const hits = res.data.hits.hits; const suggestOptions = hits.map((hit) => ({ label: getEntityName(hit._source), - value: hit._id, + value: hit._id ?? '', type: hit._source.entityType, name: hit._source.name, })); 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 6b39a5c58c5..97d4a61d68f 100644 --- a/openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/rest/miscAPI.ts @@ -14,17 +14,14 @@ import { AxiosResponse } from 'axios'; import { Edge } from '../components/Entity/EntityLineage/EntityLineage.interface'; import { ExploreSearchIndex } from '../components/Explore/ExplorePage.interface'; -import { WILD_CARD_CHAR } from '../constants/char.constants'; +import { PAGE_SIZE } from '../constants/constants'; import { SearchIndex } from '../enums/search.enum'; import { AuthenticationConfiguration } from '../generated/configuration/authenticationConfiguration'; import { AuthorizerConfiguration } from '../generated/configuration/authorizerConfiguration'; import { PipelineServiceClientConfiguration } from '../generated/configuration/pipelineServiceClientConfiguration'; import { ValidationResponse } from '../generated/system/validationResponse'; import { Paging } from '../generated/type/paging'; -import { - RawSuggestResponse, - SearchResponse, -} from '../interface/search.interface'; +import { SearchResponse } from '../interface/search.interface'; import { getSearchAPIQueryParams } from '../utils/SearchUtils'; import { escapeESReservedCharacters } from '../utils/StringsUtils'; import APIClient from './index'; @@ -91,41 +88,6 @@ export const fetchAirflowConfig = async () => { return response.data; }; -export const getSuggestions = ( - queryString: string, - searchIndex?: T -) => { - const params = { - q: queryString, - index: searchIndex ?? [ - SearchIndex.DASHBOARD, - SearchIndex.TABLE, - SearchIndex.TOPIC, - SearchIndex.PIPELINE, - SearchIndex.MLMODEL, - SearchIndex.CONTAINER, - SearchIndex.STORED_PROCEDURE, - SearchIndex.DASHBOARD_DATA_MODEL, - SearchIndex.GLOSSARY_TERM, - SearchIndex.TAG, - SearchIndex.SEARCH_INDEX, - ], - }; - - if (searchIndex) { - return APIClient.get>(`/search/suggest`, { - params, - }); - } - - return APIClient.get>( - `/search/suggest`, - { - params, - } - ); -}; - export const getVersion = async () => { const response = await APIClient.get<{ version: string }>('/system/version'); @@ -153,32 +115,6 @@ export const deleteLineageEdge = ( ); }; -export const getSuggestedUsers = (term: string) => { - return APIClient.get>( - `/search/suggest?q=${term}&index=${SearchIndex.USER}` - ); -}; - -export const getSuggestedTeams = (term: string) => { - return APIClient.get>( - `/search/suggest?q=${term}&index=${SearchIndex.TEAM}` - ); -}; - -export const getUserSuggestions = (term: string, userOnly = false) => { - const params = { - q: term || WILD_CARD_CHAR, - index: userOnly - ? SearchIndex.USER - : `${SearchIndex.USER},${SearchIndex.TEAM}`, - }; - - return APIClient.get>( - `/search/suggest`, - { params } - ); -}; - export const getTeamsByQuery = async (params: { q: string; from?: number; @@ -221,6 +157,22 @@ export const getSearchedTeams = ( ); }; +export const getUserAndTeamSearch = ( + term: string, + userOnly = false, + size = PAGE_SIZE +) => { + return searchData( + term ?? '', + 1, + size, + '', + '', + '', + userOnly ? SearchIndex.USER : [SearchIndex.USER, SearchIndex.TEAM] + ); +}; + export const deleteEntity = async ( entityType: string, entityId: string, @@ -237,18 +189,6 @@ export const deleteEntity = async ( }); }; -export const getAdvancedFieldOptions = ( - q: string, - index: SearchIndex, - field: string | undefined -) => { - const params = { index, field, q }; - - return APIClient.get>(`/search/suggest`, { - params, - }); -}; - /** * Retrieves the aggregate field options based on the provided parameters. * diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx index 0d36222e374..8b19c531aa1 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.test.tsx @@ -42,26 +42,6 @@ jest.mock('../rest/miscAPI', () => ({ }, }, }), - getUserSuggestions: jest.fn().mockResolvedValue({ - data: { - suggest: { - 'metadata-suggest': [ - { - options: [ - { - _source: { - entityType: 'User', - name: 'John Doe', - deleted: false, - }, - _id: '1', - }, - ], - }, - ], - }, - }, - }), searchData: jest.fn().mockResolvedValue({ data: { hits: { diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.test.tsx index b141b35405e..f0734d9e243 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.test.tsx @@ -16,7 +16,7 @@ import { EntityType } from '../enums/entity.enum'; import { Glossary } from '../generated/entity/data/glossary'; import { mockTableData } from '../mocks/TableVersion.mock'; import { MOCK_ASSIGNEE_DATA } from '../mocks/Task.mock'; -import { getUserSuggestions } from '../rest/miscAPI'; +import { getUserAndTeamSearch } from '../rest/miscAPI'; import { fetchOptions, getEntityTableName, @@ -26,7 +26,7 @@ import { } from './TasksUtils'; jest.mock('../rest/miscAPI', () => ({ - getUserSuggestions: jest + getUserAndTeamSearch: jest .fn() .mockImplementation(() => Promise.resolve(MOCK_ASSIGNEE_DATA)), })); @@ -178,8 +178,8 @@ describe('Tests for fetchOptions', () => { it('function fetchOptions should trigger setOptions without filtered options', async () => { const mockSetOptions = jest.fn(); - (getUserSuggestions as jest.Mock).mockImplementationOnce(() => - Promise.resolve({ data: MOCK_ASSIGNEE_DATA }) + (getUserAndTeamSearch as jest.Mock).mockImplementationOnce(() => + Promise.resolve(MOCK_ASSIGNEE_DATA) ); await act(async () => { @@ -207,8 +207,8 @@ describe('Tests for fetchOptions', () => { it('function fetchOptions should trigger setOptions with filtered options', async () => { const mockSetOptions = jest.fn(); - (getUserSuggestions as jest.Mock).mockImplementationOnce(() => - Promise.resolve({ data: MOCK_ASSIGNEE_DATA }) + (getUserAndTeamSearch as jest.Mock).mockImplementationOnce(() => + Promise.resolve(MOCK_ASSIGNEE_DATA) ); await act(async () => { diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.ts index 073adeabbe7..e9badb8155e 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.ts +++ b/openmetadata-ui/src/main/resources/ui/src/utils/TasksUtils.ts @@ -70,7 +70,7 @@ import { import { getDataModelByFqn } from '../rest/dataModelsAPI'; import { getGlossariesByName, getGlossaryTermByFQN } from '../rest/glossaryAPI'; import { getMetricByFqn } from '../rest/metricsAPI'; -import { getUserSuggestions } from '../rest/miscAPI'; +import { getUserAndTeamSearch } from '../rest/miscAPI'; import { getMlModelByFQN } from '../rest/mlModelAPI'; import { getPipelineByFqn } from '../rest/pipelineAPI'; import { getSearchIndexDetailsByFQN } from '../rest/SearchIndexAPI'; @@ -238,12 +238,12 @@ export const fetchOptions = ({ return; } - getUserSuggestions(query, onlyUsers) + getUserAndTeamSearch(query, onlyUsers) .then((res) => { - const hits = res.data.suggest['metadata-suggest'][0]['options']; + const hits = res.data.hits.hits; const suggestOptions = hits.map((hit) => ({ label: getEntityName(hit._source), - value: hit._id, + value: hit._id ?? '', type: hit._source.entityType, name: hit._source.name, displayName: hit._source.displayName,