Skip to content

Commit cb1a5c5

Browse files
authored
fix: TT-23 Clear form when adding an entry (Time Entries) (#660)
* fix: TT-23 Clear form when adding an entry (Time Entries) * fix: TT-23 rename function
1 parent 73d526a commit cb1a5c5

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@
141141
(technologyAdded)="onTechnologiesUpdated($event)"
142142
(technologyRemoved)="onTechnologiesUpdated($event)"
143143
[selectedTechnologies]="selectedTechnologies"
144-
>
144+
#technologies
145+
>
145146
</app-technologies>
146147

147148
<div class="form-group text-left">

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ describe('DetailsFieldsComponent', () => {
169169
});
170170
});
171171

172+
it('on cleanFieldsForm the project_id and project_name should be kept', () => {
173+
const entryFormValueExpected = {
174+
...formValues,
175+
activity_id: '',
176+
uri: '',
177+
start_date: formatDate(new Date(), DATE_FORMAT, 'en'),
178+
end_date: formatDate(new Date(), DATE_FORMAT, 'en'),
179+
start_hour: '00:00',
180+
end_hour: '00:00',
181+
description: '',
182+
technology: '',
183+
};
184+
185+
component.entryForm.setValue(formValues);
186+
component.cleanFieldsForm();
187+
188+
expect(component.entryForm.value).toEqual(entryFormValueExpected);
189+
});
190+
172191
it('should emit ngOnChange without data', () => {
173192
component.entryToEdit = null;
174193
component.ngOnChanges();

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { SaveEntryEvent } from './save-entry-event';
1919
import { ProjectSelectedEvent } from './project-selected-event';
2020
import { get } from 'lodash';
2121
import { DATE_FORMAT } from 'src/environments/environment';
22+
import { TechnologiesComponent } from '../technologies/technologies.component';
2223

2324
type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
2425
@Component({
@@ -33,6 +34,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
3334
@Output() saveEntry = new EventEmitter<SaveEntryEvent>();
3435
@Output() projectSelected = new EventEmitter<ProjectSelectedEvent>();
3536
@ViewChild('closeModal') closeModal: ElementRef;
37+
@ViewChild('technologies', { static: true }) technologies: TechnologiesComponent;
3638
entryForm: FormGroup;
3739
selectedTechnologies: string[] = [];
3840
isLoading = false;
@@ -151,11 +153,14 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
151153
}
152154
}
153155

154-
cleanForm() {
156+
cleanForm(skipProject: boolean = false): void {
155157
this.selectedTechnologies = [];
156-
this.entryForm.setValue({
157-
project_name: '',
158-
project_id: '',
158+
this.technologies.query = '';
159+
const projectNameField = this.project_name.value;
160+
const projectName = get(projectNameField, 'search_field', projectNameField);
161+
this.entryForm.reset({
162+
project_name: skipProject ? projectName : '',
163+
project_id: skipProject ? this.project_id.value : '',
159164
activity_id: '',
160165
description: '',
161166
start_date: formatDate(new Date(), DATE_FORMAT, 'en'),
@@ -167,6 +172,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
167172
});
168173
}
169174

175+
cleanFieldsForm(): void {
176+
this.cleanForm(true);
177+
}
178+
170179
onTechnologiesUpdated($event: string[]) {
171180
this.selectedTechnologies = $event;
172181
}

src/app/modules/time-entries/pages/time-entries.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,17 @@
6464
<div class="modal-content" cdkDrag (cdkDragEnded)="resetDraggablePosition($event)">
6565
<div class="modal-header" cdkDragHandle>
6666
<h5 class="modal-title">{{ entryId ? 'Edit Entry' : 'New Entry' }}</h5>
67+
<button type="button" class="btn" (click)="detailsFields.cleanFieldsForm()">
68+
<i class="fa fa-undo" aria-hidden="true"></i>
69+
</button>
6770
</div>
6871
<div class="modal-body">
6972
<app-details-fields
7073
[entryToEdit]="entry"
7174
(saveEntry)="saveEntry($event)"
7275
(projectSelected)="projectSelected($event)"
7376
[canMarkEntryAsWIP]='canMarkEntryAsWIP'
77+
#detailsFields
7478
>
7579
</app-details-fields>
7680
</div>

0 commit comments

Comments
 (0)