Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feature state value conversion #3946

Merged
merged 9 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/common/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ export type FeatureStateValue = {
float_value?: number | null
integer_value?: boolean | null
string_value: string
type: string
type: 'int' | 'unicode' | 'bool' | 'float'
}

export type MultivariateOption = {
Expand Down
19 changes: 10 additions & 9 deletions frontend/common/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,17 @@ const Utils = Object.assign({}, require('./base/_utils'), {
return null
}

if (typeof featureState.integer_value === 'number') {
return Utils.getTypedValue(featureState.integer_value)
}
if (typeof featureState.float_value === 'number') {
return Utils.getTypedValue(featureState.float_value)
//@ts-ignore value_type is the type key on core traits
switch (featureState.value_type || featureState.type) {
case 'bool':
return featureState.boolean_value
case 'float':
return featureState.float_value
case 'int':
return featureState.integer_value
default:
return featureState.string_value
}

return Utils.getTypedValue(
featureState.string_value || featureState.boolean_value,
)
},
findOperator(
operator: SegmentCondition['operator'],
Expand Down