diff --git a/app/components/work_packages/date_picker/date_form_component.rb b/app/components/work_packages/date_picker/date_form_component.rb index 763a4c70b6d1..f7d1bbc3895d 100644 --- a/app/components/work_packages/date_picker/date_form_component.rb +++ b/app/components/work_packages/date_picker/date_form_component.rb @@ -39,6 +39,7 @@ def initialize(work_package:, disabled:, is_milestone:, focused_field: :start_date, + touched_field_map: nil, date_mode: nil) super() @@ -46,6 +47,7 @@ def initialize(work_package:, @schedule_manually = schedule_manually @is_milestone = is_milestone @date_mode = date_mode + @touched_field_map = touched_field_map @focused_field = update_focused_field(focused_field) @disabled = disabled end @@ -60,11 +62,13 @@ def container_classes(name) end def show_text_field?(name) - return true if @is_milestone - return true unless @schedule_manually + return true if @is_milestone || !@schedule_manually + return true if @date_mode.present? && @date_mode == "range" + return true if field_value(name).present? || @touched_field_map["#{name}_touched"] - (@date_mode.present? && @date_mode == "range") || - field_value(name).present? || (name == :due_date && field_value(:start_date).nil?) + return true if name == :due_date && field_value(:start_date).nil? + + name == :due_date && @touched_field_map["start_date_touched"].present? && !@touched_field_map["start_date_touched"] end def text_field_options(name:, label:) @@ -124,13 +128,20 @@ def update_focused_field(focused_field) end def focused_field_for_single_date_mode(focused_field) - if focused_field == "duration" - :duration - elsif field_value(:start_date).nil? - :due_date - elsif field_value(:due_date).nil? - :start_date + return :duration if focused_field.to_s == "duration" + + # When the combined date is triggered, we have to actually check for the values. + # This happens only on initialization + if focused_field == "combinedDate" + return :due_date if field_value(:start_date).nil? + return :start_date if field_value(:due_date).nil? end + + # Focus the field if it is shown.. + return focused_field if show_text_field?(focused_field) + + # .. if not, focus the other one + focused_field == :start_date ? :due_date : :start_date end def disabled?(name) diff --git a/app/components/work_packages/date_picker/form_content_component.html.erb b/app/components/work_packages/date_picker/form_content_component.html.erb index 8869db9ad61b..52aeb5813a41 100644 --- a/app/components/work_packages/date_picker/form_content_component.html.erb +++ b/app/components/work_packages/date_picker/form_content_component.html.erb @@ -62,6 +62,7 @@ schedule_manually:, is_milestone: milestone?, focused_field:, + touched_field_map:, date_mode:, disabled: disabled?)) end 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 a3c1ca170874..5e7128135b98 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 @@ -139,7 +139,7 @@ export abstract class DatePickerEditFieldComponent extends EditFieldComponent im // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access url.searchParams.set('work_package[ignore_non_working_days]', this.nullAsEmptyStringFormatter(this.resource.includeNonWorkingDays)); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - if (this.resource?.id === 'new') { + if (this.resource?.id === 'new' && this.resource.startDate) { url.searchParams.set('work_package[start_date_touched]', 'true'); } diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts index 3053be19883b..342f77c205d6 100644 --- a/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts +++ b/frontend/src/stimulus/controllers/dynamic/work-packages/date-picker/preview.controller.ts @@ -404,8 +404,8 @@ export default class PreviewController extends DialogPreviewController { // This is a very special case in which only one date is set, and we want to // modify exactly that date again because it is highlighted. Then it does // not make sense to display a range as we are only changing one date. - if ((this.highlightedField?.name === 'work_package[start_date]' && this.currentStartDate && !this.currentDueDate) - || (this.highlightedField?.name === 'work_package[due_date]' && !this.currentStartDate && this.currentDueDate)) { + if ((this.highlightedField?.name === 'work_package[start_date]' && !this.currentDueDate) + || (this.highlightedField?.name === 'work_package[due_date]' && !this.currentStartDate)) { return 'single'; } diff --git a/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb b/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb index 1292bdcc483b..065d339d6bbf 100644 --- a/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb +++ b/spec/features/work_packages/datepicker/datepicker_single_date_mode_logic_spec.rb @@ -656,6 +656,7 @@ def save_and_reopen datepicker.expect_duration "3" datepicker.set_due_date "" + wait_for_network_idle datepicker.set_start_date "" datepicker.expect_start_date "" @@ -679,6 +680,7 @@ def save_and_reopen datepicker.expect_duration "3" datepicker.set_start_date "" + wait_for_network_idle datepicker.set_due_date "" datepicker.expect_start_date ""