fix(ui): sync search value with url and state value (#19050)

* fix(ui): sync search value with url and state value

* fix flaky for user spec
This commit is contained in:
Chirag Madlani 2024-12-16 21:02:16 +05:30 committed by GitHub
parent c6774bf511
commit 4d30c83c55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -97,6 +97,12 @@ export const deletedUserChecks = async (page: Page) => {
export const visitUserProfilePage = async (page: Page, userName: string) => {
await settingClick(page, GlobalSettingOptions.USERS);
await page.waitForSelector(
'[data-testid="user-list-v1-component"] [data-testid="loader"]',
{
state: 'detached',
}
);
const userResponse = page.waitForResponse(
'/api/v1/search/query?q=**&from=0&size=*&index=*'
);
@ -470,9 +476,9 @@ export const permanentDeleteUser = async (
);
await page.click('[data-testid="confirm-button"]');
await hardDeleteUserResponse;
await reFetchUsers;
await toastNotification(page, `"${displayName}" deleted successfully!`);
await reFetchUsers;
// Wait for the loader to disappear
await page.waitForSelector('[data-testid="loader"]', { state: 'hidden' });

View File

@ -14,7 +14,7 @@
import { Button, Col, Modal, Row, Space, Switch, Tooltip } from 'antd';
import { ColumnsType } from 'antd/lib/table';
import { AxiosError } from 'axios';
import { capitalize, isEmpty } from 'lodash';
import { capitalize, debounce, isEmpty } from 'lodash';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory, useParams } from 'react-router-dom';
@ -235,6 +235,7 @@ const UserListPageV1 = () => {
const handleSearch = (value: string) => {
setSearchValue(value);
handlePageChange(INITIAL_PAGING_VALUE);
const params = new URLSearchParams({ user: value });
// This function is called onChange in the search input with debouncing
// Hence using history.replace instead of history.push to avoid adding multiple routes in history
@ -459,7 +460,8 @@ const UserListPageV1 = () => {
type: t('label.user'),
})}...`}
searchValue={searchValue}
onSearch={handleSearch}
typingInterval={0}
onSearch={debounce(handleSearch, 400)}
/>
</Col>