Fix view picker small bugs (#16987)

This PR solves small bugs around the view picker.

- Couldn’t obtain optimistic update after a re-order of a view by drag
and drop, we needed to refresh the page
- Picking a new icon wouldn’t trigger optimistic update (same problem)
- Picking a new icon would change the view (difficult to understand
behavior)
- Picking a new icon would trigger left drawer collapse (z-index
problem)

Since core views are not being handled by object metadata items anymore,
and that all view logic is plugged on coreViewsState, this PR
implemented optimistic effect by upserting into this state.

Fixes https://github.com/twentyhq/twenty/issues/15422
Fixes https://github.com/twentyhq/twenty/issues/16986

# Before


https://github.com/user-attachments/assets/64099c21-df9f-4772-ab0d-9ea449aed761

# After


https://github.com/user-attachments/assets/f4e844b3-6530-4178-abdb-b7a10d2327b8

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau
2026-01-08 12:05:45 +01:00
committed by GitHub
co-authored by Charles Bochet
parent 71fd05315c
commit e9b7ad21d2
28 changed files with 404 additions and 187 deletions
@@ -0,0 +1,22 @@
import { findById } from '@/utils/array/findById';
export const upsertIntoArrayOfObjectsComparingId = <T extends { id: string }>(
arrayToUpsertInto: T[],
itemToUpsert: T,
): T[] => {
const alreadyExistingItemIndex = arrayToUpsertInto.findIndex(
findById(itemToUpsert.id),
);
const shouldReplaceItem = alreadyExistingItemIndex > -1;
if (shouldReplaceItem) {
const newArray = [...arrayToUpsertInto];
newArray.splice(alreadyExistingItemIndex, 1, itemToUpsert);
return newArray;
} else {
return arrayToUpsertInto.concat(itemToUpsert);
}
};