From c5656a7a05f6565e118c1b88c7d599edeea9a0b7 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Thu, 29 Feb 2024 23:10:02 +0100 Subject: [PATCH] refactor: remove unused createJsonpatch --- .../edit/createJsonPatchOperations.spec.ts | 49 ------------------- .../edit/createJsonPatchOperations.ts | 20 -------- src/pages/dataElementGroups/edit/index.ts | 1 - 3 files changed, 70 deletions(-) delete mode 100644 src/pages/dataElementGroups/edit/createJsonPatchOperations.spec.ts delete mode 100644 src/pages/dataElementGroups/edit/createJsonPatchOperations.ts delete mode 100644 src/pages/dataElementGroups/edit/index.ts diff --git a/src/pages/dataElementGroups/edit/createJsonPatchOperations.spec.ts b/src/pages/dataElementGroups/edit/createJsonPatchOperations.spec.ts deleted file mode 100644 index 422cf33c..00000000 --- a/src/pages/dataElementGroups/edit/createJsonPatchOperations.spec.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { createJsonPatchOperations } from './createJsonPatchOperations' - -describe('createJsonPatchOperations', () => { - describe('createJsonPatchOperations', () => { - it('should return an empty array if no dirty fields', () => { - const actual = createJsonPatchOperations({ - dirtyFields: {}, - originalValue: { id: 'foo' }, - values: {}, - }) - expect(actual).toEqual([]) - }) - - it('should return a json-patch payload for a single field', () => { - const actual = createJsonPatchOperations({ - dirtyFields: { name: true }, - originalValue: { - id: 'foo', - name: 'bar', - }, - values: { name: 'baz' }, - }) - const expected = [ - { - op: 'replace', - path: '/name', - value: 'baz', - }, - ] - expect(actual).toEqual(expected) - }) - - it('should return a json-patch payload with add if value does not exist in originalValue', () => { - const actual = createJsonPatchOperations({ - dirtyFields: { name: true }, - originalValue: { id: 'foo' }, - values: { name: 'baz' }, - }) - const expected = [ - { - op: 'add', - path: '/name', - value: 'baz', - }, - ] - expect(actual).toEqual(expected) - }) - }) -}) diff --git a/src/pages/dataElementGroups/edit/createJsonPatchOperations.ts b/src/pages/dataElementGroups/edit/createJsonPatchOperations.ts deleted file mode 100644 index bfdb1dea..00000000 --- a/src/pages/dataElementGroups/edit/createJsonPatchOperations.ts +++ /dev/null @@ -1,20 +0,0 @@ -import get from 'lodash/fp/get' -import { JsonPatchOperation } from '../../../types' - -interface FormatFormValuesArgs { - originalValue: unknown - dirtyFields: { [key in keyof FormValues]?: boolean } - values: FormValues -} - -export function createJsonPatchOperations({ - dirtyFields, - originalValue, - values, -}: FormatFormValuesArgs): JsonPatchOperation[] { - return Object.keys(dirtyFields).map((name) => ({ - op: get(name, originalValue) ? 'replace' : 'add', - path: `/${name.replace(/[.]/g, '/')}`, - value: get(name, values) || '', - })) -} diff --git a/src/pages/dataElementGroups/edit/index.ts b/src/pages/dataElementGroups/edit/index.ts deleted file mode 100644 index 0069ca37..00000000 --- a/src/pages/dataElementGroups/edit/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { createJsonPatchOperations } from './createJsonPatchOperations'