twenty
twenty copied to clipboard
Sort does not work on Board view
Bug Description
Going to the Opportunity Board view, try sort by "name". The sort won't be apply
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 (
triggerUpdateRecordOptimisticEffectcall 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.tsfunction 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!)
Here is the GitStart Ticket for this issue: https://clients.gitstart.com/twenty/5449/tickets/TWNTY-4799
@gitstart-twenty could you also look into https://github.com/twentyhq/twenty/issues/4818 that seems related
@gitstart-twenty could you also look into #4818 that seems related
Of course
Hey @charlesBochet Both these issues seem fixed
https://github.com/twentyhq/twenty/assets/140154534/74cd3ebf-c6b2-4f3d-900c-2cdf43f11e5e