mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-26 04:23:58 +03:00
Remove extra requests (#2429)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
4ca2b97345
commit
04206adaef
@ -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 ??
|
||||||
|
Loading…
Reference in New Issue
Block a user