Skip to content

Commit d8c8a43

Browse files
committed
[CST-6876] Refactoring workflow actions components in order to pass item and workflowitem objects down from paren search element component to children
1 parent ec375fb commit d8c8a43

22 files changed

+333
-149
lines changed

src/app/shared/mydspace-actions/claimed-task/abstract/claimed-task-actions-abstract.component.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import { RequestService } from '../../../../core/data/request.service';
1010
import { Observable } from 'rxjs';
1111
import { RemoteData } from '../../../../core/data/remote-data';
1212
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
13-
import { switchMap, take } from 'rxjs/operators';
13+
import { take } from 'rxjs/operators';
1414
import { CLAIMED_TASK } from '../../../../core/tasks/models/claimed-task-object.resource-type';
15-
import { getFirstSucceededRemoteDataPayload } from '../../../../core/shared/operators';
1615
import { Item } from '../../../../core/shared/item.model';
1716
import { MyDSpaceReloadableActionsComponent } from '../../mydspace-reloadable-actions';
17+
import { isEmpty } from '../../../empty.util';
1818

1919
/**
2020
* Abstract component for rendering a claimed task's action
@@ -36,13 +36,23 @@ export abstract class ClaimedTaskActionsAbstractComponent extends MyDSpaceReload
3636

3737
object: ClaimedTask;
3838

39+
/**
40+
* The item object that belonging to the ClaimedTask object
41+
*/
42+
item: Item;
43+
3944
/**
4045
* Anchor used to reload the pool task.
4146
*/
4247
itemUuid: string;
4348

4449
subs = [];
4550

51+
/**
52+
* The workflowitem object that belonging to the ClaimedTask object
53+
*/
54+
workflowitem: WorkflowItem;
55+
4656
protected constructor(protected injector: Injector,
4757
protected router: Router,
4858
protected notificationsService: NotificationsService,
@@ -85,16 +95,10 @@ export abstract class ClaimedTaskActionsAbstractComponent extends MyDSpaceReload
8595
* Retrieve the itemUuid.
8696
*/
8797
initReloadAnchor() {
88-
if (!(this.object as any).workflowitem) {
98+
if (isEmpty(this.item)) {
8999
return;
90100
}
91-
this.subs.push(this.object.workflowitem.pipe(
92-
getFirstSucceededRemoteDataPayload(),
93-
switchMap((workflowItem: WorkflowItem) => workflowItem.item.pipe(getFirstSucceededRemoteDataPayload())
94-
))
95-
.subscribe((item: Item) => {
96-
this.itemUuid = item.uuid;
97-
}));
101+
this.itemUuid = this.item.uuid;
98102
}
99103

100104
ngOnDestroy() {
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<ng-container *ngVar="(actionRD$ | async)?.payload as workflowAction">
22
<div class="mt-1 mb-3 space-children-mr">
3-
<ds-claimed-task-actions-loader *ngFor="let option of workflowAction?.options" [option]="option" [object]="object"
4-
(processCompleted)="this.processCompleted.emit($event)">
3+
<ds-claimed-task-actions-loader *ngFor="let option of workflowAction?.options"
4+
[item]="item"
5+
[option]="option"
6+
[object]="object"
7+
[workflowitem]="workflowitem"
8+
(processCompleted)="this.processCompleted.emit($event)">
59
</ds-claimed-task-actions-loader>
610

711
<button class="btn btn-primary workflow-view" ngbTooltip="{{'submission.workflow.generic.view-help' | translate}}"
8-
[routerLink]="[getWorkflowItemViewRoute((workflowitem$ | async))]">
12+
[routerLink]="[getWorkflowItemViewRoute(workflowitem)]">
913
<i class="fa fa-info-circle"></i> {{"submission.workflow.generic.view" | translate}}
1014
</button>
1115

12-
<ds-claimed-task-actions-loader [option]="returnToPoolOption" [object]="object"
13-
(processCompleted)="this.processCompleted.emit($event)">
16+
<ds-claimed-task-actions-loader [item]="item"
17+
[option]="returnToPoolOption"
18+
[object]="object"
19+
[workflowitem]="workflowitem"
20+
(processCompleted)="this.processCompleted.emit($event)">
1421
</ds-claimed-task-actions-loader>
1522
</div>
1623
</ng-container>

src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
33
import { Router } from '@angular/router';
44

55
import { of as observableOf } from 'rxjs';
6-
import { cold } from 'jasmine-marbles';
76
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
87

98
import { TranslateLoaderMock } from '../../mocks/translate-loader.mock';
@@ -123,7 +122,9 @@ describe('ClaimedTaskActionsComponent', () => {
123122
beforeEach(() => {
124123
fixture = TestBed.createComponent(ClaimedTaskActionsComponent);
125124
component = fixture.componentInstance;
125+
component.item = item;
126126
component.object = mockObject;
127+
component.workflowitem = workflowitem;
127128
notificationsServiceStub = TestBed.inject(NotificationsService as any);
128129
router = TestBed.inject(Router as any);
129130
fixture.detectChanges();
@@ -133,11 +134,11 @@ describe('ClaimedTaskActionsComponent', () => {
133134
component.object = null;
134135
component.initObjects(mockObject);
135136

137+
expect(component.item).toEqual(item);
138+
136139
expect(component.object).toEqual(mockObject);
137140

138-
expect(component.workflowitem$).toBeObservable(cold('(b|)', {
139-
b: rdWorkflowitem.payload
140-
}));
141+
expect(component.workflowitem).toEqual(workflowitem);
141142
});
142143

143144
it('should reload page on process completed', waitForAsync(() => {

src/app/shared/mydspace-actions/claimed-task/claimed-task-actions.component.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { Component, Injector, Input, OnInit } from '@angular/core';
22
import { Router } from '@angular/router';
33

44
import { Observable } from 'rxjs';
5-
import { filter, map, take } from 'rxjs/operators';
65
import { TranslateService } from '@ngx-translate/core';
76

87
import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.service';
98
import { ClaimedTask } from '../../../core/tasks/models/claimed-task-object.model';
10-
import { isNotUndefined } from '../../empty.util';
119
import { WorkflowItem } from '../../../core/submission/models/workflowitem.model';
1210
import { RemoteData } from '../../../core/data/remote-data';
1311
import { MyDSpaceActionsComponent } from '../mydspace-actions';
@@ -18,6 +16,7 @@ import { WorkflowAction } from '../../../core/tasks/models/workflow-action-objec
1816
import { WorkflowActionDataService } from '../../../core/data/workflow-action-data.service';
1917
import { WORKFLOW_TASK_OPTION_RETURN_TO_POOL } from './return-to-pool/claimed-task-actions-return-to-pool.component';
2018
import { getWorkflowItemViewRoute } from '../../../workflowitems-edit-page/workflowitems-edit-page-routing-paths';
19+
import { Item } from '../../../core/shared/item.model';
2120

2221
/**
2322
* This component represents actions related to ClaimedTask object.
@@ -34,10 +33,15 @@ export class ClaimedTaskActionsComponent extends MyDSpaceActionsComponent<Claime
3433
*/
3534
@Input() object: ClaimedTask;
3635

36+
/**
37+
* The item object that belonging to the ClaimedTask object
38+
*/
39+
@Input() item: Item;
40+
3741
/**
3842
* The workflowitem object that belonging to the ClaimedTask object
3943
*/
40-
public workflowitem$: Observable<WorkflowItem>;
44+
@Input() workflowitem: WorkflowItem;
4145

4246
/**
4347
* The workflow action available for this task
@@ -87,11 +91,6 @@ export class ClaimedTaskActionsComponent extends MyDSpaceActionsComponent<Claime
8791
*/
8892
initObjects(object: ClaimedTask) {
8993
this.object = object;
90-
91-
this.workflowitem$ = (this.object.workflowitem as Observable<RemoteData<WorkflowItem>>).pipe(
92-
filter((rd: RemoteData<WorkflowItem>) => ((!rd.isRequestPending) && isNotUndefined(rd.payload))),
93-
map((rd: RemoteData<WorkflowItem>) => rd.payload),
94-
take(1));
9594
}
9695

9796
/**

src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.spec.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ClaimedTaskActionsLoaderComponent } from './claimed-task-actions-loader.component';
2-
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
33
import { ChangeDetectionStrategy, Injector, NO_ERRORS_SCHEMA } from '@angular/core';
44
import { ClaimedTaskActionsDirective } from './claimed-task-actions.directive';
55
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
@@ -15,6 +15,8 @@ import { RequestService } from '../../../../core/data/request.service';
1515
import { PoolTaskDataService } from '../../../../core/tasks/pool-task-data.service';
1616
import { getMockSearchService } from '../../../mocks/search-service.mock';
1717
import { getMockRequestService } from '../../../mocks/request.service.mock';
18+
import { Item } from '../../../../core/shared/item.model';
19+
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
1820

1921
const searchService = getMockSearchService();
2022

@@ -27,6 +29,37 @@ describe('ClaimedTaskActionsLoaderComponent', () => {
2729
const option = 'test_option';
2830
const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' });
2931

32+
const item = Object.assign(new Item(), {
33+
metadata: {
34+
'dc.title': [
35+
{
36+
language: 'en_US',
37+
value: 'This is just another title'
38+
}
39+
],
40+
'dc.type': [
41+
{
42+
language: null,
43+
value: 'Article'
44+
}
45+
],
46+
'dc.contributor.author': [
47+
{
48+
language: 'en_US',
49+
value: 'Smith, Donald'
50+
}
51+
],
52+
'dc.date.issued': [
53+
{
54+
language: null,
55+
value: '2015-06-26'
56+
}
57+
]
58+
}
59+
});
60+
61+
const workflowitem = Object.assign(new WorkflowItem(), { id: '333' });
62+
3063
beforeEach(waitForAsync(() => {
3164
TestBed.configureTestingModule({
3265
imports: [TranslateModule.forRoot()],
@@ -52,8 +85,10 @@ describe('ClaimedTaskActionsLoaderComponent', () => {
5285
beforeEach(waitForAsync(() => {
5386
fixture = TestBed.createComponent(ClaimedTaskActionsLoaderComponent);
5487
comp = fixture.componentInstance;
88+
comp.item = item;
5589
comp.object = object;
5690
comp.option = option;
91+
comp.workflowitem = workflowitem;
5792
spyOn(comp, 'getComponentByWorkflowTaskOption').and.returnValue(ClaimedTaskActionsEditMetadataComponent);
5893

5994
fixture.detectChanges();

src/app/shared/mydspace-actions/claimed-task/switcher/claimed-task-actions-loader.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { ClaimedTaskActionsAbstractComponent } from '../abstract/claimed-task-ac
1515
import { hasValue } from '../../../empty.util';
1616
import { Subscription } from 'rxjs';
1717
import { MyDSpaceActionsResult } from '../../mydspace-actions';
18+
import { Item } from '../../../../core/shared/item.model';
19+
import { WorkflowItem } from '../../../../core/submission/models/workflowitem.model';
1820

1921
@Component({
2022
selector: 'ds-claimed-task-actions-loader',
@@ -25,6 +27,11 @@ import { MyDSpaceActionsResult } from '../../mydspace-actions';
2527
* Passes on the ClaimedTask to the component and subscribes to the processCompleted output
2628
*/
2729
export class ClaimedTaskActionsLoaderComponent implements OnInit, OnDestroy {
30+
/**
31+
* The item object that belonging to the ClaimedTask object
32+
*/
33+
@Input() item: Item;
34+
2835
/**
2936
* The ClaimedTask object
3037
*/
@@ -36,6 +43,11 @@ export class ClaimedTaskActionsLoaderComponent implements OnInit, OnDestroy {
3643
*/
3744
@Input() option: string;
3845

46+
/**
47+
* The workflowitem object that belonging to the ClaimedTask object
48+
*/
49+
@Input() workflowitem: WorkflowItem;
50+
3951
/**
4052
* Emits the success or failure of a processed action
4153
*/
@@ -69,7 +81,9 @@ export class ClaimedTaskActionsLoaderComponent implements OnInit, OnDestroy {
6981

7082
const componentRef = viewContainerRef.createComponent(componentFactory);
7183
const componentInstance = (componentRef.instance as ClaimedTaskActionsAbstractComponent);
84+
componentInstance.item = this.item;
7285
componentInstance.object = this.object;
86+
componentInstance.workflowitem = this.workflowitem;
7387
if (hasValue(componentInstance.processCompleted)) {
7488
this.subs.push(componentInstance.processCompleted.subscribe((result) => this.processCompleted.emit(result)));
7589
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import { RouterStub } from '../testing/router.stub';
1212
import { getMockSearchService } from '../mocks/search-service.mock';
1313
import { getMockRequestService } from '../mocks/request.service.mock';
1414
import { Item } from '../../core/shared/item.model';
15-
import {
16-
createFailedRemoteDataObject,
17-
createSuccessfulRemoteDataObject
18-
} from '../remote-data.utils';
15+
import { createFailedRemoteDataObject, createSuccessfulRemoteDataObject } from '../remote-data.utils';
1916
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
2017
import { TranslateLoaderMock } from '../mocks/translate-loader.mock';
2118
import { NotificationsService } from '../notifications/notifications.service';
@@ -103,7 +100,9 @@ describe('MyDSpaceReloadableActionsComponent', () => {
103100
beforeEach(() => {
104101
fixture = TestBed.createComponent(PoolTaskActionsComponent);
105102
component = fixture.componentInstance;
103+
component.item = item;
106104
component.object = mockObject;
105+
component.workflowitem = workflowitem;
107106
notificationsServiceStub = TestBed.get(NotificationsService);
108107
router = TestBed.get(Router);
109108
fixture.detectChanges();

src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</button>
99
<button class="btn btn-primary workflow-view ml-1 mt-1 mb-3" data-test="view-btn"
1010
ngbTooltip="{{'submission.workflow.generic.view-help' | translate}}"
11-
[routerLink]="[getWorkflowItemViewRoute((workflowitem$ | async))]">
11+
[routerLink]="[getWorkflowItemViewRoute(workflowitem)]">
1212
<i class="fa fa-info-circle"></i> {{"submission.workflow.generic.view" | translate}}
1313
</button>

src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Router } from '@angular/router';
44
import { By } from '@angular/platform-browser';
55

66
import { of as observableOf } from 'rxjs';
7-
import { cold } from 'jasmine-marbles';
87
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
98

109
import { TranslateLoaderMock } from '../../mocks/translate-loader.mock';
@@ -105,7 +104,9 @@ describe('PoolTaskActionsComponent', () => {
105104
beforeEach(() => {
106105
fixture = TestBed.createComponent(PoolTaskActionsComponent);
107106
component = fixture.componentInstance;
107+
component.item = item;
108108
component.object = mockObject;
109+
component.workflowitem = workflowitem;
109110
notificationsServiceStub = TestBed.inject(NotificationsService as any);
110111
router = TestBed.inject(Router as any);
111112
fixture.detectChanges();
@@ -120,11 +121,11 @@ describe('PoolTaskActionsComponent', () => {
120121
component.object = null;
121122
component.initObjects(mockObject);
122123

124+
expect(component.item).toEqual(item);
125+
123126
expect(component.object).toEqual(mockObject);
124127

125-
expect(component.workflowitem$).toBeObservable(cold('(b|)', {
126-
b: rdWorkflowitem.payload
127-
}));
128+
expect(component.workflowitem).toEqual(workflowitem);
128129
});
129130

130131
it('should display claim task button', () => {

0 commit comments

Comments
 (0)