04eb913551
## Summary
- Both \`IS_RECORD_PAGE_LAYOUT_EDITING_ENABLED\` and
\`IS_RECORD_PAGE_LAYOUT_GLOBAL_EDITION_ENABLED\` are force-enabled on
every existing workspace by the 1.23.0 upgrade command
\`BackfillRecordPageLayoutsCommand\` and seeded enabled for new
workspaces via \`DEFAULT_FEATURE_FLAGS\` +
\`seed-feature-flags.util.ts\`. They are no longer load-bearing.
- Unwrap all \`if (flag) { … }\` conditionals to their enabled branch on
both server and front.
- Delete legacy fallback files that only the disabled branch reached:
\`PageLayoutRelationWidgetsSyncEffect\`,
\`usePageLayoutWithRelationWidgets\`,
\`reInjectDynamicRelationWidgetsFromDraft\`,
\`injectRelationWidgetsIntoLayout\`, \`isDynamicRelationWidget\` (and
their tests).
- Strip the two \`enableFeatureFlags\` calls from the 1.23 upgrade
command — the page-layout backfill data logic itself is kept intact
since old workspaces upgrading from < 1.23 still need it.
- No DB cleanup migration: stale \`featureFlag\` rows are left in place,
matching the precedent set by #20531 and #20460.
Net diff: 37 files, +106 / -1727.
## Test plan
- [x] \`npx nx typecheck twenty-shared twenty-server twenty-front\` —
all pass
- [x] \`npx nx lint:diff-with-main twenty-server twenty-front\` — all
pass
- [x] \`cd packages/twenty-front && npx jest page-layout\` — 1240 tests,
all pass
- [x] \`cd packages/twenty-server && npx jest
workspace-entity-manager.spec\` — pass
- [ ] Manual smoke: open a record page, verify tabs render and \"Edit
Layout\" command-menu action is available
- [ ] Manual smoke: Settings → Data model → object → Layout tab is
visible (and hidden for remote / Dashboard objects)
- [ ] Manual smoke: edit a tab title, save, reload — confirm persistence
174 lines
6.6 KiB
TypeScript
174 lines
6.6 KiB
TypeScript
import { metadataStoreState } from '@/metadata-store/states/metadataStoreState';
|
|
import { type FlatObjectMetadataItem } from '@/metadata-store/types/FlatObjectMetadataItem';
|
|
import { PageLayoutLeftPanel } from '@/page-layout/components/PageLayoutLeftPanel';
|
|
import { PageLayoutTabList } from '@/page-layout/components/PageLayoutTabList';
|
|
import { PageLayoutTabListEffect } from '@/page-layout/components/PageLayoutTabListEffect';
|
|
import { DEFAULT_RECORD_PAGE_LAYOUT_ID } from '@/page-layout/constants/DefaultRecordPageLayoutId';
|
|
import { PAGE_LAYOUT_LEFT_PANEL_CONTAINER_WIDTH } from '@/page-layout/constants/PageLayoutLeftPanelContainerWidth';
|
|
import { useCurrentPageLayoutOrThrow } from '@/page-layout/hooks/useCurrentPageLayoutOrThrow';
|
|
import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInEditMode';
|
|
import { usePageLayoutAddTabStrategy } from '@/page-layout/hooks/usePageLayoutAddTabStrategy';
|
|
import { useReorderRecordPageLayoutTabs } from '@/page-layout/hooks/useReorderRecordPageLayoutTabs';
|
|
import { PageLayoutMainContent } from '@/page-layout/PageLayoutMainContent';
|
|
import { getScrollWrapperInstanceIdFromPageLayoutId } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutId';
|
|
import { getTabListInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutAndRecord';
|
|
import { getTabsByDisplayMode } from '@/page-layout/utils/getTabsByDisplayMode';
|
|
import { getTabsWithVisibleWidgets } from '@/page-layout/utils/getTabsWithVisibleWidgets';
|
|
import { shouldEnableTabEditingFeatures } from '@/page-layout/utils/shouldEnableTabEditingFeatures';
|
|
import { sortTabsByPosition } from '@/page-layout/utils/sortTabsByPosition';
|
|
import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';
|
|
import { activeTabIdComponentState } from '@/ui/layout/tab-list/states/activeTabIdComponentState';
|
|
import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
|
|
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
|
|
import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';
|
|
import { styled } from '@linaria/react';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { useIsMobile } from 'twenty-ui/utilities';
|
|
const StyledContainer = styled.div<{ hasPinnedTab: boolean }>`
|
|
display: grid;
|
|
grid-template-columns: ${({ hasPinnedTab }) =>
|
|
hasPinnedTab ? `${PAGE_LAYOUT_LEFT_PANEL_CONTAINER_WIDTH}px 1fr` : '1fr'};
|
|
grid-template-rows: minmax(0, 1fr);
|
|
height: 100%;
|
|
width: 100%;
|
|
`;
|
|
|
|
const StyledTabsAndDashboardContainer = styled.div`
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
`;
|
|
|
|
const StyledScrollWrapperContainer = styled.div`
|
|
flex: 1;
|
|
min-height: 0;
|
|
`;
|
|
|
|
export const PageLayoutTabsRenderer = () => {
|
|
const { currentPageLayout } = useCurrentPageLayoutOrThrow();
|
|
|
|
const { isInSidePanel, layoutType, targetRecordIdentifier } =
|
|
useLayoutRenderingContext();
|
|
|
|
const isPageLayoutInEditMode = useIsPageLayoutInEditMode();
|
|
|
|
const activeTabId = useAtomComponentStateValue(activeTabIdComponentState);
|
|
|
|
const tabListInstanceId = getTabListInstanceIdFromPageLayoutAndRecord({
|
|
pageLayoutId: currentPageLayout.id,
|
|
layoutType,
|
|
targetRecordIdentifier,
|
|
});
|
|
|
|
const addTabStrategy = usePageLayoutAddTabStrategy({
|
|
pageLayoutId: currentPageLayout.id,
|
|
tabListInstanceId,
|
|
});
|
|
|
|
const { reorderRecordPageTabs } = useReorderRecordPageLayoutTabs(
|
|
currentPageLayout.id,
|
|
);
|
|
|
|
const isMobile = useIsMobile();
|
|
|
|
const metadataStore = useAtomFamilyStateValue(
|
|
metadataStoreState,
|
|
'objectMetadataItems',
|
|
);
|
|
|
|
const isSystemObject =
|
|
(metadataStore.current as FlatObjectMetadataItem[]).find(
|
|
(item) =>
|
|
item.nameSingular === targetRecordIdentifier?.targetObjectNameSingular,
|
|
)?.isSystem ?? false;
|
|
|
|
const canEnableTabEditing =
|
|
isPageLayoutInEditMode &&
|
|
shouldEnableTabEditingFeatures(currentPageLayout.type);
|
|
|
|
const tabsWithVisibleWidgets = getTabsWithVisibleWidgets({
|
|
tabs: currentPageLayout.tabs,
|
|
isMobile,
|
|
isInSidePanel,
|
|
isEditMode: isPageLayoutInEditMode,
|
|
});
|
|
|
|
const SYSTEM_OBJECT_TABS = ['Home', 'Timeline', 'Overview', 'Flow'];
|
|
|
|
const isUsingDefaultRecordPageLayout =
|
|
currentPageLayout.id === DEFAULT_RECORD_PAGE_LAYOUT_ID;
|
|
|
|
const tabsForCurrentObject =
|
|
isSystemObject && isUsingDefaultRecordPageLayout
|
|
? tabsWithVisibleWidgets.filter((tab) =>
|
|
SYSTEM_OBJECT_TABS.includes(tab.title),
|
|
)
|
|
: tabsWithVisibleWidgets;
|
|
|
|
const { tabsToRenderInTabList, pinnedLeftTab } = getTabsByDisplayMode({
|
|
tabs: tabsForCurrentObject,
|
|
pageLayoutType: currentPageLayout.type,
|
|
isMobile,
|
|
isInSidePanel,
|
|
});
|
|
|
|
const sortedTabs = sortTabsByPosition(tabsToRenderInTabList);
|
|
|
|
const activeTabExistsInCurrentPageLayout = currentPageLayout.tabs.some(
|
|
(tab) => tab.id === activeTabId,
|
|
);
|
|
|
|
return (
|
|
<StyledContainer hasPinnedTab={isDefined(pinnedLeftTab)}>
|
|
{isDefined(pinnedLeftTab) && (
|
|
<PageLayoutLeftPanel pinnedLeftTabId={pinnedLeftTab.id} />
|
|
)}
|
|
|
|
<StyledTabsAndDashboardContainer>
|
|
<PageLayoutTabListEffect
|
|
tabs={sortedTabs}
|
|
componentInstanceId={tabListInstanceId}
|
|
defaultTabToFocusOnMobileAndSidePanelId={
|
|
currentPageLayout.defaultTabToFocusOnMobileAndSidePanelId ??
|
|
undefined
|
|
}
|
|
/>
|
|
{(sortedTabs.length > 1 || isPageLayoutInEditMode) && (
|
|
<PageLayoutTabList
|
|
tabs={sortedTabs}
|
|
behaveAsLinks={!isInSidePanel && !isPageLayoutInEditMode}
|
|
isInSidePanel={isInSidePanel}
|
|
componentInstanceId={tabListInstanceId}
|
|
addTabStrategy={addTabStrategy}
|
|
isReorderEnabled={canEnableTabEditing}
|
|
onReorder={
|
|
canEnableTabEditing
|
|
? (result, provided) =>
|
|
reorderRecordPageTabs(
|
|
result,
|
|
provided,
|
|
isDefined(pinnedLeftTab),
|
|
)
|
|
: undefined
|
|
}
|
|
pageLayoutType={currentPageLayout.type}
|
|
/>
|
|
)}
|
|
|
|
<StyledScrollWrapperContainer>
|
|
<ScrollWrapper
|
|
componentInstanceId={getScrollWrapperInstanceIdFromPageLayoutId(
|
|
currentPageLayout.id,
|
|
)}
|
|
defaultEnableXScroll={false}
|
|
>
|
|
{isDefined(activeTabId) && activeTabExistsInCurrentPageLayout && (
|
|
<PageLayoutMainContent tabId={activeTabId} />
|
|
)}
|
|
</ScrollWrapper>
|
|
</StyledScrollWrapperContainer>
|
|
</StyledTabsAndDashboardContainer>
|
|
</StyledContainer>
|
|
);
|
|
};
|