The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(ai): click the chat title in the page header to rename the thread (#26146)
Félix Malfaitdfe04d92816b
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx b/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsxindex 542976dd173..27f861b2cf1 100644--- a/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx+++ b/packages/twenty-front/src/modules/ai/components/AiChatPageThreadHeader.tsx@@ -25,10 +25,26 @@ const StyledTitle = styled.div`font-weight: ${themeCssVariables.font.weight.medium};max-width: 100%;min-width: 0;- padding: 0 ${themeCssVariables.spacing[1]};width: fit-content;`;+const StyledTitleDisplay = styled.div`+ align-items: center;+ border-radius: ${themeCssVariables.border.radius.md};+ box-sizing: border-box;+ cursor: pointer;+ display: flex;+ height: 24px;+ overflow: hidden;+ padding: 0 5px;++ &:hover,+ &:focus-visible {+ background: ${themeCssVariables.background.transparent.light};+ outline: none;+ }+`;+const StyledActions = styled.div`align-items: center;display: flex;@@ -97,7 +113,20 @@ export const AiChatPageThreadHeader = ({autoFocus/>) : (- <OverflowingTextWithTooltip text={displayTitle} />+ <StyledTitleDisplay+ role="button"+ tabIndex={0}+ aria-label={t`Rename chat`}+ onClick={startRename}+ onKeyDown={(event) => {+ if (event.key === Key.Enter || event.key === ' ') {+ event.preventDefault();+ startRename();+ }+ }}+ >+ <OverflowingTextWithTooltip text={displayTitle} />+ </StyledTitleDisplay>)}</StyledTitle><StyledActions>diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsxindex a2d942f2769..a5ca7b847eb 100644--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx@@ -251,6 +251,38 @@ describe('AiChatPageHeader', () => {expect(unarchiveChatThread).toHaveBeenCalledWith(THREAD.id);});+ it('opens the rename editor when clicking the title', async () => {+ const user = userEvent.setup();+ render(<AiChatPageHeader />, { wrapper: Wrapper });++ await user.click(screen.getByRole('button', { name: 'Rename chat' }));+ const input = screen.getByRole('textbox');+ expect(input).toHaveValue('Best leads');+ expect(input).toHaveFocus();++ await user.clear(input);+ await user.type(input, 'Qualified leads{Enter}');+ expect(renameChatThread).toHaveBeenCalledTimes(1);+ expect(renameChatThread).toHaveBeenCalledWith(THREAD.id, 'Qualified leads');+ expect(screen.queryByRole('textbox')).toBeNull();+ });++ it.each(['{Enter}', ' '])(+ 'opens the rename editor from the keyboard with %s',+ async (key) => {+ const user = userEvent.setup();+ render(<AiChatPageHeader />, { wrapper: Wrapper });++ await user.tab();+ expect(screen.getByRole('button', { name: 'Rename chat' })).toHaveFocus();+ await user.keyboard(key);++ expect(screen.getByRole('textbox')).toHaveValue('Best leads');+ expect(screen.getByRole('textbox')).toHaveFocus();+ expect(renameChatThread).not.toHaveBeenCalled();+ },+ );+it('renames the current chat and discards the rename editor when switching threads', async () => {const user = userEvent.setup();render(<AiChatPageHeader />, { wrapper: Wrapper });