From 086b1b763eaabd15fd52e08355b604b93c4f37a6 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 12 Mar 2025 22:18:41 +0530 Subject: [PATCH] feat: remove diff --- .../store/modules/conversations/helpers.js | 54 -------- .../store/modules/conversations/index.js | 12 +- .../specs/conversations/helpers.spec.js | 127 ------------------ 3 files changed, 1 insertion(+), 192 deletions(-) diff --git a/app/javascript/dashboard/store/modules/conversations/helpers.js b/app/javascript/dashboard/store/modules/conversations/helpers.js index 7d1a5d23b..0063c8cfc 100644 --- a/app/javascript/dashboard/store/modules/conversations/helpers.js +++ b/app/javascript/dashboard/store/modules/conversations/helpers.js @@ -112,57 +112,3 @@ export const sortComparator = (a, b, sortKey) => { SORT_OPTIONS[sortKey] || SORT_OPTIONS.last_activity_at_desc; return sortConfig[sortMethod](a, b, sortDirection); }; - -export const deepObjectDiff = (original, updated, maxDepth = 3) => { - const changes = { - added: {}, - removed: {}, - modified: {}, - }; - - function isObject(item) { - return item && typeof item === 'object' && !Array.isArray(item); - } - - function compareObjects(orig, upd, path = '', depth = 1) { - if (depth > maxDepth) { - if (JSON.stringify(orig) !== JSON.stringify(upd)) { - changes.modified[path] = { from: orig, to: upd }; - } - return; - } - - // Get all keys from both objects - const allKeys = [...new Set([...Object.keys(orig), ...Object.keys(upd)])]; - - allKeys.forEach(key => { - const currentPath = path ? `${path}.${key}` : key; - - // Handle removed properties - if (!Object.keys(upd).includes(key)) { - changes.removed[currentPath] = orig[key]; - return; - } - - // Handle added properties - if (!Object.keys(orig).includes(key)) { - changes.added[currentPath] = upd[key]; - return; - } - - // Handle nested objects - if (isObject(orig[key]) && isObject(upd[key])) { - compareObjects(orig[key], upd[key], currentPath, depth + 1); - return; - } - - // Handle modified values - if (JSON.stringify(orig[key]) !== JSON.stringify(upd[key])) { - changes.modified[currentPath] = { from: orig[key], to: upd[key] }; - } - }); - } - - compareObjects(original, updated); - return changes; -}; diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 034cf48fc..036fd70ac 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -1,7 +1,7 @@ import types from '../../mutation-types'; import getters, { getSelectedChatConversation } from './getters'; import actions from './actions'; -import { findPendingMessageIndex, deepObjectDiff } from './helpers'; +import { findPendingMessageIndex } from './helpers'; import { MESSAGE_STATUS } from 'shared/constants/messages'; import wootConstants from 'dashboard/constants/globals'; import { BUS_EVENTS } from '../../../../shared/constants/busEvents'; @@ -223,11 +223,6 @@ export const mutations = { scope.setContext('incoming_meta', conversation.meta); scope.setContext('stored_meta', selectedConversation.meta); - const diff = deepObjectDiff(conversation, selectedConversation); - scope.setContext('added', diff.added); - scope.setContext('removed', diff.removed); - scope.setContext('modified', diff.modified); - Sentry.captureMessage('Conversation update mismatch'); }); @@ -241,11 +236,6 @@ export const mutations = { scope.setContext('incoming_meta', conversation.meta); scope.setContext('stored_meta', selectedConversation.meta); - const diff = deepObjectDiff(conversation, selectedConversation); - scope.setContext('added', diff.added); - scope.setContext('removed', diff.removed); - scope.setContext('modified', diff.modified); - Sentry.captureMessage('Conversation update overlap'); }); diff --git a/app/javascript/dashboard/store/modules/specs/conversations/helpers.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/helpers.spec.js index 1aab3f12a..b0a3cdab3 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/helpers.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/helpers.spec.js @@ -5,7 +5,6 @@ import { filterByTeam, filterByLabel, filterByUnattended, - deepObjectDiff, } from '../../conversations/helpers'; const conversationList = [ @@ -173,129 +172,3 @@ describe('#filterByUnattended', () => { expect(filterByUnattended(true, 'mentions', 123)).toEqual(true); }); }); - -describe('#deepObjectDiff', () => { - it('should detect added properties', () => { - const original = { name: 'John', age: 30 }; - const updated = { name: 'John', age: 30, email: 'john@example.com' }; - - const result = deepObjectDiff(original, updated); - - expect(result.added).toEqual({ email: 'john@example.com' }); - expect(result.removed).toEqual({}); - expect(result.modified).toEqual({}); - }); - - it('should detect removed properties', () => { - const original = { name: 'John', age: 30, email: 'john@example.com' }; - const updated = { name: 'John', age: 30 }; - - const result = deepObjectDiff(original, updated); - - expect(result.added).toEqual({}); - expect(result.removed).toEqual({ email: 'john@example.com' }); - expect(result.modified).toEqual({}); - }); - - it('should detect modified properties', () => { - const original = { name: 'John', age: 30 }; - const updated = { name: 'John', age: 31 }; - - const result = deepObjectDiff(original, updated); - - expect(result.added).toEqual({}); - expect(result.removed).toEqual({}); - expect(result.modified).toEqual({ age: { from: 30, to: 31 } }); - }); - - it('should handle nested objects', () => { - const original = { - name: 'John', - address: { city: 'New York', country: 'USA' }, - }; - const updated = { - name: 'John', - address: { city: 'Boston', country: 'USA' }, - }; - - const result = deepObjectDiff(original, updated); - - expect(result.added).toEqual({}); - expect(result.removed).toEqual({}); - expect(result.modified).toEqual({ - 'address.city': { from: 'New York', to: 'Boston' }, - }); - }); - - it('should respect maxDepth parameter', () => { - const original = { - user: { - details: { - address: { city: 'New York', country: 'USA' }, - }, - }, - }; - const updated = { - user: { - details: { - address: { city: 'Boston', country: 'USA' }, - }, - }, - }; - - // With maxDepth of 2 - const result2 = deepObjectDiff(original, updated, 2); - expect(result2.modified).toEqual({ - 'user.details': { - from: { - address: { city: 'New York', country: 'USA' }, - }, - to: { - address: { city: 'Boston', country: 'USA' }, - }, - }, - }); - - // With maxDepth of 4 (enough to reach the deepest level) - const result4 = deepObjectDiff(original, updated, 4); - expect(result4.modified).toEqual({ - 'user.details.address.city': { from: 'New York', to: 'Boston' }, - }); - }); - - it('should handle arrays correctly', () => { - const original = { tags: ['important', 'urgent'] }; - const updated = { tags: ['important', 'normal'] }; - - const result = deepObjectDiff(original, updated); - - expect(result.modified).toEqual({ - tags: { - from: ['important', 'urgent'], - to: ['important', 'normal'], - }, - }); - }); - - it('should handle empty objects', () => { - const original = {}; - const updated = {}; - - const result = deepObjectDiff(original, updated); - - expect(result.added).toEqual({}); - expect(result.removed).toEqual({}); - expect(result.modified).toEqual({}); - }); - - it('should handle completely different objects', () => { - const original = { a: 1, b: 2 }; - const updated = { c: 3, d: 4 }; - - const result = deepObjectDiff(original, updated); - - expect(result.added).toEqual({ c: 3, d: 4 }); - expect(result.removed).toEqual({ a: 1, b: 2 }); - expect(result.modified).toEqual({}); - }); -});