mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[DSC-76] Delete pending json patch operations
This commit is contained in:
@@ -20,6 +20,7 @@ export const JsonPatchOperationsActionTypes = {
|
|||||||
ROLLBACK_JSON_PATCH_OPERATIONS: type('dspace/core/patch/ROLLBACK_JSON_PATCH_OPERATIONS'),
|
ROLLBACK_JSON_PATCH_OPERATIONS: type('dspace/core/patch/ROLLBACK_JSON_PATCH_OPERATIONS'),
|
||||||
FLUSH_JSON_PATCH_OPERATIONS: type('dspace/core/patch/FLUSH_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'),
|
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 */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@@ -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 */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -276,4 +284,5 @@ export type PatchOperationsActions
|
|||||||
| NewPatchRemoveOperationAction
|
| NewPatchRemoveOperationAction
|
||||||
| NewPatchReplaceOperationAction
|
| NewPatchReplaceOperationAction
|
||||||
| RollbacktPatchOperationsAction
|
| RollbacktPatchOperationsAction
|
||||||
| StartTransactionPatchOperationsAction;
|
| StartTransactionPatchOperationsAction
|
||||||
|
| DeletePendingJsonPatchOperationsAction;
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import * as deepFreeze from 'deep-freeze';
|
import * as deepFreeze from 'deep-freeze';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CommitPatchOperationsAction,
|
CommitPatchOperationsAction, DeletePendingJsonPatchOperationsAction,
|
||||||
FlushPatchOperationsAction,
|
FlushPatchOperationsAction,
|
||||||
NewPatchAddOperationAction,
|
NewPatchAddOperationAction,
|
||||||
NewPatchRemoveOperationAction,
|
NewPatchRemoveOperationAction,
|
||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -11,7 +11,8 @@ import {
|
|||||||
NewPatchReplaceOperationAction,
|
NewPatchReplaceOperationAction,
|
||||||
CommitPatchOperationsAction,
|
CommitPatchOperationsAction,
|
||||||
StartTransactionPatchOperationsAction,
|
StartTransactionPatchOperationsAction,
|
||||||
RollbacktPatchOperationsAction
|
RollbacktPatchOperationsAction,
|
||||||
|
DeletePendingJsonPatchOperationsAction
|
||||||
} from './json-patch-operations.actions';
|
} from './json-patch-operations.actions';
|
||||||
import { JsonPatchOperationModel, JsonPatchOperationType } from './json-patch.model';
|
import { JsonPatchOperationModel, JsonPatchOperationType } from './json-patch.model';
|
||||||
|
|
||||||
@@ -101,6 +102,10 @@ export function jsonPatchOperationsReducer(state = initialState, action: PatchOp
|
|||||||
return startTransactionPatchOperations(state, action as StartTransactionPatchOperationsAction);
|
return startTransactionPatchOperations(state, action as StartTransactionPatchOperationsAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case JsonPatchOperationsActionTypes.DELETE_PENDING_JSON_PATCH_OPERATIONS: {
|
||||||
|
return deletePendingOperations(state, action as DeletePendingJsonPatchOperationsAction);
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@@ -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.
|
* Add new JSON patch operation list.
|
||||||
*
|
*
|
||||||
|
@@ -17,6 +17,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|||||||
import { JsonPatchOperationsEntry, JsonPatchOperationsResourceEntry } from './json-patch-operations.reducer';
|
import { JsonPatchOperationsEntry, JsonPatchOperationsResourceEntry } from './json-patch-operations.reducer';
|
||||||
import {
|
import {
|
||||||
CommitPatchOperationsAction,
|
CommitPatchOperationsAction,
|
||||||
|
DeletePendingJsonPatchOperationsAction,
|
||||||
RollbacktPatchOperationsAction,
|
RollbacktPatchOperationsAction,
|
||||||
StartTransactionPatchOperationsAction
|
StartTransactionPatchOperationsAction
|
||||||
} from './json-patch-operations.actions';
|
} from './json-patch-operations.actions';
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -10,7 +10,7 @@ import { CoreState } from '../core.reducers';
|
|||||||
import { jsonPatchOperationsByResourceType } from './selectors';
|
import { jsonPatchOperationsByResourceType } from './selectors';
|
||||||
import { JsonPatchOperationsResourceEntry } from './json-patch-operations.reducer';
|
import { JsonPatchOperationsResourceEntry } from './json-patch-operations.reducer';
|
||||||
import {
|
import {
|
||||||
CommitPatchOperationsAction,
|
CommitPatchOperationsAction, DeletePendingJsonPatchOperationsAction,
|
||||||
RollbacktPatchOperationsAction,
|
RollbacktPatchOperationsAction,
|
||||||
StartTransactionPatchOperationsAction
|
StartTransactionPatchOperationsAction
|
||||||
} from './json-patch-operations.actions';
|
} from './json-patch-operations.actions';
|
||||||
@@ -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
|
* Return an instance for RestRequest class
|
||||||
*
|
*
|
||||||
|
@@ -6,5 +6,6 @@ export class SubmissionJsonPatchOperationsServiceStub {
|
|||||||
|
|
||||||
jsonPatchByResourceType = jasmine.createSpy('jsonPatchByResourceType');
|
jsonPatchByResourceType = jasmine.createSpy('jsonPatchByResourceType');
|
||||||
jsonPatchByResourceID = jasmine.createSpy('jsonPatchByResourceID');
|
jsonPatchByResourceID = jasmine.createSpy('jsonPatchByResourceID');
|
||||||
|
deletePendingJsonPatchOperations = jasmine.createSpy('deletePendingJsonPatchOperations');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,8 @@ import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
|
|||||||
import { mockSubmissionObject } from '../../shared/mocks/submission.mock';
|
import { mockSubmissionObject } from '../../shared/mocks/submission.mock';
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
import { ItemDataService } from '../../core/data/item-data.service';
|
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', () => {
|
describe('SubmissionEditComponent Component', () => {
|
||||||
|
|
||||||
@@ -25,6 +27,7 @@ describe('SubmissionEditComponent Component', () => {
|
|||||||
let fixture: ComponentFixture<SubmissionEditComponent>;
|
let fixture: ComponentFixture<SubmissionEditComponent>;
|
||||||
let submissionServiceStub: SubmissionServiceStub;
|
let submissionServiceStub: SubmissionServiceStub;
|
||||||
let itemDataService: ItemDataService;
|
let itemDataService: ItemDataService;
|
||||||
|
let submissionJsonPatchOperationsServiceStub: SubmissionJsonPatchOperationsServiceStub;
|
||||||
let router: RouterStub;
|
let router: RouterStub;
|
||||||
|
|
||||||
const submissionId = '826';
|
const submissionId = '826';
|
||||||
@@ -46,6 +49,7 @@ describe('SubmissionEditComponent Component', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
{ provide: NotificationsService, useClass: NotificationsServiceStub },
|
||||||
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
{ provide: SubmissionService, useClass: SubmissionServiceStub },
|
||||||
|
{ provide: SubmissionJsonPatchOperationsService, useClass: SubmissionJsonPatchOperationsServiceStub },
|
||||||
{ provide: ItemDataService, useValue: itemDataService },
|
{ provide: ItemDataService, useValue: itemDataService },
|
||||||
{ provide: TranslateService, useValue: getMockTranslateService() },
|
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||||
{ provide: Router, useValue: new RouterStub() },
|
{ provide: Router, useValue: new RouterStub() },
|
||||||
@@ -60,6 +64,7 @@ describe('SubmissionEditComponent Component', () => {
|
|||||||
fixture = TestBed.createComponent(SubmissionEditComponent);
|
fixture = TestBed.createComponent(SubmissionEditComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||||
|
submissionJsonPatchOperationsServiceStub = TestBed.inject(SubmissionJsonPatchOperationsService as any);
|
||||||
router = TestBed.inject(Router as any);
|
router = TestBed.inject(Router as any);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -112,4 +117,16 @@ describe('SubmissionEditComponent Component', () => {
|
|||||||
expect(comp.submissionDefinition).toBeUndefined();
|
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();
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -17,6 +17,7 @@ import { Item } from '../../core/shared/item.model';
|
|||||||
import { getAllSucceededRemoteData } from '../../core/shared/operators';
|
import { getAllSucceededRemoteData } from '../../core/shared/operators';
|
||||||
import { ItemDataService } from '../../core/data/item-data.service';
|
import { ItemDataService } from '../../core/data/item-data.service';
|
||||||
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
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.
|
* This component allows to edit an existing workspaceitem/workflowitem.
|
||||||
@@ -92,7 +93,8 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private itemDataService: ItemDataService,
|
private itemDataService: ItemDataService,
|
||||||
private submissionService: SubmissionService,
|
private submissionService: SubmissionService,
|
||||||
private translate: TranslateService) {
|
private translate: TranslateService,
|
||||||
|
private submissionJsonPatchOperationsService: SubmissionJsonPatchOperationsService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,5 +151,7 @@ export class SubmissionEditComponent implements OnDestroy, OnInit {
|
|||||||
this.subs
|
this.subs
|
||||||
.filter((sub) => hasValue(sub))
|
.filter((sub) => hasValue(sub))
|
||||||
.forEach((sub) => sub.unsubscribe());
|
.forEach((sub) => sub.unsubscribe());
|
||||||
|
|
||||||
|
this.submissionJsonPatchOperationsService.deletePendingJsonPatchOperations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user