The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Add copy button on hover to Emails/Phones/Links in the record side panel (#25940)
Charles Bochetaca4b9ddbd91
diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/useGetSecondaryRecordTableCellButton.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.tssimilarity index 92%rename from packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/useGetSecondaryRecordTableCellButton.tsrename to packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.tsindex 3e924791657..c906f811a9d 100644--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/hooks/useGetSecondaryRecordTableCellButton.ts+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/hooks/useGetSecondaryFieldButton.ts@@ -16,7 +16,7 @@ import { ensureAbsoluteUrl, isDefined } from 'twenty-shared/utils';import { IconArrowUpRight, IconCopy, IconMail } from 'twenty-ui/icon';import { useCopyToClipboard } from '~/hooks/useCopyToClipboard';-export const useGetSecondaryRecordTableCellButton = () => {+export const useGetSecondaryFieldButton = () => {const { fieldDefinition, recordId } = useContext(FieldContext);const { copyToClipboard } = useCopyToClipboard();@@ -107,10 +107,17 @@ export const useGetSecondaryRecordTableCellButton = () => {[FieldMetadataSettingsOnClickAction.OPEN_IN_APP]: IconMail,};+ const ariaLabelByAction = {+ [FieldMetadataSettingsOnClickAction.OPEN_LINK]: t`Open link`,+ [FieldMetadataSettingsOnClickAction.COPY]: t`Copy`,+ [FieldMetadataSettingsOnClickAction.OPEN_IN_APP]: t`Open in app`,+ };+return [{onClick: onClickByAction[secondaryActionOnClick],Icon: iconByAction[secondaryActionOnClick],+ ariaLabel: ariaLabelByAction[secondaryActionOnClick],},];};diff --git a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellDisplayMode.tsx b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellDisplayMode.tsxindex 28fef1762b8..c895ca04d16 100644--- a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellDisplayMode.tsx+++ b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellDisplayMode.tsx@@ -1,6 +1,7 @@import { styled } from '@linaria/react';import { FieldContext } from '@/object-record/record-field/ui/contexts/FieldContext';+import { useGetSecondaryFieldButton } from '@/object-record/record-field/ui/hooks/useGetSecondaryFieldButton';import { useIsFieldEmpty } from '@/object-record/record-field/ui/hooks/useIsFieldEmpty';import { useIsFieldInputOnly } from '@/object-record/record-field/ui/hooks/useIsFieldInputOnly';import {@@ -84,6 +85,11 @@ export const RecordInlineCellDisplayMode = ({!isFieldEmpty &&!editModeContentOnly;+ const secondaryButtons = useGetSecondaryFieldButton();++ const showSecondaryButtons =+ isHovered && !isFieldEmpty && !editModeContentOnly && !isForbidden;+const isFieldInputOnly = useIsFieldInputOnly();const emptyPlaceHolder = label ?? t`Empty`;@@ -107,6 +113,15 @@ export const RecordInlineCellDisplayMode = ({) : null}</StyledRecordInlineCellNormalModeInnerContainer></StyledRecordInlineCellNormalModeOuterContainer>+ {showSecondaryButtons &&+ secondaryButtons.map((button) => (+ <RecordInlineCellButton+ key={button.ariaLabel}+ Icon={button.Icon}+ onClick={button.onClick}+ ariaLabel={button.ariaLabel}+ />+ ))}{showEditButton && (<RecordInlineCellButton Icon={buttonIcon} onClick={onClick} />)}diff --git a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellEditButton.tsx b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellEditButton.tsxindex 2909745ff6e..4467de0297f 100644--- a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellEditButton.tsx+++ b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/RecordInlineCellEditButton.tsx@@ -11,9 +11,11 @@ const StyledInlineCellButtonContainer = styled.div`export const RecordInlineCellButton = ({Icon,onClick,+ ariaLabel,}: {Icon: IconComponent;onClick?: () => void;+ ariaLabel?: string;}) => {return (<AnimatedContainer>@@ -21,6 +23,7 @@ export const RecordInlineCellButton = ({<FloatingIconButtonsize="small"Icon={Icon}+ ariaLabel={ariaLabel}data-testid="inline-cell-edit-mode-container"/></StyledInlineCellButtonContainer>diff --git a/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsx b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsxnew file mode 100644index 00000000000..c99fa6d87fa--- /dev/null+++ b/packages/twenty-front/src/modules/object-record/record-inline-cell/components/__stories__/RecordInlineCellDisplayMode.stories.tsx@@ -0,0 +1,142 @@+import {+ type Decorator,+ type Meta,+ type StoryObj,+} from '@storybook/react-vite';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';++import { FieldDisplay } from '@/object-record/record-field/ui/components/FieldDisplay';+import {+ RecordInlineCellContext,+ type RecordInlineCellContextProps,+} from '@/object-record/record-inline-cell/components/RecordInlineCellContext';+import { RecordInlineCellDisplayMode } from '@/object-record/record-inline-cell/components/RecordInlineCellDisplayMode';+import { IconPencil } from 'twenty-ui/icon';+import { ComponentDecorator } from 'twenty-ui/testing';+import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';+import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';+import { getFieldDecorator } from '~/testing/decorators/getFieldDecorator';++const getInlineCellContextDecorator =+ (context: Partial<RecordInlineCellContextProps>): Decorator =>+ (Story) => (+ <RecordInlineCellContext.Provider+ value={{ buttonIcon: IconPencil, ...context }}+ >+ <Story />+ </RecordInlineCellContext.Provider>+ );++const spyOnClipboard = () => {+ const writeText = fn(async () => {});+ Object.defineProperty(window.navigator, 'clipboard', {+ value: { writeText },+ configurable: true,+ });+ return writeText;+};++const meta: Meta<typeof RecordInlineCellDisplayMode> = {+ title: 'Modules/ObjectRecord/RecordInlineCell/RecordInlineCellDisplayMode',+ component: RecordInlineCellDisplayMode,+ decorators: [+ MemoryRouterDecorator,+ getFieldDecorator('person', 'emails', {+ primaryEmail: '[email protected]',+ additionalEmails: [],+ }),+ getInlineCellContextDecorator({}),+ ComponentDecorator,+ SnackBarDecorator,+ ],+ args: {+ isHovered: true,+ children: <FieldDisplay />,+ },+};++export default meta;++type Story = StoryObj<typeof RecordInlineCellDisplayMode>;++export const HoveredCopiesEmail: Story = {+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const writeText = spyOnClipboard();++ const copyButton = await canvas.findByLabelText('Copy');+ expect(copyButton).toBeVisible();+ expect(canvas.getAllByRole('button')).toHaveLength(2);++ await userEvent.click(copyButton);++ await waitFor(() =>+ expect(writeText).toHaveBeenCalledWith('[email protected]'),+ );++ expect(await canvas.findByText('[email protected]')).toBeVisible();+ expect(canvas.queryByRole('textbox')).toBeNull();+ },+};++export const NotHoveredHidesButtons: Story = {+ args: {+ isHovered: false,+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(canvas.queryByLabelText('Copy')).toBeNull();+ },+};++export const ReadOnlyStillShowsCopy: Story = {+ decorators: [getInlineCellContextDecorator({ readonly: true })],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(await canvas.findByLabelText('Copy')).toBeVisible();+ expect(canvas.getAllByRole('button')).toHaveLength(1);+ },+};++export const CopiesPhoneNumber: Story = {+ decorators: [+ getFieldDecorator('person', 'phones', {+ primaryPhoneNumber: '5551234',+ primaryPhoneCallingCode: '+1',+ primaryPhoneCountryCode: 'US',+ additionalPhones: [],+ }),+ ],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const writeText = spyOnClipboard();++ await userEvent.click(await canvas.findByLabelText('Copy'));++ await waitFor(() => expect(writeText).toHaveBeenCalledWith('+15551234'));+ },+};++export const CopiesLinkUrl: Story = {+ decorators: [+ getFieldDecorator('person', 'linkedinLink', {+ primaryLinkUrl: 'https://www.linkedin.com/in/test',+ primaryLinkLabel: 'Test',+ secondaryLinks: [],+ }),+ ],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const writeText = spyOnClipboard();++ await userEvent.click(await canvas.findByLabelText('Copy'));++ await waitFor(() =>+ expect(writeText).toHaveBeenCalledWith(+ 'https://www.linkedin.com/in/test',+ ),+ );+ },+};diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellButtons.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellButtons.tsxindex fd9c35960a2..f88a77d64cd 100644--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellButtons.tsx+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellButtons.tsx@@ -24,6 +24,7 @@ const StyledButtonContainer = styled.div`type RecordTableCellButtonsProps = {onClick?: () => void;Icon: IconComponent;+ ariaLabel?: string;}[];export const RecordTableCellButtons = ({diff --git a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellEditButton.tsx b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellEditButton.tsxindex 60330a19ad8..0c8559ee847 100644--- a/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellEditButton.tsx+++ b/packages/twenty-front/src/modules/object-record/record-table/record-table-cell/components/RecordTableCellEditButton.tsx@@ -3,7 +3,7 @@ import { useIsFieldInputOnly } from '@/object-record/record-field/ui/hooks/useIsimport { RecordTableCellContext } from '@/object-record/record-table/contexts/RecordTableCellContext';import { RecordTableCellButtons } from '@/object-record/record-table/record-table-cell/components/RecordTableCellButtons';-import { useGetSecondaryRecordTableCellButton } from '@/object-record/record-table/record-table-cell/hooks/useGetSecondaryRecordTableCellButton';+import { useGetSecondaryFieldButton } from '@/object-record/record-field/ui/hooks/useGetSecondaryFieldButton';import { useOpenRecordTableCellFromCell } from '@/object-record/record-table/record-table-cell/hooks/useOpenRecordTableCellFromCell';import { useContext } from 'react';import { isDefined } from 'twenty-shared/utils';@@ -16,7 +16,7 @@ export const RecordTableCellEditButton = () => {const isFirstColumn = cellPosition.column === 0;const customButtonIcon = useGetButtonIcon();- const secondaryButton = useGetSecondaryRecordTableCellButton();+ const secondaryButton = useGetSecondaryFieldButton();const mainButtonIcon = isFirstColumn? IconArrowUpRight