move utilities from composable file

This commit is contained in:
andrewwallacespeckle
2025-09-04 15:01:40 +01:00
parent 8a64343f38
commit 735b320622
3 changed files with 50 additions and 49 deletions
@@ -42,7 +42,7 @@
<script setup lang="ts">
import { FormCheckbox } from '@speckle/ui-components'
import { useFilterUtilities } from '~/lib/viewer/composables/filtering/filtering'
import { getFilterValueCount } from '~/lib/viewer/composables/filtering/counts'
import { getFilterValueCount } from '~/lib/viewer/helpers/filters/utils'
import type { StringFilterData } from '~/lib/viewer/helpers/filters/types'
import { useInjectedViewerState } from '~~/lib/viewer/composables/setup'
import { useFilterColoringHelpers } from '~/lib/viewer/composables/filtering/coloringHelpers'
@@ -1,9 +1,9 @@
import type { PropertyInfo } from '@speckle/viewer'
import { useInjectedViewerState } from '~~/lib/viewer/composables/setup'
import {
ExistenceFilterCondition,
type FilterData
} from '~/lib/viewer/helpers/filters/types'
import { getExistenceFilterCount } from '~/lib/viewer/helpers/filters/utils'
/**
* Get count of filtered objects from the viewer state.
@@ -18,53 +18,6 @@ export function useFilteredObjectsCount() {
}
}
/**
* Get count for a specific filter value
*/
export function getFilterValueCount(filter: PropertyInfo, value: string): number {
if (!('valueGroups' in filter) || !Array.isArray(filter.valueGroups)) {
return 0
}
const valueGroups = filter.valueGroups as Array<{ value: unknown; ids?: string[] }>
for (const vg of valueGroups) {
if (String(vg.value) === value) {
return vg.ids?.length ?? 0
}
}
return 0
}
/**
* Get count for existence filters (objects that have/don't have a property set)
*/
export function getExistenceFilterCount(
filter: PropertyInfo,
condition: ExistenceFilterCondition,
totalObjectCount?: number
): number {
if (!('valueGroups' in filter) || !Array.isArray(filter.valueGroups)) {
return filter.objectCount ?? 0
}
const objectsWithProperty = filter.valueGroups.reduce((total, vg) => {
if ('ids' in vg && Array.isArray(vg.ids)) {
return total + vg.ids.length
}
return total
}, 0)
if (condition === ExistenceFilterCondition.IsSet) {
return objectsWithProperty
} else {
return totalObjectCount !== undefined
? Math.max(0, totalObjectCount - objectsWithProperty)
: 0
}
}
/**
* Composable for getting existence filter counts with proper optimization
*/
@@ -1,5 +1,6 @@
import type { PropertyInfo } from '@speckle/viewer'
import { isStringPropertyInfo } from '~/lib/viewer/helpers/sceneExplorer'
import { ExistenceFilterCondition } from './types'
export const revitPropertyRegex = /^parameters\./
export const revitPropertyRegexDui3000InstanceProps = /^properties\.Instance/
@@ -164,3 +165,50 @@ export const findFilterByKvp = (
return filter
}
/**
* Get count for a specific filter value
*/
export function getFilterValueCount(filter: PropertyInfo, value: string): number {
if (!('valueGroups' in filter) || !Array.isArray(filter.valueGroups)) {
return 0
}
const valueGroups = filter.valueGroups as Array<{ value: unknown; ids?: string[] }>
for (const vg of valueGroups) {
if (String(vg.value) === value) {
return vg.ids?.length ?? 0
}
}
return 0
}
/**
* Get count for existence filters (objects that have/don't have a property set)
*/
export function getExistenceFilterCount(
filter: PropertyInfo,
condition: ExistenceFilterCondition,
totalObjectCount?: number
): number {
if (!('valueGroups' in filter) || !Array.isArray(filter.valueGroups)) {
return filter.objectCount ?? 0
}
const objectsWithProperty = filter.valueGroups.reduce((total, vg) => {
if ('ids' in vg && Array.isArray(vg.ids)) {
return total + vg.ids.length
}
return total
}, 0)
if (condition === ExistenceFilterCondition.IsSet) {
return objectsWithProperty
} else {
return totalObjectCount !== undefined
? Math.max(0, totalObjectCount - objectsWithProperty)
: 0
}
}