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

First draft of a single date mode in datepicker. Therefore, the form was manually build to add buttons into it

Henriette Darge58cb72e37094
diff --git a/app/components/_index.sass b/app/components/_index.sass
index 85b20dad25c..802d5ae8e6b 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -7,6 +7,7 @@
@import "work_packages/activities_tab/journals/item_component/add_reactions"
@import "work_packages/activities_tab/journals/item_component/reactions"
@import "work_packages/date_picker/banner_component"
+@import "work_packages/date_picker/date_form_component"
@import "work_packages/date_picker/dialog_content_component"
@import "shares/modal_body_component"
@import "work_packages/reminder/modal_body_component"
diff --git a/app/components/work_packages/date_picker/date_form_component.html.erb b/app/components/work_packages/date_picker/date_form_component.html.erb
new file mode 100644
index 00000000000..556611367e6
--- /dev/null
+++ b/app/components/work_packages/date_picker/date_form_component.html.erb
@@ -0,0 +1,37 @@
+<%=
+ grid_layout("wp-datepicker-dialog-date-form", tag: :div) do |body|
+ body.with_area("start-date") do
+ flex_layout do |start_date|
+ start_date.with_row(classes: container_classes(:start_date, :button)) do
+ render(Primer::ButtonComponent.new(classes: "wp-datepicker-dialog-date-form--add-button")) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t("attributes.start_date")
+ end
+ end
+
+ start_date.with_row(classes: container_classes(:start_date, :text_field)) do
+ render(Primer::Alpha::TextField.new(**text_field_options(name: :start_date, label: I18n.t("attributes.start_date"))))
+ end
+ end
+ end
+
+ body.with_area("due-date") do
+ flex_layout do |due_date|
+ due_date.with_row(classes: container_classes(:due_date, :button)) do
+ render(Primer::ButtonComponent.new(classes: "wp-datepicker-dialog-date-form--add-button")) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t("attributes.due_date")
+ end
+ end
+
+ due_date.with_row(classes: container_classes(:due_date, :text_field)) do
+ render(Primer::Alpha::TextField.new(**text_field_options(name: :due_date, label: I18n.t("attributes.due_date"))))
+ end
+ end
+ end
+
+ body.with_area("duration") do
+ render(Primer::Alpha::TextField.new(**text_field_options(name: :duration, label: I18n.t("activerecord.attributes.work_package.duration"))))
+ end
+ end
+%>
diff --git a/app/forms/work_packages/date_picker/date_form.rb b/app/components/work_packages/date_picker/date_form_component.rb
similarity index 63%
rename from app/forms/work_packages/date_picker/date_form.rb
rename to app/components/work_packages/date_picker/date_form_component.rb
index 79189499c10..6a61d62ba40 100644
--- a/app/forms/work_packages/date_picker/date_form.rb
+++ b/app/components/work_packages/date_picker/date_form_component.rb
@@ -30,79 +30,53 @@
module WorkPackages
module DatePicker
- class DateForm < ApplicationForm
- ##
- # Primer::Forms::BaseComponent or ApplicationForm will always autofocus the
- # first input field with an error present on it. Despite this behavior being
- # a11y-friendly, it breaks the modal's UX when an invalid input field
- # is rendered.
- #
- # The reason for this is since we're implementing a "format on blur", when
- # we make a request to the server that will set an input field in an invalid
- # state and it is returned as such, any time we blur this autofocused field,
- # we'll perform another request that will still have the input in an invalid
- # state causing it to autofocus again and preventing us from leaving this
- # "limbo state".
- ##
- def before_render
- # no-op
- end
-
+ class DateFormComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
attr_reader :work_package
def initialize(work_package:,
schedule_manually:,
disabled:,
is_milestone:,
- focused_field: :start_date,
- touched_field_map: {})
+ focused_field: :start_date)
super()
@work_package = work_package
@schedule_manually = schedule_manually
@is_milestone = is_milestone
@focused_field = update_focused_field(focused_field)
- @touched_field_map = touched_field_map
@disabled = disabled
end
- form do |query_form|
- query_form.group(layout: :horizontal) do |group|
- group.hidden(name: "schedule_manually", value: @schedule_manually)
-
- if @is_milestone
- text_field(group, name: :start_date, label: I18n.t("attributes.date"))
-
- hidden_touched_field(group, name: :start_date)
- else
- text_field(group, name: :start_date, label: I18n.t("attributes.start_date"))
- text_field(group, name: :due_date, label: I18n.t("attributes.due_date"))
- text_field(group, name: :duration, label: I18n.t("activerecord.attributes.work_package.duration"))
-
- hidden_touched_field(group, name: :start_date)
- hidden_touched_field(group, name: :due_date)
- hidden_touched_field(group, name: :duration)
- end
-
- hidden_touched_field(group, name: :ignore_non_working_days)
- hidden_touched_field(group, name: :schedule_manually)
+ private
- group.fields_for(:initial) do |builder|
- WorkPackages::DatePicker::InitialValuesForm.new(builder, work_package:, is_milestone: @is_milestone)
- end
+ def container_classes(name, type)
+ classes = "wp-datepicker-dialog-date-form--field-container"
+ case type
+ when :button
+ classes += " wp-datepicker-dialog-date-form--field-container_hidden" if show_text_field?(name)
+ when :text_field
+ classes += " wp-datepicker-dialog-date-form--field-container_hidden" unless show_text_field?(name)
+ else
+ # Do nothing
end
+
+ classes
end
- private
+ def show_text_field?(name)
+ field_value(name).present? || (name == :due_date && field_value(:start_date).nil?)
+ end
- def text_field(group, name:, label:)
+ def text_field_options(name:, label:)
text_field_options = default_field_options(name).merge(
- name:,
+ name: "work_package[#{name.to_s}]",
+ id: "work_package_#{name.to_s}",
value: field_value(name),
disabled: disabled?(name),
label:,
caption: caption(name),
- show_clear_button: name != :duration,
+ show_clear_button: !duration_field?(name),
classes: "op-datepicker-modal--date-field #{'op-datepicker-modal--date-field_current' if @focused_field == name}",
validation_message: validation_message(name)
)
@@ -113,7 +87,7 @@ module WorkPackages
)
end
- group.text_field(**text_field_options)
+ text_field_options
end
def caption(name)
@@ -131,17 +105,6 @@ module WorkPackages
})) { text }
end
- def hidden_touched_field(group, name:)
- group.hidden(name: :"#{name}_touched",
- value: touched(name),
- data: { "work-packages--date-picker--preview-target": "touchedFieldInput",
- "referrer-field": name })
- end
-
- def touched(name)
- @touched_field_map["#{name}_touched"] || false
- end
-
def duration_field?(name)
name == :duration
end
@@ -151,7 +114,7 @@ module WorkPackages
case focused_field.to_s.underscore
when "combined_date"
- if field_value(:start_date).present? && field_value(:due_date).nil?
+ if field_value(:due_date).present? && field_value(:start_date).nil?
:due_date
else
:start_date
diff --git a/app/components/work_packages/date_picker/date_form_component.sass b/app/components/work_packages/date_picker/date_form_component.sass
new file mode 100644
index 00000000000..fa6c5d82383
--- /dev/null
+++ b/app/components/work_packages/date_picker/date_form_component.sass
@@ -0,0 +1,14 @@
+.wp-datepicker-dialog-date-form
+ display: grid
+ grid-template-columns: 1fr 1fr 170px
+ grid-template-areas: "start-date due-date duration"
+ grid-column-gap: 1rem
+
+ &--field-container
+ &_hidden
+ display: none
+
+ &--add-button
+ // The other fields have a 20px label on top + 4px space between label and field
+ margin-top: 24px
+ width: 100%
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 450d3ea05e1..82da0772d1d 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
@@ -56,14 +56,20 @@
end
if show_date_form
- body.with_row(mb: 3, classes: "FormControl-horizontalGroup--sm-vertical") do
- render(WorkPackages::DatePicker::DateForm.new(f,
- work_package:,
- schedule_manually:,
- is_milestone: milestone?,
- focused_field:,
- touched_field_map:,
- disabled: disabled?))
+ body.with_row(mb: 3) do
+ render(WorkPackages::DatePicker::DateFormComponent.new(work_package:,
+ schedule_manually:,
+ is_milestone: milestone?,
+ focused_field:,
+ disabled: disabled?))
+ end
+ body.with_row do
+ render(WorkPackages::DatePicker::HiddenValuesForm.new(f,
+ work_package:,
+ is_milestone: milestone?,
+ schedule_manually:,
+ touched_field_map:,
+ ))
end
body.with_row(mb: 3) do
diff --git a/app/forms/work_packages/date_picker/hidden_values_form.rb b/app/forms/work_packages/date_picker/hidden_values_form.rb
new file mode 100644
index 00000000000..a26e5fe2186
--- /dev/null
+++ b/app/forms/work_packages/date_picker/hidden_values_form.rb
@@ -0,0 +1,76 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module WorkPackages
+ module DatePicker
+ class HiddenValuesForm < ApplicationForm
+ attr_reader :work_package
+
+ def initialize(work_package:, is_milestone:, schedule_manually:, touched_field_map:)
+ super()
+
+ @work_package = work_package
+ @is_milestone = is_milestone
+ @schedule_manually = schedule_manually
+ @touched_field_map = touched_field_map
+ end
+
+ form do |form|
+ form.hidden(name: "schedule_manually", value: @schedule_manually)
+
+ form.fields_for(:initial) do |builder|
+ WorkPackages::DatePicker::InitialValuesForm.new(builder, work_package:, is_milestone: @is_milestone)
+ end
+
+ hidden_touched_field(form, name: :start_date)
+ hidden_touched_field(form, name: :ignore_non_working_days)
+ hidden_touched_field(form, name: :schedule_manually)
+
+ unless @is_milestone
+ hidden_touched_field(form, name: :due_date)
+ hidden_touched_field(form, name: :duration)
+ end
+ end
+
+ private
+
+ def hidden_touched_field(form, name:)
+ form.hidden(name: :"#{name}_touched",
+ value: touched(name),
+ data: { "work-packages--date-picker--preview-target": "touchedFieldInput",
+ "referrer-field": name })
+ end
+
+ def touched(name)
+ @touched_field_map["#{name}_touched"] || false
+ end
+ end
+ end
+end
diff --git a/frontend/src/global_styles/content/work_packages/_datepicker_modal.sass b/frontend/src/global_styles/content/work_packages/_datepicker_modal.sass
index f02149124f6..d19001af5d2 100644
--- a/frontend/src/global_styles/content/work_packages/_datepicker_modal.sass
+++ b/frontend/src/global_styles/content/work_packages/_datepicker_modal.sass
@@ -14,7 +14,7 @@
&--date-field
&_current,
&_current:hover
- border: 2px solid var(--control-checked-color) !important
+ outline: 2px solid var(--control-checked-color) !important
&--flatpickr-instance.inline
margin: 0.5rem auto 0 auto !important