Skip to content

Commit b1f0ed2

Browse files
authored
Merge pull request #4234 from 4Science/task/main/DURACOM-350
[DURACOM-350] fix cache issue after mydspace action
2 parents 818f60b + 7998d2d commit b1f0ed2

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

src/app/shared/mydspace-actions/mydspace-actions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,25 @@ export abstract class MyDSpaceActionsComponent<T extends DSpaceObject, TService
101101
reload(): void {
102102

103103
this.router.navigated = false;
104-
const url = decodeURIComponent(this.router.url);
105104
// override the route reuse strategy
106105
this.router.routeReuseStrategy.shouldReuseRoute = () => {
107106
return false;
108107
};
109108
// This assures that the search cache is empty before reloading mydspace.
110109
// See https://github.com/DSpace/dspace-angular/pull/468
110+
this.invalidateCacheForCurrentSearchUrl(true);
111+
}
112+
113+
invalidateCacheForCurrentSearchUrl(shouldNavigate = false): void {
114+
const url = decodeURIComponent(this.router.url);
111115
this.searchService.getEndpoint().pipe(
112116
take(1),
113117
tap((cachedHref: string) => this.requestService.removeByHrefSubstring(cachedHref)),
114-
).subscribe(() => this.router.navigateByUrl(url));
118+
).subscribe(() => {
119+
if (shouldNavigate) {
120+
this.router.navigateByUrl(url);
121+
}
122+
});
115123
}
116124

117125
/**

src/app/shared/mydspace-actions/mydspace-reloadable-actions.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ describe('MyDSpaceReloadableActionsComponent', () => {
219219
spyOn(component, 'reloadObjectExecution').and.callThrough();
220220
spyOn(component, 'convertReloadedObject').and.callThrough();
221221
spyOn(component.processCompleted, 'emit').and.callThrough();
222+
spyOn(component, 'invalidateCacheForCurrentSearchUrl').and.callThrough();
222223

223224
(component as any).objectDataService = mockDataService;
224225
});
@@ -239,10 +240,11 @@ describe('MyDSpaceReloadableActionsComponent', () => {
239240
});
240241
});
241242

242-
it('should emit the reloaded object in case of success', (done) => {
243+
it('should emit the reloaded object and invalidate cache in case of success', (done) => {
243244

244245
component.startActionExecution().subscribe( (result) => {
245246
expect(component.processCompleted.emit).toHaveBeenCalledWith({ result: true, reloadedObject: result as any });
247+
expect(component.invalidateCacheForCurrentSearchUrl).toHaveBeenCalled();
246248
done();
247249
});
248250
});

src/app/shared/mydspace-actions/mydspace-reloadable-actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export abstract class MyDSpaceReloadableActionsComponent<T extends DSpaceObject,
105105
if (result) {
106106
if (reloadedObject) {
107107
this.processCompleted.emit({ result, reloadedObject });
108+
// Ensure that next time the page is requested the objects have the correct render type.
109+
this.invalidateCacheForCurrentSearchUrl();
108110
} else {
109111
this.reload();
110112
}

src/app/shared/search/search-filters/search-filter/search-filter.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
Subscription,
2626
switchMap,
2727
} from 'rxjs';
28-
import { take } from 'rxjs/operators';
2928

3029
import { RemoteData } from '../../../../core/data/remote-data';
3130
import { SearchService } from '../../../../core/shared/search/search.service';
@@ -145,7 +144,7 @@ export class SearchFilterComponent implements OnInit, OnChanges, OnDestroy {
145144
this.filterService.expand(this.filter.name);
146145
}
147146
}),
148-
this.getIsActive().pipe(take(1)).subscribe(() => {
147+
this.getIsActive().subscribe(() => {
149148
this.isVisibilityComputed.emit(true);
150149
}),
151150
);

src/app/shared/search/search-filters/search-filters.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ <h2>{{filterLabel+'.filters.head' | translate}}</h2>
55
}
66

77
@if ((filters | async)?.hasSucceeded) {
8-
<div [class.visually-hidden]="getFinalFiltersComputed(this.currentConfiguration) !== (filters | async)?.payload?.length">
8+
<div [class.visually-hidden]="getCurrentFiltersComputed(this.currentConfiguration) < (filters | async)?.payload?.length">
99
@for (filter of (filters | async)?.payload; track filter.name) {
1010
<ds-search-filter (isVisibilityComputed)="countFiltersWithComputedVisibility($event)" [scope]="currentScope" [filter]="filter" [inPlaceSearch]="inPlaceSearch" [refreshFilters]="refreshFilters"></ds-search-filter>
1111
}
1212
</div>
1313
}
1414

15-
@if(getFinalFiltersComputed(this.currentConfiguration) !== (filters | async)?.payload?.length) {
15+
@if(getCurrentFiltersComputed(this.currentConfiguration) < (filters | async)?.payload?.length) {
1616
<ngx-skeleton-loader [count]="defaultFilterCount"/>
1717
}
1818

src/app/shared/search/search-filters/search-filters.component.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,8 @@ export class SearchFiltersComponent implements OnInit {
251251
* @param configuration The configuration identifier to get the count for
252252
* @returns The number of computed filters, or 0 if none found
253253
*/
254-
private getCurrentFiltersComputed(configuration: string) {
254+
getCurrentFiltersComputed(configuration: string): number {
255255
const configFilter = this.findConfigInCurrentFilters(configuration);
256256
return configFilter?.filtersComputed || 0;
257257
}
258-
259-
/**
260-
* Gets the final number of computed filters for a specific configuration
261-
* @param configuration The configuration identifier to get the count for
262-
* @returns The number of computed filters in the final state, or 0 if none found
263-
*/
264-
getFinalFiltersComputed(configuration: string): number {
265-
const configFilter = this.findConfigInFinalFilters(configuration);
266-
return configFilter?.filtersComputed || 0;
267-
}
268258
}

0 commit comments

Comments
 (0)