Fix array values in the "EmployeeRefPresenter" (#2859)

Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@xored.com>
This commit is contained in:
Andrey Sobolev 2023-04-05 14:04:08 +07:00 committed by GitHub
parent 1d6a3ca2f2
commit 66a8b32e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 38 deletions

View File

@ -0,0 +1,53 @@
<script lang="ts">
import { Employee } from '@hcengineering/contact'
import { Ref } from '@hcengineering/core'
import { ButtonKind } from '@hcengineering/ui'
import { PersonLabelTooltip } from '..'
import contact from '../plugin'
import { employeeByIdStore } from '../utils'
import AssigneeBox from './AssigneeBox.svelte'
import EmployeePresenter from './EmployeePresenter.svelte'
export let value: Ref<Employee> | null | undefined
export let kind: ButtonKind = 'link'
export let tooltipLabels: PersonLabelTooltip | undefined = undefined
export let onChange: ((value: Ref<Employee>) => void) | undefined = undefined
export let inline = false
$: employee = value ? $employeeByIdStore.get(value) : undefined
function getValue (
employee: Employee | undefined,
value: Ref<Employee> | null | undefined
): Employee | null | undefined {
if (value === undefined || value === null) {
return value
}
return employee
}
</script>
{#if onChange !== undefined}
<AssigneeBox
label={contact.string.Employee}
{value}
size={'medium'}
kind={'link'}
showNavigate={false}
justify={'left'}
on:change={({ detail }) => onChange?.(detail)}
/>
{:else}
<EmployeePresenter
value={getValue(employee, value)}
{inline}
{tooltipLabels}
isInteractive={false}
shouldShowAvatar
shouldShowPlaceholder
defaultName={contact.string.NotSpecified}
shouldShowName={kind !== 'list'}
avatarSize={kind === 'list-header' ? 'small' : 'x-small'}
disableClick
/>
{/if}

View File

@ -3,49 +3,31 @@
import { Ref } from '@hcengineering/core'
import { ButtonKind } from '@hcengineering/ui'
import { PersonLabelTooltip } from '..'
import contact from '../plugin'
import { employeeByIdStore } from '../utils'
import AssigneeBox from './AssigneeBox.svelte'
import EmployeePresenter from './EmployeePresenter.svelte'
import EmployeeAttributePresenter from './EmployeeAttributePresenter.svelte'
export let value: Ref<Employee> | null | undefined
export let value: Ref<Employee> | Ref<Employee>[] | null | undefined
export let kind: ButtonKind = 'link'
export let tooltipLabels: PersonLabelTooltip | undefined = undefined
export let onChange: ((value: Ref<Employee>) => void) | undefined = undefined
$: employee = value ? $employeeByIdStore.get(value) : undefined
function getValue (
employee: Employee | undefined,
value: Ref<Employee> | null | undefined
): Employee | null | undefined {
if (value === undefined || value === null) {
return value
}
return employee
}
export let inline = false
</script>
{#if onChange !== undefined}
<AssigneeBox
label={contact.string.Employee}
{value}
size={'medium'}
kind={'link'}
showNavigate={false}
justify={'left'}
on:change={({ detail }) => onChange?.(detail)}
/>
{#if Array.isArray(value)}
<div class="inline-content">
{#each value as employee}
<EmployeeAttributePresenter value={employee} {kind} {tooltipLabels} {onChange} {inline} />
{/each}
</div>
{:else}
<EmployeePresenter
value={getValue(employee, value)}
{tooltipLabels}
isInteractive={false}
shouldShowAvatar
shouldShowPlaceholder
defaultName={contact.string.NotSpecified}
shouldShowName={kind !== 'list'}
avatarSize={kind === 'list-header' ? 'small' : 'x-small'}
disableClick
/>
<EmployeeAttributePresenter {value} {kind} {tooltipLabels} {onChange} {inline} />
{/if}
<style lang="scss">
.inline-content {
display: inline-flex;
align-items: center;
flex-wrap: wrap;
min-width: 0;
gap: 0.5rem;
}
</style>