mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
fix issue where a bunch of unnecessary requests where made when creating or removing a metadata field
This commit is contained in:
@@ -158,7 +158,6 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
|
|||||||
* Emit the updated/created field using the EventEmitter submitForm
|
* Emit the updated/created field using the EventEmitter submitForm
|
||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
this.registryService.clearMetadataFieldRequests().subscribe();
|
|
||||||
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
||||||
(field) => {
|
(field) => {
|
||||||
const values = {
|
const values = {
|
||||||
|
@@ -91,7 +91,7 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
if (update) {
|
if (update) {
|
||||||
this.needsUpdate$.next(false);
|
this.needsUpdate$.next(false);
|
||||||
}
|
}
|
||||||
return this.registryService.getMetadataFieldsBySchema(schema, toFindListOptions(this.config), !update, false, followLink('schema'));
|
return this.registryService.getMetadataFieldsBySchema(schema, toFindListOptions(this.config), !update, true);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -101,6 +101,7 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
* a new REST call
|
* a new REST call
|
||||||
*/
|
*/
|
||||||
public forceUpdateFields() {
|
public forceUpdateFields() {
|
||||||
|
this.registryService.clearMetadataFieldRequests();
|
||||||
this.needsUpdate$.next(true);
|
this.needsUpdate$.next(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +161,6 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
* Delete all the selected metadata fields
|
* Delete all the selected metadata fields
|
||||||
*/
|
*/
|
||||||
deleteFields() {
|
deleteFields() {
|
||||||
this.registryService.clearMetadataFieldRequests().subscribe();
|
|
||||||
this.registryService.getSelectedMetadataFields().pipe(take(1)).subscribe(
|
this.registryService.getSelectedMetadataFields().pipe(take(1)).subscribe(
|
||||||
(fields) => {
|
(fields) => {
|
||||||
const tasks$ = [];
|
const tasks$ = [];
|
||||||
@@ -174,6 +174,8 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
const failedResponses = responses.filter((response: RemoteData<NoContent>) => response.hasFailed);
|
const failedResponses = responses.filter((response: RemoteData<NoContent>) => response.hasFailed);
|
||||||
if (successResponses.length > 0) {
|
if (successResponses.length > 0) {
|
||||||
this.showNotification(true, successResponses.length);
|
this.showNotification(true, successResponses.length);
|
||||||
|
this.registryService.clearMetadataFieldRequests();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (failedResponses.length > 0) {
|
if (failedResponses.length > 0) {
|
||||||
this.showNotification(false, failedResponses.length);
|
this.showNotification(false, failedResponses.length);
|
||||||
|
@@ -33,7 +33,7 @@ describe('MetadataFieldDataService', () => {
|
|||||||
generateRequestId: '34cfed7c-f597-49ef-9cbe-ea351f0023c2',
|
generateRequestId: '34cfed7c-f597-49ef-9cbe-ea351f0023c2',
|
||||||
send: {},
|
send: {},
|
||||||
getByUUID: observableOf({ response: new RestResponse(true, 200, 'OK') }),
|
getByUUID: observableOf({ response: new RestResponse(true, 200, 'OK') }),
|
||||||
removeByHrefSubstring: {}
|
setStaleByHrefSubstring: {}
|
||||||
});
|
});
|
||||||
halService = Object.assign(new HALEndpointServiceStub(endpoint));
|
halService = Object.assign(new HALEndpointServiceStub(endpoint));
|
||||||
notificationsService = jasmine.createSpyObj('notificationsService', {
|
notificationsService = jasmine.createSpyObj('notificationsService', {
|
||||||
@@ -64,11 +64,10 @@ describe('MetadataFieldDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('clearRequests', () => {
|
describe('clearRequests', () => {
|
||||||
it('should remove requests on the data service\'s endpoint', (done) => {
|
it('should remove requests on the data service\'s endpoint', () => {
|
||||||
metadataFieldService.clearRequests().subscribe(() => {
|
spyOn(metadataFieldService, 'getBrowseEndpoint').and.returnValue(observableOf(endpoint));
|
||||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(`${endpoint}/${(metadataFieldService as any).linkPath}`);
|
metadataFieldService.clearRequests();
|
||||||
done();
|
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith(endpoint);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -19,7 +19,7 @@ import { MetadataSchema } from '../metadata/metadata-schema.model';
|
|||||||
import { FindListOptions } from './request.models';
|
import { FindListOptions } from './request.models';
|
||||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { tap } from 'rxjs/operators';
|
import { tap, take } from 'rxjs/operators';
|
||||||
import { RequestParam } from '../cache/models/request-param.model';
|
import { RequestParam } from '../cache/models/request-param.model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,12 +105,11 @@ export class MetadataFieldDataService extends DataService<MetadataField> {
|
|||||||
* Clear all metadata field requests
|
* Clear all metadata field requests
|
||||||
* Used for refreshing lists after adding/updating/removing a metadata field from a metadata schema
|
* Used for refreshing lists after adding/updating/removing a metadata field from a metadata schema
|
||||||
*/
|
*/
|
||||||
clearRequests(): Observable<string> {
|
clearRequests(): void {
|
||||||
return this.getBrowseEndpoint().pipe(
|
this.getBrowseEndpoint().pipe(take(1)).subscribe((href: string) => {
|
||||||
tap((href: string) => {
|
this.requestService.setStaleByHrefSubstring(href);
|
||||||
this.requestService.removeByHrefSubstring(href);
|
});
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -371,7 +371,7 @@ describe('RegistryService', () => {
|
|||||||
|
|
||||||
describe('when clearMetadataSchemaRequests is called', () => {
|
describe('when clearMetadataSchemaRequests is called', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
registryService.clearMetadataSchemaRequests().subscribe();
|
registryService.clearMetadataSchemaRequests();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove the requests related to metadata schemas from cache', () => {
|
it('should remove the requests related to metadata schemas from cache', () => {
|
||||||
@@ -381,7 +381,7 @@ describe('RegistryService', () => {
|
|||||||
|
|
||||||
describe('when clearMetadataFieldRequests is called', () => {
|
describe('when clearMetadataFieldRequests is called', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
registryService.clearMetadataFieldRequests().subscribe();
|
registryService.clearMetadataFieldRequests();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove the requests related to metadata fields from cache', () => {
|
it('should remove the requests related to metadata fields from cache', () => {
|
||||||
|
@@ -280,8 +280,8 @@ export class RegistryService {
|
|||||||
/**
|
/**
|
||||||
* Method that clears a cached metadata field request and returns its REST url
|
* Method that clears a cached metadata field request and returns its REST url
|
||||||
*/
|
*/
|
||||||
public clearMetadataFieldRequests(): Observable<string> {
|
public clearMetadataFieldRequests(): void {
|
||||||
return this.metadataFieldService.clearRequests();
|
this.metadataFieldService.clearRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
private showNotifications(success: boolean, edited: boolean, isField: boolean, options: any) {
|
private showNotifications(success: boolean, edited: boolean, isField: boolean, options: any) {
|
||||||
|
Reference in New Issue
Block a user