The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
[rich-text] Compact record creation rich-text input, keeping BlockNote (#26842)
Thomas Trompette56eb9006b045
diff --git a/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx b/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsxindex 218f89ca949..04939f332c6 100644--- a/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx+++ b/packages/twenty-front/src/modules/blocknote-editor/components/BlockEditor.tsx@@ -26,6 +26,7 @@ interface BlockEditorProps {onPaste?: (event: ClipboardEvent) => void;onChange?: () => void;readonly?: boolean;+ isCompact?: boolean;}// oxlint-disable-next-line twenty/no-hardcoded-colors@@ -40,6 +41,16 @@ const StyledEditor = styled.div`font-size: 13px;min-height: 400px;}+ &[data-compact='true'] {+ background-color: ${themeCssVariables.background.transparent.lighter};+ border: 1px solid ${themeCssVariables.border.color.medium};+ border-radius: ${themeCssVariables.border.radius.md};+ box-sizing: border-box;+ }+ &[data-compact='true'] .editor {+ min-height: 120px;+ padding: ${themeCssVariables.spacing[1]} ${themeCssVariables.spacing[2]};+ }& .editor [class^='_inlineContent']:before {color: ${themeCssVariables.font.color.tertiary};font-style: normal !important;@@ -164,6 +175,7 @@ export const BlockEditor = ({onChange,onPaste,readonly,+ isCompact,}: BlockEditorProps) => {const colorScheme = useThemeColorScheme();const { t } = useLingui();@@ -207,7 +219,7 @@ export const BlockEditor = ({};return (- <StyledEditor>+ <StyledEditor data-compact={isCompact}><BlockNoteViewonFocus={handleFocus}onBlur={handleBlur}diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormRecordRichTextFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormRecordRichTextFieldInput.tsxindex 1f2c6776c30..be8e717d4ea 100644--- a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormRecordRichTextFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/FormRecordRichTextFieldInput.tsx@@ -1,9 +1,14 @@import { useCreateBlockNote } from '@blocknote/react';+import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { useEffect, useId, useState } from 'react';+import { flushSync } from 'react-dom';import { isNonEmptyArray } from 'twenty-shared/utils';-import { useToast } from 'twenty-ui/components';+import { LightIconButton, useToast } from 'twenty-ui/components';+import { IconMaximize } from 'twenty-ui/icon';import { Field } from 'twenty-ui/primitives/input';+import { themeCssVariables } from 'twenty-ui/theme';+import { useIsMobile } from 'twenty-ui/utilities';import { BLOCK_SCHEMA } from '@/blocknote-editor/blocks/Schema';import { BlockEditor } from '@/blocknote-editor/components/BlockEditor';@@ -13,6 +18,7 @@ import { filterBlocksSupportedBySchema } from '@/blocknote-editor/utils/filterBlimport { parseInitialBlocknote } from '@/blocknote-editor/utils/parseInitialBlocknote';import { type FieldRichTextValue } from '@/object-record/record-field/ui/types/FieldMetadata';import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';+import { useFullScreenModal } from '@/ui/layout/fullscreen/hooks/useFullScreenModal';import { usePushFocusItemToFocusStack } from '@/ui/utilities/focus/hooks/usePushFocusItemToFocusStack';import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';@@ -20,6 +26,28 @@ import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentTypimport '@blocknote/mantine/style.css';import '@blocknote/react/style.css';+const StyledEditorContainer = styled.div`+ position: relative;+`;++const StyledExpandButtonContainer = styled.div`+ margin-top: ${themeCssVariables.spacing[1]};+ position: absolute;+ right: ${themeCssVariables.spacing[1]};+ top: ${themeCssVariables.spacing[0]};+ z-index: 1;+`;++const StyledFullScreenEditorContainer = styled.div`+ background-color: ${themeCssVariables.background.secondary};+ border: 1px solid ${themeCssVariables.border.color.medium};+ border-radius: ${themeCssVariables.border.radius.md};+ flex: 1;+ min-height: 0;+ overflow-y: auto;+ padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[8]};+`;+type FormRecordRichTextFieldInputProps = {label?: string;defaultValue: FieldRichTextValue | undefined;@@ -45,6 +73,9 @@ export const FormRecordRichTextFieldInput = ({const { enqueueToast } = useToast();+ const isMobile = useIsMobile();+ const [isFullScreen, setIsFullScreen] = useState(false);+const [{ initialBlocks, hasUnreadableStoredValue }] = useState(() => {const parsedBlocks = parseInitialBlocknote(defaultValue?.blocknote ?? defaultValue?.markdown,@@ -120,16 +151,61 @@ export const FormRecordRichTextFieldInput = ({}}, [hasUnreadableStoredValue, enqueueToast, t]);+ const handleFullScreenChange = (isFullScreenOpen: boolean) => {+ flushSync(() => {+ setIsFullScreen(isFullScreenOpen);+ });+ editor.focus();+ };++ const { renderFullScreenModal } = useFullScreenModal({+ links: [{ children: t`Text Editor` }],+ onClose: () => handleFullScreenChange(false),+ });++ const isReadonly = readonly || hasUnreadableStoredValue;+return (- <FormFieldInputContainer>- {label ? <Field.Label>{label}</Field.Label> : null}- <BlockEditor- editor={editor}- onChange={handleChange}- onFocus={handleFocus}- onBlur={handleBlur}- readonly={readonly || hasUnreadableStoredValue}- />- </FormFieldInputContainer>+ <>+ <FormFieldInputContainer>+ {label ? <Field.Label>{label}</Field.Label> : null}+ {!isFullScreen && (+ <StyledEditorContainer>+ <BlockEditor+ editor={editor}+ onChange={handleChange}+ onFocus={handleFocus}+ onBlur={handleBlur}+ readonly={isReadonly}+ isCompact+ />+ {!isReadonly && !isMobile && (+ <StyledExpandButtonContainer>+ <LightIconButton+ size="sm"+ onClick={() => handleFullScreenChange(true)}+ emphasis="subtle"+ aria-label={t`Expand to full screen`}+ >+ <IconMaximize />+ </LightIconButton>+ </StyledExpandButtonContainer>+ )}+ </StyledEditorContainer>+ )}+ </FormFieldInputContainer>+ {renderFullScreenModal(+ <StyledFullScreenEditorContainer>+ <BlockEditor+ editor={editor}+ onChange={handleChange}+ onFocus={handleFocus}+ onBlur={handleBlur}+ readonly={isReadonly}+ />+ </StyledFullScreenEditorContainer>,+ isFullScreen,+ )}+ </>);};diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/__stories__/FormRecordRichTextFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/__stories__/FormRecordRichTextFieldInput.stories.tsxindex be6094e0306..1fc74f37fa7 100644--- a/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/__stories__/FormRecordRichTextFieldInput.stories.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/form-types/components/__stories__/FormRecordRichTextFieldInput.stories.tsx@@ -2,6 +2,7 @@ import { FormRecordRichTextFieldInput } from '@/object-record/record-field/ui/foimport { type Meta, type StoryObj } from '@storybook/react-vite';import { expect, fn, userEvent, waitFor, within } from 'storybook/test';import { ComponentDecorator } from 'twenty-ui/testing';+import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator';import { ToastDecorator } from '~/testing/decorators/ToastDecorator';import { graphqlMocks } from '~/testing/graphqlMocks';@@ -36,6 +37,7 @@ const meta: Meta<typeof FormRecordRichTextFieldInput> = {decorators: [ObjectMetadataItemsDecorator,ToastDecorator,+ MemoryRouterDecorator,ComponentDecorator,],parameters: {@@ -111,6 +113,52 @@ export const WritesBlockNoteBlocks: Story = {},};+export const KeepsContentAcrossFullScreen: Story = {+ args: {+ onChange: fn(),+ },+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const page = within(canvasElement.ownerDocument.body);++ const editor = await waitFor(() => {+ const editorElement = canvasElement.querySelector('.ProseMirror');++ expect(editorElement).toBeVisible();++ return editorElement;+ });++ if (!editor) {+ throw new Error('Editor element not found');+ }++ await userEvent.click(editor);+ await userEvent.keyboard('Hello');++ await userEvent.click(+ await canvas.findByRole('button', { name: 'Expand to full screen' }),+ );++ await page.findByText('Text Editor');+ expect(await page.findByText('Hello')).toBeVisible();++ await userEvent.keyboard(' world');++ await userEvent.click(+ await page.findByRole('button', { name: 'Close page' }),+ );++ expect(await canvas.findByText('Hello world')).toBeVisible();+ expect(page.queryByText('Text Editor')).not.toBeInTheDocument();+ expect(args.onChange).toHaveBeenLastCalledWith(+ expect.objectContaining({+ blocknote: expect.stringContaining('Hello world'),+ }),+ );+ },+};+export const Disabled: Story = {args: {defaultValue: { blocknote: BLOCKNOTE_PARAGRAPH, markdown: null },