Skip to main content

answers/index

@boldpenguin/sdk-reduxGlobals"answers/index"

Index

Variables

Variables

Const findActiveAnswerById

findActiveAnswerById: function & OutputSelectorFields‹function› & object = createSelector([getCurrentActiveQuestionSet, (_: BpSdkStore, id: string) => id], (questionSet, id) => { return questionSet?.answers.find((answer) => answer.id === id); })

Returns the active answer matching the id

param The BpSdk Redux store

param answer id


Const findActiveAnswersByGroup

findActiveAnswersByGroup: function & OutputSelectorFields‹function› & object = createSelector( [getCurrentActiveQuestionSet, (_: BpSdkStore, props: FindActiveAnswersByGroupProps) => props], (questionSet, props) => { return ( questionSet?.answers.filter( (answer: IAnswer): boolean => answer.question.question_group_id === props.groupId && answer.answer_pool_id === props.poolId, ) ?? [] ); }, )

Returns the filtered active question set's answers by question group id and pool id

param The BpSdk Redux store

param Object containing groupId and optionally an answer poolId


Const findActiveAnswersByQuestionGroup

findActiveAnswersByQuestionGroup: function & OutputSelectorFields‹function› & object = createSelector( [getCurrentActiveQuestionSet, (_: BpSdkStore, groupId: string) => groupId], (questionSet, groupId) => questionSet?.answers?.filter((answer: IAnswer): boolean => answer?.question.question_group_id === groupId) ?? [], )

Returns the filtered active question set's answers by question group id

param The BpSdk Redux store

param group id


Const findActiveAnswersByQuestionPool

findActiveAnswersByQuestionPool: function & OutputSelectorFields‹function› & object = createSelector( [getCurrentActiveQuestionSet, (_: BpSdkStore, poolId?: string) => poolId], (questionSet, poolId) => questionSet?.answers?.filter((answer: IAnswer): boolean => answer?.answer_pool_id === poolId) ?? [], )

Returns the filter active question set's answers by question pool id

param The BpSdk Redux store

param pool id


Const selectAnswersByQuestionCode

selectAnswersByQuestionCode: function & OutputSelectorFields‹function› & object = createSelector( [getQuestionSets, (_: BpSdkStore, code: string | RegExp) => code], (questionSets, code) => { return code instanceof RegExp ? questionSets.flatMap((qs) => qs.answers).filter((answer: IAnswer) => code.test(answer.question.code)) : questionSets.flatMap((qs) => qs.answers).filter((answer: IAnswer) => answer.question.code.includes(code)); }, )

Returns answers that matches the requested question code or question code regex from any question set

param The BpSdk Redux store

param Question code or question code regex


Const selectAnswersByReferenceType

selectAnswersByReferenceType: function & OutputSelectorFields‹function› & object = createSelector( [getQuestionSets, (_: BpSdkStore, referenceType: string | RegExp) => referenceType], (questionSets, referenceType) => { return referenceType instanceof RegExp ? questionSets.flatMap((qs) => qs.answers).filter((answer: IAnswer) => referenceType.test(answer.question.reference_type)) : questionSets.flatMap((qs) => qs.answers).filter((answer: IAnswer) => answer.question.code.includes(referenceType)); }, )

Returns the answers that matches the requested reference type

param The BpSdk Redux store

param Question reference type


Const selectBusinessClassification

selectBusinessClassification: function & OutputSelectorFields‹function› & object = createSelector([getQuestionSets], (questionSets) => { const answer = questionSets.flatMap((qs) => qs.answers).find((answer: IAnswer) => answer.question.reference_type === 'business_class'); const selectedChoice = answer?.question?.choices?.find((choice) => choice.id === answer?.choice_id); return selectedChoice?.value; })

Returns the business classification answer in human readable format

param The BpSdk Redux store


Const selectIsActiveAnswerIdInGroup

selectIsActiveAnswerIdInGroup: function & OutputSelectorFields‹function› & object = createSelector( [ findActiveAnswersByQuestionGroup, findActiveAnswersByQuestionPool, selectCurrentActiveAnswerId, (_: BpSdkStore, groupId: string) => groupId, ], (groupAnswers, poolAnswers, activeAnswerId) => !!groupAnswers?.find((answer: IAnswer): boolean => answer?.id === activeAnswerId) || !!poolAnswers?.find((answer: IAnswer): boolean => answer?.id === activeAnswerId), )

Returns the filtered active question set's answers by question group id

param The BpSdk Redux store

param group id