From fd7a3f19ef4ac17742fe304c5a91a07da8030e22 Mon Sep 17 00:00:00 2001 From: Karan Hotchandani <33024356+karanh37@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:11:55 +0530 Subject: [PATCH] Sort by display name in owner and mentions list (#14734) * sort by display name in owner and mentions list * maintain sort order * fix cypress --------- Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com> --- .../ui/cypress/common/Utils/Owner.ts | 4 +- .../ui/cypress/e2e/Pages/Service.spec.js | 2 +- .../FeedEditor/FeedEditor.interface.ts | 1 + .../src/components/FeedEditor/FeedEditor.tsx | 14 ++-- .../UserTeamSelectableList.component.tsx | 79 ++++++------------- .../main/resources/ui/src/utils/FeedUtils.tsx | 14 +++- 6 files changed, 46 insertions(+), 68 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/cypress/common/Utils/Owner.ts b/openmetadata-ui/src/main/resources/ui/cypress/common/Utils/Owner.ts index 53863a1e52e..c27ec5d67cc 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/common/Utils/Owner.ts +++ b/openmetadata-ui/src/main/resources/ui/cypress/common/Utils/Owner.ts @@ -15,7 +15,7 @@ import { interceptURL, verifyResponseStatusCode } from '../common'; const userURL = '/api/v1/search/query?q=**%20AND%20isBot:false&from=0&size=0&index=user_search_index'; const teamURL = - '/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=10&index=team_search_index'; + '/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=10&index=team_search_index&sort_field=displayName.keyword&sort_order=asc'; export const validateOwnerAndTeamCounts = () => { cy.getAllLocalStorage().then((data) => { @@ -122,7 +122,7 @@ export const removeOwner = (ownerName: string) => { export const addTeamAsOwner = (teamName: string) => { interceptURL( 'GET', - '/api/v1/search/query?q=*&from=0&size=*&index=team_search_index', + '/api/v1/search/query?q=*&from=0&size=*&index=team_search_index&sort_field=displayName.keyword&sort_order=asc', 'getTeams' ); diff --git a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Service.spec.js b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Service.spec.js index c882f98f4de..a2dc3fabf0c 100644 --- a/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Service.spec.js +++ b/openmetadata-ui/src/main/resources/ui/cypress/e2e/Pages/Service.spec.js @@ -80,7 +80,7 @@ describe('Services page should work properly', () => { verifyResponseStatusCode('@pipelineServiceClient', 200); interceptURL( 'GET', - '/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=*&index=team_search_index', + '/api/v1/search/query?q=*%20AND%20teamType:Group&from=0&size=*&index=team_search_index&sort_field=displayName.keyword&sort_order=asc', 'editOwner' ); cy.get('[data-testid="edit-owner"]') diff --git a/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.interface.ts b/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.interface.ts index 2f6dea1a829..9cdfe0af3f2 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.interface.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.interface.ts @@ -20,6 +20,7 @@ export interface MentionSuggestionsItem { type?: string; avatarEle?: HTMLDivElement; breadcrumbs: Array<{ name: string }>; + displayName?: string; } export interface FeedEditorProp extends HTMLAttributes { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.tsx b/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.tsx index bf875c6511d..041e0af1460 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/FeedEditor/FeedEditor.tsx @@ -87,30 +87,30 @@ export const FeedEditor = forwardRef( const newMatches: MentionSuggestionsItem[] = []; try { // Fetch profile images in case of user listing - const promises = matches.map(async (item) => { + const promises = matches.map(async (item, index) => { if (item.type === 'user') { return getUserByName(item.name, { fields: 'profile' }).then( (res) => { updateUserProfilePics({ id: item.name, user: res }); - newMatches.push({ + newMatches[index] = { ...item, avatarEle: userMentionItemWithAvatar( item, userProfilePics[item.name] ?? res ), - }); + }; } ); } else if (item.type === 'team') { - newMatches.push({ + newMatches[index] = { ...item, avatarEle: userMentionItemWithAvatar(item), - }); + }; } else { - newMatches.push({ + newMatches[index] = { ...item, - }); + }; } return Promise.resolve(); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/UserTeamSelectableList/UserTeamSelectableList.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/UserTeamSelectableList/UserTeamSelectableList.component.tsx index 891eb995656..0c55fd834aa 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/UserTeamSelectableList/UserTeamSelectableList.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/UserTeamSelectableList/UserTeamSelectableList.component.tsx @@ -105,64 +105,33 @@ export const UserTeamSelectableList = ({ const fetchTeamOptions = async (searchText: string, after?: string) => { const afterPage = isNaN(Number(after)) ? 1 : Number(after); - if (searchText) { - try { - const res = await searchData( - searchText, - afterPage, - PAGE_SIZE_MEDIUM, - 'teamType:Group', - '', - '', - SearchIndex.TEAM - ); + try { + const res = await searchData( + searchText || '', + afterPage, + PAGE_SIZE_MEDIUM, + 'teamType:Group', + 'displayName.keyword', + 'asc', + SearchIndex.TEAM + ); - const data = getEntityReferenceListFromEntities( - formatTeamsResponse(res.data.hits.hits), - EntityType.TEAM - ); + const data = getEntityReferenceListFromEntities( + formatTeamsResponse(res.data.hits.hits), + EntityType.TEAM + ); - setCount((pre) => ({ ...pre, team: res.data.hits.total.value })); + setCount((pre) => ({ ...pre, team: res.data.hits.total.value })); - return { - data, - paging: { - total: res.data.hits.total.value, - after: toString(afterPage + 1), - }, - }; - } catch (error) { - return { data: [], paging: { total: 0 } }; - } - } else { - try { - const { data } = await searchData( - '', - afterPage, - PAGE_SIZE_MEDIUM, - 'teamType:Group', - '', - '', - SearchIndex.TEAM - ); - - const filterData = getEntityReferenceListFromEntities( - formatTeamsResponse(data.hits.hits), - EntityType.TEAM - ); - - setCount((pre) => ({ ...pre, team: data.hits.total.value })); - - return { - data: filterData, - paging: { - total: data.hits.total.value, - after: toString(afterPage + 1), - }, - }; - } catch (error) { - return { data: [], paging: { total: 0 } }; - } + return { + data, + paging: { + total: res.data.hits.total.value, + after: toString(afterPage + 1), + }, + }; + } catch (error) { + return { data: [], paging: { total: 0 } }; } }; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx index 2741c64590f..43060c33aeb 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/FeedUtils.tsx @@ -69,7 +69,11 @@ import { import { getRelativeCalendar } from './date-time/DateTimeUtils'; import EntityLink from './EntityLink'; import entityUtilClassBase from './EntityUtilClassBase'; -import { ENTITY_LINK_SEPARATOR, getEntityBreadcrumbs } from './EntityUtils'; +import { + ENTITY_LINK_SEPARATOR, + getEntityBreadcrumbs, + getEntityName, +} from './EntityUtils'; import Fqn from './Fqn'; import { getImageWithResolutionAndFallback, @@ -209,6 +213,7 @@ export async function suggestions( type: hit._index === SearchIndex.USER ? UserTeam.User : UserTeam.Team, name: hit._source.name, + displayName: hit._source.displayName, }; }) ); @@ -221,7 +226,7 @@ export async function suggestions( hits.map(async (hit: any) => { const entityType = hit._source.entityType; const name = getEntityPlaceHolder( - `@${hit._source.name ?? hit._source.display_name}`, + `@${hit._source.name ?? hit._source.displayName}`, hit._source.deleted ); @@ -235,6 +240,7 @@ export async function suggestions( type: hit._index === SearchIndex.USER ? UserTeam.User : UserTeam.Team, name: hit._source.name, + displayName: hit._source.displayName, }; }) ); @@ -335,7 +341,9 @@ export const userMentionItemWithAvatar = ( )} - {item.name} + + {getEntityName(item)} + , wrapper );