From fa31ffc19873df310073b87391c8a38b6f7759d5 Mon Sep 17 00:00:00 2001 From: Maciej Ziarkowski Date: Tue, 7 Jan 2020 18:14:51 +0000 Subject: [PATCH] Check in frontend for unsaved array edits --- app/package-lock.json | 14 ++++++++++++++ app/package.json | 2 ++ app/src/frontend/helpers.ts | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/package-lock.json b/app/package-lock.json index 80debd79..cb72d65a 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1170,6 +1170,15 @@ "integrity": "sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==", "dev": true }, + "@types/lodash.isequal": { + "version": "4.5.5", + "resolved": "https://registry.npmjs.org/@types/lodash.isequal/-/lodash.isequal-4.5.5.tgz", + "integrity": "sha512-4IKbinG7MGP131wRfceK6W4E/Qt3qssEFLF30LnJbjYiSfHGGRU/Io8YxXrZX109ir+iDETC8hw8QsDijukUVg==", + "dev": true, + "requires": { + "@types/lodash": "*" + } + }, "@types/mapbox__sphericalmercator": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@types/mapbox__sphericalmercator/-/mapbox__sphericalmercator-1.1.3.tgz", @@ -9296,6 +9305,11 @@ "integrity": "sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=", "dev": true }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", diff --git a/app/package.json b/app/package.json index 9794a47e..fb83180e 100644 --- a/app/package.json +++ b/app/package.json @@ -22,6 +22,7 @@ "express": "^4.17.1", "express-session": "^1.17.0", "leaflet": "^1.6.0", + "lodash.isequal": "^4.5.0", "mapnik": "^4.2.1", "node-fs": "^0.1.7", "nodemailer": "^6.3.0", @@ -43,6 +44,7 @@ "@types/express-session": "^1.15.16", "@types/jest": "^24.0.23", "@types/lodash": "^4.14.149", + "@types/lodash.isequal": "^4.5.5", "@types/mapbox__sphericalmercator": "^1.1.3", "@types/node": "^8.10.59", "@types/nodemailer": "^6.2.2", diff --git a/app/src/frontend/helpers.ts b/app/src/frontend/helpers.ts index 9648c708..be3b5a27 100644 --- a/app/src/frontend/helpers.ts +++ b/app/src/frontend/helpers.ts @@ -1,3 +1,4 @@ +import isEqual from 'lodash.isequal'; import urlapi from 'url'; function sanitiseURL(string){ @@ -66,7 +67,7 @@ function compareObjects(objA: object, objB: object): [object, object] { const reverse = {}; const forward = {}; for (const [key, value] of Object.entries(objB)) { - if (objA[key] !== value) { + if (!isEqual(objA[key], value)) { reverse[key] = objA[key]; forward[key] = value; }