Skip to content
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

[Tables] Clean up filter code logic #5063

Closed
akhenry opened this issue Apr 12, 2022 · 6 comments · Fixed by #5284
Closed

[Tables] Clean up filter code logic #5063

akhenry opened this issue Apr 12, 2022 · 6 comments · Fixed by #5284
Labels
severity:trivial type:maintenance tests, chores, or project maintenance
Milestone

Comments

@akhenry
Copy link
Contributor

akhenry commented Apr 12, 2022

Summary

The TableRowCollection will conditionally clear the current contents of the table based on the value of a flag that is passed into the addRows function. Having addRows clear the current table is an unexpected side effect of a function called addRows. Instead the calling code should clear the table, then call addRows.

@akhenry akhenry added type:maintenance tests, chores, or project maintenance severity:trivial labels Apr 12, 2022
@JonanOribe
Copy link
Contributor

So the idea is to extract the method that cleans the table and call addRows at the end, right?.Could I take this one?

@akhenry
Copy link
Contributor Author

akhenry commented May 2, 2022

@JonanOribe Right, so find anywhere that addRows is being called with the type flag set tofilter, and instead of passing that parameter call .clear() and then addRows.

Once that's done, remove the 'type' parameter from addRows altogether.

And sure, it would be great if you could take a look at it! Thank you!

@JonanOribe
Copy link
Contributor

JonanOribe commented May 21, 2022

@akhenry looking at the code I saw that .clear() emit a 'remove' instead of the 'filter' that is called by the actual addRows when 'filter' is passed as a parameter. So, if I make the changes as you say, we have some problems with the functionality and some test cases just fail.

A workaround that I found, and with all testing goes green, is to make this:

            addRows(rows) {
                let rowsToAdd = this.manageRowsFromTables(rows);

                this.sortAndMergeRows(rowsToAdd);

                // we emit filter no matter what to trigger
                // an update of visible rows
                if (rowsToAdd.length > 0) {
                    this.emit('add', rowsToAdd);
                }
            }

            clearRowsFromTableAndFilter(rows) {

                let rowsToAdd = this.manageRowsFromTables(rows);
                // Reset of all rows, need to wipe current rows
                this.rows = [];

                this.sortAndMergeRows(rowsToAdd);

                // we emit filter and update of visible rows
                this.emit('filter', rowsToAdd);
            }

            manageRowsFromTables(rows) {
                if (this.sortOptions === undefined) {
                    throw 'Please specify sort options';
                }

                let anyActiveFilters = Object.keys(this.columnFilters).length > 0;

                return !anyActiveFilters ? rows : rows.filter(this.matchesFilters, this);
            }

Now, we have one method for cleaning and filtering and another for adding rows. I did not change the .clear() because it is called in many different places on code, but 'filter' just on one, so in my opinion, is more secure to make this change only on the new function.

What do you think? if neccesary, I look for another solution. Thank you!

@JonanOribe
Copy link
Contributor

I added the mentioned code on this PR

@akhenry
Copy link
Contributor Author

akhenry commented Dec 19, 2022

Testing Notes

This is a non-functional change with a risk of introducing regressions into tables, particularly with table filtering.

  1. Create a new table and drag-drop a telemetry point into it
  2. Set the time conductor to real-time mode, with bounds set such that you get ~100 results.
  3. Sort by timestamp and verify that the rows appear to be in the correct order
  4. Reverse the sort order and verify that the rows appear to be in the correct order.
  5. Sort by a value row (eg. Sine if using an SWG) and verify that the rows appear to be sorted correct.
  6. Set a filter value and verify that the results match the filter.
  7. Set a filter and a sort column and verify that the results match the filter and are sorted in the expected order

Testing Notes

Verify that you can filter rows and export as CSV and it reflects selection

@ozyx
Copy link
Member

ozyx commented Dec 28, 2022

Testathon 12/28/2022:

Sorting works as expected.
Filters for Value column works but throws errors continually:

image

Filtering for non-value columns (timestamp, name) works as expected with no errors.

CSV selection and export works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity:trivial type:maintenance tests, chores, or project maintenance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants