Created a new system for the Groups that will persist after having entities

This commit is contained in:
Tiago Ribeiro
2024-09-25 16:18:43 +01:00
parent 8c392f8b49
commit dd94228672
18 changed files with 823 additions and 136 deletions

View File

@@ -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);
}