The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(page-layout): render standalone rich text widget on record pages (#23435)
Thomas Trompette933ae9c20bab
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextEditorContent.tsx b/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextEditorContent.tsxindex 42da7b68f96..364f845a118 100644--- a/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextEditorContent.tsx+++ b/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextEditorContent.tsx@@ -1,6 +1,5 @@import { useCallback, useState } from 'react';-import { type Attachment } from '@/activities/files/types/Attachment';import { useUpdatePageLayoutWidget } from '@/page-layout/hooks/useUpdatePageLayoutWidget';import { isDashboardInEditModeComponentState } from '@/page-layout/states/isDashboardInEditModeComponentState';import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';@@ -11,7 +10,6 @@ import { DASHBOARD_BLOCK_SCHEMA } from '@/page-layout/widgets/standalone-rich-teimport { filterSupportedBlocks } from '@/page-layout/widgets/standalone-rich-text/utils/filterSupportedBlocks';import { BLOCK_EDITOR_GLOBAL_HOTKEYS_CONFIG } from '@/blocknote-editor/constants/BlockEditorGlobalHotkeysConfig';-import { useAttachmentSync } from '@/blocknote-editor/hooks/useAttachmentSync';import { parseInitialBlocknote } from '@/blocknote-editor/utils/parseInitialBlocknote';import { usePushFocusItemToFocusStack } from '@/ui/utilities/focus/hooks/usePushFocusItemToFocusStack';import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';@@ -28,7 +26,6 @@ import { WidgetConfigurationType } from '~/generated-metadata/graphql';type StandaloneRichTextEditorContentProps = {widget: PageLayoutWidget;currentBody: string;- attachments: Attachment[];isEditable: boolean;containerElement: HTMLDivElement | null;};@@ -36,7 +33,6 @@ type StandaloneRichTextEditorContentProps = {export const StandaloneRichTextEditorContent = ({widget,currentBody,- attachments,isEditable,containerElement,}: StandaloneRichTextEditorContentProps) => {@@ -51,8 +47,6 @@ export const StandaloneRichTextEditorContent = ({pageLayoutEditingWidgetIdComponentState,);- const { syncAttachments } = useAttachmentSync(attachments);-const store = useStore();const shouldPersistDraft = useCallback(() => {@@ -95,21 +89,10 @@ export const StandaloneRichTextEditorContent = ({});}, 300);- const handleAttachmentSync = useDebouncedCallback(- async (newStringifiedBody: string, previousBody: string) => {- if (!shouldPersistDraft()) {- return;- }- await syncAttachments(newStringifiedBody, previousBody);- },- 500,- );-const handleEditorChange = () => {const newStringifiedBody = JSON.stringify(editor.document) ?? '';handlePersistBody(newStringifiedBody);- handleAttachmentSync(newStringifiedBody, currentBody);};const handleBlockEditorFocus = () => {diff --git a/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextWidget.tsx b/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextWidget.tsxindex 64dc723769b..51dcb9dd777 100644--- a/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextWidget.tsx+++ b/packages/twenty-front/src/modules/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextWidget.tsx@@ -1,22 +1,13 @@import { useRef } from 'react';-import { type Attachment } from '@/activities/files/types/Attachment';-import { getActivityTargetObjectFieldIdName } from '@/activities/utils/getActivityTargetObjectFieldIdName';-import { CoreObjectNameSingular } from 'twenty-shared/types';-import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInEditMode';import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { StandaloneRichTextEditorContent } from '@/page-layout/widgets/standalone-rich-text/components/StandaloneRichTextEditorContent';-import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';import { styled } from '@linaria/react';-import { isDefined } from 'twenty-shared/utils';-import {- PageLayoutType,- type StandaloneRichTextConfiguration,-} from '~/generated-metadata/graphql';+import { type StandaloneRichTextConfiguration } from '~/generated-metadata/graphql';import { themeCssVariables } from 'twenty-ui/theme-constants';const StyledContainer = styled.div<{ isPageLayoutInEditMode?: boolean }>`@@ -44,35 +35,15 @@ export const StandaloneRichTextWidget = ({pageLayoutEditingWidgetIdComponentState,);- const { targetRecordIdentifier, layoutType } = useLayoutRenderingContext();-- const isDashboard = layoutType === PageLayoutType.DASHBOARD;- const dashboardId = isDashboard ? targetRecordIdentifier?.id : undefined;- const attachmentTargetFieldIdName = getActivityTargetObjectFieldIdName({- nameSingular: CoreObjectNameSingular.Dashboard,- });-const configuration = widget.configuration as| StandaloneRichTextConfiguration| undefined;const currentBody = configuration?.body?.blocknote ?? '';- const { records: attachments } = useFindManyRecords<Attachment>({- objectNameSingular: CoreObjectNameSingular.Attachment,- filter: isDefined(dashboardId)- ? { [attachmentTargetFieldIdName]: { eq: dashboardId } }- : undefined,- skip: !isDefined(dashboardId),- });-const isThisWidgetBeingEdited = pageLayoutEditingWidgetId === widget.id;const isEditable = isPageLayoutInEditMode && isThisWidgetBeingEdited;- if (!isDefined(dashboardId)) {- return null;- }-return (<StyledContainerref={containerElementRef}@@ -85,7 +56,6 @@ export const StandaloneRichTextWidget = ({key={isEditable ? 'editing' : 'readonly'}widget={widget}currentBody={currentBody}- attachments={attachments}isEditable={isEditable}containerElement={containerElementRef.current}/>