Skip to content

Commit

Permalink
Fixed filter card issue and added check to show validate action only (#…
Browse files Browse the repository at this point in the history
…1600)

* Fixed filter card issue and added check to show validate action only

* updated pr changes

---------

Co-authored-by: rachana-egov <rachana.singh@egovernment.org>
  • Loading branch information
rachana-egov and rachana-egov authored Oct 21, 2024
1 parent 4594453 commit 1def20d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ const InboxFilterWrapper = (props) => {
? { 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);


// Update selected value when defaultValue changes
// Only update selectedValue when defaultValue from props changes, but not when it's null or undefined
useEffect(() => {
setSelectedValue(defaultSelectedOption);
}, [props.defaultValue]);




if (props.defaultValue && Object.keys(props.defaultValue).length > 0) {
const newDefault = {
code: Object.keys(props.defaultValue)[0],
name: `${t(Object.keys(props.defaultValue)[0])} (${Object.values(props.defaultValue)[0]})`,
};
setSelectedValue(newDefault);
}
}, [props.defaultValue, t]);

const createArrayFromObject = (obj, t) => {
if (!obj || typeof obj !== "object" || Object.keys(obj).length === 0 || typeof t !== "function") {
Expand Down Expand Up @@ -51,7 +51,7 @@ const InboxFilterWrapper = (props) => {

// Clear filters when the user presses the secondary action button
const clearFilters = () => {
setSelectedValue(null);
setSelectedValue(selectedValue); // Clear the selection
if (props.clearFilters) {
props.clearFilters();
}
Expand All @@ -73,7 +73,7 @@ const InboxFilterWrapper = (props) => {
<RadioButtons
options={resultArray}
optionsKey={"name"} // Use "name" key for display
selectedOption={selectedValue} // Pass current selected option
selectedOption={selectedValue?.code} // Pass current selected option's code for comparison
style={{
display: "flex",
flexDirection: "column",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PopInbox = () => {
}
}, [campaignObject]);

console.log("user", user);

const {
isLoading: isPlanEmpSearchLoading,
data: planEmployee,
Expand Down Expand Up @@ -117,6 +117,10 @@ const PopInbox = () => {

const actionsMain = workflowData?.actions;

// actionsToHide array by checking for "EDIT" in the actionMap
const actionsToHide = actionsMain?.filter(action => action.action.includes("EDIT"))?.map(action => action.action);


// Custom hook to fetch census data based on microplanId and boundaryCode
const reqCriteriaResource = {
url: `/census-service/_search`,
Expand All @@ -143,6 +147,7 @@ const PopInbox = () => {
if ((selectedFilter === null || selectedFilter === undefined) && selectedFilter !== "") {
setSelectedFilter(Object.entries(data?.StatusCount)?.[0]?.[0]);
}
setVillagesSelected(0);
}
}, [data, selectedFilter]);

Expand All @@ -152,14 +157,15 @@ const PopInbox = () => {
}
}, [selectedFilter, activeLink, jurisdiction]);

useEffect(() => {}, [selectedFilter]);
useEffect(() => { }, [selectedFilter]);

const onFilter = (selectedStatus) => {
setSelectedFilter(selectedStatus?.code);
};

const clearFilters = () => {
setSelectedFilter("");
if (selectedFilter !== Object.entries(data?.StatusCount)?.[0]?.[0])
setSelectedFilter(Object.entries(data?.StatusCount)?.[0]?.[0]);
};

const handleActionClick = (action) => {
Expand Down Expand Up @@ -193,7 +199,7 @@ const PopInbox = () => {
onApplyFilters={onFilter}
clearFilters={clearFilters}
defaultValue={
selectedFilter !== "" && activeFilter ? { [Object.entries(activeFilter)?.[0]?.[0]]: Object.entries(activeFilter)?.[0]?.[1] } : null
selectedFilter === Object.entries(activeFilter)?.[0]?.[0] ? { [Object.entries(activeFilter)?.[0]?.[0]]: Object.entries(activeFilter)?.[0]?.[1] } : null
}
></InboxFilterWrapper>

Expand Down Expand Up @@ -231,7 +237,7 @@ const PopInbox = () => {
</div>

<div className={`table-actions-wrapper`}>
{actionsMain?.map((action, index) => (
{actionsMain?.filter(action => !actionsToHide.includes(action.action))?.map((action, index) => (
<Button
key={index}
variation="secondary"
Expand All @@ -244,7 +250,7 @@ const PopInbox = () => {
</div>
</div>
)}
<PopInboxTable onRowSelect={onRowSelect} censusData={censusData} />
{isFetching ? <Loader /> : <PopInboxTable onRowSelect={onRowSelect} censusData={censusData} />}
</Card>
</div>
</div>
Expand Down

0 comments on commit 1def20d

Please sign in to comment.