From ce34a7e6d7906b50f4408c7ba271690c60c19dcd Mon Sep 17 00:00:00 2001 From: Ruslan Bayandinov <45530296+wazsone@users.noreply.github.com> Date: Mon, 5 Jun 2023 12:12:51 +0700 Subject: [PATCH] [UBER-169] Allow to click and open links in contact information (#3337) Signed-off-by: Ruslan Bayandinov --- packages/ui/src/utils.ts | 16 ++++++++++++++++ plugins/contact-resources/src/index.ts | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/utils.ts b/packages/ui/src/utils.ts index 285bc9a4b9..a65be75b66 100644 --- a/packages/ui/src/utils.ts +++ b/packages/ui/src/utils.ts @@ -173,6 +173,22 @@ export function replaceURLs (text: string): string { }) } +/** + * Parse first URL from the given text or html + * + * @example + * replaceURLs("github.com") + * returns: "http://github.com" + * + * @export + * @param {string} text + * @returns {string} string with parsed URL + */ +export function parseURL (text: string): string { + const matches = autolinker.parse(text, { urls: true }) + return matches.length > 0 ? matches[0].getAnchorHref() : '' +} + /** * @public */ diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index 96c79788bb..4f158901e2 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -19,7 +19,7 @@ import { Class, Client, DocumentQuery, Ref, RelatedDocument, WithLookup } from ' import login from '@hcengineering/login' import { IntlString, Resources, getResource } from '@hcengineering/platform' import { MessageBox, ObjectSearchResult, getClient, getFileUrl } from '@hcengineering/presentation' -import { AnyComponent, AnySvelteComponent, TooltipAlignment, showPopup } from '@hcengineering/ui' +import { AnyComponent, AnySvelteComponent, TooltipAlignment, parseURL, showPopup } from '@hcengineering/ui' import AccountArrayEditor from './components/AccountArrayEditor.svelte' import AccountBox from './components/AccountBox.svelte' import AssigneeBox from './components/AssigneeBox.svelte' @@ -240,8 +240,9 @@ async function kickEmployee (doc: Employee): Promise { } } async function openChannelURL (doc: Channel): Promise { - if (doc.value.startsWith('http://') || doc.value.startsWith('https://')) { - window.open(doc.value) + const url = parseURL(doc.value) + if (url.startsWith('http://') || url.startsWith('https://')) { + window.open(url) } }