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
|
||||
*/
|
||||
onSubmit() {
|
||||
this.registryService.clearMetadataFieldRequests().subscribe();
|
||||
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
||||
(field) => {
|
||||
const values = {
|
||||
|
@@ -91,7 +91,7 @@ export class MetadataSchemaComponent implements OnInit {
|
||||
if (update) {
|
||||
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
|
||||
*/
|
||||
public forceUpdateFields() {
|
||||
this.registryService.clearMetadataFieldRequests();
|
||||
this.needsUpdate$.next(true);
|
||||
}
|
||||
|
||||
@@ -160,7 +161,6 @@ export class MetadataSchemaComponent implements OnInit {
|
||||
* Delete all the selected metadata fields
|
||||
*/
|
||||
deleteFields() {
|
||||
this.registryService.clearMetadataFieldRequests().subscribe();
|
||||
this.registryService.getSelectedMetadataFields().pipe(take(1)).subscribe(
|
||||
(fields) => {
|
||||
const tasks$ = [];
|
||||
@@ -174,6 +174,8 @@ export class MetadataSchemaComponent implements OnInit {
|
||||
const failedResponses = responses.filter((response: RemoteData<NoContent>) => response.hasFailed);
|
||||
if (successResponses.length > 0) {
|
||||
this.showNotification(true, successResponses.length);
|
||||
this.registryService.clearMetadataFieldRequests();
|
||||
|
||||
}
|
||||
if (failedResponses.length > 0) {
|
||||
this.showNotification(false, failedResponses.length);
|
||||
|
@@ -33,7 +33,7 @@ describe('MetadataFieldDataService', () => {
|
||||
generateRequestId: '34cfed7c-f597-49ef-9cbe-ea351f0023c2',
|
||||
send: {},
|
||||
getByUUID: observableOf({ response: new RestResponse(true, 200, 'OK') }),
|
||||
removeByHrefSubstring: {}
|
||||
setStaleByHrefSubstring: {}
|
||||
});
|
||||
halService = Object.assign(new HALEndpointServiceStub(endpoint));
|
||||
notificationsService = jasmine.createSpyObj('notificationsService', {
|
||||
@@ -64,11 +64,10 @@ describe('MetadataFieldDataService', () => {
|
||||
});
|
||||
|
||||
describe('clearRequests', () => {
|
||||
it('should remove requests on the data service\'s endpoint', (done) => {
|
||||
metadataFieldService.clearRequests().subscribe(() => {
|
||||
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(`${endpoint}/${(metadataFieldService as any).linkPath}`);
|
||||
done();
|
||||
});
|
||||
it('should remove requests on the data service\'s endpoint', () => {
|
||||
spyOn(metadataFieldService, 'getBrowseEndpoint').and.returnValue(observableOf(endpoint));
|
||||
metadataFieldService.clearRequests();
|
||||
expect(requestService.setStaleByHrefSubstring).toHaveBeenCalledWith(endpoint);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -19,7 +19,7 @@ import { MetadataSchema } from '../metadata/metadata-schema.model';
|
||||
import { FindListOptions } from './request.models';
|
||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
import { Observable } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { tap, take } from 'rxjs/operators';
|
||||
import { RequestParam } from '../cache/models/request-param.model';
|
||||
|
||||
/**
|
||||
@@ -105,12 +105,11 @@ export class MetadataFieldDataService extends DataService<MetadataField> {
|
||||
* Clear all metadata field requests
|
||||
* Used for refreshing lists after adding/updating/removing a metadata field from a metadata schema
|
||||
*/
|
||||
clearRequests(): Observable<string> {
|
||||
return this.getBrowseEndpoint().pipe(
|
||||
tap((href: string) => {
|
||||
this.requestService.removeByHrefSubstring(href);
|
||||
})
|
||||
);
|
||||
clearRequests(): void {
|
||||
this.getBrowseEndpoint().pipe(take(1)).subscribe((href: string) => {
|
||||
this.requestService.setStaleByHrefSubstring(href);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -371,7 +371,7 @@ describe('RegistryService', () => {
|
||||
|
||||
describe('when clearMetadataSchemaRequests is called', () => {
|
||||
beforeEach(() => {
|
||||
registryService.clearMetadataSchemaRequests().subscribe();
|
||||
registryService.clearMetadataSchemaRequests();
|
||||
});
|
||||
|
||||
it('should remove the requests related to metadata schemas from cache', () => {
|
||||
@@ -381,7 +381,7 @@ describe('RegistryService', () => {
|
||||
|
||||
describe('when clearMetadataFieldRequests is called', () => {
|
||||
beforeEach(() => {
|
||||
registryService.clearMetadataFieldRequests().subscribe();
|
||||
registryService.clearMetadataFieldRequests();
|
||||
});
|
||||
|
||||
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
|
||||
*/
|
||||
public clearMetadataFieldRequests(): Observable<string> {
|
||||
return this.metadataFieldService.clearRequests();
|
||||
public clearMetadataFieldRequests(): void {
|
||||
this.metadataFieldService.clearRequests();
|
||||
}
|
||||
|
||||
private showNotifications(success: boolean, edited: boolean, isField: boolean, options: any) {
|
||||
|
Reference in New Issue
Block a user