mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-06 07:23:26 +00:00
Fix status filter count (#3000)
This commit is contained in:
parent
60278a9423
commit
f13c501eec
@ -51,22 +51,22 @@
|
|||||||
$: clazz = hierarchy.getClass(targetClass)
|
$: clazz = hierarchy.getClass(targetClass)
|
||||||
|
|
||||||
$: isStatus = client.getHierarchy().isDerived(targetClass, core.class.Status) ?? false
|
$: isStatus = client.getHierarchy().isDerived(targetClass, core.class.Status) ?? false
|
||||||
let statusesCount: number[] = []
|
let statusesCount: Record<string, number> = {}
|
||||||
|
|
||||||
const groupValues = (val: (Status | undefined)[]): (Doc | undefined)[] => {
|
const groupValues = (val: Status[]): Doc[] => {
|
||||||
const statuses = val
|
const statuses = val
|
||||||
const result: (Doc | undefined)[] = []
|
const result: Doc[] = []
|
||||||
statusesCount = []
|
statusesCount = {}
|
||||||
const unique = [...new Set(val.map((v) => v?.name?.trim()?.toLocaleLowerCase()))]
|
const unique = [...new Set(val.map((v) => v.name.trim().toLocaleLowerCase()))]
|
||||||
unique.forEach((label, i) => {
|
unique.forEach((label, i) => {
|
||||||
let count = 0
|
let count = 0
|
||||||
statuses.forEach((state) => {
|
statuses.forEach((state) => {
|
||||||
if (state?.name?.trim()?.toLocaleLowerCase() === label?.trim()?.toLowerCase()) {
|
if (state.name.trim().toLocaleLowerCase() === label) {
|
||||||
if (!count) result[i] = state
|
if (!count) result[i] = state
|
||||||
count += targets.get(state?._id) ?? 0
|
count += targets.get(state?._id) ?? 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
statusesCount[i] = count
|
;(statusesCount as any)[label] = count
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -111,9 +111,6 @@
|
|||||||
values.unshift(undefined)
|
values.unshift(undefined)
|
||||||
}
|
}
|
||||||
if (values.length !== targets.size) {
|
if (values.length !== targets.size) {
|
||||||
for (const value of values) {
|
|
||||||
targets.delete(value?._id)
|
|
||||||
}
|
|
||||||
const oldSize = filter.value.length
|
const oldSize = filter.value.length
|
||||||
filter.value = filter.value.filter((p) => !targets.has(p._id))
|
filter.value = filter.value.filter((p) => !targets.has(p._id))
|
||||||
const removed = oldSize - (filter.value.length ?? 0)
|
const removed = oldSize - (filter.value.length ?? 0)
|
||||||
@ -156,6 +153,11 @@
|
|||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
$: if (targetClass) getValues(search)
|
$: if (targetClass) getValues(search)
|
||||||
|
|
||||||
|
function getStatusCount (value: Doc): string {
|
||||||
|
const label = (value as Status).name.trim().toLowerCase()
|
||||||
|
return statusesCount[label]?.toString() ?? ''
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="selectPopup" use:resizeObserver={() => dispatch('changeContent')}>
|
<div class="selectPopup" use:resizeObserver={() => dispatch('changeContent')}>
|
||||||
@ -197,8 +199,8 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="dark-color ml-2">
|
<div class="dark-color ml-2">
|
||||||
{#if isStatus}
|
{#if isStatus && value}
|
||||||
{statusesCount[i] ?? ''}
|
{getStatusCount(value)}
|
||||||
{:else}
|
{:else}
|
||||||
{targets.get(value?._id) ?? ''}
|
{targets.get(value?._id) ?? ''}
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
Reference in New Issue
Block a user