Skip to content

Commit 53e7aaa

Browse files
committed
fix: TT-282 removed option empty and added method activateFocus
1 parent 2ab5466 commit 53e7aaa

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

src/app/modules/time-clock/components/entry-fields/entry-fields.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
class="form-control"
77
formControlName="activity_id"
88
[class.is-invalid]="activity_id.invalid && activity_id.touched"
9+
#autofocus
910
required>
10-
<option value="" selected="selected"></option>
11-
<option *ngFor="let activity of activities" value="{{ activity.id }}">{{ activity.name }}</option>
11+
<option *ngFor="let activity of activities" value="{{ activity.id }}" class = "id">{{ activity.name }}</option>
1212
</select>
1313
</div>
1414

src/app/modules/time-clock/components/entry-fields/entry-fields.component.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,37 @@ describe('EntryFieldsComponent', () => {
557557
expect(featureToggleGeneralService.isActivated).toHaveBeenCalled();
558558
});
559559
});
560+
561+
it('when a activity is not register in DB should show activatefocus in select activity', () => {
562+
const activitiesMock = [{
563+
id: 'xyz',
564+
name: 'test',
565+
description : 'test1'
566+
}];
567+
const data = {
568+
activity_id: 'xyz',
569+
description: '',
570+
start_date: moment().format(DATE_FORMAT_YEAR),
571+
start_hour: moment().format('HH:mm'),
572+
uri: ''
573+
};
574+
component.activities = activitiesMock;
575+
component.entryForm.patchValue({
576+
description: data.description,
577+
uri: data.uri,
578+
activity_id: data.activity_id,
579+
start_date: data.start_date,
580+
start_hour: data.start_hour,
581+
});
582+
component.ngOnInit();
583+
component.activateFocus();
584+
fixture.detectChanges();
585+
fixture.whenStable().then(() => {
586+
fixture.detectChanges();
587+
const autofocus = fixture.nativeElement.querySelector('select');
588+
expect(autofocus).toHaveBeenCalled();
589+
});
590+
});
560591
});
561592

562593

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/f
22
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
33
import { EntryActionTypes, LoadActiveEntry, UpdateCurrentOrLastEntry, UpdateEntry, UpdateEntryRunning } from './../../store/entry.actions';
44
import { filter} from 'rxjs/operators';
5-
import { Component, OnDestroy, OnInit } from '@angular/core';
5+
import { Component, OnDestroy, OnInit, ElementRef, ViewChild } from '@angular/core';
66
import { FormBuilder, FormGroup } from '@angular/forms';
77
import { Store, ActionsSubject, select } from '@ngrx/store';
88
import { Activity, NewEntry } from '../../../shared/models';
@@ -19,6 +19,8 @@ import { DATE_FORMAT } from 'src/environments/environment';
1919
import { Subscription, } from 'rxjs';
2020
import { FeatureToggle } from './../../../../../environments/enum';
2121
import { CookieService } from 'ngx-cookie-service';
22+
import { head } from 'lodash';
23+
import { __await } from 'tslib';
2224

2325
type Merged = TechnologyState & ProjectState & ActivityState;
2426

@@ -28,6 +30,9 @@ type Merged = TechnologyState & ProjectState & ActivityState;
2830
styleUrls: ['./entry-fields.component.scss'],
2931
})
3032
export class EntryFieldsComponent implements OnInit, OnDestroy {
33+
34+
@ViewChild('autofocus') autofocus!: ElementRef<HTMLSelectElement>;
35+
3136
entryForm: FormGroup;
3237
selectedTechnologies: string[] = [];
3338
activities: Activity[] = [];
@@ -46,7 +51,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
4651
private actionsSubject$: ActionsSubject,
4752
private toastrService: ToastrService,
4853
private featureToggleGeneralService: FeatureToggleGeneralService,
49-
private cookiesService: CookieService
54+
private cookiesService: CookieService,
5055
) {
5156
this.entryForm = this.formBuilder.group({
5257
description: '',
@@ -60,7 +65,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
6065
ngOnInit(): void {
6166
this.store.dispatch(new LoadActivities());
6267
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1, new Date().getFullYear()));
63-
this.loadActivitiesSubscription = this.actionsSubject$
68+
this.loadActivitiesSubscription = this.actionsSubject$
6469
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
6570
.subscribe((action) => {
6671
this.activities = action.payload.filter((item) => item.status !== 'inactive');
@@ -109,6 +114,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
109114
start_date: this.activeEntry.start_date,
110115
start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en'),
111116
};
117+
this.activateFocus();
112118
});
113119
}
114120
get activity_id() {
@@ -117,6 +123,13 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
117123
get start_hour() {
118124
return this.entryForm.get('start_hour');
119125
}
126+
127+
activateFocus(){
128+
if ((this.activities.length > 0) && (this.entryForm.value.activity_id === head(this.activities).id)){
129+
this.autofocus.nativeElement.focus();
130+
}
131+
}
132+
120133
setDataToUpdate(entryData: NewEntry) {
121134
if (entryData) {
122135
this.entryForm.patchValue({

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getActiveTimeEntry } from './../../store/entry.selectors';
1717
import { Activity, } from '../../../shared/models';
1818
import { LoadActivities } from './../../../activities-management/store/activity-management.actions';
1919
import { allActivities } from 'src/app/modules/activities-management/store/activity-management.selectors';
20+
import { head } from 'lodash';
2021

2122
@Component({
2223
selector: 'app-project-list-hover',
@@ -99,7 +100,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
99100
start_date: new Date().toISOString(),
100101
timezone_offset: new Date().getTimezoneOffset(),
101102
technologies: [],
102-
activity_id: this.activities[0].id,
103+
activity_id: head(this.activities).id,
103104
};
104105
this.store.dispatch(new entryActions.ClockIn(entry));
105106
this.projectsForm.setValue({ project_id: `${customerName} - ${name}` });

0 commit comments

Comments
 (0)