diff --git a/plugins/contact-resources/src/components/ChannelEditor.svelte b/plugins/contact-resources/src/components/ChannelEditor.svelte index 9899267a52..fa8f4e83e2 100644 --- a/plugins/contact-resources/src/components/ChannelEditor.svelte +++ b/plugins/contact-resources/src/components/ChannelEditor.svelte @@ -151,7 +151,13 @@ class="select-text cover-channel" class:show class:copied={label === plugin.string.Copied} - data-tooltip={lTraslate}>{value}</span + class:cursor-pointer={openable} + data-tooltip={lTraslate} + on:click={() => { + if (openable) { + dispatch('update', 'open') + } + }}>{value}</span > <Button focusIndex={3} diff --git a/plugins/contact-resources/src/components/ChannelsDropdown.svelte b/plugins/contact-resources/src/components/ChannelsDropdown.svelte index cb74385260..350e7aa73f 100644 --- a/plugins/contact-resources/src/components/ChannelsDropdown.svelte +++ b/plugins/contact-resources/src/components/ChannelsDropdown.svelte @@ -33,6 +33,7 @@ showPopup } from '@hcengineering/ui' import { ViewAction } from '@hcengineering/view' + import { invokeAction } from '@hcengineering/view-resources' import { createEventDispatcher, tick } from 'svelte' import { getChannelProviders } from '../utils' import ChannelEditor from './ChannelEditor.svelte' @@ -58,6 +59,7 @@ presenter?: AnyComponent action?: ViewAction placeholder: IntlString + channel: AttachedData<Channel> | Channel provider: Ref<ChannelProvider> integration: boolean notification: boolean @@ -67,7 +69,7 @@ item: AttachedData<Channel>, map: Map<Ref<ChannelProvider>, ChannelProvider>, lastViews: Map<Ref<Doc>, Timestamp> - ): any | undefined { + ): Item | undefined { const provider = map.get(item.provider) if (provider) { const notification = (item as Channel)._id !== undefined ? isNew(item as Channel, lastViews) : false @@ -79,6 +81,7 @@ action: provider.action, placeholder: provider.placeholder, provider: provider._id, + channel: item, notification, integration: provider.integrationType !== undefined ? integrations.has(provider.integrationType) : false } @@ -98,7 +101,7 @@ displayItems = [] return } - const result = [] + const result: Item[] = [] const map = await getChannelProviders() if (Array.isArray(value)) { for (const item of value) { @@ -186,7 +189,7 @@ value: item.value, placeholder: item.placeholder, editable, - openable: item.presenter ?? false + openable: item.presenter ?? item.action ?? false }, el, (result) => { @@ -201,7 +204,14 @@ } if (result === undefined && item.value === '') displayItems = dropItem(n) opened = undefined - if (result === 'open') dispatch('open', item) + if (result === 'open') { + if (item.action) { + const doc = item.channel as Channel + invokeAction(doc, result, item.action) + } else { + dispatch('open', item) + } + } }, (result) => { if (result != null) { @@ -216,6 +226,21 @@ ) } } + + const updateTooltip = (result: CustomEvent, item: Item, i: number): void => { + if (result.detail === 'open') { + closeTooltip() + if (item.action) { + const doc = item.channel as Channel + invokeAction(doc, result, item.action) + } else { + dispatch('open', item) + } + } else if (result.detail === 'edit') { + closeTooltip() + editChannel(btns[i], i, item) + } + } </script> <div @@ -249,46 +274,26 @@ value: item.value, placeholder: item.placeholder, editable: editable !== undefined ? false : undefined, - openable: item.presenter ?? false + openable: item.presenter ?? item.action ?? false }, onUpdate: (result) => { - if (result.detail === 'open') { - closeTooltip() - dispatch('open', item) - } else if (result.detail === 'edit') { - closeTooltip() - editChannel(btns[i], i, item) - } + updateTooltip(result, item, i) } }} /> {/each} {#if actions.length > 0 && editable} - {#if displayItems.length === 0} - <Button - focusIndex={focusIndex === -1 ? focusIndex : focusIndex + 2 + displayItems.length} - id={presentation.string.AddSocialLinks} - bind:input={addBtn} - icon={contact.icon.SocialEdit} - label={presentation.string.AddSocialLinks} - notSelected - {kind} - {size} - {shape} - on:click={showMenu} - /> - {:else} - <Button - focusIndex={focusIndex === -1 ? focusIndex : focusIndex + 2 + displayItems.length} - id={presentation.string.AddSocialLinks} - bind:input={addBtn} - icon={contact.icon.SocialEdit} - {kind} - {size} - {shape} - showTooltip={{ label: presentation.string.AddSocialLinks }} - on:click={showMenu} - /> - {/if} + <Button + focusIndex={focusIndex === -1 ? focusIndex : focusIndex + 2 + displayItems.length} + id={presentation.string.AddSocialLinks} + bind:input={addBtn} + icon={contact.icon.SocialEdit} + label={displayItems.length === 0 ? presentation.string.AddSocialLinks : undefined} + {kind} + {size} + {shape} + showTooltip={{ label: presentation.string.AddSocialLinks }} + on:click={showMenu} + /> {/if} </div> diff --git a/plugins/contact-resources/src/components/ChannelsEditor.svelte b/plugins/contact-resources/src/components/ChannelsEditor.svelte index 2f72e18dc9..0ebe121239 100644 --- a/plugins/contact-resources/src/components/ChannelsEditor.svelte +++ b/plugins/contact-resources/src/components/ChannelsEditor.svelte @@ -107,11 +107,10 @@ } function _open (ev: any) { - if (ev.detail.presenter !== undefined && Array.isArray(channels)) { - const channel = channels[0] - if (channel !== undefined && allowOpen) { + if (ev.detail.presenter !== undefined) { + if (allowOpen) { closeTooltip() - showPopup(ev.detail.presenter, { _id: channel.attachedTo, _class: channel.attachedToClass }, 'float') + showPopup(ev.detail.presenter, { _id: attachedTo, _class: attachedClass }, 'float') } } } diff --git a/plugins/contact-resources/src/components/ChannelsPopup.svelte b/plugins/contact-resources/src/components/ChannelsPopup.svelte index 9d9c9291a6..2e2f9ef4b3 100644 --- a/plugins/contact-resources/src/components/ChannelsPopup.svelte +++ b/plugins/contact-resources/src/components/ChannelsPopup.svelte @@ -29,12 +29,6 @@ const copyLink = (): void => { copyTextToClipboard(value.value) - // .then(() => { - // console.log('Copied!', value.value) - // }) - // .catch((err) => { - // console.log('Something went wrong', err) - // }) closeTooltip() } </script> diff --git a/plugins/gmail-resources/src/components/Main.svelte b/plugins/gmail-resources/src/components/Main.svelte index c5688b6483..8cb10186c4 100644 --- a/plugins/gmail-resources/src/components/Main.svelte +++ b/plugins/gmail-resources/src/components/Main.svelte @@ -14,23 +14,22 @@ // limitations under the License. --> <script lang="ts"> - import { Ref, Doc, Class } from '@hcengineering/core' import contact, { Channel, formatName } from '@hcengineering/contact' + import { Class, Doc, Ref } from '@hcengineering/core' import { SharedMessage } from '@hcengineering/gmail' - import NewMessage from './NewMessage.svelte' - import FullMessage from './FullMessage.svelte' - import Chats from './Chats.svelte' - import { createQuery, getClient } from '@hcengineering/presentation' import { NotificationClientImpl } from '@hcengineering/notification-resources' - import { Panel, Icon, Label, Button, eventToHTMLElement, showPopup } from '@hcengineering/ui' + import { createQuery } from '@hcengineering/presentation' + import { Button, eventToHTMLElement, Icon, Label, Panel, showPopup } from '@hcengineering/ui' import { createEventDispatcher } from 'svelte' import gmail from '../plugin' + import Chats from './Chats.svelte' import Connect from './Connect.svelte' + import FullMessage from './FullMessage.svelte' + import NewMessage from './NewMessage.svelte' export let _id: Ref<Doc> export let _class: Ref<Class<Doc>> - // export let object: Contact let object: any let newMessage: boolean = false let currentMessage: SharedMessage | undefined = undefined @@ -38,17 +37,19 @@ const notificationClient = NotificationClientImpl.getClient() let enabled: boolean - const client = getClient() + const channelQuery = createQuery() const dispatch = createEventDispatcher() - client - .findOne(contact.class.Channel, { + $: channelQuery.query( + contact.class.Channel, + { attachedTo: _id, provider: contact.channelProvider.Email - }) - .then((res) => { - channel = res - }) + }, + (res) => { + channel = res[0] + } + ) const query = createQuery() $: _id && diff --git a/plugins/telegram-resources/src/components/Chat.svelte b/plugins/telegram-resources/src/components/Chat.svelte index a774a10900..35c0ea58d4 100644 --- a/plugins/telegram-resources/src/components/Chat.svelte +++ b/plugins/telegram-resources/src/components/Chat.svelte @@ -41,15 +41,18 @@ const client = getClient() const notificationClient = NotificationClientImpl.getClient() + const channelQuery = createQuery() - client - .findOne(contact.class.Channel, { + $: channelQuery.query( + contact.class.Channel, + { attachedTo: _id, provider: contact.channelProvider.Telegram - }) - .then((res) => { - channel = res - }) + }, + (res) => { + channel = res[0] + } + ) const query = createQuery() $: _id &&