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

Finance: port agent filtering to finance #1102

Merged
merged 7 commits into from
Apr 9, 2020
Merged

Conversation

Evalir
Copy link
Contributor

@Evalir Evalir commented Mar 19, 2020

Closes #1100 .

Ports agent filtering to finance, using hooks and consolidating all state regarding the filters in the useFilteredTransfers hook. Minor modifications were made due to differences in the script.js, mainly in detecting the transaction type. (Incoming, or Outgoing)

@Evalir Evalir requested review from bpierre and sohkai March 19, 2020 14:53
Copy link
Contributor Author

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments on the things I think we might wanna discuss! 😃

apps/finance/app/src/components/Transfers.js Show resolved Hide resolved
apps/finance/app/src/transfer-types.js Outdated Show resolved Hide resolved
apps/finance/app/src/transfer-types.js Outdated Show resolved Hide resolved
transferTypes={TRANSFER_TYPES_STRING}
tokenFilter={selectedToken}
transferTypeFilter={selectedTransferType}
transferTypes={READABLE_TRANSFER_TYPES}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this value should be controlled by useFilteredTransfers(), to encapsulate all the filtering logic to be within it.

It would be bad if we re-ordered the list but forgot to update it here or in that hook, which suggests we should encapsulate the concepts :).

Copy link
Contributor Author

@Evalir Evalir Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this value should be controlled by useFilteredTransfers(), to encapsulate all the filtering logic to be within it.

Now that I think about it, it makes sense, as symbols is handled by useFilteredTransfers() itself. Now, would we just import the labels and export them back with another name, like this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's what I would've done!

apps/finance/app/src/transfer-types.js Outdated Show resolved Hide resolved
apps/finance/app/src/components/useFilteredTransfers.js Outdated Show resolved Hide resolved
Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more comments!

return false
}

// Case 3: we don't have a start date, but do have an end date.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I get these changes...

What I might do instead is filter separately by start date and end date, with isAfter() and isBefore().

E.g.

if (selectedDateRange.start && isBefore(new Date(date), startOfDay(selectedDateRange.start)) {
  return false
}
// and vice-versa for the end date

export const TRANSFER_TYPES = Reflect.ownKeys(READABLE_TRANSFER_TYPES)
export const TRANSFER_TYPES_LABELS = Reflect.ownKeys(
READABLE_TRANSFER_TYPES
).map(type => READABLE_TRANSFER_TYPES[type])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having to do this, we can instead use an array of tuples and work on that instead.

E.g.

const AVAILABLE_TRANSFER_TYPES = [
  [All, 'All'], [Incoming, 'Incoming'], [Outgoing, 'Outgoing']
]

export const TRANSFER_TYPES = AVAILABLE_TRANSFER_TYPES.map(([type]) => type)
export const TRANSFER_TYPES_LABELS = AVAILABLE_TRANSFER_TYPES.map(([_, label]) => label)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks way cleaner!

@@ -32,10 +32,12 @@ function useFilteredTransfers({ transactions, tokens }) {
setSelectedDateRange(range)
}, [])
const handleTokenChange = useCallback(index => {
setSelectedToken(index || UNSELECTED_TOKEN_FILTER)
const tokenIndex = index === 0 ? -1 : index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const tokenIndex = index === 0 ? -1 : index
const tokenIndex = index === 0 ? UNSELECTED_TOKEN_FILTER : index

Maybe this is more clear and uses the constant.

Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!! 🚀

@Evalir Evalir merged commit 09d55b1 into master Apr 9, 2020
facuspagnuolo pushed a commit that referenced this pull request May 22, 2020
* Port agent filtering to finance

* Revert transfer types to symbols, rename variable for readability

* Make TRANSFER_TYPES_LABELS be provided by useFilteredTransfers()

* Move set page to effect, use Reflect for iterating over object with symbol keys

* Make index conversion to unselected standard clearer on filtering hook

* Add more robust case checking for dates

* Add individual date filtering, transform transfer types to tuple array, make handlers clearer
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
* Port agent filtering to finance

* Revert transfer types to symbols, rename variable for readability

* Make TRANSFER_TYPES_LABELS be provided by useFilteredTransfers()

* Move set page to effect, use Reflect for iterating over object with symbol keys

* Make index conversion to unselected standard clearer on filtering hook

* Add more robust case checking for dates

* Add individual date filtering, transform transfer types to tuple array, make handlers clearer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finance: port Agent filtering
2 participants