Skip to content

Commit

Permalink
Do not switch back to hiding fields when the field was already touched
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Feb 24, 2025
1 parent 52cb39a commit 2fee073
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
31 changes: 21 additions & 10 deletions app/components/work_packages/date_picker/date_form_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ def initialize(work_package:,
disabled:,
is_milestone:,
focused_field: :start_date,
touched_field_map: nil,
date_mode: nil)
super()

@work_package = 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
Expand All @@ -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

Check notice on line 72 in app/components/work_packages/date_picker/date_form_component.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/components/work_packages/date_picker/date_form_component.rb#L64-L72 <Metrics/AbcSize>

Assignment Branch Condition size for show_text_field? is too high. [<0, 11, 13> 17.03/17]
Raw output
app/components/work_packages/date_picker/date_form_component.rb:64:7: C: Metrics/AbcSize: Assignment Branch Condition size for show_text_field? is too high. [<0, 11, 13> 17.03/17]

Check notice on line 72 in app/components/work_packages/date_picker/date_form_component.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/components/work_packages/date_picker/date_form_component.rb#L64-L72 <Metrics/PerceivedComplexity>

Perceived complexity for `show_text_field?` is too high. [11/8]
Raw output
app/components/work_packages/date_picker/date_form_component.rb:64:7: C: Metrics/PerceivedComplexity: Perceived complexity for `show_text_field?` is too high. [11/8]

def text_field_options(name:, label:)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
schedule_manually:,
is_milestone: milestone?,
focused_field:,
touched_field_map:,
date_mode:,
disabled: disabled?))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 ""
Expand Down

0 comments on commit 2fee073

Please sign in to comment.