The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Restore primary pinned actions with footer-owned width measurement (#24235)
Félix Malfait3fff25bd7c19
diff --git a/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelCommandMenuDropdown.tsx b/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelCommandMenuDropdown.tsxindex 543b0aefd7d..54010c4eccb 100644--- a/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelCommandMenuDropdown.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelCommandMenuDropdown.tsx@@ -1,6 +1,7 @@import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';import { CommandMenuItemRenderer } from '@/command-menu-item/display/components/CommandMenuItemRenderer';import { usePinnedCommandMenuItemsInlineLayout } from '@/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout';+import { useSidePanelFooterPinnedItemsAvailableWidth } from '@/command-menu-item/hooks/useSidePanelFooterPinnedItemsAvailableWidth';import { getSidePanelCommandMenuDropdownIdFromCommandMenuId } from '@/command-menu-item/utils/getSidePanelCommandMenuDropdownIdFromCommandMenuId';import { CommandMenuComponentInstanceContext } from '@/command-menu/states/contexts/CommandMenuComponentInstanceContext';import { OptionsDropdownMenu } from '@/ui/layout/dropdown/components/OptionsDropdownMenu';@@ -49,12 +50,15 @@ export const RecordPageSidePanelCommandMenuDropdown = () => {[commandMenuItems],);+ const availableWidth = useSidePanelFooterPinnedItemsAvailableWidth();+// Pinned items are buttons in the footer, so the dropdown only repeats the- // ones the footer could not fit.+ // ones the footer could not fit next to this dropdown's own footprint.const { pinnedOverflowCommandMenuItems } =usePinnedCommandMenuItemsInlineLayout({pinnedCommandMenuItems,layoutKey: 'side-panel-footer',+ containerWidth: availableWidth,});// A widget owning the footer suppresses those buttons entirely, and leavesdiff --git a/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelPinnedCommandMenuItems.tsx b/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelPinnedCommandMenuItems.tsxindex fb28ecdc07d..11b2ca8b980 100644--- a/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelPinnedCommandMenuItems.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelPinnedCommandMenuItems.tsx@@ -3,6 +3,7 @@ import { isDefined } from 'twenty-shared/utils';import { CommandMenuContextProvider } from '@/command-menu-item/contexts/CommandMenuContextProvider';import { PinnedCommandMenuItemButtons } from '@/command-menu-item/display/components/PinnedCommandMenuItemButtons';+import { useSidePanelFooterPinnedItemsAvailableWidth } from '@/command-menu-item/hooks/useSidePanelFooterPinnedItemsAvailableWidth';import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';@@ -11,6 +12,8 @@ export const RecordPageSidePanelPinnedCommandMenuItems = () => {contextStoreCurrentObjectMetadataItemIdComponentState,);+ const availableWidth = useSidePanelFooterPinnedItemsAvailableWidth();+if (!isDefined(contextStoreCurrentObjectMetadataItemId)) {return null;}@@ -21,7 +24,7 @@ export const RecordPageSidePanelPinnedCommandMenuItems = () => {displayType="button"containerType={CommandMenuItemContainerType.SidePanelFooter}>- <PinnedCommandMenuItemButtons />+ <PinnedCommandMenuItemButtons containerWidth={availableWidth} /></CommandMenuContextProvider>);};diff --git a/packages/twenty-front/src/modules/command-menu-item/constants/SidePanelFooterOptionsReservedWidth.ts b/packages/twenty-front/src/modules/command-menu-item/constants/SidePanelFooterOptionsReservedWidth.tsnew file mode 100644index 00000000000..35d49a97c24--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/constants/SidePanelFooterOptionsReservedWidth.ts@@ -0,0 +1,3 @@+// Footprint of the options dropdown in the side panel footer: a small icon+// button (24px) plus the footer gap separating it from the pinned buttons.+export const SIDE_PANEL_FOOTER_OPTIONS_RESERVED_WIDTH = 32;diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsxindex b1598b580f5..e8938267723 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/PinnedCommandMenuItemButtons.tsx@@ -42,10 +42,18 @@ const StyledItemsContainer = styled.div<{ shouldReverse: boolean }>`shouldReverse ? 'row-reverse' : 'row'};gap: ${PINNED_COMMAND_MENU_ITEMS_GAP}px;max-width: 100%;+ min-width: 0;overflow: hidden;`;-export const PinnedCommandMenuItemButtons = () => {+export const PinnedCommandMenuItemButtons = ({+ containerWidth,+}: {+ // Provided when an ancestor already knows the width available to the+ // buttons; the row then shrinks to fit instead of stretching over the free+ // space to measure it, so sibling actions stay adjacent to the buttons.+ containerWidth?: number;+}) => {const { theme } = useContext(ThemeContext);const { commandMenuItems, containerType } = useContext(CommandMenuContext);const isMobile = useIsMobile();@@ -86,6 +94,7 @@ export const PinnedCommandMenuItemButtons = () => {} = usePinnedCommandMenuItemsInlineLayout({pinnedCommandMenuItems,layoutKey: isSidePanelFooter ? 'side-panel-footer' : 'page-header',+ containerWidth,});const isCommandMenuItemLabelled = (@@ -103,6 +112,35 @@ export const PinnedCommandMenuItemButtons = () => {...pinnedInlineCommandMenuItems.filter(isCommandMenuItemLabelled),];+ const inlineItemsRow = (+ <StyledItemsContainer shouldReverse={!isSidePanelFooter}>+ {displayedInlineCommandMenuItems.map((item) => (+ <StyledCommandMenuItemContainer+ key={item.id}+ initial={{ width: 0, opacity: 0 }}+ animate={{ width: 'unset', opacity: 1 }}+ exit={{ width: 0, opacity: 0 }}+ transition={{+ duration: theme.animation.duration.instant,+ ease: 'easeInOut',+ }}+ >+ <CommandMenuItemRenderer+ item={item}+ shouldHideLabel={shouldHideCommandMenuItemLabel(item.id)}+ isPrimaryAction={+ item.engineComponentKey ===+ EngineComponentKey.CREATE_NEW_RECORD ||+ item.engineComponentKey === EngineComponentKey.COMPOSE_CAMPAIGN ||+ item.engineComponentKey ===+ EngineComponentKey.SEND_MESSAGE_CAMPAIGN+ }+ />+ </StyledCommandMenuItemContainer>+ ))}+ </StyledItemsContainer>+ );+return (<><PinnedCommandMenuItemsInlineMeasurements@@ -115,39 +153,15 @@ export const PinnedCommandMenuItemButtons = () => {onCommandMenuItemDimensionChange}/>- <StyledWrapper>- <NodeDimension onDimensionChange={onContainerDimensionChange}>- <StyledContainer>- <StyledItemsContainer shouldReverse={!isSidePanelFooter}>- {displayedInlineCommandMenuItems.map((item) => (- <StyledCommandMenuItemContainer- key={item.id}- initial={{ width: 0, opacity: 0 }}- animate={{ width: 'unset', opacity: 1 }}- exit={{ width: 0, opacity: 0 }}- transition={{- duration: theme.animation.duration.instant,- ease: 'easeInOut',- }}- >- <CommandMenuItemRenderer- item={item}- shouldHideLabel={shouldHideCommandMenuItemLabel(item.id)}- isPrimaryAction={- item.engineComponentKey ===- EngineComponentKey.CREATE_NEW_RECORD ||- item.engineComponentKey ===- EngineComponentKey.COMPOSE_CAMPAIGN ||- item.engineComponentKey ===- EngineComponentKey.SEND_MESSAGE_CAMPAIGN- }- />- </StyledCommandMenuItemContainer>- ))}- </StyledItemsContainer>- </StyledContainer>- </NodeDimension>- </StyledWrapper>+ {isDefined(containerWidth) ? (+ inlineItemsRow+ ) : (+ <StyledWrapper>+ <NodeDimension onDimensionChange={onContainerDimensionChange}>+ <StyledContainer>{inlineItemsRow}</StyledContainer>+ </NodeDimension>+ </StyledWrapper>+ )}</>);};diff --git a/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.ts b/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.tsindex 44ea9bcf2b9..0308cfbc06f 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.ts+++ b/packages/twenty-front/src/modules/command-menu-item/display/hooks/usePinnedCommandMenuItemsInlineLayout.ts@@ -15,15 +15,22 @@ type ElementDimensions = {type UsePinnedCommandMenuItemsInlineLayoutParams = {pinnedCommandMenuItems: CommandMenuItemFieldsFragment[];layoutKey: PinnedCommandMenuItemsLayoutKey;+ // Overrides the self-measured container width when an ancestor already+ // knows how much space the inline buttons may occupy.+ containerWidth?: number;};export const usePinnedCommandMenuItemsInlineLayout = ({pinnedCommandMenuItems,layoutKey,+ containerWidth,}: UsePinnedCommandMenuItemsInlineLayoutParams) => {const [commandMenuPinnedInlineLayout, setCommandMenuPinnedInlineLayout] =useAtomFamilyState(commandMenuPinnedInlineLayoutFamilyState, layoutKey);+ const effectiveContainerWidth =+ containerWidth ?? commandMenuPinnedInlineLayout.containerWidth;+const pinnedCommandMenuItemKeysInDisplayOrder = useMemo(() => pinnedCommandMenuItems.map((item) => item.id),[pinnedCommandMenuItems],@@ -31,7 +38,7 @@ export const usePinnedCommandMenuItemsInlineLayout = ({const hasKnownPinnedInlineLayout = useMemo(() =>- commandMenuPinnedInlineLayout.containerWidth > 0 &&+ effectiveContainerWidth > 0 &&pinnedCommandMenuItemKeysInDisplayOrder.every((commandMenuItemKey) =>isNumber(commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey[@@ -39,7 +46,11 @@ export const usePinnedCommandMenuItemsInlineLayout = ({],),),- [commandMenuPinnedInlineLayout, pinnedCommandMenuItemKeysInDisplayOrder],+ [+ commandMenuPinnedInlineLayout,+ effectiveContainerWidth,+ pinnedCommandMenuItemKeysInDisplayOrder,+ ],);const visiblePinnedCommandMenuItemCount = useMemo(@@ -50,13 +61,13 @@ export const usePinnedCommandMenuItemsInlineLayout = ({pinnedCommandMenuItemKeysInDisplayOrder,commandMenuItemWidthsByKey:commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey,- commandMenuItemsContainerWidth:- commandMenuPinnedInlineLayout.containerWidth,+ commandMenuItemsContainerWidth: effectiveContainerWidth,commandMenuItemsGapWidth: PINNED_COMMAND_MENU_ITEMS_GAP,}): 0,[commandMenuPinnedInlineLayout,+ effectiveContainerWidth,hasKnownPinnedInlineLayout,pinnedCommandMenuItemKeysInDisplayOrder,],diff --git a/packages/twenty-front/src/modules/command-menu-item/hooks/useSidePanelFooterPinnedItemsAvailableWidth.ts b/packages/twenty-front/src/modules/command-menu-item/hooks/useSidePanelFooterPinnedItemsAvailableWidth.tsnew file mode 100644index 00000000000..9d867ea75a9--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/hooks/useSidePanelFooterPinnedItemsAvailableWidth.ts@@ -0,0 +1,15 @@+import { SIDE_PANEL_FOOTER_OPTIONS_RESERVED_WIDTH } from '@/command-menu-item/constants/SidePanelFooterOptionsReservedWidth';+import { SidePanelFooterWidthContext } from '@/ui/layout/side-panel/contexts/SidePanelFooterWidthContext';+import { useContext } from 'react';++// Width left for the pinned buttons once the options dropdown footprint is+// reserved out of the measured footer row. The buttons and the overflow+// dropdown both size against this so they can never disagree on what fits.+export const useSidePanelFooterPinnedItemsAvailableWidth = () => {+ const sidePanelFooterWidth = useContext(SidePanelFooterWidthContext);++ return Math.max(+ sidePanelFooterWidth - SIDE_PANEL_FOOTER_OPTIONS_RESERVED_WIDTH,+ 0,+ );+};diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsxindex ef1207925c8..1d7597d2ce8 100644--- a/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx+++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx@@ -65,7 +65,7 @@ export const CommandMenuButton = ({<IconButtonIcon={command.Icon}size="small"- variant={buttonAccent === 'blue' ? 'primary' : 'tertiary'}+ variant="primary"accent={buttonAccent}to={to}onClick={onClick}diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsxindex 13034b1e2a5..3583e0f6516 100644--- a/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx+++ b/packages/twenty-front/src/modules/object-record/record-show/components/PageLayoutRecordPageRenderer.tsx@@ -124,9 +124,7 @@ export const PageLayoutRecordPageRenderer = ({<Buttonkey={commandMenuItem.id}size="small"- variant={- commandMenuItem.isPrimaryCTA ? 'primary' : 'secondary'- }+ variant="primary"accent={commandMenuItem.isPrimaryCTA ? 'blue' : 'default'}title={commandMenuItem.label}Icon={commandMenuItem.Icon}diff --git a/packages/twenty-front/src/modules/side-panel/components/SidePanelTopBar.tsx b/packages/twenty-front/src/modules/side-panel/components/SidePanelTopBar.tsxindex 239d5228fa5..e751858e443 100644--- a/packages/twenty-front/src/modules/side-panel/components/SidePanelTopBar.tsx+++ b/packages/twenty-front/src/modules/side-panel/components/SidePanelTopBar.tsx@@ -217,7 +217,7 @@ export const SidePanelTopBar = () => {<IconButtonIcon={IconX}size="small"- variant="tertiary"+ variant="primary"onClick={closeSidePanelMenu}ariaLabel={t`Close side panel`}/>diff --git a/packages/twenty-front/src/modules/side-panel/pages/compose-email/components/SidePanelComposeEmailPage.tsx b/packages/twenty-front/src/modules/side-panel/pages/compose-email/components/SidePanelComposeEmailPage.tsxindex 01761170311..4affe842e22 100644--- a/packages/twenty-front/src/modules/side-panel/pages/compose-email/components/SidePanelComposeEmailPage.tsx+++ b/packages/twenty-front/src/modules/side-panel/pages/compose-email/components/SidePanelComposeEmailPage.tsx@@ -96,7 +96,7 @@ export const SidePanelComposeEmailPage = () => {<IconButtonkey="discard"size="small"- variant="secondary"+ variant="primary"Icon={IconTrash}ariaLabel={t`Discard`}onClick={goBackFromSidePanel}@@ -104,7 +104,7 @@ export const SidePanelComposeEmailPage = () => {<IconButtonkey="attach"size="small"- variant="secondary"+ variant="primary"Icon={IconPaperclip}ariaLabel={t`Attach files`}onClick={openAttachmentPicker}diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/OptionsDropdownMenu.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/OptionsDropdownMenu.tsxindex d283d505afe..c72d1f13cc0 100644--- a/packages/twenty-front/src/modules/ui/layout/dropdown/components/OptionsDropdownMenu.tsx+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/OptionsDropdownMenu.tsx@@ -70,7 +70,7 @@ export const OptionsDropdownMenu = ({Icon={IconDotsVertical}ariaLabel={t`Options`}size="small"- variant="tertiary"+ variant="primary"/>}dropdownPlacement="top-end"diff --git a/packages/twenty-front/src/modules/ui/layout/side-panel/components/SidePanelFooter.tsx b/packages/twenty-front/src/modules/ui/layout/side-panel/components/SidePanelFooter.tsxindex 18529be36df..90a4628a9c6 100644--- a/packages/twenty-front/src/modules/ui/layout/side-panel/components/SidePanelFooter.tsx+++ b/packages/twenty-front/src/modules/ui/layout/side-panel/components/SidePanelFooter.tsx@@ -1,17 +1,23 @@+import { SidePanelFooterWidthContext } from '@/ui/layout/side-panel/contexts/SidePanelFooterWidthContext';+import { NodeDimension } from '@/ui/utilities/dimensions/components/NodeDimension';import { styled } from '@linaria/react';-import { Fragment } from 'react';+import { Fragment, useCallback, useState } from 'react';import { themeCssVariables } from 'twenty-ui/theme-constants';const StyledContainer = styled.div`- align-items: center;background: ${themeCssVariables.background.secondary};border-top: 1px solid ${themeCssVariables.border.color.light};bottom: 0;box-sizing: border-box;+ padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[3]};+ width: 100%;+`;++const StyledActionsRow = styled(NodeDimension)`+ align-items: center;display: flex;gap: ${themeCssVariables.spacing[2]};justify-content: flex-end;- padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[3]};width: 100%;`;@@ -20,11 +26,24 @@ type SidePanelFooterProps = {};export const SidePanelFooter = ({ actions }: SidePanelFooterProps) => {+ const [actionsRowWidth, setActionsRowWidth] = useState(0);++ const handleActionsRowDimensionChange = useCallback(+ (dimensions: { width: number; height: number }) => {+ setActionsRowWidth(dimensions.width);+ },+ [],+ );+return (<StyledContainer>- {actions.map((action, index) => (- <Fragment key={index}>{action}</Fragment>- ))}+ <SidePanelFooterWidthContext.Provider value={actionsRowWidth}>+ <StyledActionsRow onDimensionChange={handleActionsRowDimensionChange}>+ {actions.map((action, index) => (+ <Fragment key={index}>{action}</Fragment>+ ))}+ </StyledActionsRow>+ </SidePanelFooterWidthContext.Provider></StyledContainer>);};diff --git a/packages/twenty-front/src/modules/ui/layout/side-panel/contexts/SidePanelFooterWidthContext.ts b/packages/twenty-front/src/modules/ui/layout/side-panel/contexts/SidePanelFooterWidthContext.tsnew file mode 100644index 00000000000..0d97c83d735--- /dev/null+++ b/packages/twenty-front/src/modules/ui/layout/side-panel/contexts/SidePanelFooterWidthContext.ts@@ -0,0 +1,5 @@+import { createContext } from 'react';++// Content width of the footer actions row, so an action that adapts to the+// available space can size itself without stretching over the row to measure.+export const SidePanelFooterWidthContext = createContext<number>(0);