Fix free text search
Summary:
In diff D36663929 (e07d5c5bfe) the behaviour of data table was changed so that it only searched fields that were columns in the table. Due to user request we are restoring the functionality where you can search and it will look in all top level fields in the underlying object for the row
changelog: Fixed 'free text search' for data table. E.g network plugin
Reviewed By: mweststrate
Differential Revision: D37552492
fbshipit-source-id: 00ec942b2a2336c19a7d067d85cc6c81b8a175e1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
873c03396e
commit
1353e0630b
@@ -637,13 +637,19 @@ export function computeDataTableFilter(
|
||||
}
|
||||
}
|
||||
|
||||
return columns
|
||||
.map((c) => getValueAtPath(item, c.key))
|
||||
.some((v) =>
|
||||
searchRegex
|
||||
//free search all top level keys as well as any (nested) columns in the table
|
||||
const nestedColumns = columns
|
||||
.map((col) => col.key)
|
||||
.filter((path) => path.includes('.'));
|
||||
|
||||
return [...Object.keys(item), ...nestedColumns]
|
||||
.map((key) => getValueAtPath(item, key))
|
||||
.filter((val) => typeof val !== 'object')
|
||||
.some((v) => {
|
||||
return searchRegex
|
||||
? searchRegex.test(String(v))
|
||||
: String(v).toLowerCase().includes(searchString),
|
||||
);
|
||||
: String(v).toLowerCase().includes(searchString);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -359,7 +359,11 @@ test('compute filters', () => {
|
||||
const filter = computeDataTableFilter('tEsT', false, baseColumns)!;
|
||||
expect(data.filter(filter)).toEqual([]);
|
||||
}
|
||||
|
||||
{
|
||||
//no columns but should still find rows
|
||||
const filter = computeDataTableFilter('EE', false, [])!;
|
||||
expect(data.filter(filter)).toEqual([coffee, meet]);
|
||||
}
|
||||
{
|
||||
const filter = computeDataTableFilter('EE', false, baseColumns)!;
|
||||
expect(data.filter(filter)).toEqual([coffee, meet]);
|
||||
|
||||
Reference in New Issue
Block a user