fix(ui): ui fixes for search dropdown suggestions API for owner and tag quick filters (#9961)

* Made changes for default options API calls for owner dropdown
Fixed glossary suggestions not showing for tag quick filters

* Fixed cypress tests
This commit is contained in:
Aniket Katkar 2023-01-27 21:38:13 +05:30 committed by GitHub
parent e2d94a66e4
commit d9ea00b2f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 18 deletions

View File

@ -11,14 +11,16 @@
* limitations under the License. * limitations under the License.
*/ */
import { COMMON_DROPDOWN_ITEMS } from '../constants/advancedSearchQuickFilters.constants';
import { interceptURL, verifyResponseStatusCode } from './common'; import { interceptURL, verifyResponseStatusCode } from './common';
export const openFilterDropdown = (asset, filter) => { export const openFilterDropdown = (asset, filter) => {
interceptURL( let aggregateAPIURL =
'GET', filter.key === COMMON_DROPDOWN_ITEMS[0].key
`http://localhost:8585/api/v1/search/aggregate?index=${asset.searchIndex}&field=${filter.key}`, ? `/api/v1/search/aggregate?index=${filter.filterSearchIndex}&field=${filter.aggregateKey}`
'aggregateAPI' : `/api/v1/search/aggregate?index=${asset.searchIndex}&field=${filter.key}`;
);
interceptURL('GET', aggregateAPIURL, 'aggregateAPI');
// Click on desired dropdown // Click on desired dropdown
cy.get(`[data-testid="search-dropdown-${filter.label}"]`) cy.get(`[data-testid="search-dropdown-${filter.label}"]`)
@ -37,12 +39,21 @@ export const searchAndClickOnOption = (
checkedAfterClick checkedAfterClick
) => { ) => {
// Search for filter // Search for filter
interceptURL(
'GET',
`/api/v1/search/suggest?*q=${encodeURI(optionName)}*`,
'suggestAPI'
);
cy.get('[data-testid="search-input"]') cy.get('[data-testid="search-input"]')
.should('exist') .should('exist')
.and('be.visible') .and('be.visible')
.clear() .clear()
.type(optionName); .type(optionName);
verifyResponseStatusCode('@suggestAPI', 200);
cy.get(`[data-testid="${optionTestId}"]`) cy.get(`[data-testid="${optionTestId}"]`)
.should('exist') .should('exist')
.and('be.visible') .and('be.visible')

View File

@ -17,6 +17,8 @@ export const COMMON_DROPDOWN_ITEMS = [
{ {
label: 'Owner', label: 'Owner',
key: 'owner.displayName', key: 'owner.displayName',
aggregateKey: 'displayName.keyword',
filterSearchIndex: 'user_search_index%2Cteam_search_index',
selectOption1: 'admin', selectOption1: 'admin',
selectOptionTestId1: 'admin', selectOptionTestId1: 'admin',
selectOption2: 'Aaron Singh', selectOption2: 'Aaron Singh',
@ -25,6 +27,7 @@ export const COMMON_DROPDOWN_ITEMS = [
{ {
label: 'Tag', label: 'Tag',
key: 'tags.tagFQN', key: 'tags.tagFQN',
filterSearchIndex: 'tag_search_index%2Cglossary_search_index',
selectOption1: 'PersonalData.Personal', selectOption1: 'PersonalData.Personal',
selectOptionTestId1: 'PersonalData.Personal', selectOptionTestId1: 'PersonalData.Personal',
selectOption2: 'PII.Sensitive', selectOption2: 'PII.Sensitive',

View File

@ -54,7 +54,7 @@ QUICK_FILTERS_BY_ASSETS.map((asset) => {
searchAndClickOnOption(optionName1, optionTestId1, true); searchAndClickOnOption(optionName1, optionTestId1, true);
let querySearchURL = `http://localhost:8585/api/v1/search/query?*index=${ let querySearchURL = `/api/v1/search/query?*index=${
asset.searchIndex asset.searchIndex
}*query_filter=*should*${filter.key}*${encodeURI(optionName1)}*`; }*query_filter=*should*${filter.key}*${encodeURI(optionName1)}*`;

View File

@ -13,6 +13,7 @@
import { Divider, Space } from 'antd'; import { Divider, Space } from 'antd';
import { AxiosError } from 'axios'; import { AxiosError } from 'axios';
import { SearchIndex } from 'enums/search.enum';
import { isEqual, isUndefined, uniqWith } from 'lodash'; import { isEqual, isUndefined, uniqWith } from 'lodash';
import React, { FC, useState } from 'react'; import React, { FC, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -22,7 +23,10 @@ import {
getTagSuggestions, getTagSuggestions,
getUserSuggestions, getUserSuggestions,
} from 'rest/miscAPI'; } from 'rest/miscAPI';
import { MISC_FIELDS } from '../../constants/AdvancedSearch.constants'; import {
MISC_FIELDS,
OWNER_QUICK_FILTER_DEFAULT_OPTIONS_KEY,
} from '../../constants/AdvancedSearch.constants';
import { import {
getAdvancedField, getAdvancedField,
getOptionsObject, getOptionsObject,
@ -43,19 +47,34 @@ const ExploreQuickFilters: FC<ExploreQuickFiltersProps> = ({
const [options, setOptions] = useState<SearchDropdownOption[]>(); const [options, setOptions] = useState<SearchDropdownOption[]>();
const [isOptionsLoading, setIsOptionsLoading] = useState<boolean>(false); const [isOptionsLoading, setIsOptionsLoading] = useState<boolean>(false);
const fetchDefaultOptions = async (
index: SearchIndex | SearchIndex[],
key: string
) => {
const res = await getAdvancedFieldDefaultOptions(index, key);
const buckets = res.data.aggregations[`sterms#${key}`].buckets;
const optionsArray = buckets.map((option) => ({
key: option.key,
label: option.key,
}));
setOptions(uniqWith(optionsArray, isEqual));
};
const getInitialOptions = async (key: string) => { const getInitialOptions = async (key: string) => {
setIsOptionsLoading(true); setIsOptionsLoading(true);
setOptions([]); setOptions([]);
try { try {
const res = await getAdvancedFieldDefaultOptions(index, key); if (key === MISC_FIELDS[0]) {
const buckets = res.data.aggregations[`sterms#${key}`].buckets; await fetchDefaultOptions(
[SearchIndex.USER, SearchIndex.TEAM],
const optionsArray = buckets.map((option) => ({ OWNER_QUICK_FILTER_DEFAULT_OPTIONS_KEY
key: option.key, );
label: option.label ?? option.key, } else {
})); await fetchDefaultOptions(index, key);
}
setOptions(uniqWith(optionsArray, isEqual));
} catch (error) { } catch (error) {
showErrorToast(error as AxiosError); showErrorToast(error as AxiosError);
} finally { } finally {

View File

@ -457,3 +457,5 @@ export const getQbConfigs: (searchIndex: SearchIndex) => BasicConfig = (
}; };
export const MISC_FIELDS = ['owner.displayName', 'tags.tagFQN']; export const MISC_FIELDS = ['owner.displayName', 'tags.tagFQN'];
export const OWNER_QUICK_FILTER_DEFAULT_OPTIONS_KEY = 'displayName.keyword';

View File

@ -183,7 +183,7 @@ export const getTeamsByQuery = async (params: {
export const getTagSuggestions = (term: string) => { export const getTagSuggestions = (term: string) => {
const params = { const params = {
q: term, q: term,
index: `${SearchIndex.TAG},${SearchIndex.TAG}`, index: `${SearchIndex.TAG},${SearchIndex.GLOSSARY}`,
}; };
return APIClient.get<RawSuggestResponse<SearchIndex.TAG>>(`/search/suggest`, { return APIClient.get<RawSuggestResponse<SearchIndex.TAG>>(`/search/suggest`, {
@ -249,7 +249,7 @@ export const getAdvancedFieldOptions = (
}; };
export const getAdvancedFieldDefaultOptions = ( export const getAdvancedFieldDefaultOptions = (
index: SearchIndex, index: SearchIndex | SearchIndex[],
field: string field: string
) => { ) => {
const params = { index, field }; const params = { index, field };