Employee status requests flood fix (#1759)

This commit is contained in:
Denis Bykhov 2022-05-16 11:02:40 +06:00 committed by GitHub
parent 9cecb990ee
commit 0231234f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 57 deletions

View File

@ -60,7 +60,10 @@
res.map((r) => { res.map((r) => {
return [r._id, r] return [r._id, r]
}) })
)) )),
{
lookup: { _id: { statuses: contact.class.Status } }
}
) )
$: updateQuery(space) $: updateQuery(space)

View File

@ -70,7 +70,10 @@
res.map((r) => { res.map((r) => {
return [r._id, r] return [r._id, r]
}) })
)) )),
{
lookup: { _id: { statuses: contact.class.Status } }
}
) )
const pinnedQuery = createQuery() const pinnedQuery = createQuery()

View File

@ -124,7 +124,10 @@
res.map((r) => { res.map((r) => {
return [r._id, r] return [r._id, r]
}) })
)) )),
{
lookup: { _id: { statuses: contact.class.Status } }
}
) )
const savedMessagesQuery = createQuery() const savedMessagesQuery = createQuery()

View File

@ -56,6 +56,7 @@
"TypeLabel": "Type", "TypeLabel": "Type",
"StatusDueDateTooltip": "Until {date}", "StatusDueDateTooltip": "Until {date}",
"CopyToClipboard": "Copy to clipboard", "CopyToClipboard": "Copy to clipboard",
"Copied": "Copied" "Copied": "Copied",
"ViewFullProfile": "View full profile"
} }
} }

View File

@ -56,6 +56,7 @@
"TypeLabel": "Тип", "TypeLabel": "Тип",
"StatusDueDateTooltip": "До {date}", "StatusDueDateTooltip": "До {date}",
"CopyToClipboard": "Скопировать в буфер обмена", "CopyToClipboard": "Скопировать в буфер обмена",
"Copied": "Скопировано" "Copied": "Скопировано",
"ViewFullProfile": "Посмотреть профиль"
} }
} }

View File

@ -4,8 +4,9 @@
import PersonPresenter from '../components/PersonPresenter.svelte' import PersonPresenter from '../components/PersonPresenter.svelte'
import { showPopup } from '@anticrm/ui' import { showPopup } from '@anticrm/ui'
import EmployeePreviewPopup from './EmployeePreviewPopup.svelte' import EmployeePreviewPopup from './EmployeePreviewPopup.svelte'
import { WithLookup } from '@anticrm/core'
export let value: Employee export let value: WithLookup<Employee>
export let shouldShowAvatar: boolean = true export let shouldShowAvatar: boolean = true
let container: HTMLElement let container: HTMLElement
@ -14,8 +15,7 @@
showPopup( showPopup(
EmployeePreviewPopup, EmployeePreviewPopup,
{ {
employeeId: value._id, employeeId: value._id
space: value.space
}, },
container container
) )
@ -26,9 +26,11 @@
<div class="pr-2 over-underline"> <div class="pr-2 over-underline">
<PersonPresenter {value} {onEdit} {shouldShowAvatar} /> <PersonPresenter {value} {onEdit} {shouldShowAvatar} />
</div> </div>
<div class="status content-color"> {#if value.$lookup?.statuses?.length}
<EmployeeStatusPresenter employeeId={value._id} /> <div class="status content-color">
</div> <EmployeeStatusPresenter employee={value} />
</div>
{/if}
</div> </div>
<style lang="scss"> <style lang="scss">

View File

@ -1,27 +1,27 @@
<script lang="ts"> <script lang="ts">
import { Employee, EmployeeAccount, formatName, Status } from '@anticrm/contact' import { Employee, EmployeeAccount, formatName, Status } from '@anticrm/contact'
import { getCurrentAccount, Ref, Space, WithLookup } from '@anticrm/core' import { getCurrentAccount, Ref, Hierarchy, WithLookup } from '@anticrm/core'
import { Avatar, createQuery, getClient } from '@anticrm/presentation' import { Avatar, createQuery, getClient } from '@anticrm/presentation'
import { Button, Label, showPopup } from '@anticrm/ui' import { Button, getPanelURI, Label, showPopup } from '@anticrm/ui'
import EmployeeSetStatusPopup from './EmployeeSetStatusPopup.svelte' import EmployeeSetStatusPopup from './EmployeeSetStatusPopup.svelte'
import contact from '../plugin' import contact from '../plugin'
import EmployeeStatusPresenter from './EmployeeStatusPresenter.svelte' import EmployeeStatusPresenter from './EmployeeStatusPresenter.svelte'
import Edit from './icons/Edit.svelte' import Edit from './icons/Edit.svelte'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import view from '@anticrm/view'
export let employeeId: Ref<Employee> export let employeeId: Ref<Employee>
export let space: Ref<Space>
const client = getClient() const client = getClient()
const me = (getCurrentAccount() as EmployeeAccount).employee const me = (getCurrentAccount() as EmployeeAccount).employee
$: editable = employeeId === me $: editable = employeeId === me
const stattusQuery = createQuery() const employeeQuery = createQuery()
let status: WithLookup<Status> $: status = employee?.$lookup?.statuses?.[0]
$: employee = status?.$lookup?.attachedTo let employee: WithLookup<Employee> | undefined
stattusQuery.query(contact.class.Status, { attachedTo: employeeId }, (res) => (status = res[0]), { employeeQuery.query(contact.class.Employee, { _id: employeeId }, (res) => (employee = res[0]), {
lookup: { lookup: {
attachedTo: contact.class.Employee _id: { statuses: contact.class.Status }
} }
}) })
@ -41,7 +41,7 @@
} else if (status && !newStatus) { } else if (status && !newStatus) {
client.removeDoc(contact.class.Status, status.space, status._id) client.removeDoc(contact.class.Status, status.space, status._id)
} else { } else {
client.createDoc(contact.class.Status, space, { client.createDoc(contact.class.Status, employee!.space, {
attachedTo: employeeId, attachedTo: employeeId,
attachedToClass: contact.class.Employee, attachedToClass: contact.class.Employee,
collection: 'statuses', collection: 'statuses',
@ -56,28 +56,33 @@
</script> </script>
<div class="antiPopup p-4 flex-col"> <div class="antiPopup p-4 flex-col">
<div class="flex-col-center pb-2"> {#if employee}
<Avatar size="x-large" avatar={employee?.avatar} /> <div class="flex-col-center pb-2">
</div> <Avatar size="x-large" avatar={employee?.avatar} />
<div class="pb-2">{formatName(employee?.name ?? '')}</div> </div>
{#if status} <div class="pb-2">{formatName(employee?.name ?? '')}</div>
<div class="pb-2"> <a href={`#${getPanelURI(view.component.EditDoc, employee._id, Hierarchy.mixinOrClass(employee), 'content')}`}
<Label label={contact.string.Status} /> ><Label label={contact.string.ViewFullProfile} /></a
<div class="flex-row-stretch statusContainer"> >
<div class="pr-2"> {#if status}
<EmployeeStatusPresenter {employeeId} withTooltip={false} /> <div class="pb-2">
</div> <Label label={contact.string.Status} />
{#if editable} <div class="flex-row-stretch statusContainer">
<div class="setStatusButton"> <div class="pr-2">
<Button icon={Edit} title={contact.string.SetStatus} on:click={onEdit} /> <EmployeeStatusPresenter {employee} withTooltip={false} />
</div> </div>
{/if} {#if editable}
<div class="setStatusButton">
<Button icon={Edit} title={contact.string.SetStatus} on:click={onEdit} />
</div>
{/if}
</div>
</div> </div>
</div> {:else if editable}
{:else if editable} <div class="flex-row-stretch over-underline pb-2" on:click={onEdit}>
<div class="flex-row-stretch over-underline pb-2" on:click={onEdit}> <Label label={contact.string.SetStatus} />
<Label label={contact.string.SetStatus} /> </div>
</div> {/if}
{/if} {/if}
</div> </div>

View File

@ -1,38 +1,31 @@
<script lang="ts"> <script lang="ts">
import { Employee, Status } from '@anticrm/contact' import { Employee, Status } from '@anticrm/contact'
import { Ref } from '@anticrm/core' import { WithLookup } from '@anticrm/core'
import { Label, Tooltip } from '@anticrm/ui' import { Label, Tooltip } from '@anticrm/ui'
import { createQuery } from '@anticrm/presentation'
import contact from '../plugin' import contact from '../plugin'
import { formatDate } from '../utils' import { formatDate } from '../utils'
import { IntlString } from '@anticrm/platform' import { IntlString } from '@anticrm/platform'
export let employeeId: Ref<Employee> export let employee: WithLookup<Employee>
export let withTooltip: boolean = true export let withTooltip: boolean = true
const statusQuery = createQuery() $: status = employee?.$lookup?.statuses?.[0] as Status | undefined
let status: Status $: formattedDate = status && (formatDate(status.dueDate) as IntlString)
$: statusQuery.query(contact.class.Status, { attachedTo: employeeId }, (res) => {
status = res[0]
})
$: formattedDate = formatDate(status?.dueDate) as IntlString
</script> </script>
{#if status} {#if status}
{#if withTooltip} {#if withTooltip}
<Tooltip <Tooltip
label={status?.dueDate ? contact.string.StatusDueDateTooltip : contact.string.NoExpire} label={status.dueDate ? contact.string.StatusDueDateTooltip : contact.string.NoExpire}
props={{ date: formattedDate }} props={{ date: formattedDate }}
> >
<div class="overflow-label statusName">{status?.name}</div> <div class="overflow-label statusName">{status.name}</div>
</Tooltip> </Tooltip>
{:else} {:else}
<div class="flex"> <div class="flex">
<div class="pr-4">{status?.name}</div> <div class="pr-4">{status.name}</div>
{#if status?.dueDate} {#if status.dueDate}
<div>{formatDate(status?.dueDate)}</div> <div>{formattedDate}</div>
{:else} {:else}
<Label label={contact.string.NoExpire} /> <Label label={contact.string.NoExpire} />
{/if} {/if}

View File

@ -52,6 +52,7 @@ export default mergeIds(contactId, contact, {
NoExpire: '' as IntlString, NoExpire: '' as IntlString,
StatusDueDateTooltip: '' as IntlString, StatusDueDateTooltip: '' as IntlString,
CopyToClipboard: '' as IntlString, CopyToClipboard: '' as IntlString,
Copied: '' as IntlString Copied: '' as IntlString,
ViewFullProfile: '' as IntlString
} }
}) })