Remove extra requests (#2429)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2022-12-07 21:57:00 +06:00 committed by GitHub
parent 4ca2b97345
commit 04206adaef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@
--> -->
<script lang="ts"> <script lang="ts">
import { WithLookup, SortingOrder } from '@hcengineering/core' import { WithLookup, SortingOrder } from '@hcengineering/core'
import { getClient } from '@hcengineering/presentation' import { createQuery, getClient } from '@hcengineering/presentation'
import { IssueStatus, IssueStatusCategory } from '@hcengineering/tracker' import { IssueStatus, IssueStatusCategory } from '@hcengineering/tracker'
import { getPlatformColor, IconSize } from '@hcengineering/ui' import { getPlatformColor, IconSize } from '@hcengineering/ui'
import tracker from '../../plugin' import tracker from '../../plugin'
@ -24,38 +24,45 @@
export let size: IconSize export let size: IconSize
export let fill: string | undefined = undefined export let fill: string | undefined = undefined
const dynamicFillCategories = [tracker.issueStatusCategory.Started]
const client = getClient() const client = getClient()
let category: IssueStatusCategory | undefined let category: IssueStatusCategory | undefined
let categories: IssueStatus[] | undefined let statuses: IssueStatus[] = []
let statusIcon: { const statusIcon: {
index: number | undefined index: number | undefined
count: number | undefined count: number | undefined
} = { index: undefined, count: undefined } } = { index: undefined, count: undefined }
async function updateCategory (status: WithLookup<IssueStatus>) { const categoriesQuery = createQuery()
categoriesQuery.query(
tracker.class.IssueStatus,
{ category: tracker.issueStatusCategory.Started },
(res) => (statuses = res),
{ sort: { rank: SortingOrder.Ascending } }
)
async function updateCategory (status: WithLookup<IssueStatus>, statuses: IssueStatus[]) {
if (status.$lookup?.category) { if (status.$lookup?.category) {
category = status.$lookup.category category = status.$lookup.category
} }
if (category === undefined) { if (category === undefined) {
category = await client.findOne(tracker.class.IssueStatusCategory, { _id: value.category }) category = await client.findOne(tracker.class.IssueStatusCategory, { _id: value.category })
} }
if (value.category === tracker.issueStatusCategory.Started) { if (dynamicFillCategories.includes(value.category)) {
categories = await client.findAll( const index = statuses.findIndex((p) => p._id === value._id)
tracker.class.IssueStatus, if (index !== -1) {
{ category: tracker.issueStatusCategory.Started }, statusIcon.index = index + 1
{ sort: { rank: SortingOrder.Ascending } } statusIcon.count = statuses.length + 1
) } else {
if (categories) { statusIcon.index = undefined
categories.map((cat, i) => { statusIcon.count = undefined
if (cat._id === value._id) statusIcon = { index: i + 1, count: categories ? categories.length + 1 : 0 }
return true
})
} }
} }
} }
$: updateCategory(value) $: updateCategory(value, statuses)
$: icon = category?.icon $: icon = category?.icon
$: color = $: color =
fill ?? fill ??