Skip to content

Commit

Permalink
Update Inbox Filter Wrapper to support count (#1562)
Browse files Browse the repository at this point in the history
* Update Inbox Filter Wrapper to support count

* Resolved code rabbit comments
  • Loading branch information
Ramkrishna-egov authored Oct 18, 2024
1 parent 89f3af7 commit d95ec76
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -38,8 +59,8 @@ const InboxFilterWrapper = (props) => {
>
<LabelFieldPair>
<RadioButtons
options={props.options}
optionsKey={props?.optionsKey} // Use "name" key by default
options={resultArray}
optionsKey={"name"} // Use "name" key by default
selectedOption={selectedValue} // Pass the current selected option
style={{
display: "flex",
Expand Down

0 comments on commit d95ec76

Please sign in to comment.