@ -11,8 +11,8 @@ export const prefetchViewsFromObjectMetadataItemFamilySelector = selectorFamily<
|
||||
({ objectMetadataItemId }) =>
|
||||
({ get }) => {
|
||||
const views = get(prefetchViewsState);
|
||||
return views.filter(
|
||||
(view) => view.objectMetadataId === objectMetadataItemId,
|
||||
);
|
||||
return views
|
||||
.filter((view) => view.objectMetadataId === objectMetadataItemId)
|
||||
.sort((a, b) => a.position - b.position);
|
||||
},
|
||||
});
|
||||
|
||||
@ -20,9 +20,9 @@ import { viewPickerReferenceViewIdComponentState } from '@/views/view-picker/sta
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { moveArrayItem } from '~/utils/array/moveArrayItem';
|
||||
import { IconPlus } from 'twenty-ui/display';
|
||||
import { MenuItem } from 'twenty-ui/navigation';
|
||||
import { moveArrayItem } from '~/utils/array/moveArrayItem';
|
||||
|
||||
const StyledBoldDropdownMenuItemsContainer = styled(DropdownMenuItemsContainer)`
|
||||
font-weight: ${({ theme }) => theme.font.weight.regular};
|
||||
@ -74,17 +74,21 @@ export const ViewPickerListContent = () => {
|
||||
};
|
||||
|
||||
const handleDragEnd = useCallback(
|
||||
(result: DropResult) => {
|
||||
async (result: DropResult) => {
|
||||
if (!result.destination) return;
|
||||
|
||||
moveArrayItem(viewsOnCurrentObject, {
|
||||
const viewsReordered = moveArrayItem(viewsOnCurrentObject, {
|
||||
fromIndex: result.source.index,
|
||||
toIndex: result.destination.index,
|
||||
}).forEach((view, index) => {
|
||||
if (view.position !== index) {
|
||||
updateView({ ...view, position: index });
|
||||
}
|
||||
});
|
||||
|
||||
Promise.all(
|
||||
viewsReordered.map(async (view, index) => {
|
||||
if (view.position !== index) {
|
||||
await updateView({ ...view, position: index });
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
[updateView, viewsOnCurrentObject],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user