The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(front): share the scroll overlay button between AI chat and transcript (#24914)
nitinb30a8cb61bc8
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatScrollToBottomButton.tsx b/packages/twenty-front/src/modules/ai/components/AiChatScrollToBottomButton.tsxindex e58b8d8296a..a715d3b429b 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatScrollToBottomButton.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatScrollToBottomButton.tsx@@ -1,40 +1,11 @@import { agentChatIsScrolledToBottomComponentSelector } from '@/ai/states/selectors/agentChatIsScrolledToBottomComponentSelector';import { scrollAiChatToBottom } from '@/ai/utils/scrollAiChatToBottom';+import { ScrollOverlayButton } from '@/ui/utilities/scroll/components/ScrollOverlayButton';import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement';import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';-import { styled } from '@linaria/react';+import { t } from '@lingui/core/macro';import { isDefined } from 'twenty-shared/utils';import { IconArrowDown } from 'twenty-ui/icon';-import { themeCssVariables } from 'twenty-ui/theme-constants';--const StyledScrollToBottomButton = styled.button<{ isVisible: boolean }>`- align-items: center;- background: ${themeCssVariables.background.primary};- border: 1px solid ${themeCssVariables.border.color.medium};- border-radius: ${themeCssVariables.border.radius.rounded};- bottom: ${themeCssVariables.spacing[3]};- box-shadow: ${themeCssVariables.boxShadow.light};- color: ${themeCssVariables.font.color.secondary};- corner-shape: round;- cursor: pointer;- display: flex;- height: 32px;- justify-content: center;- left: 50%;- opacity: ${({ isVisible }) => (isVisible ? 1 : 0)};- pointer-events: ${({ isVisible }) => (isVisible ? 'auto' : 'none')};- position: absolute;- transform: translateX(-50%);- transition:- opacity calc(${themeCssVariables.animation.duration.normal} * 1s) ease,- background calc(${themeCssVariables.animation.duration.fast} * 1s) ease;- width: 32px;- z-index: 1;-- &:hover {- background: ${themeCssVariables.background.tertiary};- }-`;export const AiChatScrollToBottomButton = () => {const agentChatIsScrolledToBottom = useAtomComponentSelectorValue(@@ -52,11 +23,11 @@ export const AiChatScrollToBottomButton = () => {};return (- <StyledScrollToBottomButton+ <ScrollOverlayButton+ Icon={IconArrowDown}+ ariaLabel={t`Scroll to bottom`}isVisible={!agentChatIsScrolledToBottom}onClick={handleClick}- >- <IconArrowDown size={16} />- </StyledScrollToBottomButton>+ />);};diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsxindex e76816d4bb6..97a1adfa7af 100644--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryList.tsx@@ -2,6 +2,7 @@ import { CallRecordingTranscriptEntryListItem } from '@/page-layout/widgets/callimport { CallRecordingTranscriptFollowScrollEffect } from '@/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptFollowScrollEffect';import { type CallRecordingTranscriptPlayback } from '@/page-layout/widgets/call-recording-transcript/types/CallRecordingTranscriptPlayback';import { getCallRecordingTranscriptEntryPlaybackPhase } from '@/page-layout/widgets/call-recording-transcript/utils/getCallRecordingTranscriptEntryPlaybackPhase';+import { ScrollOverlayButton } from '@/ui/utilities/scroll/components/ScrollOverlayButton';import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';import {@@ -13,7 +14,6 @@ import {} from 'react';import { type CallRecordingParsedTranscriptEntry } from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';-import { Button } from 'twenty-ui/input';import { themeCssVariables } from 'twenty-ui/theme-constants';const StyledTranscriptContainer = styled.div`@@ -40,13 +40,6 @@ const StyledEntryList = styled.ul<{ hasPlaybackControls: boolean }>`: '0'};`;-const StyledResumeFollowButton = styled.div`- bottom: ${themeCssVariables.spacing[3]};- left: 50%;- position: absolute;- transform: translateX(-50%);-`;-const MANUAL_SCROLL_KEYS = ['ArrowDown','ArrowUp',@@ -141,16 +134,13 @@ export const CallRecordingTranscriptEntryList = ({})}</StyledEntryList></StyledTranscriptScrollContainer>- {hasPlayback && !isFollowingPlayback && (- <StyledResumeFollowButton>- <Button- ariaLabel={t`Jump to current`}- size="small"- title={t`Jump to current`}- variant="secondary"- onClick={resumeFollowingPlayback}- />- </StyledResumeFollowButton>+ {hasPlayback && (+ <ScrollOverlayButton+ ariaLabel={t`Jump to current`}+ isVisible={!isFollowingPlayback}+ title={t`Jump to current`}+ onClick={resumeFollowingPlayback}+ />)}</StyledTranscriptContainer>);diff --git a/packages/twenty-front/src/modules/ui/utilities/scroll/components/ScrollOverlayButton.tsx b/packages/twenty-front/src/modules/ui/utilities/scroll/components/ScrollOverlayButton.tsxnew file mode 100644index 00000000000..6f1372c56f4--- /dev/null+++ b/packages/twenty-front/src/modules/ui/utilities/scroll/components/ScrollOverlayButton.tsx@@ -0,0 +1,75 @@+import { styled } from '@linaria/react';+import { isDefined } from 'twenty-shared/utils';+import { type IconComponent } from 'twenty-ui/icon';+import { themeCssVariables, useTheme } from 'twenty-ui/theme-constants';++const StyledScrollOverlayButton = styled.button<{+ hasTitle: boolean;+ isVisible: boolean;+}>`+ align-items: center;+ background: ${themeCssVariables.background.primary};+ border: 1px solid ${themeCssVariables.border.color.medium};+ border-radius: ${themeCssVariables.border.radius.pill};+ bottom: ${themeCssVariables.spacing[3]};+ box-shadow: ${themeCssVariables.boxShadow.light};+ color: ${themeCssVariables.font.color.secondary};+ corner-shape: round;+ cursor: pointer;+ display: flex;+ font-family: ${themeCssVariables.font.family};+ font-size: ${themeCssVariables.font.size.md};+ font-weight: ${themeCssVariables.font.weight.regular};+ gap: ${themeCssVariables.spacing[1]};+ height: 32px;+ justify-content: center;+ left: 50%;+ opacity: ${({ isVisible }) => (isVisible ? 1 : 0)};+ padding: ${({ hasTitle }) =>+ hasTitle ? `0 ${themeCssVariables.spacing[3]}` : '0'};+ pointer-events: ${({ isVisible }) => (isVisible ? 'auto' : 'none')};+ position: absolute;+ transform: translateX(-50%);+ transition:+ opacity calc(${themeCssVariables.animation.duration.normal} * 1s) ease,+ background calc(${themeCssVariables.animation.duration.fast} * 1s) ease;+ width: ${({ hasTitle }) => (hasTitle ? 'auto' : '32px')};+ z-index: 1;++ &:hover {+ background: ${themeCssVariables.background.tertiary};+ }+`;++type ScrollOverlayButtonProps = {+ ariaLabel: string;+ isVisible: boolean;+ onClick: () => void;+ Icon?: IconComponent;+ title?: string;+};++export const ScrollOverlayButton = ({+ ariaLabel,+ isVisible,+ onClick,+ Icon,+ title,+}: ScrollOverlayButtonProps) => {+ const theme = useTheme();++ return (+ <StyledScrollOverlayButton+ aria-hidden={!isVisible}+ aria-label={ariaLabel}+ hasTitle={isDefined(title)}+ isVisible={isVisible}+ tabIndex={isVisible ? 0 : -1}+ type="button"+ onClick={onClick}+ >+ {isDefined(Icon) && <Icon size={theme.icon.size.md} />}+ {title}+ </StyledScrollOverlayButton>+ );+};diff --git a/packages/twenty-front/src/modules/ui/utilities/scroll/components/__stories__/ScrollOverlayButton.stories.tsx b/packages/twenty-front/src/modules/ui/utilities/scroll/components/__stories__/ScrollOverlayButton.stories.tsxnew file mode 100644index 00000000000..310d528f640--- /dev/null+++ b/packages/twenty-front/src/modules/ui/utilities/scroll/components/__stories__/ScrollOverlayButton.stories.tsx@@ -0,0 +1,85 @@+import { ScrollOverlayButton } from '@/ui/utilities/scroll/components/ScrollOverlayButton';+import { styled } from '@linaria/react';+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, within } from 'storybook/test';+import { IconArrowDown } from 'twenty-ui/icon';+import { ComponentDecorator } from 'twenty-ui/testing';+import { themeCssVariables } from 'twenty-ui/theme-constants';++const StyledScrollAreaMock = styled.div`+ background: ${themeCssVariables.background.secondary};+ height: 120px;+ position: relative;+ width: 320px;+`;++const meta: Meta<typeof ScrollOverlayButton> = {+ title: 'UI/Utilities/Scroll/ScrollOverlayButton',+ component: ScrollOverlayButton,+ decorators: [+ (Story) => (+ <StyledScrollAreaMock>+ <Story />+ </StyledScrollAreaMock>+ ),+ ComponentDecorator,+ ],+ args: {+ isVisible: true,+ onClick: fn(),+ },+};++export default meta;++type Story = StoryObj<typeof ScrollOverlayButton>;++export const IconOnly: Story = {+ args: {+ Icon: IconArrowDown,+ ariaLabel: 'Scroll to bottom',+ },+ play: async ({ args, canvasElement }) => {+ const canvas = within(canvasElement);++ await userEvent.click(+ await canvas.findByRole('button', { name: 'Scroll to bottom' }),+ );++ expect(args.onClick).toHaveBeenCalled();+ },+};++export const WithTitle: Story = {+ args: {+ ariaLabel: 'Jump to current',+ title: 'Jump to current',+ },+ play: async ({ args, canvasElement }) => {+ const canvas = within(canvasElement);+ const button = await canvas.findByRole('button', {+ name: 'Jump to current',+ });++ expect(button).toBeVisible();++ await userEvent.click(button);++ expect(args.onClick).toHaveBeenCalled();+ },+};++export const Hidden: Story = {+ args: {+ ariaLabel: 'Jump to current',+ isVisible: false,+ title: 'Jump to current',+ },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(+ canvas.queryByRole('button', { name: 'Jump to current' }),+ ).not.toBeInTheDocument();+ },+};