-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(#16584): filterTableData source of truth #36849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
72f3828
4d5c7e8
fbcd17f
b08abe7
39d4e5e
6869df8
6632e4a
01e008f
d89cb67
163e7b6
c10dd6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -446,25 +446,42 @@ export default { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| sortedTableData = transformedTableDataForSorting.sort((a, b) => { | ||||||||||||||||||||||||||||||||
| if (_.isPlainObject(a) && _.isPlainObject(b)) { | ||||||||||||||||||||||||||||||||
| let [processedA, processedB] = [a, b]; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (!selectColumnKeysWithSortByLabel.length) { | ||||||||||||||||||||||||||||||||
| const originalA = (props.tableData ?? | ||||||||||||||||||||||||||||||||
| transformedTableDataForSorting)[a.__originalIndex__]; | ||||||||||||||||||||||||||||||||
| const originalB = (props.tableData ?? | ||||||||||||||||||||||||||||||||
| transformedTableDataForSorting)[b.__originalIndex__]; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [processedA, processedB] = [ | ||||||||||||||||||||||||||||||||
| { ...a, ...originalA }, | ||||||||||||||||||||||||||||||||
| { ...b, ...originalB }, | ||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||
| isEmptyOrNil(a[sortByColumnOriginalId]) || | ||||||||||||||||||||||||||||||||
| isEmptyOrNil(b[sortByColumnOriginalId]) | ||||||||||||||||||||||||||||||||
| isEmptyOrNil(processedA[sortByColumnOriginalId]) || | ||||||||||||||||||||||||||||||||
| isEmptyOrNil(processedB[sortByColumnOriginalId]) | ||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||
| /* push null, undefined and "" values to the bottom. */ | ||||||||||||||||||||||||||||||||
| return isEmptyOrNil(a[sortByColumnOriginalId]) ? 1 : -1; | ||||||||||||||||||||||||||||||||
| return isEmptyOrNil(processedA[sortByColumnOriginalId]) ? 1 : -1; | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| switch (columnType) { | ||||||||||||||||||||||||||||||||
| case "number": | ||||||||||||||||||||||||||||||||
| case "currency": | ||||||||||||||||||||||||||||||||
| return sortByOrder( | ||||||||||||||||||||||||||||||||
| Number(a[sortByColumnOriginalId]) > | ||||||||||||||||||||||||||||||||
| Number(b[sortByColumnOriginalId]), | ||||||||||||||||||||||||||||||||
| Number(processedA[sortByColumnOriginalId]) > | ||||||||||||||||||||||||||||||||
| Number(processedB[sortByColumnOriginalId]), | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| case "date": | ||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||
| return sortByOrder( | ||||||||||||||||||||||||||||||||
| moment(a[sortByColumnOriginalId], inputFormat).isAfter( | ||||||||||||||||||||||||||||||||
| moment(b[sortByColumnOriginalId], inputFormat), | ||||||||||||||||||||||||||||||||
| moment( | ||||||||||||||||||||||||||||||||
| processedA[sortByColumnOriginalId], | ||||||||||||||||||||||||||||||||
| inputFormat, | ||||||||||||||||||||||||||||||||
| ).isAfter( | ||||||||||||||||||||||||||||||||
| moment(processedB[sortByColumnOriginalId], inputFormat), | ||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||
|
|
@@ -489,8 +506,8 @@ export default { | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||
| return sortByOrder( | ||||||||||||||||||||||||||||||||
| a[sortByColumnOriginalId].toString().toLowerCase() > | ||||||||||||||||||||||||||||||||
| b[sortByColumnOriginalId].toString().toLowerCase(), | ||||||||||||||||||||||||||||||||
| processedA[sortByColumnOriginalId].toString().toLowerCase() > | ||||||||||||||||||||||||||||||||
| processedB[sortByColumnOriginalId].toString().toLowerCase(), | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
@@ -676,6 +693,9 @@ export default { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const finalTableData = sortedTableData.filter((row) => { | ||||||||||||||||||||||||||||||||
| let isSearchKeyFound = true; | ||||||||||||||||||||||||||||||||
| const originalRow = (props.tableData ?? sortedTableData)[ | ||||||||||||||||||||||||||||||||
| row.__originalIndex__ | ||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||
| const columnWithDisplayText = Object.values(props.primaryColumns).filter( | ||||||||||||||||||||||||||||||||
| (column) => column.columnType === "url" && column.displayText, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
|
@@ -780,7 +800,10 @@ export default { | |||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (searchKey) { | ||||||||||||||||||||||||||||||||
| isSearchKeyFound = Object.values(_.omit(displayedRow, hiddenColumns)) | ||||||||||||||||||||||||||||||||
| isSearchKeyFound = [ | ||||||||||||||||||||||||||||||||
| ...Object.values(_.omit(displayedRow, hiddenColumns)), | ||||||||||||||||||||||||||||||||
| ...Object.values(_.omit(originalRow, hiddenColumns)), | ||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||
| .join(", ") | ||||||||||||||||||||||||||||||||
| .toLowerCase() | ||||||||||||||||||||||||||||||||
| .includes(searchKey); | ||||||||||||||||||||||||||||||||
|
|
@@ -811,10 +834,15 @@ export default { | |||||||||||||||||||||||||||||||
| ConditionFunctions[props.filters[i].condition]; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (conditionFunction) { | ||||||||||||||||||||||||||||||||
| filterResult = conditionFunction( | ||||||||||||||||||||||||||||||||
| displayedRow[props.filters[i].column], | ||||||||||||||||||||||||||||||||
| props.filters[i].value, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| filterResult = | ||||||||||||||||||||||||||||||||
| conditionFunction( | ||||||||||||||||||||||||||||||||
| originalRow[props.filters[i].column], | ||||||||||||||||||||||||||||||||
| props.filters[i].value, | ||||||||||||||||||||||||||||||||
| ) || | ||||||||||||||||||||||||||||||||
| conditionFunction( | ||||||||||||||||||||||||||||||||
| displayedRow[props.filters[i].column], | ||||||||||||||||||||||||||||||||
| props.filters[i].value, | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+837
to
+845
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Let's make the filter condition check more readable! Class, while the logic is correct, we can make it more maintainable by extracting the condition check into a helper function. Consider this refactor to improve readability: -filterResult =
- conditionFunction(
- originalRow[props.filters[i].column],
- props.filters[i].value,
- ) ||
- conditionFunction(
- displayedRow[props.filters[i].column],
- props.filters[i].value,
- );
+const checkCondition = (row, column, value) =>
+ conditionFunction(row[column], value);
+
+filterResult =
+ checkCondition(originalRow, props.filters[i].column, props.filters[i].value) ||
+ checkCondition(displayedRow, props.filters[i].column, props.filters[i].value);📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||
| filterResult = false; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider optimizing the search operation.
While including both displayed and original values in the search is thorough, let's think about performance. When dealing with large datasets, concatenating all values and performing string operations could be expensive.
Consider this optimization:
This approach stops searching as soon as a match is found, potentially improving performance with large datasets.