Skip to content

Commit 156544a

Browse files
authored
Tta 189 create an anchor for the edit a customer action (#953)
* noworking commit * refactor: TTA-189 dropped unused function * refactor: TTA-189 dropped another unused function * refactor: TTA-189 erased test Test erased for case being already covered in separate existing test. * refactor: TTA-189 scrollToCustomerForm * refactor: TTA-189 scrollToCustomer
1 parent 4ef6ec2 commit 156544a

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@
1414
<th class="col-2 text-center">Visibility</th>
1515
</tr>
1616
</thead>
17-
<app-loading-bar *ngIf="(isLoading$ | async)"></app-loading-bar>
18-
<tbody *ngIf="((isLoading$ | async) === false)">
17+
<app-loading-bar *ngIf="isLoading$ | async"></app-loading-bar>
18+
<tbody *ngIf="(isLoading$ | async) === false">
1919
<tr class="d-flex" *ngFor="let customer of customers">
2020
<td class="col-4 text-break">{{ customer.id }}</td>
2121
<td class="col-4 text-break">{{ customer.name }}</td>
2222
<td class="col-2 text-center">
2323
<button
2424
data-toggle="modal"
25-
(click)="editCustomer(customer.id)"
26-
type="button" data-target="#editModal"
27-
class="btn btn-sm btn-primary">
25+
(click)="editCustomer(customer.id); goToCustomerForm()"
26+
type="button"
27+
data-target="#editModal"
28+
class="btn btn-sm btn-primary"
29+
>
2830
<i class="fa fa-pen fa-xs"></i>
2931
</button>
3032
</td>
3133
<td class="col-2 text-center">
32-
<app-dropdown
33-
[info] = "customer"
34-
(updateInfo) = "switchStatus($event)"
35-
> </app-dropdown>
34+
<app-dropdown [info]="customer" (updateInfo)="switchStatus($event)"> </app-dropdown>
3635
</td>
3736
</tr>
3837
</tbody>
@@ -62,5 +61,5 @@
6261
[title]="'Edit Customer'"
6362
[body]="message"
6463
(closeModalEvent)="closeModal()"
65-
>
64+
>
6665
</app-dialog>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ describe('CustomerTableListComponent', () => {
8484

8585
it('Onclick Edit, if there are changes, the modal must be presented ', () => {
8686
component.hasChange = true;
87-
const expectMessage = 'Do you have changes in a client, do you want to discard them?';
87+
const expectMessage = 'You have changes in a client, do you want to discard them?';
8888

8989
component.editCustomer('1');
9090

9191
expect(component.message).toEqual(expectMessage);
9292
expect(component.showModal).toBeTrue();
9393
});
9494

95-
it('onClick edit, if there are not have changes dispatch SetCustomerToEdit, enable customer form and hidden modal', () => {
95+
it('onClick edit, if there are no unsaved changes dispatch SetCustomerToEdit, enable customer form and hide modal', () => {
9696
component.hasChange = false;
9797

9898
spyOn(store, 'dispatch');
@@ -115,7 +115,7 @@ describe('CustomerTableListComponent', () => {
115115
expect(store.dispatch).toHaveBeenCalledWith(new ResetProjectTypeToEdit());
116116
});
117117

118-
it('when you click close modal, you should close the modal, discard the current changes and load a new client for edit', () => {
118+
it('when you click close modal, modal should close, discard the current changes and load a new client to edit', () => {
119119
spyOn(component.changeValueShowCustomerForm, 'emit');
120120
spyOn(store, 'dispatch');
121121

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import { ResetProjectToEdit, SetProjectToEdit } from '../../../projects/componen
1919
import { ResetProjectTypeToEdit, SetProjectTypeToEdit } from '../../../projects-type/store';
2020
import { UnarchiveCustomer } from '../../../../store/customer-management.actions';
2121

22+
23+
export function scrollToCustomerForm(): void {
24+
const element = document.getElementById('customerForm');
25+
element.scrollIntoView();
26+
}
27+
2228
@Component({
2329
selector: 'app-customer-list',
2430
templateUrl: './customer-list.component.html',
@@ -117,7 +123,7 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
117123
editCustomer(customerId: string) {
118124
this.idToEdit = customerId;
119125
if (this.hasChange) {
120-
this.message = 'Do you have changes in a client, do you want to discard them?';
126+
this.message = 'You have changes in a client, do you want to discard them?';
121127
this.showModal = true;
122128
} else {
123129
this.showCustomerForm = true;
@@ -199,4 +205,8 @@ export class CustomerListComponent implements OnInit, OnDestroy, AfterViewInit {
199205
this.store.dispatch(new UnarchiveCustomer(this.idToDelete, this.changeOppositeStatus(this.statusToEdit)));
200206
}
201207

208+
goToCustomerForm(){
209+
scrollToCustomerForm();
210+
}
211+
202212
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<div class="container-fluid px-0 full-height">
22
<div class="row">
33
<div style="padding: 15px;">
4-
<button (click)="activateCustomerForm()" class="btn btn-primary">Add new customer</button>
4+
<button (click)="activateCustomerForm(); goToCustomerForm()" class="btn btn-primary">Add new customer</button>
55
</div>
66
</div>
77
<app-customer-list
88
[showCustomerForm]="showCustomerForm"
99
[hasChange]="hasChangeComponent"
1010
(changeValueShowCustomerForm)="showCustomerForm = $event"
1111
></app-customer-list>
12-
<div class="row" *ngIf="showCustomerForm">
13-
<div class="col">
14-
<app-management-customer-projects (sendChanges)="getChangesInputs($event)" (closeCustemerForm)="closeCustomerForm($event)"></app-management-customer-projects>
12+
<div id="customerForm">
13+
<div class="row" *ngIf="showCustomerForm">
14+
<div class="col">
15+
<app-management-customer-projects
16+
(sendChanges)="getChangesInputs($event)"
17+
(closeCustemerForm)="closeCustomerForm($event)"
18+
></app-management-customer-projects>
19+
</div>
1520
</div>
1621
</div>
1722
</div>

src/app/modules/customer-management/pages/customer.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Store } from '@ngrx/store';
22
import { Customer } from 'src/app/modules/shared/models';
33
import { SetCustomerToEdit } from 'src/app/modules/customer-management/store';
44
import { Component } from '@angular/core';
5+
import { scrollToCustomerForm } from '../components/customer-info/components/customer-list/customer-list.component';
6+
57

68
@Component({
79
selector: 'app-customer',
@@ -28,4 +30,9 @@ export class CustomerComponent {
2830
getChangesInputs(event) {
2931
this.hasChangeComponent = event;
3032
}
33+
34+
goToCustomerForm(){
35+
scrollToCustomerForm();
36+
}
37+
3138
}

0 commit comments

Comments
 (0)