Skip to content

Commit 98aa196

Browse files
authored
feat: TTL-909 add warning for max time entries (#998)
* feat: TTL-909 add warning for max time entries * Update src/app/modules/time-clock/store/entry.effects.ts
1 parent bd0d48a commit 98aa196

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { DatePipe } from '@angular/common';
1010
import { Entry } from '../../shared/models';
1111
import * as moment from 'moment';
1212

13+
14+
export const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999;
15+
1316
@Injectable({
1417
providedIn: 'root',
1518
})
@@ -69,7 +72,6 @@ export class EntryService {
6972
}
7073

7174
loadEntriesByTimeRange(range: TimeEntriesTimeRange, userId: string[] | string ): Observable<any> {
72-
const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999;
7375
const loadEntriesByTimeRangeURL = this.urlInProductionLegacy ? this.baseUrl : this.baseUrl + '/report/';
7476
return this.http.get(loadEntriesByTimeRangeURL,
7577
{

src/app/modules/time-clock/store/entry.effects.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import * as moment from 'moment';
99
import { ToastrModule, ToastrService } from 'ngx-toastr';
1010
import { Observable, of, throwError } from 'rxjs';
1111
import { TimeEntriesTimeRange } from '../models/time-entries-time-range';
12-
import { EntryService } from '../services/entry.service';
12+
import { EntryService, MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service';
1313
import { INFO_SAVED_SUCCESSFULLY } from './../../shared/messages';
1414
import { EntryActionTypes, SwitchTimeEntry, DeleteEntry, CreateEntry } from './entry.actions';
1515
import { EntryEffects } from './entry.effects';
1616

17+
1718
describe('TimeEntryActionEffects', () => {
1819

1920
let actions$: Observable<Action>;
@@ -385,7 +386,7 @@ describe('TimeEntryActionEffects', () => {
385386
spyOn(toastrService, 'success');
386387

387388
effects.updateCurrentOrLastEntry$.subscribe(action => {
388-
expect(toastrService.success).toHaveBeenCalledWith('You change the time-in successfully');
389+
expect(toastrService.success).toHaveBeenCalledWith('You changed the time-in successfully');
389390
expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY_RUNNING);
390391
});
391392
});
@@ -399,4 +400,26 @@ describe('TimeEntryActionEffects', () => {
399400
});
400401
});
401402

403+
it('should show a warning when maximum number of entries is received', async () => {
404+
const timeRange: TimeEntriesTimeRange = { start_date: moment(new Date()), end_date: moment(new Date()) };
405+
const userId = '*';
406+
const entries = [];
407+
for (let i = 0; i < MAX_NUMBER_OF_ENTRIES_FOR_REPORTS; i++){
408+
entries.push({...entry, id: i.toString() });
409+
}
410+
411+
const serviceSpy = spyOn(service, 'loadEntriesByTimeRange');
412+
serviceSpy.and.returnValue(of(entries));
413+
spyOn(toastrService, 'warning');
414+
415+
actions$ = of({ type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange, userId });
416+
417+
effects.loadEntriesByTimeRange$.subscribe(action => {
418+
expect(toastrService.warning).toHaveBeenCalledWith(
419+
'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS +
420+
' entries reached, try filtering the request by users or date.' +
421+
' Some information may be missing.'
422+
);
423+
});
424+
});
402425
});

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Action } from '@ngrx/store';
55
import { ToastrService } from 'ngx-toastr';
66
import { Observable, of } from 'rxjs';
77
import { catchError, map, mergeMap, switchMap } from 'rxjs/operators';
8-
import { EntryService } from '../services/entry.service';
8+
import { EntryService, MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service';
99
import * as actions from './entry.actions';
1010
import * as moment from 'moment';
1111

@@ -241,7 +241,7 @@ export class EntryEffects {
241241
if (isStartTimeInLastEntry) {
242242
return new actions.UpdateEntry({ id: lastEntry.id, end_date: entry.start_date });
243243
} else {
244-
this.toastrService.success('You change the time-in successfully');
244+
this.toastrService.success('You changed the time-in successfully');
245245
return new actions.UpdateEntryRunning(entry);
246246
}
247247
}),
@@ -260,6 +260,13 @@ export class EntryEffects {
260260
mergeMap((action) =>
261261
this.entryService.loadEntriesByTimeRange(action.timeRange, action.userId).pipe(
262262
map((response) => {
263+
if (response.length >= MAX_NUMBER_OF_ENTRIES_FOR_REPORTS){
264+
this.toastrService.warning(
265+
'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS +
266+
' entries reached, try filtering the request.' +
267+
' Some information may be missing.'
268+
);
269+
}
263270
return new actions.LoadEntriesByTimeRangeSuccess(response);
264271
}),
265272
catchError((error) => {

0 commit comments

Comments
 (0)