Skip to content

Commit 5843c36

Browse files
fix: Custom dates and few more (#4016)
* initial commit * eslint fix * eslint fix * eslint fix * test fix * test fix * test fix * test fix * test fix
1 parent 4090d16 commit 5843c36

File tree

9 files changed

+127
-37
lines changed

9 files changed

+127
-37
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface DisplayObject {
2+
display: string;
3+
}
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { DisplayObject } from './display-object.model';
2+
3+
export type ValueType = string | number | boolean | null | undefined | DisplayObject | unknown[];
4+

src/app/fyle/view-team-report/view-team-report.page.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,14 @@ export class ViewTeamReportPage {
375375

376376
this.loadReportDetails$.next(null);
377377

378-
this.report$ = this.loadReports().pipe(
379-
map((report) => this.setupReportData(report)),
380-
filter((report): report is Report => !!report),
378+
this.report$ = this.loadReportDetails$.pipe(
379+
switchMap(() =>
380+
this.loadReports().pipe(
381+
map((report) => this.setupReportData(report)),
382+
filter((report): report is Report => !!report),
383+
),
384+
),
385+
shareReplay(1),
381386
);
382387

383388
this.eou$ = from(this.authService.getEou());
@@ -621,6 +626,7 @@ export class ViewTeamReportPage {
621626
this.isCommentAdded = true;
622627

623628
this.approverReportsService.postComment(this.objectId, comment).subscribe(() => {
629+
this.loadReportDetails$.next();
624630
this.refreshApprovals$.next(null);
625631
setTimeout(() => {
626632
this.content().scrollToBottom(500);
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
@if (isValueList) {
22
<div class="statuses-diff">
33
<div class="statuses-diff--expense-issues">
4-
@if (key === 'Please contact your admin to configure the following') {
5-
<span>{{ key | snakeCaseToSpaceCase }} </span>
4+
@if (key() === 'Please contact your admin to configure the following') {
5+
<span>{{ key() | snakeCaseToSpaceCase }} </span>
66
}
7-
@if (key === 'Violating Transactions') {
8-
<span class="statuses-diff--violating-txns">{{ key | snakeCaseToSpaceCase }}</span>
7+
@if (key() === 'Violating Transactions') {
8+
<span class="statuses-diff--violating-txns">{{ key() | snakeCaseToSpaceCase }}</span>
99
}
10-
@if (key !== 'Please contact your admin to configure the following' && key !== 'Violating Transactions') {
11-
<span class="text-capitalize">{{ key | snakeCaseToSpaceCase }}</span>
10+
@if (key() !== 'Please contact your admin to configure the following' && key() !== 'Violating Transactions') {
11+
<span class="text-capitalize">{{ key() | snakeCaseToSpaceCase }}</span>
1212
}
1313
</div>
1414
<ul class="statuses-diff--values-list">
15-
@for (detail of value; track detail) {
15+
@for (detail of value(); track detail) {
1616
<div>
1717
<li class="text-capitalize">{{ detail }}</li>
1818
</div>
@@ -23,7 +23,7 @@
2323
@if (!isValueList) {
2424
<div>
2525
<li class="text-capitalize">
26-
{{ key === 'vehicle type' ? ('statusesDiff.mileageRateName' | transloco) : key }} : {{ value }}
26+
{{ key() === 'vehicle type' ? ('statusesDiff.mileageRateName' | transloco) : key() }} : {{ displayValue }}
2727
</li>
2828
</div>
2929
}

src/app/shared/components/comments-history/audit-history/statuses-diff/statuses-diff.component.spec.ts

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,29 @@ describe('StatusesDiffComponent', () => {
4646

4747
return translation;
4848
});
49-
fixture.detectChanges();
5049
}));
5150

5251
it('should create', () => {
5352
expect(component).toBeTruthy();
5453
});
5554

5655
it('should set isValueList to true if value is an array', () => {
57-
56+
fixture.componentRef.setInput('value', ['[email protected]', '[email protected]', '[email protected]']);
5857
component.ngOnInit();
5958
expect(component.isValueList).toBeTrue();
6059
});
6160

6261
it('should set isValueList to false if value is not an array', () => {
63-
component.value = 4000;
62+
fixture.componentRef.setInput('value', 4000);
6463
component.ngOnInit();
6564
expect(component.isValueList).toBeFalse();
6665
});
6766

6867
it('should render key and value as list items if value is an array', () => {
69-
component.key = 'User List';
70-
68+
fixture.componentRef.setInput('key', 'User List');
69+
fixture.componentRef.setInput('value', ['[email protected]', '[email protected]', '[email protected]']);
70+
component.isValueList = undefined;
71+
component.displayValue = undefined;
7172
component.ngOnInit();
7273
fixture.detectChanges();
7374
const listItems = getAllElementsBySelector(fixture, 'li');
@@ -78,17 +79,21 @@ describe('StatusesDiffComponent', () => {
7879
});
7980

8081
it('should render key and value as plain text if value is not an array', () => {
81-
component.key = 'Distance';
82-
component.value = 4000;
82+
fixture.componentRef.setInput('key', 'Distance');
83+
fixture.componentRef.setInput('value', 4000);
84+
component.isValueList = undefined;
85+
component.displayValue = undefined;
8386
component.ngOnInit();
8487
fixture.detectChanges();
8588
const listItem = getElementBySelector(fixture, 'li');
8689
expect(getTextContent(listItem)).toEqual('Distance : 4000');
8790
});
8891

8992
it('should render key as Mileage Rate Name if key is vehicle type', fakeAsync(() => {
90-
component.key = 'vehicle type';
91-
component.value = 'Two Wheeler';
93+
fixture.componentRef.setInput('key', 'vehicle type');
94+
fixture.componentRef.setInput('value', 'Two Wheeler');
95+
component.isValueList = undefined;
96+
component.displayValue = undefined;
9297
component.ngOnInit();
9398
fixture.detectChanges();
9499
tick();
@@ -98,20 +103,47 @@ describe('StatusesDiffComponent', () => {
98103
}));
99104

100105
it('should render Please contact your admin to configure the following key correctly', () => {
101-
component.key = 'Please contact your admin to configure the following';
102-
component.value = ['Designated Level Approver'];
106+
fixture.componentRef.setInput('key', 'Please contact your admin to configure the following');
107+
fixture.componentRef.setInput('value', ['Designated Level Approver']);
103108
component.ngOnInit();
104109
fixture.detectChanges();
105110
const title = getElementBySelector(fixture, 'span');
106111
expect(getTextContent(title)).toEqual('Please contact your admin to configure the following');
107112
});
108113

109114
it('should render Violating Transactions key correctly', () => {
110-
component.key = 'Violating Transactions';
111-
component.value = ['E/2022/10/T/14 (INR 555, Flight)', 'E/2022/10/T/18 (INR 128, Mileage)'];
115+
fixture.componentRef.setInput('key', 'Violating Transactions');
116+
fixture.componentRef.setInput('value', ['E/2022/10/T/14 (INR 555, Flight)', 'E/2022/10/T/18 (INR 128, Mileage)']);
112117
component.ngOnInit();
113118
fixture.detectChanges();
114119
const title = getElementBySelector(fixture, 'span.statuses-diff--violating-txns');
115120
expect(getTextContent(title)).toEqual('Violating Transactions');
116121
});
122+
123+
it('should display "-" when value is null', () => {
124+
fixture.componentRef.setInput('key', 'Location');
125+
fixture.componentRef.setInput('value', null);
126+
component.ngOnInit();
127+
fixture.detectChanges();
128+
const listItem = getElementBySelector(fixture, 'li');
129+
expect(getTextContent(listItem)).toEqual('Location : -');
130+
});
131+
132+
it('should display "-" when value is undefined', () => {
133+
fixture.componentRef.setInput('key', 'Category');
134+
fixture.componentRef.setInput('value', undefined);
135+
component.ngOnInit();
136+
fixture.detectChanges();
137+
const listItem = getElementBySelector(fixture, 'li');
138+
expect(getTextContent(listItem)).toEqual('Category : -');
139+
});
140+
141+
it('should extract display property from DisplayObject', () => {
142+
fixture.componentRef.setInput('key', 'Location');
143+
fixture.componentRef.setInput('value', { display: 'San Francisco, CA' });
144+
component.ngOnInit();
145+
fixture.detectChanges();
146+
const listItem = getElementBySelector(fixture, 'li');
147+
expect(getTextContent(listItem)).toEqual('Location : San Francisco, CA');
148+
});
117149
});
Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Component, OnInit, Input } from '@angular/core';
1+
import { Component, OnInit, input } from '@angular/core';
22
import { TranslocoPipe } from '@jsverse/transloco';
33
import { SnakeCaseToSpaceCase } from '../../../../pipes/snake-case-to-space-case.pipe';
4+
import { DisplayObject } from '../../../../../core/models/display-object.model';
5+
import { ValueType } from '../../../../../core/models/statuses-diff-value-type.model';
46

57
@Component({
68
selector: 'app-statuses-diff',
@@ -9,19 +11,45 @@ import { SnakeCaseToSpaceCase } from '../../../../pipes/snake-case-to-space-case
911
imports: [TranslocoPipe, SnakeCaseToSpaceCase],
1012
})
1113
export class StatusesDiffComponent implements OnInit {
12-
// TODO: Skipped for migration because:
13-
// Your application code writes to the input. This prevents migration.
14-
@Input() key;
14+
readonly key = input<string>();
1515

16-
// TODO: Skipped for migration because:
17-
// Your application code writes to the input. This prevents migration.
18-
@Input() value;
16+
readonly value = input<ValueType>();
1917

2018
isValueList: boolean;
2119

20+
displayValue: string;
21+
2222
constructor() {}
2323

2424
ngOnInit() {
25-
this.isValueList = this.value instanceof Array;
25+
const value = this.value();
26+
this.isValueList = value instanceof Array;
27+
if (!this.isValueList) {
28+
this.displayValue = this.formatValue(value);
29+
}
30+
}
31+
32+
private formatValue(value: ValueType): string {
33+
if (value === null || value === undefined) {
34+
return '-';
35+
}
36+
37+
// Handle location objects with display property
38+
if (this.isDisplayObject(value)) {
39+
return value.display;
40+
}
41+
42+
// For primitives, return as string
43+
return String(value);
44+
}
45+
46+
private isDisplayObject(value: ValueType): value is DisplayObject {
47+
return (
48+
typeof value === 'object' &&
49+
value !== null &&
50+
!Array.isArray(value) &&
51+
'display' in value &&
52+
typeof value.display === 'string'
53+
);
2654
}
2755
}

src/app/shared/components/fy-filters/fy-filters.component.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@
123123
[(ngModel)]="startDate"
124124
(ngModelChange)="onDateChange()"
125125
[matDatepicker]="picker1"
126+
(click)="openPicker1()"
126127
/>
127-
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
128-
<mat-datepicker #picker1></mat-datepicker>
128+
<mat-datepicker-toggle matSuffix [for]="picker1" (click)="openPicker1()"></mat-datepicker-toggle>
129+
<mat-datepicker touchUi="true" #picker1></mat-datepicker>
129130
</mat-form-field>
130131
<mat-form-field>
131132
<mat-label>{{ 'fyFilters.endDate' | transloco }}</mat-label>
@@ -135,9 +136,10 @@
135136
[(ngModel)]="endDate"
136137
(ngModelChange)="onDateChange()"
137138
[matDatepicker]="picker2"
139+
(click)="openPicker2()"
138140
/>
139-
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
140-
<mat-datepicker #picker2></mat-datepicker>
141+
<mat-datepicker-toggle matSuffix [for]="picker2" (click)="openPicker2()"></mat-datepicker-toggle>
142+
<mat-datepicker touchUi="true" #picker2></mat-datepicker>
141143
</mat-form-field>
142144
</div>
143145
}

src/app/shared/components/fy-filters/fy-filters.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
44
/* eslint-disable @typescript-eslint/explicit-function-return-type */
55
/* eslint-disable @typescript-eslint/no-explicit-any */
6-
import { Component, Input, OnInit, inject } from '@angular/core';
6+
import { Component, Input, OnInit, inject, viewChild } from '@angular/core';
77
import { FilterOptions } from './filter-options.interface';
88
import { SelectedFilters } from './selected-filters.interface';
99
import { FilterOptionType } from './filter-option-type.enum';
@@ -50,6 +50,10 @@ import { TranslocoPipe } from '@jsverse/transloco';
5050
export class FyFiltersComponent implements OnInit {
5151
private modalController = inject(ModalController);
5252

53+
readonly picker1 = viewChild<MatDatepicker<Date>>('picker1');
54+
55+
readonly picker2 = viewChild<MatDatepicker<Date>>('picker2');
56+
5357
// TODO: Skipped for migration because:
5458
// Your application code writes to the input. This prevents migration.
5559
@Input() simplifyReportsSettings$: Observable<any> = of({ enabled: false });
@@ -125,6 +129,14 @@ export class FyFiltersComponent implements OnInit {
125129
});
126130
}
127131

132+
openPicker1(): void {
133+
this.picker1()?.open();
134+
}
135+
136+
openPicker2(): void {
137+
this.picker2()?.open();
138+
}
139+
128140
getNoOfFilters() {
129141
return Object.values(this.currentFilterValueMap).filter((value) => value && value.length).length;
130142
}

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ConfigService } from './app/core/services/config.service';
2626
import { TIMEZONE, PAGINATION_SIZE, DEVICE_PLATFORM, FORMAT_PREFERENCES } from './app/constants';
2727
import { appRoutes } from './app/app-routes';
2828
import { provideAnimations } from '@angular/platform-browser/animations';
29+
import { provideNativeDateAdapter } from '@angular/material/core';
2930
import { NgOtpInputModule } from 'ng-otp-input';
3031
import { AppComponent } from './app/app.component';
3132
import { FyCurrencyPipe } from './app/shared/pipes/fy-currency.pipe';
@@ -194,6 +195,7 @@ bootstrapApplication(AppComponent, {
194195
},
195196
provideHttpClient(withInterceptorsFromDi(), withJsonpSupport()),
196197
provideAnimations(),
198+
provideNativeDateAdapter(),
197199
provideIonicAngular({
198200
innerHTMLTemplatesEnabled: true,
199201
useSetInputAPI: true,

0 commit comments

Comments
 (0)