Skip to content

Commit a94214a

Browse files
[DSC-2163] add page reload after import - cherry-picked from [CST-18837]
1 parent cd04bef commit a94214a

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/app/my-dspace-page/my-dspace-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="container">
22
<ds-suggestions-notification></ds-suggestions-notification>
3-
<ds-my-dspace-new-submission *dsShowOnlyForRole="[roleTypeEnum.Submitter]"></ds-my-dspace-new-submission>
3+
<ds-my-dspace-new-submission (uploadEnd)="refreshData($event)" *dsShowOnlyForRole="[roleTypeEnum.Submitter]"></ds-my-dspace-new-submission>
44
</div>
55

66
<ds-search

src/app/my-dspace-page/my-dspace-page.component.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { MyDSpaceConfigurationValueType } from './my-dspace-configuration-value-
1515
import { Context } from '../core/shared/context.model';
1616
import SpyObj = jasmine.SpyObj;
1717
import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service';
18+
import { RequestService } from '../core/data/request.service';
19+
import { getMockRequestService } from '../shared/mocks/request.service.mock';
20+
import { RequestEntry } from '../core/data/request-entry.model';
1821

1922
describe('MyDSpacePageComponent', () => {
2023
let comp: MyDSpacePageComponent;
@@ -42,6 +45,12 @@ describe('MyDSpacePageComponent', () => {
4245
}
4346
];
4447

48+
const getRequestEntry$ = (successful: boolean) => {
49+
return observableOf({
50+
response: { isSuccessful: successful, payload: {} } as any
51+
} as RequestEntry);
52+
};
53+
4554
const selectableListService = jasmine.createSpyObj('selectableListService', {
4655
selectSingle: jasmine.createSpy('selectSingle'),
4756
deselectSingle: jasmine.createSpy('deselectSingle'),
@@ -63,6 +72,10 @@ describe('MyDSpacePageComponent', () => {
6372
{
6473
provide: SEARCH_CONFIG_SERVICE,
6574
useValue: myDSpaceConfigurationServiceStub
75+
},
76+
{
77+
provide: RequestService,
78+
useValue: getMockRequestService(getRequestEntry$(true))
6679
}
6780
]
6881
}

src/app/my-dspace-page/my-dspace-page.component.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ChangeDetectionStrategy, Component, Inject, InjectionToken, OnInit } from '@angular/core';
22

33
import { Observable } from 'rxjs';
4-
import { take } from 'rxjs/operators';
4+
import { take, tap } from 'rxjs/operators';
55

66
import { SearchService } from '../core/shared/search/search.service';
77
import { MyDSpaceResponseParsingService } from '../core/data/mydspace-response-parsing.service';
@@ -12,6 +12,10 @@ import { ViewMode } from '../core/shared/view-mode.model';
1212
import { MyDSpaceRequest } from '../core/data/request.models';
1313
import { Context } from '../core/shared/context.model';
1414
import { RoleType } from '../core/roles/role-types';
15+
import { Router } from '@angular/router';
16+
import { SearchResult } from '../shared/search/models/search-result.model';
17+
import { DSpaceObject } from '../core/shared/dspace-object.model';
18+
import { RequestService } from '../core/data/request.service';
1519
import { MyDSpaceConfigurationValueType } from './my-dspace-configuration-value-type';
1620
import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service';
1721
import { PoolTaskSearchResult } from '../shared/object-collection/shared/pool-task-search-result.model';
@@ -75,6 +79,8 @@ export class MyDSpacePageComponent implements OnInit {
7579

7680
constructor(
7781
private service: SearchService,
82+
private router: Router,
83+
protected requestService: RequestService,
7884
protected selectableListService: SelectableListService,
7985
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: MyDSpaceConfigurationService
8086
) {
@@ -113,6 +119,25 @@ export class MyDSpacePageComponent implements OnInit {
113119

114120
}
115121

122+
/**
123+
* Refresh current page
124+
*/
125+
refreshData(searchResult: SearchResult<DSpaceObject>[]) {
126+
if (searchResult?.length > 0) {
127+
// We use the same logic as the workspace action component as the search component need the cache to be emptied and the page to be reloaded
128+
this.router.navigated = false;
129+
const url = decodeURIComponent(this.router.url);
130+
// override the route reuse strategy
131+
this.router.routeReuseStrategy.shouldReuseRoute = () => {
132+
return false;
133+
};
134+
// This assures that the search cache is empty before reloading mydspace.
135+
this.service.getEndpoint().pipe(
136+
take(1),
137+
tap((cachedHref: string) => this.requestService.removeByHrefSubstring(cachedHref))
138+
).subscribe(() => this.router.navigateByUrl(url));
139+
}
140+
}
116141
/**
117142
* Deselect object from selection list
118143
* @param task

0 commit comments

Comments
 (0)