Skip to content

The open alternative to Salesforce, designed for AI.

Let navigation links point to a path inside the app (#27484)

Thomas Trompette520ee32a7717
diff --git a/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx b/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
index 6bc644c4c23..8f3e9caec9a 100644
--- a/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
+++ b/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
@@ -30,13 +30,12 @@ import { useResetFocusStackToFocusItem } from '@/ui/utilities/focus/hooks/useRes
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-import { isSafeInternalPath } from '@/ui/navigation/utils/isSafeInternalPath';
import { currentPageLayoutIdState } from '@/page-layout/states/currentPageLayoutIdState';
import { useStore } from 'jotai';
import { useEffect, useState } from 'react';
import { matchPath, useLocation, useNavigate } from 'react-router-dom';
import { AppBasePath, AppPath, SidePanelPages } from 'twenty-shared/types';
-import { isDefined } from 'twenty-shared/utils';
+import { isDefined, isSafeInternalPath } from 'twenty-shared/utils';
import { usePageChangeEffectNavigateLocation } from '@/app/hooks/usePageChangeEffectNavigateLocation';
import { getPageLayoutIdForLocation } from '@/app/utils/getPageLayoutIdForLocation';
import { isMatchingLocation } from '~/utils/isMatchingLocation';
diff --git a/packages/twenty-front/src/modules/auth/utils/isValidReturnToPath.ts b/packages/twenty-front/src/modules/auth/utils/isValidReturnToPath.ts
index 02877ad0a78..4676ff111d7 100644
--- a/packages/twenty-front/src/modules/auth/utils/isValidReturnToPath.ts
+++ b/packages/twenty-front/src/modules/auth/utils/isValidReturnToPath.ts
@@ -1,6 +1,6 @@
+import { isSafeInternalPath } from 'twenty-shared/utils';
import { ONBOARDING_PATHS } from '@/auth/constants/OnboardingPaths';
import { ONGOING_USER_CREATION_PATHS } from '@/auth/constants/OngoingUserCreationPaths';
-import { isSafeInternalPath } from '@/ui/navigation/utils/isSafeInternalPath';
import { AppPath } from 'twenty-shared/types';
const extractPathPrefix = (appPath: string): string => appPath.split('/:')[0];
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildCreateNavigationMenuItemInput.test.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildCreateNavigationMenuItemInput.test.ts
index 3de6553140d..872255060da 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildCreateNavigationMenuItemInput.test.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildCreateNavigationMenuItemInput.test.ts
@@ -31,4 +31,24 @@ describe('buildCreateNavigationMenuItemInput', () => {
position: 0,
});
});
+
+ it.each([
+ ['/workflows', '/workflows'],
+ ['twenty.com', 'https://twenty.com'],
+ ])('saves the link %s as %s', (link, expectedLink) => {
+ const input = buildCreateNavigationMenuItemInput(
+ {
+ id: 'navigation-item',
+ type: NavigationMenuItemType.LINK,
+ name: 'Link',
+ link,
+ position: 0,
+ createdAt: '',
+ updatedAt: '',
+ },
+ () => 'saved-folder',
+ );
+
+ expect(input.link).toBe(expectedLink);
+ });
});
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/getLinkNavigationMenuItemComputedLink.test.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/getLinkNavigationMenuItemComputedLink.test.ts
new file mode 100644
index 00000000000..de2d20c092d
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/getLinkNavigationMenuItemComputedLink.test.ts
@@ -0,0 +1,51 @@
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
+
+describe('getLinkNavigationMenuItemComputedLink', () => {
+ it('keeps absolute URLs', () => {
+ expect(
+ getLinkNavigationMenuItemComputedLink({ link: 'https://twenty.com' }),
+ ).toBe('https://twenty.com');
+ });
+
+ it('prefixes bare domains with https', () => {
+ expect(getLinkNavigationMenuItemComputedLink({ link: 'twenty.com' })).toBe(
+ 'https://twenty.com',
+ );
+ });
+
+ it('keeps internal app paths', () => {
+ expect(getLinkNavigationMenuItemComputedLink({ link: '/workflows' })).toBe(
+ '/workflows',
+ );
+ });
+
+ it('keeps protocol-relative URLs external', () => {
+ expect(getLinkNavigationMenuItemComputedLink({ link: '//evil.com' })).toBe(
+ 'https:////evil.com',
+ );
+ });
+
+ it('keeps a path with control characters external', () => {
+ expect(
+ getLinkNavigationMenuItemComputedLink({ link: '/\t/evil.com' }),
+ ).toBe('https:///\t/evil.com');
+ });
+
+ it('keeps an uppercase scheme as is', () => {
+ expect(
+ getLinkNavigationMenuItemComputedLink({ link: 'HTTPS://twenty.com' }),
+ ).toBe('HTTPS://twenty.com');
+ });
+
+ it('keeps localhost URLs external', () => {
+ expect(
+ getLinkNavigationMenuItemComputedLink({
+ link: 'localhost:3000/workflows',
+ }),
+ ).toBe('https://localhost:3000/workflows');
+ });
+
+ it('returns an empty string without a link', () => {
+ expect(getLinkNavigationMenuItemComputedLink({ link: null })).toBe('');
+ });
+});
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/buildCreateNavigationMenuItemInput.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/buildCreateNavigationMenuItemInput.ts
index 5970a09b344..13719aea4bc 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/buildCreateNavigationMenuItemInput.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/buildCreateNavigationMenuItemInput.ts
@@ -3,8 +3,9 @@ import type {
NavigationMenuItem,
} from '~/generated-metadata/graphql';
-import { ensureAbsoluteUrl, isDefined } from 'twenty-shared/utils';
+import { isDefined } from 'twenty-shared/utils';
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
import { isNavigationMenuItemFolder } from '@/navigation-menu-item/common/utils/isNavigationMenuItemFolder';
import { isNavigationMenuItemLink } from '@/navigation-menu-item/common/utils/isNavigationMenuItemLink';
import { isNavigationMenuItemObject } from '@/navigation-menu-item/common/utils/isNavigationMenuItemObject';
@@ -25,7 +26,9 @@ export const buildCreateNavigationMenuItemInput = (
} else if (isNavigationMenuItemLink(draftItem)) {
input.name = draftItem.name ?? 'Link';
const linkUrl = (draftItem.link ?? '').trim();
- input.link = linkUrl ? ensureAbsoluteUrl(linkUrl) : undefined;
+ input.link = linkUrl
+ ? getLinkNavigationMenuItemComputedLink({ link: linkUrl })
+ : undefined;
} else if (isNavigationMenuItemObject(draftItem)) {
input.targetObjectMetadataId =
draftItem.targetObjectMetadataId ?? undefined;
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink.ts
new file mode 100644
index 00000000000..ff4371fd306
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink.ts
@@ -0,0 +1,19 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { ensureAbsoluteUrl, isSafeInternalPath } from 'twenty-shared/utils';
+import { type NavigationMenuItem } from '~/generated-metadata/graphql';
+
+export const getLinkNavigationMenuItemComputedLink = (
+ item: Pick<NavigationMenuItem, 'link'>,
+): string => {
+ const linkUrl = (item.link ?? '').trim();
+
+ if (!isNonEmptyString(linkUrl)) {
+ return '';
+ }
+
+ if (isSafeInternalPath(linkUrl)) {
+ return linkUrl;
+ }
+
+ return ensureAbsoluteUrl(linkUrl);
+};
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/components/NavigationMenuItemIcon.tsx b/packages/twenty-front/src/modules/navigation-menu-item/display/components/NavigationMenuItemIcon.tsx
index 22e02e04cfe..31fe4bf9429 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/components/NavigationMenuItemIcon.tsx
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/components/NavigationMenuItemIcon.tsx
@@ -2,7 +2,7 @@ import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/st
import { NavigationMenuItemIconWithOverlay } from '@/navigation-menu-item/display/components/NavigationMenuItemIconWithOverlay';
import { ColoredIcon } from '@/ui/icon/components/ColoredIcon';
import { NavigationMenuItemType } from 'twenty-shared/types';
-import { isDefined } from 'twenty-shared/utils';
+import { isDefined, isSafeInternalPath } from 'twenty-shared/utils';
import { getIconTileColorShades } from 'twenty-ui/components/data-display';
import { IconLink, IconPerspective, IconWorld, useIcons } from 'twenty-ui/icon';
import { Avatar } from 'twenty-ui/primitives/data-display';
@@ -119,6 +119,20 @@ export const NavigationMenuItemIcon = ({
views,
isInitialObjectViewEnabled,
});
+
+ if (isSafeInternalPath(computedLink)) {
+ return (
+ <ColoredIcon
+ Icon={
+ isDefined(navigationMenuItem.icon)
+ ? getIcon(navigationMenuItem.icon)
+ : IconLink
+ }
+ color={getNavigationMenuItemColor(navigationMenuItem)}
+ />
+ );
+ }
+
return (
<LinkIconWithLinkOverlay
link={computedLink}
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useIdentifyActiveNavigationMenuItems.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useIdentifyActiveNavigationMenuItems.ts
index 8e931c23384..744b0115846 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useIdentifyActiveNavigationMenuItems.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useIdentifyActiveNavigationMenuItems.ts
@@ -6,7 +6,9 @@ import { getAppPath, isDefined } from 'twenty-shared/utils';
import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
import { lastClickedNavigationMenuItemIdState } from '@/navigation-menu-item/common/states/lastClickedNavigationMenuItemIdState';
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
import { navigationMenuItemsSelector } from '@/navigation-menu-item/common/states/navigationMenuItemsSelector';
+import { isLinkNavigationMenuItemActive } from '@/navigation-menu-item/display/link/utils/isLinkNavigationMenuItemActive';
import { getObjectMetadataForNavigationMenuItem } from '@/navigation-menu-item/display/object/utils/getObjectMetadataForNavigationMenuItem';
import { getNavigationMenuItemComputedLink } from '@/navigation-menu-item/display/utils/getNavigationMenuItemComputedLink';
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
@@ -42,6 +44,7 @@ export const useIdentifyActiveNavigationMenuItems = (): {
} = useParams();
const currentPath = location.pathname;
+ const currentSearch = location.search;
const currentPathWithSearch = location.pathname + location.search;
const currentObjectMetadataItem = activeObjectMetadataItems.find(
@@ -105,6 +108,17 @@ export const useIdentifyActiveNavigationMenuItems = (): {
}
}
+ const matchingLinkNavigationMenuItemIds = navigationMenuItems
+ .filter(
+ (item) =>
+ item.type === NavigationMenuItemType.LINK &&
+ isLinkNavigationMenuItemActive({
+ computedLink: getLinkNavigationMenuItemComputedLink(item),
+ location: { pathname: currentPath, search: currentSearch },
+ }),
+ )
+ .map((item) => item.id);
+
if (isOnRecordShowPage) {
const matchingRecordNavigationMenuItemIds = navigationMenuItems
.filter((item) => {
@@ -138,6 +152,7 @@ export const useIdentifyActiveNavigationMenuItems = (): {
const activeNavigationMenuItemIds = [
...matchingRecordNavigationMenuItemIds,
+ ...matchingLinkNavigationMenuItemIds,
...matchingObjectNavigationMenuItemIds,
];
@@ -166,6 +181,13 @@ export const useIdentifyActiveNavigationMenuItems = (): {
};
}
+ if (matchingLinkNavigationMenuItemIds.length > 0) {
+ return {
+ activeNavigationMenuItemIds: matchingLinkNavigationMenuItemIds,
+ objectMetadataIdForOpenedSection: null,
+ };
+ }
+
const matchingObjectNavigationMenuItemIds = navigationMenuItems
.filter(
(item) =>
@@ -190,6 +212,7 @@ export const useIdentifyActiveNavigationMenuItems = (): {
lastVisitedViewPerObjectMetadataItem,
currentPathWithSearch,
currentPath,
+ currentSearch,
currentObjectMetadataItem,
isOnRecordShowPage,
contextStoreCurrentViewId,
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/link/components/NavigationMenuItemLinkDisplay.tsx b/packages/twenty-front/src/modules/navigation-menu-item/display/link/components/NavigationMenuItemLinkDisplay.tsx
index 6a4d07917ca..0c942154cac 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/link/components/NavigationMenuItemLinkDisplay.tsx
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/link/components/NavigationMenuItemLinkDisplay.tsx
@@ -1,9 +1,11 @@
+import { isSafeInternalPath } from 'twenty-shared/utils';
import { IconArrowUpRight } from 'twenty-ui/icon';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';
import { NavigationMenuItemIcon } from '@/navigation-menu-item/display/components/NavigationMenuItemIcon';
-import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/display/link/utils/getLinkNavigationMenuItemComputedLink';
+import { useIdentifyActiveNavigationMenuItems } from '@/navigation-menu-item/display/hooks/useIdentifyActiveNavigationMenuItems';
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
import { getLinkNavigationMenuItemLabel } from '@/navigation-menu-item/display/link/utils/getLinkNavigationMenuItemLabel';
import type { NavigationMenuItemSectionContentProps } from '@/navigation-menu-item/display/sections/types/NavigationMenuItemSectionContentProps';
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
@@ -22,16 +24,21 @@ export const NavigationMenuItemLinkDisplay = ({
);
const theme = useTheme();
+ const { activeNavigationMenuItemIds } =
+ useIdentifyActiveNavigationMenuItems();
+
const label = getLinkNavigationMenuItemLabel(item);
const computedLink = getLinkNavigationMenuItemComputedLink(item);
+ const isInternalLink = isSafeInternalPath(computedLink);
- const defaultRightOptions = !isLayoutCustomizationModeEnabled && (
- <IconArrowUpRight
- size={theme.icon.size.sm}
- stroke={theme.icon.stroke.md}
- color={themeCssVariables.font.color.light}
- />
- );
+ const defaultRightOptions = !isLayoutCustomizationModeEnabled &&
+ !isInternalLink && (
+ <IconArrowUpRight
+ size={theme.icon.size.sm}
+ stroke={theme.icon.stroke.md}
+ color={themeCssVariables.font.color.light}
+ />
+ );
return (
<NavigationDrawerItem
@@ -47,7 +54,7 @@ export const NavigationMenuItemLinkDisplay = ({
: undefined
}
Icon={() => <NavigationMenuItemIcon navigationMenuItem={item} />}
- active={false}
+ active={activeNavigationMenuItemIds.includes(item.id)}
isSelectedInEditMode={editModeProps?.isSelectedInEditMode}
isDragging={isDragging}
triggerEvent="CLICK"
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/__tests__/isLinkNavigationMenuItemActive.test.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/__tests__/isLinkNavigationMenuItemActive.test.ts
new file mode 100644
index 00000000000..e9b7200e266
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/__tests__/isLinkNavigationMenuItemActive.test.ts
@@ -0,0 +1,81 @@
+import { isLinkNavigationMenuItemActive } from '@/navigation-menu-item/display/link/utils/isLinkNavigationMenuItemActive';
+
+describe('isLinkNavigationMenuItemActive', () => {
+ it('is active on the page an internal link points to', () => {
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/workflows',
+ location: { pathname: '/workflows', search: '' },
+ }),
+ ).toBe(true);
+ });
+
+ it('matches the query of a link that has one', () => {
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/objects/companies?viewId=1',
+ location: { pathname: '/objects/companies', search: '?viewId=1' },
+ }),
+ ).toBe(true);
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/objects/companies?viewId=1',
+ location: { pathname: '/objects/companies', search: '?viewId=2' },
+ }),
+ ).toBe(false);
+ });
+
+ it('stays active when the page adds other query params', () => {
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/objects/companies?viewId=1',
+ location: {
+ pathname: '/objects/companies',
+ search: '?viewId=1&panel=%2Fobject%2Fcompany%2F2',
+ },
+ }),
+ ).toBe(true);
+ });
+
+ it('matches a query whether or not it is percent-encoded', () => {
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/objects/companies?filter=Acme Corp',
+ location: {
+ pathname: '/objects/companies',
+ search: '?filter=Acme Corp',
+ },
+ }),
+ ).toBe(true);
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/objects/companies?filter=Acme Corp',
+ location: {
+ pathname: '/objects/companies',
+ search: '?filter=Acme%20Corp',
+ },
+ }),
+ ).toBe(true);
+ });
+
+ it('is never active for another page or an external link', () => {
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '/workflows',
+ location: { pathname: '/objects/companies', search: '' },
+ }),
+ ).toBe(false);
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: 'https://twenty.com',
+ location: { pathname: '/', search: '' },
+ }),
+ ).toBe(false);
+ expect(
+ isLinkNavigationMenuItemActive({
+ computedLink: '#section',
+ location: { pathname: '/', search: '' },
+ }),
+ ).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/getLinkNavigationMenuItemComputedLink.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/getLinkNavigationMenuItemComputedLink.ts
deleted file mode 100644
index 72ba6e96251..00000000000
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/getLinkNavigationMenuItemComputedLink.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import { type NavigationMenuItem } from '~/generated-metadata/graphql';
-
-export const getLinkNavigationMenuItemComputedLink = (
- item: Pick<NavigationMenuItem, 'link'>,
-): string => {
- const linkUrl = (item.link ?? '').trim();
- if (linkUrl.startsWith('http://') || linkUrl.startsWith('https://')) {
- return linkUrl;
- }
- return linkUrl ? `https://${linkUrl}` : '';
-};
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/isLinkNavigationMenuItemActive.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/isLinkNavigationMenuItemActive.ts
new file mode 100644
index 00000000000..24d99883ac3
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/link/utils/isLinkNavigationMenuItemActive.ts
@@ -0,0 +1,26 @@
+import { parsePath } from 'react-router-dom';
+import { isSafeInternalPath } from 'twenty-shared/utils';
+
+export const isLinkNavigationMenuItemActive = ({
+ computedLink,
+ location,
+}: {
+ computedLink: string;
+ location: { pathname: string; search: string };
+}): boolean => {
+ if (!isSafeInternalPath(computedLink)) {
+ return false;
+ }
+
+ const link = parsePath(computedLink);
+
+ if (link.pathname !== location.pathname) {
+ return false;
+ }
+
+ const currentSearchParams = new URLSearchParams(location.search);
+
+ return [...new URLSearchParams(link.search)].every(
+ ([key, value]) => currentSearchParams.get(key) === value,
+ );
+};
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/utils/getNavigationMenuItemComputedLink.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/utils/getNavigationMenuItemComputedLink.ts
index aad2b205f2a..7386ceab314 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/utils/getNavigationMenuItemComputedLink.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/utils/getNavigationMenuItemComputedLink.ts
@@ -1,4 +1,4 @@
-import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/display/link/utils/getLinkNavigationMenuItemComputedLink';
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
import { getObjectNavigationMenuItemComputedLink } from '@/navigation-menu-item/display/object/utils/getObjectNavigationMenuItemComputedLink';
import { getPageLayoutNavigationMenuItemComputedLink } from '@/navigation-menu-item/display/page-layout/utils/getPageLayoutNavigationMenuItemComputedLink';
import { getRecordNavigationMenuItemComputedLink } from '@/navigation-menu-item/display/record/utils/getRecordNavigationMenuItemComputedLink';
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/edit/components/NavigationMenuItemLinkEditor.tsx b/packages/twenty-front/src/modules/navigation-menu-item/edit/components/NavigationMenuItemLinkEditor.tsx
index a74bb434ff0..ad0b08c554f 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/edit/components/NavigationMenuItemLinkEditor.tsx
+++ b/packages/twenty-front/src/modules/navigation-menu-item/edit/components/NavigationMenuItemLinkEditor.tsx
@@ -5,10 +5,11 @@ import { Key } from 'ts-key-enum';
import { type FieldDoubleText } from '@/object-record/record-field/ui/types/FieldDoubleText';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
-import { ensureAbsoluteUrl, isDefined, isValidUrl } from 'twenty-shared/utils';
+import { isDefined, isSafeInternalPath, isValidUrl } from 'twenty-shared/utils';
import { themeCssVariables } from 'twenty-ui/theme';
import { type NavigationMenuItem } from '~/generated-metadata/graphql';
import { DoubleTextInput } from '@/ui/field/input/components/DoubleTextInput';
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
import { useNavigationMenuItemEditController } from '@/navigation-menu-item/edit/hooks/useNavigationMenuItemEditController';
const StyledError = styled.div`
@@ -44,8 +45,8 @@ export const NavigationMenuItemLinkEditor = ({
firstValue: string;
secondValue: string;
}) => {
- const link = ensureAbsoluteUrl(secondValue.trim());
- if (!isValidUrl(link)) {
+ const link = getLinkNavigationMenuItemComputedLink({ link: secondValue });
+ if (!isValidUrl(link) && !isSafeInternalPath(link)) {
setError(true);
return;
}
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/edit/utils/buildUpdateInputsFromDraft.ts b/packages/twenty-front/src/modules/navigation-menu-item/edit/utils/buildUpdateInputsFromDraft.ts
index 260868a2882..1767c7458ea 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/edit/utils/buildUpdateInputsFromDraft.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/edit/utils/buildUpdateInputsFromDraft.ts
@@ -1,9 +1,10 @@
-import { ensureAbsoluteUrl, isDefined } from 'twenty-shared/utils';
+import { isDefined } from 'twenty-shared/utils';
import {
type NavigationMenuItem,
type UpdateOneNavigationMenuItemInput,
} from '~/generated-metadata/graphql';
+import { getLinkNavigationMenuItemComputedLink } from '@/navigation-menu-item/common/utils/getLinkNavigationMenuItemComputedLink';
import { isNavigationMenuItemFolder } from '@/navigation-menu-item/common/utils/isNavigationMenuItemFolder';
import { isNavigationMenuItemLink } from '@/navigation-menu-item/common/utils/isNavigationMenuItemLink';
@@ -76,7 +77,9 @@ export const buildUpdateInputsFromDraft = ({
}
if (linkChanged && isNavigationMenuItemLink(draftItem)) {
const linkUrl = (draftItem.link ?? '').trim();
- updatePayload.link = linkUrl ? ensureAbsoluteUrl(linkUrl) : null;
+ updatePayload.link = linkUrl
+ ? getLinkNavigationMenuItemComputedLink({ link: linkUrl })
+ : null;
}
if (iconChanged && isNavigationMenuItemFolder(draftItem)) {
updatePayload.icon = draftItem.icon ?? null;
diff --git a/packages/twenty-front/src/modules/side-panel/routing/components/SidePanelPathUrlSyncEffect.tsx b/packages/twenty-front/src/modules/side-panel/routing/components/SidePanelPathUrlSyncEffect.tsx
index 4792b090c6c..f8b3d877dd0 100644
--- a/packages/twenty-front/src/modules/side-panel/routing/components/SidePanelPathUrlSyncEffect.tsx
+++ b/packages/twenty-front/src/modules/side-panel/routing/components/SidePanelPathUrlSyncEffect.tsx
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
-import { isDefined } from 'twenty-shared/utils';
+import { isDefined, isSafeInternalPath } from 'twenty-shared/utils';
import { useWorkspaceRouteObjects } from '@/app/routing/components/WorkspaceRouteObjectsProvider';
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
@@ -8,7 +8,6 @@ import { SIDE_PANEL_PATH_SEARCH_PARAM } from '@/side-panel/routing/constants/Sid
import { useCurrentSidePanelRoutedPath } from '@/side-panel/routing/hooks/useCurrentSidePanelRoutedPath';
import { useOpenRoutedPageInSidePanel } from '@/side-panel/routing/hooks/useOpenRoutedPageInSidePanel';
import { isWorkspaceLocationAvailableOnSurface } from '@/app/routing/utils/isWorkspaceLocationAvailableOnSurface';
-import { isSafeInternalPath } from '@/ui/navigation/utils/isSafeInternalPath';
export const SidePanelPathUrlSyncEffect = () => {
const location = useLocation();
diff --git a/packages/twenty-front/src/modules/side-panel/routing/hooks/useOpenRoutedPageInSidePanel.ts b/packages/twenty-front/src/modules/side-panel/routing/hooks/useOpenRoutedPageInSidePanel.ts
index 10355feb3d9..854c2160b4e 100644
--- a/packages/twenty-front/src/modules/side-panel/routing/hooks/useOpenRoutedPageInSidePanel.ts
+++ b/packages/twenty-front/src/modules/side-panel/routing/hooks/useOpenRoutedPageInSidePanel.ts
@@ -1,7 +1,7 @@
import { useStore } from 'jotai';
import { useCallback } from 'react';
import { SidePanelPages } from 'twenty-shared/types';
-import { isDefined } from 'twenty-shared/utils';
+import { isDefined, isSafeInternalPath } from 'twenty-shared/utils';
import { IconDotsVertical } from 'twenty-ui/icon';
import { v4 } from 'uuid';
@@ -11,7 +11,6 @@ import { isWorkspaceLocationAvailableOnSurface } from '@/app/routing/utils/isWor
import { toSidePanelLocation } from '@/side-panel/routing/utils/toSidePanelLocation';
import { sidePanelNavigationStackState } from '@/side-panel/states/sidePanelNavigationStackState';
import { releaseRemovedRoutedFlowStateScopes } from '@/side-panel/routing/utils/releaseRemovedRoutedFlowStateScopes';
-import { isSafeInternalPath } from '@/ui/navigation/utils/isSafeInternalPath';
export const useOpenRoutedPageInSidePanel = () => {
const store = useStore();
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
index de073906349..8a23a98807c 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerItem.tsx
@@ -17,7 +17,7 @@ import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
import { useContext } from 'react';
import { Link } from 'react-router-dom';
-import { isDefined } from 'twenty-shared/utils';
+import { isAbsoluteUrl, isDefined } from 'twenty-shared/utils';
import { Pill } from 'twenty-ui/primitives/data-display';
import { Tooltip } from 'twenty-ui/primitives/surfaces';
import {
@@ -248,8 +248,7 @@ export const NavigationDrawerItem = ({
}
};
- const isExternalLink =
- isDefined(to) && (to.startsWith('http://') || to.startsWith('https://'));
+ const isExternalLink = isDefined(to) && isAbsoluteUrl(to);
const isInternalLink = isDefined(to) && !isExternalLink;
const handleExternalLinkClick = () => {
diff --git a/packages/twenty-front/src/pages/settings/applications/utils/getApplicationHealthBanner.ts b/packages/twenty-front/src/pages/settings/applications/utils/getApplicationHealthBanner.ts
index f543f88072f..5e4023c97fe 100644
--- a/packages/twenty-front/src/pages/settings/applications/utils/getApplicationHealthBanner.ts
+++ b/packages/twenty-front/src/pages/settings/applications/utils/getApplicationHealthBanner.ts
@@ -1,6 +1,5 @@
import { isNonEmptyString } from '@sniptt/guards';
-import { isDefined } from 'twenty-shared/utils';
-import { isSafeInternalPath } from '@/ui/navigation/utils/isSafeInternalPath';
+import { isDefined, isSafeInternalPath } from 'twenty-shared/utils';
import { type RunApplicationHealthCheckMutation } from '~/generated-metadata/graphql';
type ApplicationHealthCheckResult = NonNullable<
diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/__tests__/validate-navigation-menu-item-type-required-properties.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/__tests__/validate-navigation-menu-item-type-required-properties.util.spec.ts
index b74fcab6d54..9126ac9ff33 100644
--- a/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/__tests__/validate-navigation-menu-item-type-required-properties.util.spec.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/__tests__/validate-navigation-menu-item-type-required-properties.util.spec.ts
@@ -110,6 +110,10 @@ describe('validateNavigationMenuItemTypeRequiredProperties', () => {
type: NavigationMenuItemType.LINK,
overrides: { link: 'https://twenty.com' },
},
+ {
+ type: NavigationMenuItemType.LINK,
+ overrides: { link: '/workflows' },
+ },
{
type: NavigationMenuItemType.PAGE_LAYOUT,
overrides: { pageLayoutUniversalIdentifier: VALID_UUID },
diff --git a/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/validate-navigation-menu-item-type-required-properties.util.ts b/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/validate-navigation-menu-item-type-required-properties.util.ts
index 380a1fd2269..9f95447b6e8 100644
--- a/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/validate-navigation-menu-item-type-required-properties.util.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/flat-navigation-menu-item/validators/utils/validate-navigation-menu-item-type-required-properties.util.ts
@@ -4,7 +4,12 @@ import {
type AssertUnreachable,
NavigationMenuItemType,
} from 'twenty-shared/types';
-import { isDefined, isValidUrl, isValidUuid } from 'twenty-shared/utils';
+import {
+ isDefined,
+ isSafeInternalPath,
+ isValidUrl,
+ isValidUuid,
+} from 'twenty-shared/utils';
import { NavigationMenuItemExceptionCode } from 'src/engine/metadata-modules/navigation-menu-item/navigation-menu-item.exception';
import { type UniversalFlatNavigationMenuItem } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-navigation-menu-item.type';
@@ -99,7 +104,7 @@ export const validateNavigationMenuItemTypeRequiredProperties = ({
];
}
case NavigationMenuItemType.LINK: {
- return isDefined(link) && isValidUrl(link)
+ return isDefined(link) && (isValidUrl(link) || isSafeInternalPath(link))
? []
: [
buildInvalidInputError(
diff --git a/packages/twenty-shared/src/utils/index.ts b/packages/twenty-shared/src/utils/index.ts
index 735a9f2e3fa..7effe39e982 100644
--- a/packages/twenty-shared/src/utils/index.ts
+++ b/packages/twenty-shared/src/utils/index.ts
@@ -306,6 +306,7 @@ export { getLinkUrlNormalizer } from './url/getLinkUrlNormalizer';
export { getSafeUrl } from './url/getSafeUrl';
export { getUrlHostnameOrThrow } from './url/getUrlHostnameOrThrow';
export { isAbsoluteUrl } from './url/isAbsoluteUrl';
+export { isSafeInternalPath } from './url/isSafeInternalPath';
export { isSafeUrl } from './url/isSafeUrl';
export { isValidDomain } from './url/isValidDomain';
export { isValidHostname } from './url/isValidHostname';
diff --git a/packages/twenty-shared/src/utils/url/__tests__/isSafeInternalPath.test.ts b/packages/twenty-shared/src/utils/url/__tests__/isSafeInternalPath.test.ts
new file mode 100644
index 00000000000..b04878080fc
--- /dev/null
+++ b/packages/twenty-shared/src/utils/url/__tests__/isSafeInternalPath.test.ts
@@ -0,0 +1,18 @@
+import { isSafeInternalPath } from '@/utils/url/isSafeInternalPath';
+
+describe('isSafeInternalPath', () => {
+ it('accepts a path or a hash of the app', () => {
+ expect(isSafeInternalPath('/workflows')).toBe(true);
+ expect(isSafeInternalPath('/objects/companies?viewId=1')).toBe(true);
+ expect(isSafeInternalPath('#section')).toBe(true);
+ });
+
+ it('rejects anything a browser could resolve to another origin', () => {
+ expect(isSafeInternalPath('https://twenty.com')).toBe(false);
+ expect(isSafeInternalPath('//evil.com/workflows')).toBe(false);
+ expect(isSafeInternalPath('/\\evil.com')).toBe(false);
+ expect(isSafeInternalPath('/\t/evil.com')).toBe(false);
+ expect(isSafeInternalPath('workflows')).toBe(false);
+ expect(isSafeInternalPath('')).toBe(false);
+ });
+});
diff --git a/packages/twenty-shared/src/utils/url/index.ts b/packages/twenty-shared/src/utils/url/index.ts
index 135f7ba34ad..3a2661d7312 100644
--- a/packages/twenty-shared/src/utils/url/index.ts
+++ b/packages/twenty-shared/src/utils/url/index.ts
@@ -5,6 +5,7 @@ export * from './ensureAbsoluteUrl';
export * from './getAbsoluteUrlOrThrow';
export * from './getUrlHostnameOrThrow';
export * from './isAbsoluteUrl';
+export * from './isSafeInternalPath';
export * from './isValidDomain';
export * from './isValidHostname';
export * from './isValidUrl';
diff --git a/packages/twenty-front/src/modules/ui/navigation/utils/isSafeInternalPath.ts b/packages/twenty-shared/src/utils/url/isSafeInternalPath.ts
similarity index 100%
rename from packages/twenty-front/src/modules/ui/navigation/utils/isSafeInternalPath.ts
rename to packages/twenty-shared/src/utils/url/isSafeInternalPath.ts