Fix navigation “add before/after” insertion index (#18879)

Before: 
<video
src="https://github.com/user-attachments/assets/f0b0740d-414f-4c59-a712-cdf96d4f3eb1"
/>


After:
<video
src="https://github.com/user-attachments/assets/48ce878c-4a29-4666-89d4-4d60882dd5ab"
/>

---------

Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com>
This commit is contained in:
Abdul Rahman
2026-03-24 21:19:07 +05:30
committed by GitHub
parent 341c13bf32
commit 27c0ca975f
3 changed files with 15 additions and 19 deletions
@@ -5,14 +5,14 @@ import { ensureAbsoluteUrl } from 'twenty-shared/utils';
import { type NavigationMenuItem } from '~/generated-metadata/graphql';
import { extractDomainFromUrl } from '@/navigation-menu-item/display/link/utils/extractDomainFromUrl';
import { SidePanelGroup } from '@/side-panel/components/SidePanelGroup';
import { SidePanelList } from '@/side-panel/components/SidePanelList';
import {
type OrganizeActionsProps,
SidePanelEditOrganizeActions,
} from '@/navigation-menu-item/edit/side-panel/components/SidePanelEditOrganizeActions';
import { SidePanelEditOwnerSection } from '@/navigation-menu-item/edit/side-panel/components/SidePanelEditOwnerSection';
import { getOrganizeActionsSelectableItemIds } from '@/navigation-menu-item/edit/side-panel/utils/getOrganizeActionsSelectableItemIds';
import { SidePanelGroup } from '@/side-panel/components/SidePanelGroup';
import { SidePanelList } from '@/side-panel/components/SidePanelList';
import { TextInput } from '@/ui/input/components/TextInput';
type SidePanelEditLinkItemViewProps = OrganizeActionsProps & {
@@ -93,7 +93,6 @@ export const SidePanelEditLinkItemView = ({
onAddAfter={onAddAfter}
showMoveToFolder
onMoveToFolder={onOpenFolderPicker}
moveToFolderHasSubMenu
/>
<SidePanelEditOwnerSection applicationId={selectedItem.applicationId} />
</SidePanelList>
@@ -26,7 +26,6 @@ export type OrganizeActionsProps = {
type SidePanelEditOrganizeActionsProps = OrganizeActionsProps & {
showMoveToFolder?: boolean;
onMoveToFolder?: () => void;
moveToFolderHasSubMenu?: boolean;
};
export const SidePanelEditOrganizeActions = ({
@@ -39,7 +38,6 @@ export const SidePanelEditOrganizeActions = ({
onAddAfter,
showMoveToFolder = false,
onMoveToFolder,
moveToFolderHasSubMenu = false,
}: SidePanelEditOrganizeActionsProps) => {
const { t } = useLingui();
@@ -78,7 +76,7 @@ export const SidePanelEditOrganizeActions = ({
Icon={IconFolderSymlink}
label={t`Move to folder`}
id={SidePanelNavigationItemActions.MOVE_TO_FOLDER}
hasSubMenu={moveToFolderHasSubMenu}
hasSubMenu
onClick={onMoveToFolder}
/>
</SelectableListItem>
@@ -14,33 +14,32 @@ import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { SidePanelPages } from 'twenty-shared/types';
import { type NavigationMenuItem } from '~/generated-metadata/graphql';
const getAddMenuItemInsertionContext = (
selectedItem: { id: string; folderId?: string | null },
workspaceNavigationMenuItems: Array<{
id: string;
folderId?: string | null;
userWorkspaceId?: string | null;
}>,
workspaceNavigationMenuItems: NavigationMenuItem[],
offset: 0 | 1,
): AddMenuItemInsertionContext | null => {
const targetFolderId = selectedItem.folderId ?? null;
const itemsInFolder = workspaceNavigationMenuItems.filter(
(item) =>
(item.folderId ?? null) === targetFolderId &&
!isDefined(item.userWorkspaceId),
);
const selectedIndexInFolder = itemsInFolder.findIndex(
const itemsInFolderSorted = workspaceNavigationMenuItems
.filter(
(item) =>
(item.folderId ?? null) === targetFolderId &&
!isDefined(item.userWorkspaceId),
)
.sort((a, b) => a.position - b.position);
const selectedIndexSorted = itemsInFolderSorted.findIndex(
(item) => item.id === selectedItem.id,
);
if (selectedIndexInFolder < 0) {
if (selectedIndexSorted < 0) {
return null;
}
return {
targetFolderId,
targetIndex: selectedIndexInFolder + offset,
targetIndex: selectedIndexSorted + offset,
disableDrag: true,
};
};