Skip to content

Commit 73f2127

Browse files
authored
fix: TT-24 Display project type in projects table (#685)
* fix: TT-24 Display project type in projects table * fix: TT-24 Solving code smell problem and some fail test * fix: TT-24 rename some variables
1 parent 3b5bb5c commit 73f2127

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

src/app/modules/customer-management/components/projects/components/project-list/project-list.component.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
<thead class="thead-blue">
44
<tr class="d-flex">
55
<th scope="col" class="col-4 text-center">Project ID</th>
6-
<th scope="col" class="col-4 text-center">Project</th>
7-
<th scope="col" class="col-2 text-center">Options</th>
8-
<th scope="col" class="col-2 text-center">Visibility</th>
6+
<th scope="col" class="col-3 text-center">Project</th>
7+
<th scope="col" class="col-3 text-center">Project Type</th>
8+
<th scope="col" class="col-1 text-center">Options</th>
9+
<th scope="col" class="col-1 text-center">Visibility</th>
910
</tr>
1011
</thead>
1112
<tbody>
1213
<tr class="d-flex" *ngFor="let project of projects">
1314
<td class="col-sm-4">{{ project.id }}</td>
14-
<td class="col-sm-4">{{ project.name }}</td>
15-
<td class="col-sm-2 text-center">
15+
<td class="col-sm-3">{{ project.name }}</td>
16+
<td class="col-sm-3">{{ getProjectTypeName(project.project_type_id) }}</td>
17+
<td class="col-sm-1 text-center">
1618
<button type="button" class="btn btn-sm btn-primary" (click)="updateProject(project)">
1719
<i class="fa fa-pencil fa-xs"></i>
1820
</button>
1921
</td>
20-
<td class="col-sm-2 text-center">
21-
<button
22+
<td class="col-sm-1 text-center">
23+
<button
2224
class="btn btn-sm"
23-
data-toggle="modal"
25+
data-toggle="modal"
2426
data-target="#deleteModal"
2527
[ngClass]="project.btnColor"
2628
(click)="switchStatus(project)"

src/app/modules/customer-management/components/projects/components/project-list/project-list.component.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,44 @@ describe('ProjectListComponent', () => {
154154
component.switchStatus(itemData);
155155
expect(component.showModal).toBeFalse();
156156
});
157+
158+
it('getProjectType should be called to display it in projects table', () => {
159+
const projectType = {
160+
id: '1234',
161+
name: 'BK',
162+
description: 'test',
163+
};
164+
const id = '1234';
165+
166+
component.projectsTypes = [projectType];
167+
component.ngOnInit();
168+
169+
const projectNameTest = component.getProjectTypeName(id);
170+
expect(projectNameTest).toBe('BK');
171+
});
172+
173+
it('projects table should display Project Type', (done) => {
174+
const projectType = {
175+
id: '1234',
176+
name: 'BK',
177+
description: 'test',
178+
};
179+
180+
component.projectsTypes = [projectType];
181+
fixture.detectChanges();
182+
fixture.whenStable().then(() => {
183+
fixture.detectChanges();
184+
185+
const tableRows = fixture.nativeElement.querySelectorAll('tr');
186+
expect(tableRows.length).toBe(2);
187+
188+
const headerRow = tableRows[0];
189+
expect(headerRow.cells[2].innerHTML).toBe('Project Type');
190+
191+
const dataRow = tableRows[1];
192+
expect(dataRow.cells[2].innerHTML).toBe('BK');
193+
194+
done();
195+
});
196+
});
157197
});

src/app/modules/customer-management/components/projects/components/project-list/project-list.component.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { ProjectState } from '../store/project.reducer';
66
import { getCustomerProjects } from '../store/project.selectors';
77
import * as actions from '../store/project.actions';
88
import { ProjectUI } from '../../../../../shared/models/project.model';
9+
import { allProjectTypes, ProjectTypeState } from '../../../projects-type/store';
10+
import { ProjectType } from 'src/app/modules/shared/models';
911

1012
@Component({
1113
selector: 'app-project-list',
@@ -17,14 +19,19 @@ export class ProjectListComponent implements OnInit, OnDestroy {
1719
itemsPerPage = ITEMS_PER_PAGE;
1820
isLoading = false;
1921
projects: ProjectUI[] = [];
22+
projectsTypes: ProjectType[] = [];
2023
filterProjects = '';
2124
showModal = false;
2225
idToDelete: string;
2326
message: string;
2427

2528
projectsSubscription: Subscription;
29+
projectTypesSubscription: Subscription;
2630

27-
constructor(private store: Store<ProjectState>) {}
31+
constructor(
32+
private store: Store<ProjectState>,
33+
private projectTypeStore: Store<ProjectTypeState>
34+
) {}
2835

2936
ngOnInit(): void {
3037
const btnProps = [
@@ -44,6 +51,13 @@ export class ProjectListComponent implements OnInit, OnDestroy {
4451
},
4552
];
4653

54+
const projectsTypes$ = this.projectTypeStore.pipe(select(allProjectTypes));
55+
this.projectTypesSubscription = projectsTypes$.subscribe((projectsType) => {
56+
this.projectsTypes = projectsType.map((type: ProjectType) => {
57+
return type;
58+
});
59+
});
60+
4761
const projects$ = this.store.pipe(select(getCustomerProjects));
4862
this.projectsSubscription = projects$.subscribe((response) => {
4963
this.isLoading = response.isLoading;
@@ -56,6 +70,16 @@ export class ProjectListComponent implements OnInit, OnDestroy {
5670

5771
ngOnDestroy() {
5872
this.projectsSubscription.unsubscribe();
73+
if (this.projectTypesSubscription){
74+
this.projectTypesSubscription.unsubscribe();
75+
}
76+
}
77+
78+
getProjectTypeName(typeId: string) {
79+
const typeProject = this.projectsTypes.find(
80+
(prop) => prop.id === typeId
81+
);
82+
return typeProject !== undefined ? typeProject.name : '';
5983
}
6084

6185
updateProject(project) {

0 commit comments

Comments
 (0)