import { TopicFactorParameter } from '@/services/data/tuples/factor-calculator-types' ; import { Factor } from '@/services/data/tuples/factor-types' ; import { Topic } from '@/services/data/tuples/topic-types' ; import { DropdownOption } from '../../basic/types' ; import { useForceUpdate } from '../../basic/utils' ; import { useParameterEventBus } from '../parameter-event-bus' ; import { ParameterEventTypes } from '../parameter-event-bus-types' ; export const useTopicFactor = ( parameter ) => { const { fire } = useParameterEventBus ( ) ; const forceUpdate = useForceUpdate ( ) ; const { topicId , factorId } = parameter ; const onTopicChange = ( { value } ) => { const selectedTopic = value as Topic ; if ( selectedTopic . topicId === topicId ) { return ; } parameter . topicId = selectedTopic . topicId ; parameter . factorId = '' ; forceUpdate ( ) ; fire ( ParameterEventTypes . TOPIC_CHANGED , parameter , selectedTopic ) ; fire ( ParameterEventTypes . FACTOR_CHANGED , parameter ) ; } ; const onFactorChange = ( { value } ) => { const selectedFactor = value as Factor ; if ( selectedFactor . factorId === factorId ) { return ; } parameter . factorId = selectedFactor . factorId ; forceUpdate ( ) ; fire ( ParameterEventTypes . FACTOR_CHANGED , parameter , selectedFactor ) ; } ; return { onTopicChange , onFactorChange , topicId , factorId } ; } ;