Skip to content
Merged
Prev Previous commit
Next Next commit
refactor: TT-106 Use the exponentialGrowth flag to destroy unnecessar…
…y requests in EntryFields, ProjectListHover, TimeClock components
  • Loading branch information
VanessaIniguezG authored and scastillo-jp committed Feb 17, 2021
commit 480f0332328b126c9b3a56a64bada1a9fd4caf05
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ProjectState } from '../../../customer-management/components/projects/c
import { TechnologyState } from '../../../shared/store/technology.reducers';
import { ActivityState, LoadActivities } from '../../../activities-management/store';
import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service';

import * as entryActions from '../../store/entry.actions';
import { get } from 'lodash';
import * as moment from 'moment';
Expand Down Expand Up @@ -37,10 +36,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
loadActivitiesSubscribe: Subscription;
loadActiveEntrySubscribe: Subscription;
actionSetDateSubscribe: Subscription;
loadActivitiesSubject;
loadActiveEntrySubject;
actionSetDateSubject;

exponentialGrowth;

constructor(
Expand All @@ -59,20 +54,17 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
});
}


async ngOnInit(): Promise<void> {
this.exponentialGrowth = await this.isFeatureToggleActivated();
this.store.dispatch(new LoadActivities());
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1, new Date().getFullYear()));
this.loadActivitiesSubject = this.actionsSubject$
this.loadActivitiesSubscribe = this.actionsSubject$
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
.subscribe((action) => {
this.activities = action.payload;
this.store.dispatch(new LoadActiveEntry());
});
// tslint:disable-next-line
this.exponentialGrowth ? this.loadActivitiesSubscribe = this.loadActivitiesSubject : this.loadActivitiesSubject;
this.loadActiveEntrySubject = this.actionsSubject$
this.loadActiveEntrySubscribe = this.actionsSubject$
.pipe(
filter(
(action: any) =>
Expand All @@ -90,9 +82,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
this.store.dispatch(new entryActions.LoadEntriesSummary());
}
});
// tslint:disable-next-line
this.exponentialGrowth ? this.loadActiveEntrySubscribe = this.loadActiveEntrySubject : this.loadActiveEntrySubject;
this.actionSetDateSubject = this.actionsSubject$
this.actionSetDateSubscribe = this.actionsSubject$
.pipe(filter((action: any) => action.type === EntryActionTypes.LOAD_ACTIVE_ENTRY_SUCCESS))
.subscribe((action) => {
this.activeEntry = action.payload;
Expand All @@ -106,8 +96,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
start_hour: formatDate(this.activeEntry.start_date, 'HH:mm', 'en'),
};
});
// tslint:disable-next-line
this.exponentialGrowth ? this.actionSetDateSubscribe = this.actionSetDateSubject : this.actionSetDateSubject;
}
get activity_id() {
return this.entryForm.get('activity_id');
Expand Down Expand Up @@ -191,7 +179,6 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {


ngOnDestroy(): void {

if (this.exponentialGrowth) {
this.loadActivitiesSubscribe.unsubscribe();
this.loadActiveEntrySubscribe.unsubscribe();
Expand All @@ -200,10 +187,10 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
}

isFeatureToggleActivated() {
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
map((enabled) => {
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
map((enabled) => {
return enabled === true ? true : false;
})
).toPromise();
})
).toPromise();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
isLoading$: Observable<boolean>;
projectsSubscribe: Subscription;
activeEntrySubscribe: Subscription;
projectsSubject;
activeEntrySubject;
exponentialGrowth;

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

async ngOnInit(): Promise<void> {

this.exponentialGrowth = await this.isFeatureToggleActivated();

this.store.dispatch(new actions.LoadProjects());
const projects$ = this.store.pipe(select(getProjects));
this.projectsSubject = projects$.subscribe((projects) => {
this.projectsSubscribe = projects$.subscribe((projects) => {
this.listProjects = [];
projects.forEach((project) => {
const projectWithSearchField = {...project};
Expand All @@ -54,8 +50,6 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
);
this.loadActiveTimeEntry();
});
// tslint:disable-next-line
this.exponentialGrowth ? this.projectsSubscribe = this.projectsSubject : this.projectsSubject;
this.updateEntrySubscription = this.actionsSubject$.pipe(
filter((action: any) => (
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS
Expand All @@ -65,13 +59,12 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
this.activeEntry = action.payload;
this.setSelectedProject();
});

}

loadActiveTimeEntry() {
this.store.dispatch(new entryActions.LoadActiveEntry());
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
this.activeEntrySubject = activeEntry$.subscribe((activeEntry) => {
this.activeEntrySubscribe = activeEntry$.subscribe((activeEntry) => {
this.activeEntry = activeEntry;
if (activeEntry) {
this.showClockIn = false;
Expand All @@ -81,9 +74,8 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
this.projectsForm.setValue({ project_id: null });
}
});
// tslint:disable-next-line
this.exponentialGrowth ? this.activeEntrySubscribe = this.activeEntrySubject : this.activeEntrySubject;
}

setSelectedProject() {
this.listProjects.forEach( (project) => {
if (project.id === this.activeEntry.project_id) {
Expand Down Expand Up @@ -130,9 +122,9 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {

isFeatureToggleActivated() {
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
map((enabled) => {
map((enabled) => {
return enabled === true ? true : false;
})
).toPromise();
})
).toPromise();
}
}
25 changes: 7 additions & 18 deletions src/app/modules/time-clock/pages/time-clock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ export class TimeClockComponent implements OnInit, OnDestroy {
activeTimeEntry: Entry;
clockOutSubscription: Subscription;
storeSubscribe: Subscription;
storeSubject;
exponentialGrowth;



constructor(
private featureManagerService: FeatureManagerService,
private azureAdB2CService: AzureAdB2CService,
Expand All @@ -38,11 +35,8 @@ export class TimeClockComponent implements OnInit, OnDestroy {
) {}

async ngOnInit(): Promise<void> {

this.exponentialGrowth = await this.isFeatureToggleActivated();

this.username = this.azureAdB2CService.isLogin() ? this.azureAdB2CService.getName() : '';

this.storeSubscribe = this.store.pipe(select(getActiveTimeEntry)).subscribe((activeTimeEntry) => {
this.activeTimeEntry = activeTimeEntry;
if (this.activeTimeEntry) {
Expand All @@ -51,9 +45,6 @@ export class TimeClockComponent implements OnInit, OnDestroy {
this.areFieldsVisible = false;
}
});
// tslint:disable-next-line
this.exponentialGrowth ? this.storeSubscribe = this.storeSubject : this.storeSubject;

this.reloadSummariesOnClockOut();
}

Expand Down Expand Up @@ -83,20 +74,18 @@ export class TimeClockComponent implements OnInit, OnDestroy {
}

ngOnDestroy(): void {
// tslint:disable-next-line
this.exponentialGrowth && this.storeSubscribe.unsubscribe();
this.clockOutSubscription.unsubscribe();
this.storeSubscribe.unsubscribe();
}

isFeatureToggleActivated() {
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
map((enabled) => {
return enabled === true ? true : false;
})
).toPromise();
}

isFeatureToggleActivated() {
return this.featureManagerService.isToggleEnabledForUser('exponential-growth').pipe(
map((enabled) => {
return enabled === true ? true : false;
})
).toPromise();
}
}