From 0582e878629ea13c1cd5a2af845000aaa8abc916 Mon Sep 17 00:00:00 2001 From: Diego Tinitana Date: Mon, 11 May 2020 11:36:25 -0500 Subject: [PATCH] fix: #172 Create-time-entries-manually fix view --- .../details-fields/details-fields.component.html | 2 +- .../details-fields/details-fields.component.ts | 7 +++++-- .../time-clock/pages/time-clock.component.spec.ts | 2 -- src/app/modules/time-clock/store/entry.actions.spec.ts | 7 +++++-- src/app/modules/time-clock/store/entry.actions.ts | 2 +- src/app/modules/time-clock/store/entry.reducer.spec.ts | 10 +++++++++- src/app/modules/time-clock/store/entry.reducer.ts | 9 +++++---- .../time-entries/pages/time-entries.component.html | 2 +- .../time-entries/pages/time-entries.component.ts | 7 +++---- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.html b/src/app/modules/shared/components/details-fields/details-fields.component.html index c870051c7..1408ce625 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.html +++ b/src/app/modules/shared/components/details-fields/details-fields.component.html @@ -1,5 +1,5 @@
-
+
Project
diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index 5ebd8c933..1b403deb8 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -68,7 +68,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { const technologies$ = this.store.pipe(select(allTechnologies)); technologies$.subscribe((response) => { this.isLoading = response.isLoading; - const filteredItems = response.technologyList.items.filter(item => !this.selectedTechnology.includes(item.name)); + const filteredItems = response.technologyList.items.filter( + (item) => !this.selectedTechnology.includes(item.name) + ); this.technology = { items: filteredItems }; }); @@ -87,7 +89,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { ngOnChanges(): void { if (this.entryToEdit) { - this.selectedTechnology = this.entryToEdit.technologies; + this.selectedTechnology = this.entryToEdit.technologies ? this.entryToEdit.technologies : []; this.project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id); const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id); this.projectName = this.project.name; @@ -145,6 +147,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { uri: this.entryForm.value.uri, }; this.saveEntry.emit(entry); + this.ngOnChanges(); this.closeModal.nativeElement.click(); } } diff --git a/src/app/modules/time-clock/pages/time-clock.component.spec.ts b/src/app/modules/time-clock/pages/time-clock.component.spec.ts index e67ac8fe8..8d33de27f 100644 --- a/src/app/modules/time-clock/pages/time-clock.component.spec.ts +++ b/src/app/modules/time-clock/pages/time-clock.component.spec.ts @@ -11,8 +11,6 @@ import { ProjectListHoverComponent } from '../components'; import { FilterProjectPipe } from '../../shared/pipes'; import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service'; -import { ActionsSubject } from '@ngrx/store'; - describe('TimeClockComponent', () => { let component: TimeClockComponent; let fixture: ComponentFixture; diff --git a/src/app/modules/time-clock/store/entry.actions.spec.ts b/src/app/modules/time-clock/store/entry.actions.spec.ts index cc10bec91..c5b6ce429 100644 --- a/src/app/modules/time-clock/store/entry.actions.spec.ts +++ b/src/app/modules/time-clock/store/entry.actions.spec.ts @@ -46,8 +46,11 @@ describe('Actions for Entries', () => { it('UpdateActiveEntrySuccess type is EntryActionTypes.UDPATE_ACTIVE_ENTRY_SUCCESS', () => { const updateActiveEntrySuccess = new actions.UpdateActiveEntrySuccess({ - project_id: '1', - description: 'It is good for learning', + id: '1', + start_date: new Date(), + end_date: new Date(), + activity: '', + technologies: ['abc', 'abc'], }); expect(updateActiveEntrySuccess.type).toEqual(actions.EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS); }); diff --git a/src/app/modules/time-clock/store/entry.actions.ts b/src/app/modules/time-clock/store/entry.actions.ts index 63fa9c2fc..d6f745595 100644 --- a/src/app/modules/time-clock/store/entry.actions.ts +++ b/src/app/modules/time-clock/store/entry.actions.ts @@ -97,7 +97,7 @@ export class UpdateActiveEntry implements Action { export class UpdateActiveEntrySuccess implements Action { public readonly type = EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS; - constructor(public payload: NewEntry) {} + constructor(public payload: Entry) {} } export class UpdateActiveEntryFail implements Action { diff --git a/src/app/modules/time-clock/store/entry.reducer.spec.ts b/src/app/modules/time-clock/store/entry.reducer.spec.ts index 93b200aa7..9cc018f5d 100644 --- a/src/app/modules/time-clock/store/entry.reducer.spec.ts +++ b/src/app/modules/time-clock/store/entry.reducer.spec.ts @@ -11,6 +11,14 @@ describe('entryReducer', () => { technologies: ['angular', 'typescript'], }; + const newEntry: Entry = { + id: '1', + start_date: new Date(), + end_date: new Date(), + activity: '', + technologies: ['abc', 'abc'], + }; + it('on Default, ', () => { const action = new actions.DefaultEntry(); const state = entryReducer(initialState, action); @@ -124,7 +132,7 @@ describe('entryReducer', () => { isLoading: false, message: '', }; - const action = new actions.UpdateActiveEntrySuccess(entry); + const action = new actions.UpdateActiveEntrySuccess(newEntry); const state = entryReducer(currentState, action); expect(state.isLoading).toEqual(false); diff --git a/src/app/modules/time-clock/store/entry.reducer.ts b/src/app/modules/time-clock/store/entry.reducer.ts index 99fbbb9e6..dc6f185da 100644 --- a/src/app/modules/time-clock/store/entry.reducer.ts +++ b/src/app/modules/time-clock/store/entry.reducer.ts @@ -72,7 +72,7 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi return { ...state, active: action.payload, - entryList: [...state.entryList, action.payload], + entryList: [action.payload, ...state.entryList], isLoading: false, message: 'You clocked-in successfully', }; @@ -120,11 +120,12 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi } case EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS: { - const activeEntry = { ...state.active, ...action.payload }; - + const entryList = [...state.entryList]; + const index = entryList.findIndex((entry) => entry.id === action.payload.id); + entryList[index] = action.payload; return { ...state, - active: activeEntry, + entryList, isLoading: false, }; } diff --git a/src/app/modules/time-entries/pages/time-entries.component.html b/src/app/modules/time-entries/pages/time-entries.component.html index 1a40727db..ea6362e92 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.html +++ b/src/app/modules/time-entries/pages/time-entries.component.html @@ -34,7 +34,7 @@ > {{ item.project_id }} {{ item.time }} - {{ item.date }} + {{ item.start_date | date:'dd/MM/yyyy' }}