Created a new system for the Groups that will persist after having entities
This commit is contained in:
@@ -3,11 +3,20 @@
|
||||
['companyInformation', 'companyInformation', 'name']
|
||||
]*/
|
||||
|
||||
const getFieldValue = (fields: string[], data: any): string => {
|
||||
const getFieldValue = (fields: string[], data: any): string | string[] => {
|
||||
if (fields.length === 0) return data;
|
||||
const [key, ...otherFields] = fields;
|
||||
|
||||
if (data[key]) return getFieldValue(otherFields, data[key]);
|
||||
if (Array.isArray(data[key])) {
|
||||
// If the key points to an array, like "participants", iterate through each item in the array
|
||||
return data[key]
|
||||
.map((item: any) => getFieldValue(otherFields, item)) // Get the value for each item
|
||||
.filter(Boolean); // Filter out undefined or null values
|
||||
} else if (data[key] !== undefined) {
|
||||
// If it's not an array, just go deeper in the object
|
||||
return getFieldValue(otherFields, data[key]);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -16,6 +25,11 @@ export const search = (text: string, fields: string[][], rows: any[]) => {
|
||||
return rows.filter((row) => {
|
||||
return fields.some((fieldsKeys) => {
|
||||
const value = getFieldValue(fieldsKeys, row);
|
||||
if (Array.isArray(value)) {
|
||||
// If it's an array (e.g., participants' names), check each value in the array
|
||||
return value.some((v) => v && typeof v === "string" && v.toLowerCase().includes(searchText));
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
return value.toLowerCase().includes(searchText);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user