twenty icon indicating copy to clipboard operation
twenty copied to clipboard

Sort does not work on Board view

Open charlesBochet opened this issue 1 year ago • 4 comments

Bug Description

Going to the Opportunity Board view, try sort by "name". The sort won't be apply image

Technical input

We have recently introduced the notion of position. The position is a float that specifies the position between record in list. This is useful if you want to re-order cards in a kanban column for example. So we actually have two sorts applied: { name, position }. The issue is that our code does not handle sorting by two fields well

Getting down to the root cause in details:

  • in packages/twenty-front/src/modules/object-record/record-board/hooks/internal/useSetRecordBoardRecordIds.ts, we hard apply a sort by position to make sure that drag and drop position is working. We should remove this
  • Once removed, the name sort will work but the position won't work anymore (if you drag and drop a card in the same column, the position of the record will be updated but the sorting won't be applied on position.
  • What's happening is that when you update a record (by modifying its position), we are sending a query to the server AND handling the optimistic rendering ourselve (triggerUpdateRecordOptimisticEffect call in useUpdateOneRecord). This optimistic effect logic will loop over all queries mentioning the record and artificially re-compute the result.
  • In the end, the sortCachedObjectEdges.ts function is called and as you can see: const [orderByFieldName, orderByFieldValue] = Object.entries(orderBy)[0]; only supports one sort

How to fix this:

  • Remove the line in useSetRecordBoardRecordIds.ts
  • Update sortCachedObjectEdges.ts function to allow multiple sorts.
  • Add tests to cover sortCachedObjectEdges

The good point is that the issue is located in one file, the hard part is that code needs to be designed well to be robust (and tested!)

charlesBochet avatar Apr 04 '24 10:04 charlesBochet

Here is the GitStart Ticket for this issue: https://clients.gitstart.com/twenty/5449/tickets/TWNTY-4799

gitstart-app[bot] avatar Apr 04 '24 10:04 gitstart-app[bot]

@gitstart-twenty could you also look into https://github.com/twentyhq/twenty/issues/4818 that seems related

charlesBochet avatar Apr 04 '24 16:04 charlesBochet

@gitstart-twenty could you also look into #4818 that seems related

Of course

gitstart-twenty avatar Apr 17 '24 15:04 gitstart-twenty

Hey @charlesBochet Both these issues seem fixed

https://github.com/twentyhq/twenty/assets/140154534/74cd3ebf-c6b2-4f3d-900c-2cdf43f11e5e

gitstart-twenty avatar Apr 22 '24 05:04 gitstart-twenty