diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/InboxFilterWrapper.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/InboxFilterWrapper.js index 94d20dee97d..2b725e301e0 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/InboxFilterWrapper.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/InboxFilterWrapper.js @@ -4,8 +4,29 @@ import { FilterCard, LabelFieldPair, RadioButtons } from "@egovernments/digit-ui const InboxFilterWrapper = (props) => { const { t } = useTranslation(); - // State to store the selected radio button value - const [selectedValue, setSelectedValue] = useState(props?.defaultValue || null); + + // defaultValue structure: {"key": value} + // defaultSelectedOption structure: { code: string, name: string } + const defaultSelectedOption = props.defaultValue + ? { code: Object.keys(props.defaultValue)[0], name: `${t(Object.keys(props.defaultValue)[0])} (${Object.values(props.defaultValue)[0]})` } + : null; + + // Initialize state with the default selected option + const [selectedValue, setSelectedValue] = useState(defaultSelectedOption); + + const createArrayFromObject = (obj, t) => { + if (!obj || typeof obj !== 'object' || typeof t !== 'function') { + console.error('Invalid input to createArrayFromObject'); + return []; + } + return Object.entries(obj).map(([key, value]) => ({ + code: key, + name: `${t(key)} (${value})` + })); + }; + + // Usage of the function + const resultArray = createArrayFromObject(props?.options, t); // Function to handle selection from the radio buttons const handleSelect = (option) => { @@ -38,8 +59,8 @@ const InboxFilterWrapper = (props) => { >