From aac4f2337933d42b88e81f778a55d0fe606edbb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20V=C3=A9lez=20Vidal?= Date: Sat, 29 Apr 2023 11:36:31 +0200 Subject: [PATCH] MM-52175 - fix button formatting and add anchor to the end (#23048) * MM-52175 - fix button formatting and add anchor to the end * make anchor optional * use built in URL function to extract the anchor * add anchor to tasklitst download apps --------- Co-authored-by: Mattermost Build --- .../external_link/external_link.test.tsx | 29 +++++++++++++++++++ .../src/components/external_link/index.tsx | 6 +++- .../onboarding_tasklist_completed.tsx | 9 ++++-- .../onboarding_tasks_manager.tsx | 2 +- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/webapp/channels/src/components/external_link/external_link.test.tsx b/webapp/channels/src/components/external_link/external_link.test.tsx index 756cb743f8..67e237286d 100644 --- a/webapp/channels/src/components/external_link/external_link.test.tsx +++ b/webapp/channels/src/components/external_link/external_link.test.tsx @@ -161,4 +161,33 @@ describe('components/external_link', () => { expect.stringMatching('test'), ); }); + + it('renders href correctly when url contains anchor by setting anchor at the end', () => { + const state = { + ...initialState, + entities: { + ...initialState.entities, + general: { + ...initialState?.entities?.general, + config: { + DiagnosticsEnabled: 'true', + }, + }, + }, + }; + const store: GlobalState = JSON.parse(JSON.stringify(state)); + renderWithIntlAndStore( + + {'Click Me'} + , + store, + ); + + expect(screen.queryByText('Click Me')).toHaveAttribute( + 'href', + 'https://mattermost.com?utm_source=mattermost&utm_medium=in-product-cloud&utm_content=&uid=currentUserId&sid=#desktop', + ); + }); }); diff --git a/webapp/channels/src/components/external_link/index.tsx b/webapp/channels/src/components/external_link/index.tsx index d72779e212..76e34aff6f 100644 --- a/webapp/channels/src/components/external_link/index.tsx +++ b/webapp/channels/src/components/external_link/index.tsx @@ -52,7 +52,11 @@ export default function ExternalLink(props: Props) { // If the href already has query params, remove them before adding them back with the addition of the new ones href = href?.split('?')[0]; } - href = `${href}?${queryString}`; + const anchor = new URL(href).hash; + if (anchor) { + href = href.replace(anchor, ''); + } + href = `${href}?${queryString}${anchor ?? ''}`; } const handleClick = (e: React.MouseEvent) => { diff --git a/webapp/channels/src/components/onboarding_tasklist/onboarding_tasklist_completed.tsx b/webapp/channels/src/components/onboarding_tasklist/onboarding_tasklist_completed.tsx index f584541422..790602fe1a 100644 --- a/webapp/channels/src/components/onboarding_tasklist/onboarding_tasklist_completed.tsx +++ b/webapp/channels/src/components/onboarding_tasklist/onboarding_tasklist_completed.tsx @@ -49,7 +49,7 @@ const CompletedWrapper = styled.div` &.fade-exit-done { transform: scale(1); } - .start-trial-btn { + .start-trial-btn, .got-it-button { padding: 13px 20px; background: var(--button-bg); border-radius: 4px; @@ -223,7 +223,10 @@ const Completed = (props: Props): JSX.Element => { ) : ( -