Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export const createAddress = ({ address, oldContact, t }) => {
* @returns {Record<string, { data: { _id: string, _type: string }[] }>} - The related contacts relationships
*/
export const getRelatedContactRelationships = relatedContact => {
if (!relatedContact) return {}

Comment on lines +213 to +214
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Returning {} here can keep stale relationships.related

On Line 213, returning {} when relatedContact is null/falsy means no related key is produced. In formValuesToContact (packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/formValuesToContact.js:38-52), that allows previously merged oldContactCleaned?.relationships.related to survive instead of being cleared.

Suggested fix
 export const getRelatedContactRelationships = relatedContact => {
-  if (!relatedContact) return {}
+  if (!relatedContact) return { related: { data: [] } }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!relatedContact) return {}
export const getRelatedContactRelationships = relatedContact => {
if (!relatedContact) return { related: { data: [] } }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js` around
lines 213 - 214, The helper early-return currently returns an empty object when
relatedContact is falsy, which omits the related key and lets
oldContactCleaned?.relationships.related persist; update the early-return in the
helper (the branch that checks relatedContact) to return an object that
explicitly clears relationships.related (e.g., return { related: [] }) so
formValuesToContact correctly replaces prior related entries when calling
formValuesToContact/merging with oldContactCleaned.

// Tips filter Boolean to remove undefined value from array when relatedContact is empty (see contactToFormValues)
const data = relatedContact.filter(Boolean).reduce((acc, curr) => {
const relationType = curr.relatedContactLabel
Expand Down
Loading