Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[44152] On work package creation, dates are not reverted when date picker is cancelled (#11320)

Behrokh Satarnejada0c3b2673214
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
index 0b575767d42..1b02baeea93 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.ts
@@ -26,10 +26,7 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import {
- ChangeDetectionStrategy,
- Component,
-} from '@angular/core';
+import { Component } from '@angular/core';
import { DatePickerEditFieldComponent } from 'core-app/shared/components/fields/edit/field-types/date-picker-edit-field.component';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
@@ -40,7 +37,6 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packag
class="op-input"
type="text" />
`,
- changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent {
dates = '';
@@ -61,12 +57,18 @@ export class CombinedDateEditFieldComponent extends DatePickerEditFieldComponent
});
}
+ protected onModalClosed():void {
+ this.resetDates();
+ super.onModalClosed();
+ }
+
// Overwrite super in order to set the initial dates.
protected initialize():void {
super.initialize();
+ this.resetDates();
+ }
- // this breaks the preceived abstraction of the edit fields. But the date picker
- // is already highly specific to start and due Date.
+ protected resetDates():void {
this.dates = `${this.currentStartDate} - ${this.currentDueDate}`;
}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts
index 02590ccfdd4..efcc0ce334a 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/date-picker-edit-field.component.ts
@@ -84,7 +84,11 @@ export abstract class DatePickerEditFieldComponent extends EditFieldComponent im
.closingEvent
.pipe(take(1))
.subscribe(() => {
- void this.handler.handleUserSubmit();
+ this.onModalClosed();
});
}
+
+ protected onModalClosed():void {
+ void this.handler.handleUserSubmit();
+ }
}
diff --git a/spec/features/work_packages/new/new_work_package_spec.rb b/spec/features/work_packages/new/new_work_package_spec.rb
index fc58b6aa39b..68d77f6ee65 100644
--- a/spec/features/work_packages/new/new_work_package_spec.rb
+++ b/spec/features/work_packages/new/new_work_package_spec.rb
@@ -338,6 +338,31 @@ describe 'new work package', js: true do
expect(wp.assigned_to).to eq user
end
+ it 'resets the dates when opening the datepicker and cancelling (Regression #44152)' do
+ create_work_package_globally(type_task, project.name)
+ expect(page).to have_selector(safeguard_selector, wait: 10)
+
+ # Open datepicker
+ date_field = wp_page.edit_field(:combinedDate)
+ date_field.input_element.click
+
+ # Select date
+ datepicker = date_field.datepicker
+ start = (Time.zone.today - 1.day).iso8601
+ datepicker.focus_start_date
+ datepicker.set_date start
+
+ due = (Time.zone.today + 1.day).iso8601
+ datepicker.focus_due_date
+ datepicker.set_date due
+
+ date_field.expect_value "#{start} - #{due}"
+
+ # Cancel
+ date_field.cancel_by_click
+ date_field.expect_value 'no start date - no finish date'
+ end
+
context 'with a project without type_bug' do
let!(:project_without_bug) do
create(:project, name: 'Unrelated project', types: [type_task])
diff --git a/spec/support/edit_fields/date_edit_field.rb b/spec/support/edit_fields/date_edit_field.rb
index 269b45338f6..7eee541ab4e 100644
--- a/spec/support/edit_fields/date_edit_field.rb
+++ b/spec/support/edit_fields/date_edit_field.rb
@@ -146,7 +146,9 @@ class DateEditField < EditField
end
def expect_value(value)
- expect(input_element.value).to eq(value)
+ expect(page).to have_selector (".#{property_name} input") do |input|
+ input.value == value
+ end
end
def set_active_date(value)