From 66832eeb28af5c96ea66f4438380ba6c5efd9aae Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Tue, 6 Feb 2024 16:53:30 +0100 Subject: [PATCH 1/3] embed the item to submission patch request to fix issue where the submission form would revert to the previous data on save --- src/app/core/json-patch/json-patch-operations.service.spec.ts | 4 ++-- src/app/core/json-patch/json-patch-operations.service.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/core/json-patch/json-patch-operations.service.spec.ts b/src/app/core/json-patch/json-patch-operations.service.spec.ts index 10fc2f2ed84..3fba1c6cf69 100644 --- a/src/app/core/json-patch/json-patch-operations.service.spec.ts +++ b/src/app/core/json-patch/json-patch-operations.service.spec.ts @@ -147,7 +147,7 @@ describe('JsonPatchOperationsService test suite', () => { }); it('should send a new SubmissionPatchRequest', () => { - const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref, patchOpBody); + const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref + '?embed=item', patchOpBody); scheduler.schedule(() => service.jsonPatchByResourceType(resourceEndpoint, resourceScope, testJsonPatchResourceType).subscribe()); scheduler.flush(); @@ -237,7 +237,7 @@ describe('JsonPatchOperationsService test suite', () => { }); it('should send a new SubmissionPatchRequest', () => { - const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref, patchOpBody); + const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref + '?embed=item', patchOpBody); scheduler.schedule(() => service.jsonPatchByResourceID(resourceEndpoint, resourceScope, testJsonPatchResourceType, testJsonPatchResourceId).subscribe()); scheduler.flush(); diff --git a/src/app/core/json-patch/json-patch-operations.service.ts b/src/app/core/json-patch/json-patch-operations.service.ts index 1dfbd404cc6..1b37665f220 100644 --- a/src/app/core/json-patch/json-patch-operations.service.ts +++ b/src/app/core/json-patch/json-patch-operations.service.ts @@ -18,6 +18,7 @@ import { getFirstCompletedRemoteData } from '../shared/operators'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteData } from '../data/remote-data'; import { CoreState } from '../core-state.model'; +import { URLCombiner } from '../url-combiner/url-combiner'; /** * An abstract class that provides methods to make JSON Patch requests. @@ -125,7 +126,7 @@ export abstract class JsonPatchOperationsService Date: Wed, 24 Apr 2024 10:54:54 +0200 Subject: [PATCH 2/3] move embed item fix to SubmissionJsonPatchOperationsService --- .../json-patch-operations.service.spec.ts | 4 ++-- .../json-patch/json-patch-operations.service.ts | 3 +-- ...ission-json-patch-operations.service.spec.ts | 15 +++++++++++++++ .../submission-json-patch-operations.service.ts | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/app/core/json-patch/json-patch-operations.service.spec.ts b/src/app/core/json-patch/json-patch-operations.service.spec.ts index 3fba1c6cf69..10fc2f2ed84 100644 --- a/src/app/core/json-patch/json-patch-operations.service.spec.ts +++ b/src/app/core/json-patch/json-patch-operations.service.spec.ts @@ -147,7 +147,7 @@ describe('JsonPatchOperationsService test suite', () => { }); it('should send a new SubmissionPatchRequest', () => { - const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref + '?embed=item', patchOpBody); + const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref, patchOpBody); scheduler.schedule(() => service.jsonPatchByResourceType(resourceEndpoint, resourceScope, testJsonPatchResourceType).subscribe()); scheduler.flush(); @@ -237,7 +237,7 @@ describe('JsonPatchOperationsService test suite', () => { }); it('should send a new SubmissionPatchRequest', () => { - const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref + '?embed=item', patchOpBody); + const expected = new SubmissionPatchRequest(requestService.generateRequestId(), resourceHref, patchOpBody); scheduler.schedule(() => service.jsonPatchByResourceID(resourceEndpoint, resourceScope, testJsonPatchResourceType, testJsonPatchResourceId).subscribe()); scheduler.flush(); diff --git a/src/app/core/json-patch/json-patch-operations.service.ts b/src/app/core/json-patch/json-patch-operations.service.ts index 1b37665f220..1dfbd404cc6 100644 --- a/src/app/core/json-patch/json-patch-operations.service.ts +++ b/src/app/core/json-patch/json-patch-operations.service.ts @@ -18,7 +18,6 @@ import { getFirstCompletedRemoteData } from '../shared/operators'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteData } from '../data/remote-data'; import { CoreState } from '../core-state.model'; -import { URLCombiner } from '../url-combiner/url-combiner'; /** * An abstract class that provides methods to make JSON Patch requests. @@ -126,7 +125,7 @@ export abstract class JsonPatchOperationsService { const rdbService = {} as RemoteDataBuildService; const halEndpointService = {} as HALEndpointService; + const uuid = '91ecbeda-99fe-42ac-9430-b9b75af56f78'; + const href = 'https://rest.api/some/self/link?with=maybe&a=few&other=parameters'; + function initTestService() { return new SubmissionJsonPatchOperationsService( requestService, @@ -37,4 +40,16 @@ describe('SubmissionJsonPatchOperationsService', () => { expect((service as any).patchRequestConstructor).toEqual(SubmissionPatchRequest); }); + describe(`getRequestInstance`, () => { + it(`should add a parameter to embed the item to the request URL`, () => { + const result = (service as any).getRequestInstance(uuid, href); + const resultURL = new URL(result.href); + expect(resultURL.searchParams.get('embed')).toEqual('item'); + + // if we delete the embed item param, it should be identical to the original url + resultURL.searchParams.delete('embed', 'item'); + expect(href).toEqual(resultURL.toString()); + }); + }); + }); diff --git a/src/app/core/submission/submission-json-patch-operations.service.ts b/src/app/core/submission/submission-json-patch-operations.service.ts index 5771c85b574..117056008a2 100644 --- a/src/app/core/submission/submission-json-patch-operations.service.ts +++ b/src/app/core/submission/submission-json-patch-operations.service.ts @@ -9,6 +9,7 @@ import { SubmitDataResponseDefinitionObject } from '../shared/submit-data-respon import { SubmissionPatchRequest } from '../data/request.models'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { CoreState } from '../core-state.model'; +import { URLCombiner } from '../url-combiner/url-combiner'; /** * A service that provides methods to make JSON Patch requests. @@ -27,4 +28,20 @@ export class SubmissionJsonPatchOperationsService extends JsonPatchOperationsSer super(); } + /** + * Return an instance for RestRequest class + * + * @param uuid + * The request uuid + * @param href + * The request href + * @param body + * The request body + * @return Object + * instance of PatchRequestDefinition + */ + protected getRequestInstance(uuid: string, href: string, body?: any): SubmissionPatchRequest { + return new this.patchRequestConstructor(uuid, new URLCombiner(href, '?embed=item').toString(), body); + } + } From 3edb663b21b817071a3bf6c31655ba268f5c6ef4 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Wed, 15 May 2024 13:28:19 -0500 Subject: [PATCH 3/3] Minor bug fix to specs --- .../submission/submission-json-patch-operations.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/submission/submission-json-patch-operations.service.spec.ts b/src/app/core/submission/submission-json-patch-operations.service.spec.ts index c67d171537d..b186c27c337 100644 --- a/src/app/core/submission/submission-json-patch-operations.service.spec.ts +++ b/src/app/core/submission/submission-json-patch-operations.service.spec.ts @@ -47,7 +47,7 @@ describe('SubmissionJsonPatchOperationsService', () => { expect(resultURL.searchParams.get('embed')).toEqual('item'); // if we delete the embed item param, it should be identical to the original url - resultURL.searchParams.delete('embed', 'item'); + resultURL.searchParams.delete('embed'); expect(href).toEqual(resultURL.toString()); }); });