twenty
twenty copied to clipboard
RecordTable - Create new record - New row as temporary local state
Scope & Context
Following Optimistic Effect implementation v2 (https://github.com/twentyhq/twenty/issues/3509).
Current behavior
When a new record is added from the Record table, if a filter is set, the empty record row is temporarily shown even though it does not match the current filter.
This is the wanted behavior, except, we're adding the new, empty record to all the cached lists in the Apollo cache, even if the empty record does not match the list's filters.
For instance, in the Companies table, if a filter on the name is applied that filters all companies which name contains "a"; when I add a new person with the "+" button:
- I see a new empty Company row added at the top of the Companies table, even though the name is empty and does not contain "a" => this is the wanted behavior
- In the Apollo cache, the empty Company record has been added to the
companies({ filter: { name: { ilike: "%a%" } } })list, which is incoherent. - When I blur the empty row without updating it, the row is deleted from backend and from the cache, so the cached, filtered list is coherent again. However, it seems sometimes the empty row is not deleted, which means the empty record is now present in all cached
companieslists even though it does not match the variables.
Expected behavior
Instead of adding the created, empty record to all the cached lists:
triggerCreateRecordsOptimisticEffectshould only add the record to lists with filters it matches/without any filters.- a local state should temporarily display the empty row as the first row in the table until the filters are reset.
Technical inputs
In triggerCreateRecordsOptimisticEffect, the code for only adding the record to lists with filters it matches/without any filters already exists and is commented for now. Once we implement the local state for the empty row, we can uncomment this code.