diff --git a/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect.tsx b/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect.tsx index a9c2204bb1..7caca074f7 100644 --- a/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect.tsx +++ b/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect.tsx @@ -1,11 +1,6 @@ import Select from 'component/common/select'; import { type SelectChangeEvent, useTheme } from '@mui/material'; -import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext'; - -type OptionType = { key: string; label: string }; - -const DEFAULT_RANDOM_OPTION = 'random'; -const DEFAULT_STICKINESS_OPTION = 'default'; +import { useStickinessOptions } from 'hooks/useStickinessOptions'; interface IStickinessSelectProps { label: string; @@ -21,37 +16,9 @@ export const StickinessSelect = ({ onChange, dataTestId, }: IStickinessSelectProps) => { - const { context } = useUnleashContext(); const theme = useTheme(); + const stickinessOptions = useStickinessOptions(value); - const resolveStickinessOptions = () => { - const options = context - .filter((field) => field.stickiness) - .map((c) => ({ key: c.name, label: c.name })) as OptionType[]; - - if ( - !options.find((option) => option.key === 'default') && - !context.find((field) => field.name === DEFAULT_STICKINESS_OPTION) - ) { - options.push({ key: 'default', label: 'default' }); - } - - if ( - !options.find((option) => option.key === 'random') && - !context.find((field) => field.name === DEFAULT_RANDOM_OPTION) - ) { - options.push({ key: 'random', label: 'random' }); - } - - // Add existing value to the options - if (value && !options.find((option) => option.key === value)) { - options.push({ key: value, label: value }); - } - - return options; - }; - - const stickinessOptions = resolveStickinessOptions(); return (