Skip to content

Commit

Permalink
fix: improve value merging logic in useUrlFromCurrentTab
Browse files Browse the repository at this point in the history
- Updated the logic to prioritize form values over action values for non-tree views.
- For tree views with active_ids, merged form values with action values.
- Simplified the final action data structure by directly assigning merged values.
  • Loading branch information
mguellsegarra committed Jan 24, 2025
1 parent 9fd9d6a commit 1b5d7dd
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/hooks/useUrlFromCurrentTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,32 @@ export function useUrlFromCurrentTab({
};

const { action_id } = currentTab.action;

let finalValues = currentTab.action.values || {};
const formValues = formRef.current?.getPlainValues() || {};

// For tree view with active_ids, action values have priority over form values
if (initialView.type === "tree" && finalValues.active_ids) {
finalValues = {
...formValues,
...finalValues,
};
} else {
// For all other cases, form values (if any) have priority over action values
finalValues = {
...finalValues,
...formValues,
};
}

const finalActionData: ActionInfo = {
...currentTab.action,
...(initialView && { initialView }),
...(searchParams && { searchParams }),
...(currentId && { res_id: currentId }),
actionRawData: {
...currentTab.action.actionRawData,
values: {
...currentTab.action.values,
...(formRef.current?.getPlainValues() || {}),
},
values: finalValues,
},
};

Expand Down

0 comments on commit 1b5d7dd

Please sign in to comment.