From 22f881046105d387d8dc29881f4de1834f587041 Mon Sep 17 00:00:00 2001 From: VaibhavTalkhande Date: Thu, 28 Dec 2023 18:44:15 +0530 Subject: [PATCH] Revert "Added the Filtering Functionality (#1281)" This reverts commit f1c4e3e1f71a0b578870b727c8110dd57518a038. --- public/locales/en.json | 3 +- public/locales/fr.json | 3 +- public/locales/hi.json | 3 +- public/locales/sp.json | 3 +- public/locales/zh.json | 3 +- src/screens/Users/Users.test.tsx | 111 +------------------------- src/screens/Users/Users.tsx | 86 +++----------------- src/screens/Users/UsersMocks.ts | 132 ------------------------------- 8 files changed, 20 insertions(+), 324 deletions(-) diff --git a/public/locales/en.json b/public/locales/en.json index 37793acd5f..17313741e3 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -147,8 +147,7 @@ "noOrgError": "Organizations not found, please create an organization through dashboard", "roleUpdated": "Role Updated.", "noResultsFoundFor": "No results found for ", - "talawaApiUnavailable": "Talawa-API service is unavailable. Is it running? Check your network connectivity too.", - "cancel": "Cancel" + "talawaApiUnavailable": "Talawa-API service is unavailable. Is it running? Check your network connectivity too." }, "requests": { "title": "Talawa Requests", diff --git a/public/locales/fr.json b/public/locales/fr.json index 4c2f34ce8e..ab23401603 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -137,8 +137,7 @@ "filter": "Filtre", "roleUpdated": "Rôle mis à jour.", "noResultsFoundFor": "Aucun résultat trouvé pour ", - "talawaApiUnavailable": "Le service Talawa-API n'est pas disponible. Est-il en cours d'exécution ? Vérifiez également votre connectivité réseau.", - "cancel": "Annuler" + "talawaApiUnavailable": "Le service Talawa-API n'est pas disponible. Est-il en cours d'exécution ? Vérifiez également votre connectivité réseau." }, "requests": { "title": "Demandes Talawa", diff --git a/public/locales/hi.json b/public/locales/hi.json index c5c57ec206..ce53bf4ff8 100644 --- a/public/locales/hi.json +++ b/public/locales/hi.json @@ -136,8 +136,7 @@ "filter": "फ़िल्टर", "roleUpdated": "भूमिका अपडेट की गई।", "noResultsFoundFor": "के लिए कोई परिणाम नहीं मिला ", - "talawaApiUnavailable": "तलवा-एपीआई सेवा उपलब्ध नहीं है। क्या यह चल रहा है? अपनी नेटवर्क कनेक्टिविटी भी जांचें।", - "cancel": "रद्द करें" + "talawaApiUnavailable": "तलवा-एपीआई सेवा उपलब्ध नहीं है। क्या यह चल रहा है? अपनी नेटवर्क कनेक्टिविटी भी जांचें।" }, "requests": { "title": "तलवा अनुरोध", diff --git a/public/locales/sp.json b/public/locales/sp.json index 66e1d78c17..26f7288d8a 100644 --- a/public/locales/sp.json +++ b/public/locales/sp.json @@ -136,8 +136,7 @@ "filter": "Filtrar", "roleUpdated": "Rol actualizado.", "noResultsFoundFor": "No se encontraron resultados para ", - "talawaApiUnavailable": "El servicio Talawa-API no está disponible. ¿Está funcionando? Compruebe también la conectividad de su red.", - "cancel": "Cancelar" + "talawaApiUnavailable": "El servicio Talawa-API no está disponible. ¿Está funcionando? Compruebe también la conectividad de su red." }, "requests": { "title": "Solicitudes Talawa", diff --git a/public/locales/zh.json b/public/locales/zh.json index beb5649088..d782fd897e 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -136,8 +136,7 @@ "filter": "過濾", "roleUpdated": "角色已更新。", "noResultsFoundFor": "未找到结果 ", - "talawaApiUnavailable": "服務不可用。它在運行嗎?還要檢查您的網絡連接。", - "cancel": "取消" + "talawaApiUnavailable": "服務不可用。它在運行嗎?還要檢查您的網絡連接。" }, "requests": { "title": "塔拉瓦請求", diff --git a/src/screens/Users/Users.test.tsx b/src/screens/Users/Users.test.tsx index 7879d833fb..4484518529 100644 --- a/src/screens/Users/Users.test.tsx +++ b/src/screens/Users/Users.test.tsx @@ -12,11 +12,10 @@ import { store } from 'state/store'; import { StaticMockLink } from 'utils/StaticMockLink'; import i18nForTest from 'utils/i18nForTest'; import Users from './Users'; -import { EMPTY_MOCKS, MOCKS, MOCKS2 } from './UsersMocks'; +import { EMPTY_MOCKS, MOCKS } from './UsersMocks'; const link = new StaticMockLink(MOCKS, true); const link2 = new StaticMockLink(EMPTY_MOCKS, true); -const link3 = new StaticMockLink(MOCKS2, true); async function wait(ms = 100): Promise { await act(() => { @@ -122,27 +121,6 @@ describe('Testing Users screen', () => { userEvent.type(screen.getByTestId(/searchByName/i), ''); }); - test('testing search not found', async () => { - render( - - - - - - - - - - ); - - await wait(); - - const search = 'hello{enter}'; - await act(() => - userEvent.type(screen.getByTestId(/searchByName/i), search) - ); - }); - test('Testing User data is not present', async () => { render( @@ -201,7 +179,7 @@ describe('Testing Users screen', () => { ); }); - test('Testing sorting functionality', async () => { + test('Testing sort Newest and oldest toggle', async () => { await act(async () => { render( @@ -224,96 +202,15 @@ describe('Testing Users screen', () => { const inputText = screen.getByTestId('sortUsers'); fireEvent.click(inputText); - const toggleText = screen.getByTestId('oldest'); - fireEvent.click(toggleText); - - expect(searchInput).toBeInTheDocument(); - - fireEvent.click(inputText); - const toggleTite = screen.getByTestId('newest'); - fireEvent.click(toggleTite); - - expect(searchInput).toBeInTheDocument(); - }); - }); - - test('Testing filter functionality', async () => { - await act(async () => { - render( - - - - - - - - - - - ); - - await wait(); + const toggleText = screen.getByTestId('newest'); - const searchInput = screen.getByTestId('filter'); - expect(searchInput).toBeInTheDocument(); - - const inputText = screen.getByTestId('filterUsers'); - - fireEvent.click(inputText); - const toggleText = screen.getByTestId('admin'); fireEvent.click(toggleText); expect(searchInput).toBeInTheDocument(); - - fireEvent.click(inputText); - let toggleTite = screen.getByTestId('superAdmin'); - fireEvent.click(toggleTite); - - expect(searchInput).toBeInTheDocument(); - - fireEvent.click(inputText); - toggleTite = screen.getByTestId('user'); - fireEvent.click(toggleTite); - - expect(searchInput).toBeInTheDocument(); - fireEvent.click(inputText); - toggleTite = screen.getByTestId('cancel'); + const toggleTite = screen.getByTestId('oldest'); fireEvent.click(toggleTite); - - await wait(); - expect(searchInput).toBeInTheDocument(); }); }); - - test('check for rerendering', async () => { - const { rerender } = render( - - - - - - - - - - - ); - - await wait(); - rerender( - - - - - - - - - - - ); - await wait(); - }); }); diff --git a/src/screens/Users/Users.tsx b/src/screens/Users/Users.tsx index 93eaa3f10c..0cdac832b5 100644 --- a/src/screens/Users/Users.tsx +++ b/src/screens/Users/Users.tsx @@ -31,7 +31,7 @@ const Users = (): JSX.Element => { const [isLoadingMore, setIsLoadingMore] = useState(false); const [searchByName, setSearchByName] = useState(''); const [sortingOption, setSortingOption] = useState('newest'); - const [filteringOption, setFilteringOption] = useState('cancel'); + const userType = localStorage.getItem('UserType'); const loggedInUserId = localStorage.getItem('id'); @@ -68,11 +68,10 @@ const Users = (): JSX.Element => { setHasMore(false); } if (usersData && usersData.users) { - let newDisplayedUsers = sortUsers(usersData.users, sortingOption); - newDisplayedUsers = filterUsers(newDisplayedUsers, filteringOption); + const newDisplayedUsers = sortUsers(usersData.users, sortingOption); setDisplayedUsers(newDisplayedUsers); } - }, [usersData, sortingOption, filteringOption]); + }, [usersData, sortingOption]); // To clear the search when the component is unmounted useEffect(() => { @@ -180,44 +179,14 @@ const Users = (): JSX.Element => { (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ); - return sortedUsers; - } else { + } else if (sortingOption === 'oldest') { sortedUsers.sort( (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() ); - return sortedUsers; } - }; - const handleFiltering = (option: string): void => { - setFilteringOption(option); - }; - - const filterUsers = ( - allUsers: InterfaceQueryUserListItem[], - filteringOption: string - ): InterfaceQueryUserListItem[] => { - const filteredUsers = [...allUsers]; - - if (filteringOption === 'cancel') { - return filteredUsers; - } else if (filteringOption === 'user') { - const output = filteredUsers.filter((user) => { - return user.userType === 'USER'; - }); - return output; - } else if (filteringOption === 'admin') { - const output = filteredUsers.filter((user) => { - return user.userType == 'ADMIN'; - }); - return output; - } else { - const output = filteredUsers.filter((user) => { - return user.userType == 'SUPERADMIN'; - }); - return output; - } + return sortedUsers; }; const headerTitles: string[] = [ @@ -253,7 +222,6 @@ const Users = (): JSX.Element => { @@ -288,44 +256,15 @@ const Users = (): JSX.Element => { -