Skip to content

Commit

Permalink
fix(resource view): dsp app the resource viewer does not reload prope…
Browse files Browse the repository at this point in the history
…rly after deselecting a resource from the comparison viewer(Dev-1123) (#793)

* open image in new tab

* feat(resource.component): introduce forceResourceReload

* feat(resource.component): introduce forceReload

* feat(resource.component): pass forceResourceReload

* refactor(resourceIds): change to map (faster, shorter, less side effects)

* feat(reload resource): add force reload

* feat(reload resource): pass force reload

* feat(reload resource): pass force reload to comparison-component

* refactor(force reload): remove forceReload Input and simply compare the state of the iri

* refactor(force reload): remove forceReload Input

* refactor(force reload): remove forceResourceReload

* refactor(force reload): remove forceResourceReload

* refactor(forceReload): remove forceReload

* chore: restore from main
  • Loading branch information
domsteinbach committed Aug 11, 2022
1 parent e8adde9 commit f690a37
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/app/workspace/comparison/comparison.component.ts
Expand Up @@ -37,10 +37,7 @@ export class ComparisonComponent implements OnChanges {
ngOnChanges(): void {

if (this.resources && this.resources.length) {
this.resourceIds = [];
this.resources.forEach(res => {
this.resourceIds.push(res.id);
});
this.resourceIds = this.resources.map(res => res.id);
}

if (!this.noOfResources) {
Expand Down
9 changes: 6 additions & 3 deletions src/app/workspace/resource/resource.component.ts
Expand Up @@ -57,6 +57,8 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {

@Input() splitSizeChanged: SplitSize;

oldResourceIri: string; // for change detection

projectCode: string;

resourceUuid: string;
Expand Down Expand Up @@ -127,6 +129,7 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
this.valueUuid = params['value'];
if (this.projectCode && this.resourceUuid) {
this.resourceIri = this._resourceService.getResourceIri(this.projectCode, this.resourceUuid);
this.oldResourceIri = this.resourceIri;
}
this.getResource(this.resourceIri);
});
Expand Down Expand Up @@ -164,12 +167,11 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
}

ngOnInit() {

}

ngOnChanges(changes: { [propName: string]: SimpleChange }) {
// do not reload the whole resource when the split size has changed
if (this.splitSizeChanged) {
// do not reload the whole resource when the iri did not change
if (this.oldResourceIri === this.resourceIri) {
return;
}

Expand All @@ -185,6 +187,7 @@ export class ResourceComponent implements OnInit, OnChanges, OnDestroy {
if (this.resourceIri) {
this.getResource(this.resourceIri);
}
this.oldResourceIri = this.resourceIri;
}

ngOnDestroy() {
Expand Down
15 changes: 10 additions & 5 deletions src/app/workspace/results/results.component.html
@@ -1,23 +1,28 @@
<!-- In case if results present -->
<div class="content" *ngIf="searchParams">

<as-split direction="horizontal" (dragEnd)="splitSizeChanged = $event">
<as-split direction="horizontal" (dragEnd)="splitSize = $event">
<as-split-area [size]="40">
<app-list-view [search]="searchParams" [displayViewSwitch]="false" [withMultipleSelection]="true"
(selectedResources)="openSelectedResources($event)">
(selectedResources)="onSelectionChange($event)">
</app-list-view>
</as-split-area>
<as-split-area [size]="60" *ngIf="selectedResources?.count > 0" cdkScrollable>
<div [ngSwitch]="viewMode">
<!-- single resource view -->
<app-resource *ngSwitchCase="'single'" [resourceIri]="selectedResources.resInfo[0].id" [splitSizeChanged]="splitSizeChanged"></app-resource>
<app-resource *ngSwitchCase="'single'"
[resourceIri]="resourceIri"
[splitSizeChanged]="splitSize">
</app-resource>

<!-- intermediate view -->
<app-intermediate *ngSwitchCase="'intermediate'" [resources]="selectedResources" (action)="viewMode=$event"></app-intermediate>

<!-- multiple resources view / comparison viewer -->
<app-comparison *ngSwitchCase="'compare'" [noOfResources]="selectedResources.count"
[resources]="selectedResources.resInfo" [splitSizeChanged]="splitSizeChanged">
<app-comparison *ngSwitchCase="'compare'"
[noOfResources]="selectedResources.count"
[resources]="selectedResources.resInfo"
[splitSizeChanged]="splitSize">
</app-comparison>
</div>
</as-split-area>
Expand Down
8 changes: 4 additions & 4 deletions src/app/workspace/results/results.component.ts
Expand Up @@ -33,7 +33,7 @@ export class ResultsComponent {

loading = true;

splitSizeChanged: SplitSize;
splitSize: SplitSize;

constructor(
private _route: ActivatedRoute,
Expand Down Expand Up @@ -61,18 +61,18 @@ export class ResultsComponent {
this._titleService.setTitle('Search results for ' + this.searchParams.mode + ' search');
}

openSelectedResources(res: FilteredResources) {

onSelectionChange(res: FilteredResources) {
this.selectedResources = res;
this.resourceIri = this.selectedResources.resInfo[0].id;

if (!res || res.count <= 1) {
this.viewMode = 'single';

} else {
if (this.viewMode !== 'compare') {
this.viewMode = ((res && res.count > 0) ? 'intermediate' : 'single');
}
}

}

}

0 comments on commit f690a37

Please sign in to comment.