The users tab of admin panel of SUSI.AI provides a list of all users registered on SUSI. This helps admins to get an overview of users and also provides the admins option like change user roles and delete accounts. The list of users is displayed in a table which also uses pagination to handle larger number of users. But to find a particular user can be a difficult task if the user base is large. Therefore a feature to search for users by their email has been implement which searches for users on SUSI server and then sends the searched users to the client. In this post we will discuss both about the server and client side implementation of this feature.
On the server, the getUsers API is used to list all users based on pagination or search terms. For searching users we need to make the following request to this API,
The search parameter contains the value of the keyword which will be searched in emails of users by the server. All users are stored in the authorization.json files in the data directory on the server. First we need to fetch users list from this file and then create a list of all users. This is done by the DAO.getAuthorizedClients() method which returns a collection of authorized clients. This is converted into a list of strings and then into an array of strings where each entry is the email of the user.
The ‘keysArray’ is iterated for each user and also searched for the search term and users with the search term are appended into the userList json array. The elements of keysArray has the substring ’email:’ at the beginning of their emails which needs to be sliced before searching for the keyword.
Once the iteration is completed the json array ‘userList’ is then send as the response to our query with a success message telling that we fetched all users with the search keyword in their emails.
On the client side, a search input component with a placeholder telling to search by email is displayed which pass the search keyword to the handleSearch() function which handles the search queries.
The handleSearch function makes the API call and then process the response into the required format displayed on the screen.
The response from the server is a json array with data about each user. This data is then processed into the format which is used in ant design tables using the code block below