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 <build@mattermost.com>
Этот коммит содержится в:
Pablo Andrés Vélez Vidal
2023-04-29 11:36:31 +02:00
коммит произвёл GitHub
родитель 62d52e096e
Коммит aac4f23379
4 изменённых файлов: 41 добавлений и 5 удалений

Просмотреть файл

@@ -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(
<ExternalLink
href='https://mattermost.com#desktop'
>
{'Click Me'}
</ExternalLink>,
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',
);
});
});

Просмотреть файл

@@ -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<HTMLElement>) => {