The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix side panel email reply crashing with Invalid Configuration (#24944)
neo773b2d570989f06
diff --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 11b2ca8b980..e0ec7e2c462 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@@ -5,16 +5,32 @@ import { CommandMenuContextProvider } from '@/command-menu-item/contexts/Commandimport { PinnedCommandMenuItemButtons } from '@/command-menu-item/display/components/PinnedCommandMenuItemButtons';import { useSidePanelFooterPinnedItemsAvailableWidth } from '@/command-menu-item/hooks/useSidePanelFooterPinnedItemsAvailableWidth';import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState';+import { sidePanelWidgetFooterCommandMenuItemsState } from '@/ui/layout/side-panel/states/sidePanelWidgetFooterCommandMenuItemsState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';export const RecordPageSidePanelPinnedCommandMenuItems = () => {const contextStoreCurrentObjectMetadataItemId = useAtomComponentStateValue(contextStoreCurrentObjectMetadataItemIdComponentState,);+ const sidePanelWidgetFooterCommandMenuItems = useAtomStateValue(+ sidePanelWidgetFooterCommandMenuItemsState,+ );+const availableWidth = useSidePanelFooterPinnedItemsAvailableWidth();- if (!isDefined(contextStoreCurrentObjectMetadataItemId)) {+ // A widget that contributes footer actions, such as the email composer,+ // supersedes the record's own actions rather than doubling up with them.+ const hasPinnedWidgetCommandMenuItems =+ sidePanelWidgetFooterCommandMenuItems.some(+ (commandMenuItem) => commandMenuItem.isPinned !== false,+ );++ if (+ !isDefined(contextStoreCurrentObjectMetadataItemId) ||+ hasPinnedWidgetCommandMenuItems+ ) {return null;}diff --git a/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelWidgetCommandMenuItems.tsx b/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelWidgetCommandMenuItems.tsxnew file mode 100644index 00000000000..bfe2c8a7b70--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/components/RecordPageSidePanelWidgetCommandMenuItems.tsx@@ -0,0 +1,32 @@+import { sidePanelWidgetFooterCommandMenuItemsState } from '@/ui/layout/side-panel/states/sidePanelWidgetFooterCommandMenuItemsState';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';+import { Button } from 'twenty-ui/input';++export const RecordPageSidePanelWidgetCommandMenuItems = () => {+ const sidePanelWidgetFooterCommandMenuItems = useAtomStateValue(+ sidePanelWidgetFooterCommandMenuItemsState,+ );++ const pinnedWidgetCommandMenuItems =+ sidePanelWidgetFooterCommandMenuItems.filter(+ (commandMenuItem) => commandMenuItem.isPinned !== false,+ );++ return (+ <>+ {pinnedWidgetCommandMenuItems.map((commandMenuItem) => (+ <Button+ key={commandMenuItem.id}+ size="small"+ variant="primary"+ accent={commandMenuItem.isPrimaryCTA ? 'blue' : 'default'}+ title={commandMenuItem.label}+ Icon={commandMenuItem.Icon}+ hotkeys={commandMenuItem.hotkeys}+ onClick={commandMenuItem.onClick}+ disabled={commandMenuItem.disabled}+ />+ ))}+ </>+ );+};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 3583e0f6516..27b6d2f5577 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@@ -1,5 +1,6 @@import { RecordPageSidePanelCommandMenu } from '@/command-menu-item/components/RecordPageSidePanelCommandMenu';import { RecordPageSidePanelPinnedCommandMenuItems } from '@/command-menu-item/components/RecordPageSidePanelPinnedCommandMenuItems';+import { RecordPageSidePanelWidgetCommandMenuItems } from '@/command-menu-item/components/RecordPageSidePanelWidgetCommandMenuItems';import { InformationBannerDeletedRecord } from '@/information-banner/components/deleted-record/InformationBannerDeletedRecord';import { RecordShowContainerContextStoreTargetedRecordsEffect } from '@/object-record/record-show/components/RecordShowContainerContextStoreTargetedRecordsEffect';import { RecordShowEffect } from '@/object-record/record-show/components/RecordShowEffect';@@ -9,13 +10,10 @@ import { usePageLayoutIdForRecord } from '@/page-layout/hooks/usePageLayoutIdForimport { LayoutRenderingProvider } from '@/ui/layout/contexts/LayoutRenderingContext';import { type TargetRecordIdentifier } from '@/ui/layout/contexts/TargetRecordIdentifier';import { SidePanelFooter } from '@/ui/layout/side-panel/components/SidePanelFooter';-import { sidePanelWidgetFooterCommandMenuItemsState } from '@/ui/layout/side-panel/states/sidePanelWidgetFooterCommandMenuItemsState';import { useAtomFamilySelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilySelectorValue';-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { styled } from '@linaria/react';import { CoreObjectNameSingular } from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';-import { Button } from 'twenty-ui/input';import { themeCssVariables } from 'twenty-ui/theme-constants';import { PageLayoutType } from '~/generated-metadata/graphql';@@ -58,20 +56,6 @@ export const PageLayoutRecordPageRenderer = ({targetObjectNameSingular: targetRecordIdentifier.targetObjectNameSingular,});- const sidePanelWidgetFooterCommandMenuItems = useAtomStateValue(- sidePanelWidgetFooterCommandMenuItemsState,- );-- const pinnedWidgetCommandMenuItems =- sidePanelWidgetFooterCommandMenuItems.filter(- (commandMenuItem) => commandMenuItem.isPinned !== false,- );-- // A widget that contributes footer actions, such as the email composer,- // supersedes the record's own actions rather than doubling up with them.- const hasPinnedWidgetCommandMenuItems =- pinnedWidgetCommandMenuItems.length > 0;-return (<><RecordShowEffect@@ -119,21 +103,8 @@ export const PageLayoutRecordPageRenderer = ({<SidePanelFooteractions={[<RecordPageSidePanelCommandMenu key="options" />,- ...(hasPinnedWidgetCommandMenuItems- ? pinnedWidgetCommandMenuItems.map((commandMenuItem) => (- <Button- key={commandMenuItem.id}- size="small"- variant="primary"- accent={commandMenuItem.isPrimaryCTA ? 'blue' : 'default'}- title={commandMenuItem.label}- Icon={commandMenuItem.Icon}- hotkeys={commandMenuItem.hotkeys}- onClick={commandMenuItem.onClick}- disabled={commandMenuItem.disabled}- />- ))- : [<RecordPageSidePanelPinnedCommandMenuItems key="pinned" />]),+ <RecordPageSidePanelWidgetCommandMenuItems key="widget" />,+ <RecordPageSidePanelPinnedCommandMenuItems key="pinned" />,]}/>)}diff --git a/packages/twenty-front/src/modules/object-record/record-show/components/__stories__/PageLayoutRecordPageRendererEmailThread.stories.tsx b/packages/twenty-front/src/modules/object-record/record-show/components/__stories__/PageLayoutRecordPageRendererEmailThread.stories.tsxnew file mode 100644index 00000000000..088394fb6c1--- /dev/null+++ b/packages/twenty-front/src/modules/object-record/record-show/components/__stories__/PageLayoutRecordPageRendererEmailThread.stories.tsx@@ -0,0 +1,296 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { graphql, HttpResponse } from 'msw';+import { useEffect } from 'react';+import { expect, userEvent, within } from 'storybook/test';+import { CoreObjectNameSingular } from 'twenty-shared/types';++import { type TargetRecordIdentifier } from '@/ui/layout/contexts/TargetRecordIdentifier';++import { useUpdateMetadataStoreDraft } from '@/metadata-store/hooks/useUpdateMetadataStoreDraft';+import { isMinimalMetadataReadyState } from '@/metadata-store/states/isMinimalMetadataReadyState';+import { PageLayoutRecordPageRenderer } from '@/object-record/record-show/components/PageLayoutRecordPageRenderer';+import { CommandMenuComponentInstanceContext } from '@/command-menu/states/contexts/CommandMenuComponentInstanceContext';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';+import {+ PageLayoutTabLayoutMode,+ PageLayoutType,+ WidgetConfigurationType,+ WidgetType,+} from '~/generated-metadata/graphql';+import { ContextStoreDecorator } from '~/testing/decorators/ContextStoreDecorator';+import { FileUploadDecorator } from '~/testing/decorators/FileUploadDecorator';+import {+ PageDecorator,+ type PageDecoratorArgs,+} from '~/testing/decorators/PageDecorator';+import { graphqlMocks } from '~/testing/graphqlMocks';+import { getMockObjectMetadataItemOrThrow } from '~/testing/utils/getMockObjectMetadataItemOrThrow';++const THREAD_ID = '20202020-0000-4000-8000-00000000thr1';+const MESSAGE_ID = '20202020-0000-4000-8000-00000000msg1';+const PARTICIPANT_ID = '20202020-0000-4000-8000-00000000par1';+const ASSOCIATION_ID = '20202020-0000-4000-8000-00000000ass1';+const MESSAGE_CHANNEL_ID = '20202020-0000-4000-8000-00000000cha1';+const CONNECTED_ACCOUNT_ID = '20202020-0000-4000-8000-00000000acc1';++const PAGE_LAYOUT_ID = 'email-thread-record-layout';+const PAGE_LAYOUT_TAB_ID = 'email-thread-record-tab';++const messageThreadObjectMetadataItem =+ getMockObjectMetadataItemOrThrow('messageThread');++const buildConnection = (typename: string, records: object[]) => ({+ __typename: `${typename}Connection`,+ edges: records.map((node) => ({ __typename: `${typename}Edge`, node })),+ pageInfo: {+ __typename: 'PageInfo',+ hasNextPage: false,+ hasPreviousPage: false,+ startCursor: null,+ endCursor: null,+ },+ totalCount: records.length,+});++const senderParticipant = {+ __typename: 'MessageParticipant',+ id: PARTICIPANT_ID,+ role: 'from',+ displayName: 'Hanns Moongazer',+ handle: '[email protected]',+ messageId: MESSAGE_ID,+ person: null,+ workspaceMember: null,+};++const threadMessage = {+ __typename: 'Message',+ id: MESSAGE_ID,+ createdAt: '2026-08-01T10:00:00.000Z',+ headerMessageId: '<[email protected]>',+ subject: 'Quarterly report',+ text: 'Here is the report you asked for.',+ receivedAt: '2026-08-01T10:00:00.000Z',+ isDraft: false,+ messageThreadId: THREAD_ID,+ messageThread: { __typename: 'MessageThread', id: THREAD_ID },+ messageParticipants: buildConnection('MessageParticipant', [+ senderParticipant,+ ]),+};++const emailThreadPageLayout = {+ __typename: 'PageLayout' as const,+ id: PAGE_LAYOUT_ID,+ name: 'Message Thread',+ type: PageLayoutType.RECORD_PAGE,+ objectMetadataId: messageThreadObjectMetadataItem.id,+ isSystemSideEffect: false,+ applicationId: '',+ universalIdentifier: 'email-thread-record-layout',+ createdAt: '2026-01-01T00:00:00Z',+ updatedAt: '2026-01-01T00:00:00Z',+ deletedAt: null,+};++const emailThreadPageLayoutTab = {+ __typename: 'PageLayoutTab' as const,+ id: PAGE_LAYOUT_TAB_ID,+ pageLayoutId: PAGE_LAYOUT_ID,+ title: 'Thread',+ position: 0,+ isActive: true,+ isSystemSideEffect: false,+ layoutMode: PageLayoutTabLayoutMode.GRID,+ applicationId: '',+ universalIdentifier: 'email-thread-record-tab',+ createdAt: '2026-01-01T00:00:00Z',+ updatedAt: '2026-01-01T00:00:00Z',+ deletedAt: null,+};++const emailThreadPageLayoutWidget = {+ __typename: 'PageLayoutWidget' as const,+ id: 'email-thread-widget',+ pageLayoutTabId: PAGE_LAYOUT_TAB_ID,+ type: WidgetType.EMAIL_THREAD,+ title: 'Thread',+ objectMetadataId: messageThreadObjectMetadataItem.id,+ isActive: true,+ isSystemSideEffect: false,+ applicationId: '',+ universalIdentifier: 'email-thread-widget',+ gridPosition: {+ __typename: 'GridPosition' as const,+ row: 0,+ column: 0,+ rowSpan: 12,+ columnSpan: 12,+ },+ configuration: {+ __typename: 'FieldsConfiguration' as const,+ configurationType: WidgetConfigurationType.FIELDS,+ },+ createdAt: '2026-01-01T00:00:00Z',+ updatedAt: '2026-01-01T00:00:00Z',+ deletedAt: null,+};++// The mocked minimal metadata ships no page layouts, so the record page has no+// layout to render until this seeds one holding the email thread widget.+const SeedEmailThreadPageLayoutEffect = () => {+ const { replaceDraft, applyChanges } = useUpdateMetadataStoreDraft();+ const isMinimalMetadataReady = useAtomStateValue(isMinimalMetadataReadyState);++ useEffect(() => {+ if (!isMinimalMetadataReady) {+ return;+ }++ replaceDraft('pageLayouts', [emailThreadPageLayout], 'mocked');+ replaceDraft('pageLayoutTabs', [emailThreadPageLayoutTab], 'mocked');+ replaceDraft('pageLayoutWidgets', [emailThreadPageLayoutWidget], 'mocked');+ applyChanges();+ }, [isMinimalMetadataReady, replaceDraft, applyChanges]);++ return null;+};++type EmailThreadStoryArgs = PageDecoratorArgs & {+ targetRecordIdentifier: TargetRecordIdentifier;+ isInSidePanel: boolean;+};++const meta: Meta<EmailThreadStoryArgs> = {+ title:+ 'Modules/ObjectRecord/RecordShow/PageLayoutRecordPageRendererEmailThread',+ component: PageLayoutRecordPageRenderer,+ decorators: [+ (Story) => (+ <CommandMenuComponentInstanceContext.Provider+ value={{ instanceId: 'story-command-menu' }}+ >+ <SeedEmailThreadPageLayoutEffect />+ <Story />+ </CommandMenuComponentInstanceContext.Provider>+ ),+ FileUploadDecorator,+ ContextStoreDecorator,+ PageDecorator,+ ],+ args: {+ routePath: '/object/:objectNameSingular/:objectRecordId',+ routeParams: {+ ':objectNameSingular': 'messageThread',+ ':objectRecordId': THREAD_ID,+ },+ targetRecordIdentifier: {+ id: THREAD_ID,+ targetObjectNameSingular: CoreObjectNameSingular.MessageThread,+ },+ isInSidePanel: true,+ },+ parameters: {+ layout: 'fullscreen',+ msw: {+ handlers: [+ graphql.query('FindOneMessageThread', () =>+ HttpResponse.json({+ data: {+ messageThread: { __typename: 'MessageThread', id: THREAD_ID },+ },+ }),+ ),+ graphql.query('FindManyMessages', () =>+ HttpResponse.json({+ data: {+ messages: buildConnection('Message', [threadMessage]),+ },+ }),+ ),+ graphql.query('FindManyMessageParticipants', () =>+ HttpResponse.json({+ data: {+ messageParticipants: buildConnection('MessageParticipant', [+ senderParticipant,+ ]),+ },+ }),+ ),+ graphql.query('FindManyMessageChannelMessageAssociations', () =>+ HttpResponse.json({+ data: {+ messageChannelMessageAssociations: buildConnection(+ 'MessageChannelMessageAssociation',+ [+ {+ __typename: 'MessageChannelMessageAssociation',+ id: ASSOCIATION_ID,+ messageId: MESSAGE_ID,+ messageChannelId: MESSAGE_CHANNEL_ID,+ messageThreadExternalId: 'thread-external-id',+ messageExternalId: 'message-external-id',+ },+ ],+ ),+ },+ }),+ ),+ graphql.query('MyConnectedAccounts', () =>+ HttpResponse.json({+ data: {+ myConnectedAccounts: [+ {+ __typename: 'ConnectedAccount',+ id: CONNECTED_ACCOUNT_ID,+ handle: '[email protected]',+ provider: 'google',+ },+ ],+ },+ }),+ ),+ graphql.query('MyMessageChannels', () =>+ HttpResponse.json({+ data: {+ myMessageChannels: [+ {+ __typename: 'MessageChannel',+ id: MESSAGE_CHANNEL_ID,+ connectedAccountId: CONNECTED_ACCOUNT_ID,+ },+ ],+ },+ }),+ ),+ graphqlMocks.handlers,+ ],+ },+ },+};++export default meta;++type Story = StoryObj<typeof meta>;++export const ReplyOpensComposerInSidePanel: Story = {+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ const replyButton = await canvas.findByRole(+ 'button',+ { name: /reply/i },+ { timeout: 20000 },+ );++ await userEvent.click(replyButton);++ // The render loop this guards against killed the widget subtree, so the+ // composer never survived past its first frame.+ await expect(+ await canvas.findByRole('button', { name: /send/i }, { timeout: 20000 }),+ ).toBeVisible();++ expect(canvas.queryByText(/invalid configuration/i)).toBeNull();+ },+};