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;
from?: number;
size?: number;
isJoinable?: boolean;
}) => {
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;

View File

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