The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
[Page layouts] Sync tabs with URL hash (#16341)
Baptiste Devessier51c0a8dd863d
diff --git a/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/dashboard-actions/components/EditDashboardSingleRecordAction.tsx b/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/dashboard-actions/components/EditDashboardSingleRecordAction.tsxindex bcdb9b90ac9..dd9676dede9 100644--- a/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/dashboard-actions/components/EditDashboardSingleRecordAction.tsx+++ b/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/dashboard-actions/components/EditDashboardSingleRecordAction.tsx@@ -3,6 +3,7 @@ import { useSelectedRecordIdOrThrow } from '@/action-menu/actions/record-actionsimport { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';import { useSetIsPageLayoutInEditMode } from '@/page-layout/hooks/useSetIsPageLayoutInEditMode';import { useRecoilValue } from 'recoil';+import { useResetLocationHash } from 'twenty-ui/utilities';export const EditDashboardSingleRecordAction = () => {const recordId = useSelectedRecordIdOrThrow();@@ -14,8 +15,11 @@ export const EditDashboardSingleRecordAction = () => {const { setIsPageLayoutInEditMode } =useSetIsPageLayoutInEditMode(pageLayoutId);+ const { resetLocationHash } = useResetLocationHash();+const handleClick = () => {setIsPageLayoutInEditMode(true);+ resetLocationHash();};return <Action onClick={handleClick} />;diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutRendererContent.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutRendererContent.tsxindex 5e56df43c38..40d3f7d79de 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutRendererContent.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutRendererContent.tsx@@ -18,12 +18,12 @@ import { getTabsWithVisibleWidgets } from '@/page-layout/utils/getTabsWithVisiblimport { sortTabsByPosition } from '@/page-layout/utils/sortTabsByPosition';import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';-import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';import { useSetRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentState';import styled from '@emotion/styled';import { isDefined } from 'twenty-shared/utils';+import { useIsMobile } from 'twenty-ui/utilities';const StyledContainer = styled.div<{ hasPinnedTab: boolean }>`display: grid;@@ -120,7 +120,7 @@ export const PageLayoutRendererContent = () => {{(sortedTabs.length > 1 || isPageLayoutInEditMode) && (<StyledPageLayoutTabListtabs={sortedTabs}- behaveAsLinks={false}+ behaveAsLinks={!isInRightDrawer && !isPageLayoutInEditMode}componentInstanceId={tabListInstanceId}onAddTab={handleAddTab}isReorderEnabled={isPageLayoutInEditMode}diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsxindex 0a4a88f0bd5..9891927696a 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsx@@ -15,7 +15,6 @@ import { IconButton } from 'twenty-ui/input';import { isPageLayoutTabDraggingComponentState } from '@/page-layout/states/isPageLayoutTabDraggingComponentState';import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown';import { useOpenDropdown } from '@/ui/layout/dropdown/hooks/useOpenDropdown';-import { TabListFromUrlOptionalEffect } from '@/ui/layout/tab-list/components/TabListFromUrlOptionalEffect';import { TabListHiddenMeasurements } from '@/ui/layout/tab-list/components/TabListHiddenMeasurements';import { TAB_LIST_GAP } from '@/ui/layout/tab-list/constants/TabListGap';import { useTabListMeasurements } from '@/ui/layout/tab-list/hooks/useTabListMeasurements';@@ -38,6 +37,7 @@ import { isPageLayoutInEditModeComponentState } from '@/page-layout/states/isPagimport { pageLayoutTabListCurrentDragDroppableIdComponentState } from '@/page-layout/states/pageLayoutTabListCurrentDragDroppableIdComponentState';import { pageLayoutTabSettingsOpenTabIdComponentState } from '@/page-layout/states/pageLayoutTabSettingsOpenTabIdComponentState';import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';+import { TabListFromUrlOptionalEffect } from '@/ui/layout/tab-list/components/TabListFromUrlOptionalEffect';import { type SingleTabProps } from '@/ui/layout/tab-list/types/SingleTabProps';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';@@ -74,12 +74,13 @@ type PageLayoutTabListProps = Omit<TabListProps, 'tabs'> & {isReorderEnabled: boolean;onAddTab?: () => void;onReorder?: (result: DropResult, provided: ResponderProvided) => boolean;+ behaveAsLinks: boolean;};export const PageLayoutTabList = ({tabs,loading,- behaveAsLinks = true,+ behaveAsLinks,isInRightDrawer,className,componentInstanceId,diff --git a/packages/twenty-ui/src/utilities/index.ts b/packages/twenty-ui/src/utilities/index.tsindex 95138389886..832ad501954 100644--- a/packages/twenty-ui/src/utilities/index.ts+++ b/packages/twenty-ui/src/utilities/index.ts@@ -26,6 +26,7 @@ export { getOsShortcutSeparator } from './device/getOsShortcutSeparator';export { getUserDevice } from './device/getUserDevice';export { AutogrowWrapper } from './dimensions/components/AutogrowWrapper';export { useMouseDownNavigation } from './navigation/hooks/useMouseDownNavigation';+export { useResetLocationHash } from './navigation/hooks/useResetLocationHash';export { isNavigationModifierPressed } from './navigation/isNavigationModifierPressed';export type { TriggerEventType } from './navigation/types/trigger-event.type';export { useIsMobile } from './responsive/hooks/useIsMobile';diff --git a/packages/twenty-ui/src/utilities/navigation/hooks/useResetLocationHash.ts b/packages/twenty-ui/src/utilities/navigation/hooks/useResetLocationHash.tsnew file mode 100644index 00000000000..c6173c1eff6--- /dev/null+++ b/packages/twenty-ui/src/utilities/navigation/hooks/useResetLocationHash.ts@@ -0,0 +1,13 @@+import { useLocation, useNavigate } from 'react-router-dom';++export const useResetLocationHash = () => {+ const navigate = useNavigate();+ const location = useLocation();++ // eslint-disable-next-line @nx/workspace-no-navigate-prefer-link+ const resetLocationHash = () => {+ navigate(location.pathname, { replace: true });+ };++ return { resetLocationHash };+};