fix(fe): add gradient property to filters data store

fix(fe): add gradient property to filters data store
This commit is contained in:
andrewwallacespeckle
2025-09-12 14:47:59 +01:00
committed by GitHub
4 changed files with 49 additions and 6 deletions
@@ -44,6 +44,7 @@ import { containsAll } from '~~/lib/common/helpers/utils'
import type { Automate } from '@speckle/shared'
import type { NumericFilterData } from '~/lib/viewer/helpers/filters/types'
import { isNumericFilter } from '~/lib/viewer/helpers/filters/types'
import { injectGradientDataIntoDataStore } from '~/lib/viewer/helpers/filters/utils'
type ObjectResult = Automate.AutomateTypes.ResultsSchema['values']['objectResults'][0]
@@ -54,7 +55,7 @@ const props = defineProps<{
const {
viewer: {
metadata: { filteringState }
metadata: { filteringState, filteringDataStore }
}
} = useInjectedViewerState()
@@ -166,13 +167,14 @@ const setOrUnsetGradient = () => {
resetFilters()
if (!props.result.metadata) return
if (!computedPropInfo.value) return
if (!props.functionId) return
const gradientValues = props.result.metadata?.gradientValues || {}
injectGradientDataIntoDataStore(filteringDataStore, props.functionId, gradientValues)
metadataGradientIsSet.value = true
const filterId = addActiveFilter(computedPropInfo.value)
toggleFilterApplied(filterId)
const ids = resultObjectIds.value
setSelectionFromObjectIds(ids)
}
const iconAndColor = computed(() => {
@@ -3,6 +3,7 @@
v-model:open="showMenu"
:class="noPadding ? '' : 'pl-9'"
:items="menuItems"
mount-menu-on-body
show-ticks="right"
:custom-menu-items-classes="[
'!text-body-2xs',
@@ -1,5 +1,5 @@
<template>
<div class="pt-0.5">
<div class="pt-0.5 w-full">
<ViewerFiltersFilterConditionSelector
:filter="filter"
:no-padding="noPadding"
@@ -1,6 +1,6 @@
import type { PropertyInfo } from '@speckle/viewer'
import { isStringPropertyInfo } from '~/lib/viewer/helpers/sceneExplorer'
import { ExistenceFilterCondition } from './types'
import { ExistenceFilterCondition, FilterType, type DataSource } from './types'
export const revitPropertyRegex = /^parameters\./
export const revitPropertyRegexDui3000InstanceProps = /^properties\.Instance/
@@ -219,3 +219,43 @@ export function getExistenceFilterCount(
return Math.max(0, relevantObjectCount - objectsWithProperty)
}
}
/**
* Injects gradient data into the filtering data store so it can be used for filtering
*/
export function injectGradientDataIntoDataStore(
filteringDataStore: unknown,
propertyKey: string,
gradientValues: Record<string, { gradientValue: number }>
): void {
if (!filteringDataStore || Object.keys(gradientValues).length === 0) {
return
}
const store = filteringDataStore as {
dataSources: {
value: DataSource[]
}
}
if (!store.dataSources?.value) {
return
}
for (const dataSource of store.dataSources.value) {
for (const [objectId, { gradientValue }] of Object.entries(gradientValues)) {
// Add the gradient property to the object if it exists in this data source
if (dataSource.objectProperties[objectId]) {
dataSource.objectProperties[objectId][propertyKey] = gradientValue
}
}
// Add property info to the propertyMap if not already present
if (!dataSource.propertyMap[propertyKey]) {
dataSource.propertyMap[propertyKey] = {
concatenatedPath: propertyKey,
value: Object.values(gradientValues)[0]?.gradientValue || 0,
type: FilterType.Numeric
}
}
}
}