Skip to content

Filters from Application.display should migrate to Data #30

@ncdulo

Description

@ncdulo

Is your feature request related to a problem? Please describe.
Our current implementation to handle filtering arguments (--more, --before, --name, etc) is by filtering our copy of the data using if blocks to iteratively filter our data. This approach works, and it works well -- within Application.display. Those same arguments and filters are also desired in other modes. To repeat the code in each place would be an unnecessary burden and leave much more room for bugs & errors.

Describe the solution you'd like
The statements which actually perform the filtering can be made more general-purpose and broken down into individual members of Data. To do so, would allow us to re-use the same set of filtering logic throughout Application without repeating in each location.

I propose a set of filtering methods added in to Data that will accept a filter criteria and apply that filter onto the instance's copy of Data._data. Methods such as Data.amount_less_than, Data.date_before, and Date.new_equal are envisioned here. They can probably be made even more general purpose to handle any column, or set of criteria. That may not be a bad idea to prevent another refactor in the future and allow far greater extensibility.

Because we will be applying the filters to an internal copy of the data, we need to consider how we actually access pieces of that data from within Application. Data._data is not intended to be directly accessed and the changes proposed here may effect how methods such as Application.display work.

I would also like to update Arguments so that we do not need to re-create the same sets of sub-parsers, or arguments for each mode where we want to re-use the data filters we create. However, that is getting a bit out of scope and would best serve in it's own issue.

Describe alternatives you've considered
I have briefly considered the implementation above using two separate copies of the data. Data._data and Data._display_data. The latter being used when applying sort or filtering operations so that we can write back to disk without worry of losing data. This is not being further considered because I feel it would just create complexity where none is needed.

As long as any write operations follow the format: read, apply, write; there should be no issues with data loss. At least due to this, anyway. Plenty of other ways to watch out for!

Additional context
No additional context required at this time.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions