refactor: added null check while searching for dashboard (#4421)

* refactor: added null check while searching for dashboard

* refactor: flitering null value out

* chore: removed extra space

* refactor: remove unnecessary null check
This commit is contained in:
Rajat Dabade 2024-01-23 16:36:25 +05:30 committed by GitHub
parent 204cad8448
commit 199d52b39f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,16 +3,16 @@ import { Dashboard } from 'types/api/dashboard/getAll';
export const filterDashboard = ( export const filterDashboard = (
searchValue: string, searchValue: string,
dashboardList: Dashboard[], dashboardList: Dashboard[],
): any[] => { ): Dashboard[] => {
// Convert the searchValue to lowercase for case-insensitive search // Convert the searchValue to lowercase for case-insensitive search
const searchValueLowerCase = searchValue.toLowerCase(); const searchValueLowerCase = searchValue.toLowerCase();
// Use the filter method to find matching objects // Use the filter method to find matching objects
return dashboardList.filter((item: Dashboard) => { return dashboardList.filter((item: Dashboard) => {
// Convert each property value to lowercase for case-insensitive search // Convert each property value to lowercase for case-insensitive search
const itemValues = Object.values(item?.data).map((value) => const itemValues = Object.values(item?.data).map((value) => {
value.toString().toLowerCase(), if (value === null || value === undefined) return '';
); return value.toString().toLowerCase();
});
// Check if any property value contains the searchValue // Check if any property value contains the searchValue
return itemValues.some((value) => value.includes(searchValueLowerCase)); return itemValues.some((value) => value.includes(searchValueLowerCase));