Channels presenter fix (#908)

Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com>
This commit is contained in:
Denis Bykhov 2022-02-02 19:24:52 +06:00 committed by GitHub
parent fa3b298af9
commit d8219734aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 15 deletions

View File

@ -26,7 +26,7 @@
import contact from '@anticrm/contact' import contact from '@anticrm/contact'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
export let value: AttachedData<Channel>[] | null export let value: AttachedData<Channel>[] | AttachedData<Channel> | null
export let size: 'small' | 'medium' | 'large' | 'x-large' = 'large' export let size: 'small' | 'medium' | 'large' | 'x-large' = 'large'
export let reverse: boolean = false export let reverse: boolean = false
export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>() export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>()
@ -51,21 +51,35 @@
return map return map
} }
async function update (value: AttachedData<Channel>[]) { function getProvider (item: AttachedData<Channel>, map: Map<Ref<ChannelProvider>, ChannelProvider>): any | undefined {
const provider = map.get(item.provider)
if (provider) {
return {
label: provider.label as IntlString,
icon: provider.icon as Asset,
value: item.value,
presenter: provider.presenter,
integration: provider.integrationType !== undefined ? integrations.has(provider.integrationType) : false
}
} else {
console.log('provider not found: ', item.provider)
}
}
async function update (value: AttachedData<Channel>[] | AttachedData<Channel>) {
const result = [] const result = []
const map = await getProviders() const map = await getProviders()
for (const item of value) { if (Array.isArray(value)) {
const provider = map.get(item.provider) for (const item of value) {
if (provider) { const provider = getProvider(item, map)
result.push({ if (provider !== undefined) {
label: provider.label as IntlString, result.push(provider)
icon: provider.icon as Asset, }
value: item.value, }
presenter: provider.presenter, } else {
integration: provider.integrationType !== undefined ? integrations.has(provider.integrationType) : false const provider = getProvider(value, map)
}) if (provider !== undefined) {
} else { result.push(provider)
console.log('provider not found: ', item.provider)
} }
} }
displayItems = result displayItems = result

View File

@ -17,7 +17,7 @@
import type { Channel } from '@anticrm/contact' import type { Channel } from '@anticrm/contact'
import { Channels } from '@anticrm/presentation' import { Channels } from '@anticrm/presentation'
export let value: Channel[] | null export let value: Channel[] | Channel | null
</script> </script>
<Channels {value} size={'small'} reverse /> <Channels {value} size={'small'} reverse />