Skip to content

Commit b20432f

Browse files
Fix/frontend bugs (#3931)
* Add snack-bar instead 'offline' field in header * Add filter tags for Customers * Fix sorting in customers orders table * Remove coma * Add tests for snack bar and filter tags * Fix coderabbit issues * Fix coderabbit issues * Remove commas
1 parent 133b7d2 commit b20432f

File tree

9 files changed

+172
-20
lines changed

9 files changed

+172
-20
lines changed

src/app/app.component.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
<div *ngIf="offline" class="offline">
2-
<span>offline</span>
3-
</div>
4-
51
<router-outlet></router-outlet>
62

73
<app-chat-contact-admin-pop-up></app-chat-contact-admin-pop-up>

src/app/app.component.scss

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
@import '../typography/typography';
22

3-
.offline {
4-
top: 50px;
5-
left: 50%;
6-
position: fixed;
7-
font-weight: 500;
8-
font-size: larger;
9-
background: transparent;
10-
color: var(--error-red);
11-
z-index: 999;
12-
}
13-
143
::ng-deep .mat-select:focus-visible {
154
outline: 2px solid currentcolor !important;
165
}

src/app/app.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { filter, Subject } from 'rxjs';
77
import { LocalStorageService } from 'src/app/shared/services/localstorage/local-storage.service';
88
import { MetaService } from 'src/app/shared/services/meta/meta.service';
99
import { SwUpdate, VersionReadyEvent } from '@angular/service-worker';
10+
import { MatSnackBarService } from '@global-service/mat-snack-bar/mat-snack-bar.service';
1011

1112
@Component({
1213
selector: 'app-root',
@@ -21,7 +22,7 @@ export class AppComponent implements OnInit, OnDestroy {
2122
private readonly destroy$: Subject<void> = new Subject<void>();
2223
router: Router = inject(Router);
2324
metaService: MetaService = inject(MetaService);
24-
offline: boolean;
25+
private readonly snackBar = inject(MatSnackBarService);
2526

2627
ngOnInit(): void {
2728
this.metaService.setMetaOnRouteChange();
@@ -45,7 +46,9 @@ export class AppComponent implements OnInit, OnDestroy {
4546
}
4647

4748
onNetworkStatusChange(): void {
48-
this.offline = !navigator.onLine;
49+
if (!navigator.onLine) {
50+
this.snackBar.openSnackBar('noInternet');
51+
}
4952
}
5053

5154
ngOnDestroy(): void {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface FilterCustomers {
2+
key: string;
3+
labelKey: string;
4+
fromValue?: string | null;
5+
toValue?: string | null;
6+
fromControl: string;
7+
toControl: string;
8+
isDate?: boolean;
9+
}

src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customer-orders/ubs-admin-customer-orders.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
<th id="head" mat-header-cell *matHeaderCellDef [appResizeColumn]="{ resizable: true, index: i }">
1919
<div class="columns_header">
2020
<span>{{ column.title | serverTranslate: currentLang }}</span>
21-
<mat-icon *ngIf="arrowDirection !== column.title.key" (click)="onSortTable(column.title.key, 'DESC')">
21+
<mat-icon *ngIf="arrowDirection !== column.title.key" (click)="onSortTable(column.title.key, 'ASC')">
2222
arrow_downward
2323
</mat-icon>
24-
<mat-icon *ngIf="arrowDirection === column.title.key" (click)="onSortTable(column.title.key, 'ASC')"> arrow_upward </mat-icon>
24+
<mat-icon *ngIf="arrowDirection === column.title.key" (click)="onSortTable(column.title.key, 'DESC')">
25+
arrow_upward
26+
</mat-icon>
2527
</div>
2628
</th>
2729
<td mat-cell *matCellDef="let row">

src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customers.component.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,25 @@
285285
</div>
286286
</div>
287287
</div>
288+
<div class="tag-filtrs-list" *ngIf="activeFilters.length">
289+
<div class="tag-filter-item" *ngFor="let filter of activeFilters">
290+
<button
291+
type="button"
292+
class="remove-item-btn"
293+
(click)="removeActiveFilter(filter)"
294+
[attr.aria-label]="'ubs-tables.clear-filters' | translate"
295+
></button>
296+
<span class="filter-content">
297+
{{ filter.labelKey | translate }}
298+
<ng-container *ngIf="filter.fromValue">
299+
{{ 'ubs-customer-filters.from' | translate }} {{ filter.fromValue }}
300+
</ng-container>
301+
<ng-container *ngIf="filter.toValue">
302+
{{ 'ubs-customer-filters.to' | translate }} {{ filter.toValue }}
303+
</ng-container>
304+
</span>
305+
</div>
306+
</div>
288307

289308
<div id="table-container" class="scrolling" infiniteScroll [infiniteScrollThrottle]="100" (scrolled)="onScroll()" [scrollWindow]="false">
290309
<mat-table [dataSource]="dataSource" id="table" class="customers_table" *ngIf="!isLoading" cdkDropListGroup>

src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customers.component.scss

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,40 @@ button:disabled {
404404
background-color: var(--ubs-primary-light-grey);
405405
border-color: var(--ubs-quaternary-light-grey);
406406
}
407+
408+
.tag-filtrs-list {
409+
display: flex;
410+
flex-wrap: wrap;
411+
gap: 6px;
412+
margin-top: 10px;
413+
margin-bottom: 10px;
414+
}
415+
416+
.tag-filter-item {
417+
display: flex;
418+
flex-direction: row;
419+
align-items: center;
420+
padding: 2px 6px;
421+
border-radius: 4px;
422+
font-size: 12px;
423+
line-height: 16px;
424+
max-width: fit-content;
425+
}
426+
427+
.remove-item-btn {
428+
width: 6px;
429+
height: 6px;
430+
margin-left: 1px;
431+
margin-right: 5px;
432+
background-image: url('/assets/img/ubs-admin-employees/cross.svg');
433+
background-size: contain;
434+
background-repeat: no-repeat;
435+
cursor: pointer;
436+
border: 0;
437+
background-color: transparent
438+
}
439+
440+
.filter-content {
441+
color: var(--ubs-dark-purple);
442+
white-space: nowrap;
443+
}

src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customers.component.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,28 @@ describe('UbsAdminCustomersComponent', () => {
335335
expect((component as any)['getTable']).toHaveBeenCalledTimes(1);
336336
});
337337

338+
it('should remove active filter and reset form controls', () => {
339+
spyOn(component, 'submitFilterForm');
340+
component.activeFilters = [{
341+
key: 'bonuses',
342+
labelKey: 'ubs-customer-filters.bonuses',
343+
fromValue: '10',
344+
toValue: '20',
345+
fromControl: 'bonusesFrom',
346+
toControl: 'bonusesTo',
347+
isDate: false
348+
}];
349+
component.filterForm.patchValue({
350+
bonusesFrom: 10,
351+
bonusesTo: 20
352+
});
353+
component.removeActiveFilter(component.activeFilters[0]);
354+
expect(component.activeFilters.length).toBe(0);
355+
expect(component.filterForm.value.bonusesFrom).toBe('');
356+
expect(component.filterForm.value.bonusesTo).toBe('');
357+
expect(component.submitFilterForm).toHaveBeenCalled();
358+
});
359+
338360
it('should clear all filters and submit form', () => {
339361
component.filterForm.get('bonusesFrom').setValue('10');
340362
spyOn(component, 'submitFilterForm').and.callThrough();

src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customers.component.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import { ClientStatusEnum } from '@ubs/ubs/enums/client-status.enum';
3434
import { MatSelectChange } from '@angular/material/select';
3535
import { IAppState } from '../../../../store/state/app.state';
3636
import { ColumnParam, columnsParams } from '@ubs/ubs-admin/components/ubs-admin-customers/columnsParams.mock';
37+
import { DatePipe } from '@angular/common';
38+
import { FilterCustomers } from './customers-filters.interface';
3739

3840
export const CUSTOM_DATE_FORMATS = {
3941
parse: {
@@ -78,6 +80,7 @@ export class UbsAdminCustomersComponent implements OnInit, AfterViewChecked, OnD
7880
enterPressed: boolean;
7981
adminTableOfCustomersSelector$ = this.store.select(adminTableOfCustomersSelector);
8082
tableData: any[];
83+
activeFilters: FilterCustomers[] = [];
8184
readonly customerStatus = Object.values(ClientStatusEnum);
8285
private sortType: string;
8386
private sortingColumn: string;
@@ -256,7 +259,79 @@ export class UbsAdminCustomersComponent implements OnInit, AfterViewChecked, OnD
256259
this.currentPage = 0;
257260
this.getTable();
258261
}
259-
}
262+
this.buildActiveFilters();
263+
}
264+
265+
private buildActiveFilters(): void {
266+
this.activeFilters = [];
267+
268+
const map = [
269+
{
270+
key: 'registrationDate',
271+
label: 'ubs-customer-filters.registration-date',
272+
from: 'registrationDateFrom',
273+
to: 'registrationDateTo',
274+
isDate: true
275+
},
276+
{
277+
key: 'lastOrderDate',
278+
label: 'ubs-customer-filters.last-order-date',
279+
from: 'lastOrderDateFrom',
280+
to: 'lastOrderDateTo',
281+
isDate: true
282+
},
283+
{
284+
key: 'ordersCount',
285+
label: 'ubs-customer-filters.orders-amount',
286+
from: 'ordersCountFrom',
287+
to: 'ordersCountTo'
288+
},
289+
{
290+
key: 'violations',
291+
label: 'ubs-customer-filters.violations',
292+
from: 'violationsFrom',
293+
to: 'violationsTo'
294+
},
295+
{
296+
key: 'bonuses',
297+
label: 'ubs-customer-filters.bonuses',
298+
from: 'bonusesFrom',
299+
to: 'bonusesTo'
300+
}
301+
];
302+
303+
const locale = this.currentLang === 'uk' ? 'uk-UA' : 'en-GB';
304+
const datePipe = new DatePipe(locale);
305+
306+
map.forEach((f) => {
307+
let from = this.filterForm.get(f.from).value;
308+
let to = this.filterForm.get(f.to).value;
309+
310+
if (f.isDate) {
311+
from = from ? datePipe.transform(new Date(from), 'dd/MM/yyyy') : from;
312+
to = to ? datePipe.transform(new Date(to), 'dd/MM/yyyy') : to;
313+
}
314+
315+
if (from || to) {
316+
this.activeFilters.push({
317+
key: f.key,
318+
labelKey: f.label,
319+
fromValue: from,
320+
toValue: to,
321+
fromControl: f.from,
322+
toControl: f.to,
323+
isDate: f.isDate
324+
});
325+
}
326+
});
327+
}
328+
329+
removeActiveFilter(filter): void {
330+
this.filterForm.get(filter.fromControl).setValue('');
331+
this.filterForm.get(filter.toControl).setValue('');
332+
this.activeFilters = this.activeFilters.filter(f => f.key !== filter.key);
333+
this.submitFilterForm();
334+
}
260335

261336
onDeleteFilter(filterFrom: string, filterTo: string) {
262337
this.filterForm.get(filterFrom).setValue('');

0 commit comments

Comments
 (0)