Skip to content

Commit 7f9215d

Browse files
fix: TT-106 Exponential growth in the EntryFields component and ProjectListHover component
1 parent d198dd0 commit 7f9215d

File tree

4 files changed

+66
-9
lines changed

4 files changed

+66
-9
lines changed

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

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions';
22
import { EntryActionTypes, LoadActiveEntry } from './../../store/entry.actions';
3-
import { filter } from 'rxjs/operators';
4-
import { Component, OnInit } from '@angular/core';
3+
import { filter, map } from 'rxjs/operators';
4+
import { Component, OnDestroy, OnInit } from '@angular/core';
55
import { FormBuilder, FormGroup } from '@angular/forms';
66
import { Store, ActionsSubject, select } from '@ngrx/store';
77
import { Activity, NewEntry } from '../../../shared/models';
88
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
99
import { TechnologyState } from '../../../shared/store/technology.reducers';
1010
import { ActivityState, LoadActivities } from '../../../activities-management/store';
11+
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';
1112

1213
import * as entryActions from '../../store/entry.actions';
1314
import { get } from 'lodash';
@@ -16,6 +17,7 @@ import { ToastrService } from 'ngx-toastr';
1617
import { formatDate } from '@angular/common';
1718
import { getTimeEntriesDataSource } from '../../store/entry.selectors';
1819
import { DATE_FORMAT } from 'src/environments/environment';
20+
import { Subscription } from 'rxjs';
1921

2022
type Merged = TechnologyState & ProjectState & ActivityState;
2123

@@ -24,16 +26,24 @@ type Merged = TechnologyState & ProjectState & ActivityState;
2426
templateUrl: './entry-fields.component.html',
2527
styleUrls: ['./entry-fields.component.scss'],
2628
})
27-
export class EntryFieldsComponent implements OnInit {
29+
export class EntryFieldsComponent implements OnInit, OnDestroy {
2830
entryForm: FormGroup;
2931
selectedTechnologies: string[] = [];
3032
activities: Activity[] = [];
3133
activeEntry;
3234
newData;
3335
lastEntry;
3436
showTimeInbuttons = false;
37+
loadActivitiesSubscribe: Subscription;
38+
loadActiveEntrySubscribe: Subscription;
39+
actionSetDateSubscribe: Subscription;
40+
loadActivitiesSubject;
41+
loadActiveEntrySubject;
42+
actionSetDateSubject;
43+
exponentialGrowth;
3544

3645
constructor(
46+
private featureManagerService: FeatureManagerService,
3747
private formBuilder: FormBuilder,
3848
private store: Store<Merged>,
3949
private actionsSubject$: ActionsSubject,
@@ -49,16 +59,23 @@ export class EntryFieldsComponent implements OnInit {
4959
}
5060

5161
ngOnInit(): void {
62+
63+
this.isFeatureToggleActivated().subscribe((flag) => {
64+
console.log(flag);
65+
});
66+
5267
this.store.dispatch(new LoadActivities());
5368
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1, new Date().getFullYear()));
54-
this.actionsSubject$
69+
this.loadActivitiesSubject = this.actionsSubject$
5570
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
5671
.subscribe((action) => {
5772
this.activities = action.payload;
5873
this.store.dispatch(new LoadActiveEntry());
5974
});
6075

61-
this.actionsSubject$
76+
this.exponentialGrowth ? this.loadActivitiesSubscribe = this.loadActivitiesSubject : this.loadActivitiesSubject;
77+
78+
this.loadActiveEntrySubject = this.actionsSubject$
6279
.pipe(
6380
filter(
6481
(action: any) =>
@@ -77,7 +94,9 @@ export class EntryFieldsComponent implements OnInit {
7794
}
7895
});
7996

80-
this.actionsSubject$
97+
this.exponentialGrowth ? this.loadActiveEntrySubscribe = this.loadActiveEntrySubject : this.loadActiveEntrySubject;
98+
99+
this.actionSetDateSubject = this.actionsSubject$
81100
.pipe(filter((action: any) => action.type === EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS))
82101
.subscribe((action) => {
83102
this.activeEntry = action.payload;
@@ -91,6 +110,8 @@ export class EntryFieldsComponent implements OnInit {
91110
start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en'),
92111
};
93112
});
113+
114+
this.exponentialGrowth ? this.actionSetDateSubscribe = this.actionSetDateSubject : this.actionSetDateSubject;
94115
}
95116

96117
get activity_id() {
@@ -174,4 +195,22 @@ export class EntryFieldsComponent implements OnInit {
174195
onTechnologyRemoved($event: string[]) {
175196
this.store.dispatch(new entryActions.UpdateEntryRunning({ ...this.newData, technologies: $event }));
176197
}
198+
199+
200+
ngOnDestroy(): void {
201+
if(this.exponentialGrowth){
202+
this.loadActivitiesSubscribe.unsubscribe();
203+
this.loadActiveEntrySubscribe.unsubscribe();
204+
this.actionSetDateSubscribe.unsubscribe();
205+
}
206+
console.log('OnDestroy');
207+
}
208+
209+
isFeatureToggleActivated() {
210+
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
211+
map((enabled) => {
212+
console.log(enabled);
213+
})
214+
)
215+
}
177216
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
2626
updateEntrySubscription: Subscription;
2727
isLoading$: Observable<boolean>;
2828

29+
30+
/**
31+
* subscription variables
32+
*/
33+
projectsSubscribe : Subscription;
34+
activeEntrySubscribe : Subscription;
35+
2936
constructor(private formBuilder: FormBuilder, private store: Store<ProjectState>,
3037
private actionsSubject$: ActionsSubject, private toastrService: ToastrService) {
3138
this.projectsForm = this.formBuilder.group({ project_id: null, });
@@ -35,7 +42,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
3542
ngOnInit(): void {
3643
this.store.dispatch(new actions.LoadProjects());
3744
const projects$ = this.store.pipe(select(getProjects));
38-
projects$.subscribe((projects) => {
45+
this.projectsSubscribe = projects$.subscribe((projects) => {
3946
this.listProjects = [];
4047
projects.forEach((project) => {
4148
const projectWithSearchField = {...project};
@@ -61,7 +68,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
6168
loadActiveTimeEntry() {
6269
this.store.dispatch(new entryActions.LoadActiveEntry());
6370
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
64-
activeEntry$.subscribe((activeEntry) => {
71+
this.activeEntrySubscribe = activeEntry$.subscribe((activeEntry) => {
6572
this.activeEntry = activeEntry;
6673
if (activeEntry) {
6774
this.showClockIn = false;
@@ -111,5 +118,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
111118

112119
ngOnDestroy(): void {
113120
this.updateEntrySubscription.unsubscribe();
121+
this.projectsSubscribe.unsubscribe();
122+
this.activeEntrySubscribe.unsubscribe();
114123
}
115124
}

src/app/modules/time-clock/pages/time-clock.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ActionsSubject, select, Store } from '@ngrx/store';
33
import { ToastrService } from 'ngx-toastr';
44
import { Subscription } from 'rxjs';
55
import { filter } from 'rxjs/operators';
6+
import { threadId } from 'worker_threads';
67
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service';
78
import { EntryFieldsComponent } from '../components/entry-fields/entry-fields.component';
89
import { Entry } from './../../shared/models/entry.model';
@@ -22,6 +23,12 @@ export class TimeClockComponent implements OnInit, OnDestroy {
2223
clockOutSubscription: Subscription;
2324

2425

26+
/**
27+
* subscription variables
28+
*/
29+
storeSubscribe : Subscription;
30+
31+
2532
constructor(
2633
private azureAdB2CService: AzureAdB2CService,
2734
private store: Store<Entry>,
@@ -31,11 +38,12 @@ export class TimeClockComponent implements OnInit, OnDestroy {
3138

3239
ngOnDestroy(): void {
3340
this.clockOutSubscription.unsubscribe();
41+
this.storeSubscribe.unsubscribe();
3442
}
3543

3644
ngOnInit() {
3745
this.username = this.azureAdB2CService.isLogin() ? this.azureAdB2CService.getName() : '';
38-
this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
46+
this.storeSubscribe = this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
3947
this.activeTimeEntry = activeTimeEntry;
4048
if (this.activeTimeEntry) {
4149
this.areFieldsVisible = true;

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class EntryService {
2020
baseUrl = `${environment.timeTrackerApiUrl}/time-entries`;
2121

2222
loadActiveEntry(): Observable<any> {
23+
console.log('Method Call');
2324
return this.http.get(`${this.baseUrl}/running`);
2425
}
2526

0 commit comments

Comments
 (0)