Skip to content

Commit bae6c8d

Browse files
refactor: TT-106 Use the exponentialGrowth flag to destroy unnecessary requests in EntryFields, ProjectListHover, TimeClock components
1 parent 0a97c63 commit bae6c8d

File tree

3 files changed

+20
-52
lines changed

3 files changed

+20
-52
lines changed

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ProjectState } from '../../../customer-management/components/projects/c
99
import { TechnologyState } from '../../../shared/store/technology.reducers';
1010
import { ActivityState, LoadActivities } from '../../../activities-management/store';
1111
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';
12-
1312
import * as entryActions from '../../store/entry.actions';
1413
import { get } from 'lodash';
1514
import * as moment from 'moment';
@@ -37,10 +36,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
3736
loadActivitiesSubscribe: Subscription;
3837
loadActiveEntrySubscribe: Subscription;
3938
actionSetDateSubscribe: Subscription;
40-
loadActivitiesSubject;
41-
loadActiveEntrySubject;
42-
actionSetDateSubject;
43-
4439
exponentialGrowth;
4540

4641
constructor(
@@ -59,20 +54,17 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
5954
});
6055
}
6156

62-
6357
async ngOnInit(): Promise<void> {
6458
this.exponentialGrowth = await this.isFeatureToggleActivated();
6559
this.store.dispatch(new LoadActivities());
6660
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1, new Date().getFullYear()));
67-
this.loadActivitiesSubject = this.actionsSubject$
61+
this.loadActivitiesSubscribe = this.actionsSubject$
6862
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
6963
.subscribe((action) => {
7064
this.activities = action.payload;
7165
this.store.dispatch(new LoadActiveEntry());
7266
});
73-
// tslint:disable-next-line
74-
this.exponentialGrowth ? this.loadActivitiesSubscribe = this.loadActivitiesSubject : this.loadActivitiesSubject;
75-
this.loadActiveEntrySubject = this.actionsSubject$
67+
this.loadActiveEntrySubscribe = this.actionsSubject$
7668
.pipe(
7769
filter(
7870
(action: any) =>
@@ -90,9 +82,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
9082
this.store.dispatch(new entryActions.LoadEntriesSummary());
9183
}
9284
});
93-
// tslint:disable-next-line
94-
this.exponentialGrowth ? this.loadActiveEntrySubscribe = this.loadActiveEntrySubject : this.loadActiveEntrySubject;
95-
this.actionSetDateSubject = this.actionsSubject$
85+
this.actionSetDateSubscribe = this.actionsSubject$
9686
.pipe(filter((action: any) => action.type === EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS))
9787
.subscribe((action) => {
9888
this.activeEntry = action.payload;
@@ -106,8 +96,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
10696
start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en'),
10797
};
10898
});
109-
// tslint:disable-next-line
110-
this.exponentialGrowth ? this.actionSetDateSubscribe = this.actionSetDateSubject : this.actionSetDateSubject;
11199
}
112100
get activity_id() {
113101
return this.entryForm.get('activity_id');
@@ -191,7 +179,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
191179

192180

193181
ngOnDestroy(): void {
194-
195182
if (this.exponentialGrowth) {
196183
this.loadActivitiesSubscribe.unsubscribe();
197184
this.loadActiveEntrySubscribe.unsubscribe();
@@ -200,10 +187,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
200187
}
201188

202189
isFeatureToggleActivated() {
203-
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
204-
map((enabled) => {
190+
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
191+
map((enabled) => {
205192
return enabled === true ? true : false;
206-
})
207-
).toPromise();
193+
})
194+
).toPromise();
208195
}
209196
}

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
2727
isLoading$: Observable<boolean>;
2828
projectsSubscribe: Subscription;
2929
activeEntrySubscribe: Subscription;
30-
projectsSubject;
31-
activeEntrySubject;
3230
exponentialGrowth;
3331

3432
constructor(private featureManagerService: FeatureManagerService,
@@ -39,12 +37,10 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
3937
}
4038

4139
async ngOnInit(): Promise<void> {
42-
4340
this.exponentialGrowth = await this.isFeatureToggleActivated();
44-
4541
this.store.dispatch(new actions.LoadProjects());
4642
const projects$ = this.store.pipe(select(getProjects));
47-
this.projectsSubject = projects$.subscribe((projects) => {
43+
this.projectsSubscribe = projects$.subscribe((projects) => {
4844
this.listProjects = [];
4945
projects.forEach((project) => {
5046
const projectWithSearchField = {...project};
@@ -54,8 +50,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
5450
);
5551
this.loadActiveTimeEntry();
5652
});
57-
// tslint:disable-next-line
58-
this.exponentialGrowth ? this.projectsSubscribe = this.projectsSubject : this.projectsSubject;
5953
this.updateEntrySubscription = this.actionsSubject$.pipe(
6054
filter((action: any) => (
6155
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS
@@ -65,13 +59,12 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
6559
this.activeEntry = action.payload;
6660
this.setSelectedProject();
6761
});
68-
6962
}
7063

7164
loadActiveTimeEntry() {
7265
this.store.dispatch(new entryActions.LoadActiveEntry());
7366
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
74-
this.activeEntrySubject = activeEntry$.subscribe((activeEntry) => {
67+
this.activeEntrySubscribe = activeEntry$.subscribe((activeEntry) => {
7568
this.activeEntry = activeEntry;
7669
if (activeEntry) {
7770
this.showClockIn = false;
@@ -81,9 +74,8 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
8174
this.projectsForm.setValue({ project_id: null });
8275
}
8376
});
84-
// tslint:disable-next-line
85-
this.exponentialGrowth ? this.activeEntrySubscribe = this.activeEntrySubject : this.activeEntrySubject;
8677
}
78+
8779
setSelectedProject() {
8880
this.listProjects.forEach( (project) => {
8981
if (project.id === this.activeEntry.project_id) {
@@ -130,9 +122,9 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
130122

131123
isFeatureToggleActivated() {
132124
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
133-
map((enabled) => {
125+
map((enabled) => {
134126
return enabled === true ? true : false;
135-
})
136-
).toPromise();
127+
})
128+
).toPromise();
137129
}
138130
}

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ export class TimeClockComponent implements OnInit, OnDestroy {
2424
activeTimeEntry: Entry;
2525
clockOutSubscription: Subscription;
2626
storeSubscribe: Subscription;
27-
storeSubject;
2827
exponentialGrowth;
2928

30-
31-
3229
constructor(
3330
private featureManagerService: FeatureManagerService,
3431
private azureAdB2CService: AzureAdB2CService,
@@ -38,11 +35,8 @@ export class TimeClockComponent implements OnInit, OnDestroy {
3835
) {}
3936

4037
async ngOnInit(): Promise<void> {
41-
4238
this.exponentialGrowth = await this.isFeatureToggleActivated();
43-
4439
this.username = this.azureAdB2CService.isLogin() ? this.azureAdB2CService.getName() : '';
45-
4640
this.storeSubscribe = this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
4741
this.activeTimeEntry = activeTimeEntry;
4842
if (this.activeTimeEntry) {
@@ -51,9 +45,6 @@ export class TimeClockComponent implements OnInit, OnDestroy {
5145
this.areFieldsVisible = false;
5246
}
5347
});
54-
// tslint:disable-next-line
55-
this.exponentialGrowth ? this.storeSubscribe = this.storeSubject : this.storeSubject;
56-
5748
this.reloadSummariesOnClockOut();
5849
}
5950

@@ -83,20 +74,18 @@ export class TimeClockComponent implements OnInit, OnDestroy {
8374
}
8475

8576
ngOnDestroy(): void {
86-
// tslint:disable-next-line
8777
this.exponentialGrowth && this.storeSubscribe.unsubscribe();
8878
this.clockOutSubscription.unsubscribe();
8979
this.storeSubscribe.unsubscribe();
9080
}
9181

92-
isFeatureToggleActivated() {
93-
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
94-
map((enabled) => {
95-
return enabled === true ? true : false;
96-
})
97-
).toPromise();
98-
}
99-
82+
isFeatureToggleActivated() {
83+
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
84+
map((enabled) => {
85+
return enabled === true ? true : false;
86+
})
87+
).toPromise();
88+
}
10089
}
10190

10291

0 commit comments

Comments
 (0)