Fix(Ui): Fixed the teams search irrelevant suggestions issue (#6516)

* Fixed the issue where teams suggestions when searched were not showing relevant results

* Fixed isJoinable param issue
This commit is contained in:
Aniket Katkar 2022-08-02 21:47:13 +05:30 committed by GitHub
parent 6e8da06b12
commit 13eabfe2db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 29 deletions

View File

@ -148,10 +148,16 @@ export const getTeamsByQuery = async (params: {
q: string; q: string;
from?: number; from?: number;
size?: number; size?: number;
isJoinable?: boolean;
}) => { }) => {
const response = await APIClient.get(`/search/query`, { const response = await APIClient.get(`/search/query`, {
params: { index: SearchIndex.TEAM, ...params }, params: {
index: SearchIndex.TEAM,
...params,
// eslint-disable-next-line @typescript-eslint/camelcase
sort_field: 'name.keyword',
// eslint-disable-next-line @typescript-eslint/camelcase
sort_order: 'asc',
},
}); });
return response.data; return response.data;

View File

@ -14,10 +14,9 @@
import { SelectableOption } from 'Models'; import { SelectableOption } from 'Models';
import React, { useState } from 'react'; import React, { useState } from 'react';
import AsyncSelect from 'react-select/async'; import AsyncSelect from 'react-select/async';
import { getSuggestedTeams, getTeamsByQuery } from '../../axiosAPIs/miscAPI'; import { getTeamsByQuery } from '../../axiosAPIs/miscAPI';
import { Team } from '../../generated/entity/teams/team'; import { Team } from '../../generated/entity/teams/team';
import { EntityReference } from '../../generated/type/entityReference'; import { EntityReference } from '../../generated/type/entityReference';
import { formatTeamsResponse } from '../../utils/APIUtils';
import { getEntityName } from '../../utils/CommonUtils'; import { getEntityName } from '../../utils/CommonUtils';
import SVGIcons from '../../utils/SvgUtils'; import SVGIcons from '../../utils/SvgUtils';
import { reactSingleSelectCustomStyle } from '../common/react-select-component/reactSelectCustomStyle'; import { reactSingleSelectCustomStyle } from '../common/react-select-component/reactSelectCustomStyle';
@ -49,11 +48,7 @@ const TeamsSelectable = ({
}; };
const getOptions = (teams: Team[]) => { const getOptions = (teams: Team[]) => {
const filteredTeams = filterJoinable return teams.map((team) => ({
? teams.filter((team) => team.isJoinable)
: teams;
return filteredTeams.map((team) => ({
label: getEntityName(team as EntityReference), label: getEntityName(team as EntityReference),
value: team.id, value: team.id,
})); }));
@ -61,26 +56,19 @@ const TeamsSelectable = ({
const loadOptions = (text: string) => { const loadOptions = (text: string) => {
return new Promise<SelectableOption[]>((resolve) => { return new Promise<SelectableOption[]>((resolve) => {
if (text) { const trimmedText = text.trim();
getSuggestedTeams(text).then((res) => { getTeamsByQuery({
const teams: Team[] = formatTeamsResponse( q:
res.data.suggest['metadata-suggest'][0].options (trimmedText ? `*${trimmedText}*` : '*') +
); (filterJoinable ? ` AND isJoinable:true` : ''),
resolve(getOptions(teams)); from: 0,
}); size: TEAM_OPTION_PAGE_LIMIT,
} else { }).then((res) => {
getTeamsByQuery({ const teams: Team[] =
q: '*', res.hits.hits.map((t: { _source: Team }) => t._source) || [];
from: 0, showTeamsAlert && setNoTeam(teams.length === 0);
size: TEAM_OPTION_PAGE_LIMIT, resolve(getOptions(teams));
isJoinable: filterJoinable, });
}).then((res) => {
const teams: Team[] =
res.hits.hits.map((t: { _source: Team }) => t._source) || [];
showTeamsAlert && setNoTeam(teams.length === 0);
resolve(getOptions(teams));
});
}
}); });
}; };