#18008: global search should persist quick filter in explore (#19611)

* gloabl search should have applied quick filter

* added playwright test for it
This commit is contained in:
Ashish Gupta 2025-01-31 22:16:47 +05:30 committed by GitHub
parent ea0e26b7da
commit 647bab6019
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 75 additions and 25 deletions

View File

@ -10,12 +10,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import test from '@playwright/test'; import test, { expect } from '@playwright/test';
import { SidebarItem } from '../../constant/sidebar'; import { SidebarItem } from '../../constant/sidebar';
import { Domain } from '../../support/domain/Domain'; import { Domain } from '../../support/domain/Domain';
import { TableClass } from '../../support/entity/TableClass'; import { TableClass } from '../../support/entity/TableClass';
import { import {
assignDomain, assignDomain,
clickOutside,
createNewPage, createNewPage,
redirectToHomePage, redirectToHomePage,
} from '../../utils/common'; } from '../../utils/common';
@ -91,7 +92,7 @@ test('should search for empty or null filters', async ({ page }) => {
} }
}); });
test('should search for multiple values alongwith null filters', async ({ test('should search for multiple values along with null filters', async ({
page, page,
}) => { }) => {
const items = [ const items = [
@ -111,3 +112,37 @@ test('should search for multiple values alongwith null filters', async ({
await selectNullOption(page, filter); await selectNullOption(page, filter);
} }
}); });
test('should persist quick filter on global search', async ({ page }) => {
const items = [{ label: 'Owners', key: 'owners.displayName.keyword' }];
for (const filter of items) {
await selectNullOption(page, filter, false);
}
const waitForSearchResponse = page.waitForResponse(
'/api/v1/search/query?q=*index=dataAsset*'
);
await page
.getByTestId('searchBox')
.fill(table.entityResponseData.fullyQualifiedName);
await waitForSearchResponse;
await clickOutside(page);
// expect the quick filter to be persisted
await expect(
page.getByRole('button', { name: 'Owners : No Owners' })
).toBeVisible();
await page.getByTestId('searchBox').click();
await page.keyboard.down('Enter');
await page.waitForLoadState('networkidle');
// expect the quick filter to be persisted
await expect(
page.getByRole('button', { name: 'Owners : No Owners' })
).toBeVisible();
});

View File

@ -35,7 +35,7 @@ for (const searchItem of navbarSearchItems) {
); );
const searchRes = page.waitForResponse( const searchRes = page.waitForResponse(
`/api/v1/search/query?q=*&index=${searchIndex}` `/api/v1/search/query?q=*&index=${searchIndex}**`
); );
await page.getByTestId('searchBox').fill('dim'); await page.getByTestId('searchBox').fill('dim');
await searchRes; await searchRes;

View File

@ -45,7 +45,8 @@ export const searchAndClickOnOption = async (
export const selectNullOption = async ( export const selectNullOption = async (
page: Page, page: Page,
filter: { key: string; label: string; value?: string } filter: { key: string; label: string; value?: string },
clearFilter = true
) => { ) => {
const queryFilter = JSON.stringify({ const queryFilter = JSON.stringify({
query: { query: {
@ -101,7 +102,9 @@ export const selectNullOption = async (
expect(isQueryFilterPresent).toBeTruthy(); expect(isQueryFilterPresent).toBeTruthy();
if (clearFilter) {
await page.click(`[data-testid="clear-filters"]`); await page.click(`[data-testid="clear-filters"]`);
}
}; };
export const checkCheckboxStatus = async ( export const checkCheckboxStatus = async (

View File

@ -76,7 +76,7 @@ const Appbar: React.FC = (): JSX.Element => {
getExplorePath({ getExplorePath({
tab: defaultTab, tab: defaultTab,
search: value, search: value,
isPersistFilters: false, isPersistFilters: true,
extraParameters: { extraParameters: {
sort: '_score', sort: '_score',
}, },

View File

@ -13,8 +13,15 @@
import { Typography } from 'antd'; import { Typography } from 'antd';
import { AxiosError } from 'axios'; import { AxiosError } from 'axios';
import { isEmpty } from 'lodash'; import { isEmpty, isString } from 'lodash';
import React, { useCallback, useEffect, useRef, useState } from 'react'; import Qs from 'qs';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { PAGE_SIZE_BASE } from '../../constants/constants'; import { PAGE_SIZE_BASE } from '../../constants/constants';
import { import {
@ -43,7 +50,7 @@ import {
DashboardDataModelSearchSource, DashboardDataModelSearchSource,
StoredProcedureSearchSource, StoredProcedureSearchSource,
} from '../../interface/search.interface'; } from '../../interface/search.interface';
import { searchData } from '../../rest/miscAPI'; import { searchQuery } from '../../rest/searchAPI';
import { Transi18next } from '../../utils/CommonUtils'; import { Transi18next } from '../../utils/CommonUtils';
import searchClassBase from '../../utils/SearchClassBase'; import searchClassBase from '../../utils/SearchClassBase';
import { import {
@ -171,6 +178,18 @@ const Suggestions = ({
); );
}; };
const quickFilter = useMemo(() => {
const parsedSearch = Qs.parse(
location.search.startsWith('?')
? location.search.substring(1)
: location.search
);
return !isString(parsedSearch.quickFilter)
? {}
: JSON.parse(parsedSearch.quickFilter);
}, [location.search]);
const getSuggestionsForIndex = ( const getSuggestionsForIndex = (
suggestions: SearchSuggestions, suggestions: SearchSuggestions,
searchIndex: SearchIndex searchIndex: SearchIndex
@ -264,23 +283,16 @@ const Suggestions = ({
const fetchSearchData = useCallback(async () => { const fetchSearchData = useCallback(async () => {
try { try {
setIsLoading(true); setIsLoading(true);
const res = await searchData(
searchText,
1,
PAGE_SIZE_BASE,
'',
'',
'',
searchCriteria ?? SearchIndex.DATA_ASSET,
false,
false,
false
);
if (res.data) { const res = await searchQuery({
setOptions(res.data.hits.hits as unknown as Option[]); query: searchText,
updateSuggestions(res.data.hits.hits as unknown as Option[]); searchIndex: searchCriteria ?? SearchIndex.DATA_ASSET,
} queryFilter: quickFilter,
pageSize: PAGE_SIZE_BASE,
});
setOptions(res.hits.hits as unknown as Option[]);
updateSuggestions(res.hits.hits as unknown as Option[]);
} catch (err) { } catch (err) {
showErrorToast( showErrorToast(
err as AxiosError, err as AxiosError,