From 98aa196c8349d64e11f215cff580d0bef8268f52 Mon Sep 17 00:00:00 2001 From: mmaquina Date: Fri, 4 Aug 2023 14:21:37 -0300 Subject: [PATCH 1/2] 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 --- .../time-clock/services/entry.service.ts | 4 ++- .../time-clock/store/entry.effects.spec.ts | 27 +++++++++++++++++-- .../modules/time-clock/store/entry.effects.ts | 11 ++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/app/modules/time-clock/services/entry.service.ts b/src/app/modules/time-clock/services/entry.service.ts index ebe4ddd0c..c93aba502 100644 --- a/src/app/modules/time-clock/services/entry.service.ts +++ b/src/app/modules/time-clock/services/entry.service.ts @@ -10,6 +10,9 @@ import { DatePipe } from '@angular/common'; import { Entry } from '../../shared/models'; import * as moment from 'moment'; + +export const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999; + @Injectable({ providedIn: 'root', }) @@ -69,7 +72,6 @@ export class EntryService { } loadEntriesByTimeRange(range: TimeEntriesTimeRange, userId: string[] | string ): Observable { - const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999; const loadEntriesByTimeRangeURL = this.urlInProductionLegacy ? this.baseUrl : this.baseUrl + '/report/'; return this.http.get(loadEntriesByTimeRangeURL, { diff --git a/src/app/modules/time-clock/store/entry.effects.spec.ts b/src/app/modules/time-clock/store/entry.effects.spec.ts index 562f68269..e18c1b123 100644 --- a/src/app/modules/time-clock/store/entry.effects.spec.ts +++ b/src/app/modules/time-clock/store/entry.effects.spec.ts @@ -9,11 +9,12 @@ import * as moment from 'moment'; import { ToastrModule, ToastrService } from 'ngx-toastr'; import { Observable, of, throwError } from 'rxjs'; import { TimeEntriesTimeRange } from '../models/time-entries-time-range'; -import { EntryService } from '../services/entry.service'; +import { EntryService, MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service'; import { INFO_SAVED_SUCCESSFULLY } from './../../shared/messages'; import { EntryActionTypes, SwitchTimeEntry, DeleteEntry, CreateEntry } from './entry.actions'; import { EntryEffects } from './entry.effects'; + describe('TimeEntryActionEffects', () => { let actions$: Observable; @@ -385,7 +386,7 @@ describe('TimeEntryActionEffects', () => { spyOn(toastrService, 'success'); effects.updateCurrentOrLastEntry$.subscribe(action => { - expect(toastrService.success).toHaveBeenCalledWith('You change the time-in successfully'); + expect(toastrService.success).toHaveBeenCalledWith('You changed the time-in successfully'); expect(action.type).toEqual(EntryActionTypes.UPDATE_ENTRY_RUNNING); }); }); @@ -399,4 +400,26 @@ describe('TimeEntryActionEffects', () => { }); }); + it('should show a warning when maximum number of entries is received', async () => { + const timeRange: TimeEntriesTimeRange = { start_date: moment(new Date()), end_date: moment(new Date()) }; + const userId = '*'; + const entries = []; + for (let i = 0; i < MAX_NUMBER_OF_ENTRIES_FOR_REPORTS; i++){ + entries.push({...entry, id: i.toString() }); + } + + const serviceSpy = spyOn(service, 'loadEntriesByTimeRange'); + serviceSpy.and.returnValue(of(entries)); + spyOn(toastrService, 'warning'); + + actions$ = of({ type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange, userId }); + + effects.loadEntriesByTimeRange$.subscribe(action => { + expect(toastrService.warning).toHaveBeenCalledWith( + 'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS + + ' entries reached, try filtering the request by users or date.' + + ' Some information may be missing.' + ); + }); + }); }); diff --git a/src/app/modules/time-clock/store/entry.effects.ts b/src/app/modules/time-clock/store/entry.effects.ts index f3041bb35..1fea3ba58 100644 --- a/src/app/modules/time-clock/store/entry.effects.ts +++ b/src/app/modules/time-clock/store/entry.effects.ts @@ -5,7 +5,7 @@ import { Action } from '@ngrx/store'; import { ToastrService } from 'ngx-toastr'; import { Observable, of } from 'rxjs'; import { catchError, map, mergeMap, switchMap } from 'rxjs/operators'; -import { EntryService } from '../services/entry.service'; +import { EntryService, MAX_NUMBER_OF_ENTRIES_FOR_REPORTS } from '../services/entry.service'; import * as actions from './entry.actions'; import * as moment from 'moment'; @@ -241,7 +241,7 @@ export class EntryEffects { if (isStartTimeInLastEntry) { return new actions.UpdateEntry({ id: lastEntry.id, end_date: entry.start_date }); } else { - this.toastrService.success('You change the time-in successfully'); + this.toastrService.success('You changed the time-in successfully'); return new actions.UpdateEntryRunning(entry); } }), @@ -260,6 +260,13 @@ export class EntryEffects { mergeMap((action) => this.entryService.loadEntriesByTimeRange(action.timeRange, action.userId).pipe( map((response) => { + if (response.length >= MAX_NUMBER_OF_ENTRIES_FOR_REPORTS){ + this.toastrService.warning( + 'Still loading. Limit of ' + MAX_NUMBER_OF_ENTRIES_FOR_REPORTS + + ' entries reached, try filtering the request.' + + ' Some information may be missing.' + ); + } return new actions.LoadEntriesByTimeRangeSuccess(response); }), catchError((error) => { From 79d03977c63830c6973b9455e1d0425bcacee12e Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 4 Aug 2023 17:23:27 +0000 Subject: [PATCH 2/2] chore(release): 2.5.0 [skip ci]nn --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fae210b0d..3d5222872 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "time-tracker", - "version": "2.4.1", + "version": "2.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1664e07d8..e60355754 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "time-tracker", - "version": "2.4.1", + "version": "2.5.0", "scripts": { "preinstall": "npx npm-force-resolutions", "ng": "ng",