Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion src/app/core/json-patch/json-patch-operations.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const JsonPatchOperationsActionTypes = {
ROLLBACK_JSON_PATCH_OPERATIONS: type('dspace/core/patch/ROLLBACK_JSON_PATCH_OPERATIONS'),
FLUSH_JSON_PATCH_OPERATIONS: type('dspace/core/patch/FLUSH_JSON_PATCH_OPERATIONS'),
START_TRANSACTION_JSON_PATCH_OPERATIONS: type('dspace/core/patch/START_TRANSACTION_JSON_PATCH_OPERATIONS'),
DELETE_PENDING_JSON_PATCH_OPERATIONS: type('dspace/core/patch/DELETE_PENDING_JSON_PATCH_OPERATIONS'),
};

/* tslint:disable:max-classes-per-file */
Expand Down Expand Up @@ -261,6 +262,13 @@ export class NewPatchReplaceOperationAction implements Action {
}
}

/**
* An ngrx action to delete all pending JSON Patch Operations.
*/
export class DeletePendingJsonPatchOperationsAction implements Action {
type = JsonPatchOperationsActionTypes.DELETE_PENDING_JSON_PATCH_OPERATIONS;
}

/* tslint:enable:max-classes-per-file */

/**
Expand All @@ -276,4 +284,5 @@ export type PatchOperationsActions
| NewPatchRemoveOperationAction
| NewPatchReplaceOperationAction
| RollbacktPatchOperationsAction
| StartTransactionPatchOperationsAction;
| StartTransactionPatchOperationsAction
| DeletePendingJsonPatchOperationsAction;
17 changes: 16 additions & 1 deletion src/app/core/json-patch/json-patch-operations.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as deepFreeze from 'deep-freeze';

import {
CommitPatchOperationsAction,
CommitPatchOperationsAction, DeletePendingJsonPatchOperationsAction,
FlushPatchOperationsAction,
NewPatchAddOperationAction,
NewPatchRemoveOperationAction,
Expand Down Expand Up @@ -323,4 +323,19 @@ describe('jsonPatchOperationsReducer test suite', () => {

});

describe('When DeletePendingJsonPatchOperationsAction has been dispatched', () => {
it('should set set the JsonPatchOperationsState to null ', () => {
const action = new DeletePendingJsonPatchOperationsAction();
initState = Object.assign({}, testState, {
[testJsonPatchResourceType]: Object.assign({}, testState[testJsonPatchResourceType], {
transactionStartTime: startTimestamp,
commitPending: true
})
});
const newState = jsonPatchOperationsReducer(initState, action);

expect(newState).toBeNull();
});
});

});
21 changes: 20 additions & 1 deletion src/app/core/json-patch/json-patch-operations.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
NewPatchReplaceOperationAction,
CommitPatchOperationsAction,
StartTransactionPatchOperationsAction,
RollbacktPatchOperationsAction
RollbacktPatchOperationsAction,
DeletePendingJsonPatchOperationsAction
} from './json-patch-operations.actions';
import { JsonPatchOperationModel, JsonPatchOperationType } from './json-patch.model';

Expand Down Expand Up @@ -101,6 +102,10 @@ export function jsonPatchOperationsReducer(state = initialState, action: PatchOp
return startTransactionPatchOperations(state, action as StartTransactionPatchOperationsAction);
}

case JsonPatchOperationsActionTypes.DELETE_PENDING_JSON_PATCH_OPERATIONS: {
return deletePendingOperations(state, action as DeletePendingJsonPatchOperationsAction);
}

default: {
return state;
}
Expand Down Expand Up @@ -178,6 +183,20 @@ function rollbackOperations(state: JsonPatchOperationsState, action: RollbacktPa
}
}

/**
* Set the JsonPatchOperationsState to its initial value.
*
* @param state
* the current state
* @param action
* an DeletePendingJsonPatchOperationsAction
* @return JsonPatchOperationsState
* the new state.
*/
function deletePendingOperations(state: JsonPatchOperationsState, action: DeletePendingJsonPatchOperationsAction): JsonPatchOperationsState {
return null;
}

/**
* Add new JSON patch operation list.
*
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/json-patch/json-patch-operations.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { JsonPatchOperationsEntry, JsonPatchOperationsResourceEntry } from './json-patch-operations.reducer';
import {
CommitPatchOperationsAction,
DeletePendingJsonPatchOperationsAction,
RollbacktPatchOperationsAction,
StartTransactionPatchOperationsAction
} from './json-patch-operations.actions';
Expand Down Expand Up @@ -288,4 +289,19 @@ describe('JsonPatchOperationsService test suite', () => {
});
});

describe('deletePendingJsonPatchOperations', () => {
beforeEach(() => {
store.dispatch.and.callFake(() => { /* */ });
});

it('should dispatch a new DeletePendingJsonPatchOperationsAction', () => {

const expectedAction = new DeletePendingJsonPatchOperationsAction();
scheduler.schedule(() => service.deletePendingJsonPatchOperations());
scheduler.flush();

expect(store.dispatch).toHaveBeenCalledWith(expectedAction);
});
});

});
9 changes: 8 additions & 1 deletion src/app/core/json-patch/json-patch-operations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CoreState } from '../core.reducers';
import { jsonPatchOperationsByResourceType } from './selectors';
import { JsonPatchOperationsResourceEntry } from './json-patch-operations.reducer';
import {
CommitPatchOperationsAction,
CommitPatchOperationsAction, DeletePendingJsonPatchOperationsAction,
RollbacktPatchOperationsAction,
StartTransactionPatchOperationsAction
} from './json-patch-operations.actions';
Expand Down Expand Up @@ -105,6 +105,13 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
);
}

/**
* Dispatch an action to delete all pending JSON patch Operations.
*/
public deletePendingJsonPatchOperations() {
this.store.dispatch(new DeletePendingJsonPatchOperationsAction());
}

/**
* Return an instance for RestRequest class
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export class SubmissionJsonPatchOperationsServiceStub {

jsonPatchByResourceType = jasmine.createSpy('jsonPatchByResourceType');
jsonPatchByResourceID = jasmine.createSpy('jsonPatchByResourceID');
deletePendingJsonPatchOperations = jasmine.createSpy('deletePendingJsonPatchOperations');

}
17 changes: 17 additions & 0 deletions src/app/submission/edit/submission-edit.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
import { mockSubmissionObject } from '../../shared/mocks/submission.mock';
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
import { ItemDataService } from '../../core/data/item-data.service';
import { SubmissionJsonPatchOperationsServiceStub } from '../../shared/testing/submission-json-patch-operations-service.stub';
import { SubmissionJsonPatchOperationsService } from '../../core/submission/submission-json-patch-operations.service';

describe('SubmissionEditComponent Component', () => {

let comp: SubmissionEditComponent;
let fixture: ComponentFixture<SubmissionEditComponent>;
let submissionServiceStub: SubmissionServiceStub;
let itemDataService: ItemDataService;
let submissionJsonPatchOperationsServiceStub: SubmissionJsonPatchOperationsServiceStub;
let router: RouterStub;

const submissionId = '826';
Expand All @@ -46,6 +49,7 @@ describe('SubmissionEditComponent Component', () => {
providers: [
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: SubmissionService, useClass: SubmissionServiceStub },
{ provide: SubmissionJsonPatchOperationsService, useClass: SubmissionJsonPatchOperationsServiceStub },
{ provide: ItemDataService, useValue: itemDataService },
{ provide: TranslateService, useValue: getMockTranslateService() },
{ provide: Router, useValue: new RouterStub() },
Expand All @@ -60,6 +64,7 @@ describe('SubmissionEditComponent Component', () => {
fixture = TestBed.createComponent(SubmissionEditComponent);
comp = fixture.componentInstance;
submissionServiceStub = TestBed.inject(SubmissionService as any);
submissionJsonPatchOperationsServiceStub = TestBed.inject(SubmissionJsonPatchOperationsService as any);
router = TestBed.inject(Router as any);
});

Expand Down Expand Up @@ -112,4 +117,16 @@ describe('SubmissionEditComponent Component', () => {
expect(comp.submissionDefinition).toBeUndefined();
});

describe('ngOnDestroy', () => {
it('should call delete pending json patch operations', fakeAsync(() => {

submissionJsonPatchOperationsServiceStub.deletePendingJsonPatchOperations.and.callFake(() => { /* */ });
comp.ngOnDestroy();

expect(submissionJsonPatchOperationsServiceStub.deletePendingJsonPatchOperations).toHaveBeenCalled();
}));

});


});
6 changes: 5 additions & 1 deletion src/app/submission/edit/submission-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Item } from '../../core/shared/item.model';
import { getAllSucceededRemoteData } from '../../core/shared/operators';
import { ItemDataService } from '../../core/data/item-data.service';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
import { SubmissionJsonPatchOperationsService } from '../../core/submission/submission-json-patch-operations.service';

/**
* This component allows to edit an existing workspaceitem/workflowitem.
Expand Down Expand Up @@ -92,7 +93,8 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
private router: Router,
private itemDataService: ItemDataService,
private submissionService: SubmissionService,
private translate: TranslateService) {
private translate: TranslateService,
private submissionJsonPatchOperationsService: SubmissionJsonPatchOperationsService) {
}

/**
Expand Down Expand Up @@ -149,5 +151,7 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
this.subs
.filter((sub) => hasValue(sub))
.forEach((sub) => sub.unsubscribe());

this.submissionJsonPatchOperationsService.deletePendingJsonPatchOperations();
}
}