Skip to content

Commit adb88c9

Browse files
committed
Some more test fixing.. There is light and the end of the tunnel :fingers_crossed:
1 parent b943d56 commit adb88c9

File tree

17 files changed

+271
-343
lines changed

17 files changed

+271
-343
lines changed

app/components/open_project/common/inplace_edit_field_component.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,7 @@ def display_field_class
8484
def display_field_component
8585
return nil if display_field_class.nil?
8686

87-
@display_field_component ||= begin
88-
has_comment = custom_field? && custom_field&.has_comment?
89-
additional_args = open_in_dialog? ? dialog_display_arguments : {}
90-
display_field_class.new(
91-
model:,
92-
attribute:,
93-
writable: writable?,
94-
truncated:,
95-
has_comment:,
96-
# Show comment as read-only text when a non-writable user opens the dialog.
97-
# enforce_edit_mode identifies the dialog context.
98-
show_comment: enforce_edit_mode && !writable? && has_comment,
99-
**@system_arguments.merge(additional_args)
100-
)
101-
end
87+
@display_field_component ||= build_display_field_component
10288
end
10389

10490
def wrapper_key
@@ -163,6 +149,22 @@ def model_class
163149

164150
private
165151

152+
def build_display_field_component
153+
has_comment = custom_field? && custom_field&.has_comment?
154+
additional_args = open_in_dialog? ? dialog_display_arguments : {}
155+
display_field_class.new(
156+
model:,
157+
attribute:,
158+
writable: writable?,
159+
truncated:,
160+
has_comment:,
161+
# Show comment as read-only text when a non-writable user opens the dialog.
162+
# enforce_edit_mode identifies the dialog context.
163+
show_comment: enforce_edit_mode && !writable? && has_comment,
164+
**@system_arguments.merge(additional_args)
165+
)
166+
end
167+
166168
def dialog_trigger_arguments
167169
{
168170
dialog_controller_name: "inplace-edit",

app/components/open_project/common/inplace_edit_fields/boolean_input_component.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def call
4646

4747
private
4848

49-
def submit_url
50-
inplace_edit_field_submit_path(
49+
def reset_url
50+
inplace_edit_field_reset_path(
5151
model: model.class.name,
5252
id: model.id,
5353
attribute:,
@@ -59,6 +59,7 @@ def additional_arguments
5959
if show_action_buttons
6060
{
6161
data: { controller: "inplace-edit",
62+
inplace_edit_url_value: reset_url,
6263
action: "click->inplace-edit#submitForm keydown.esc->inplace-edit#request",
6364
qa_field_name: }
6465
}

app/components/open_project/common/inplace_edit_fields/date_input_component.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def additional_arguments
5656
{
5757
data: { controller: "inplace-edit",
5858
inplace_edit_url_value: reset_url,
59-
action: "keydown.esc->inplace-edit#request change->inplace-edit#submitForm",
59+
action: "keydown.esc->inplace-edit#request " \
60+
"keydown.enter->inplace-edit#submitForm " \
61+
"change->inplace-edit#submitForm",
6062
qa_field_name: }
6163
}
6264
else

app/components/open_project/common/inplace_edit_fields/display_fields/calculated_value_input_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def render_calculation_error
4949

5050
render(Primer::OpenProject::FlexLayout.new(
5151
align_items: :flex_start,
52-
data: { test_selector: "error-cf-#{custom_field.id}" }
52+
data: { test_selector: "error--custom_field_#{custom_field.id}" }
5353
)) do |container|
5454
container.with_column do
5555
render Primer::Beta::Octicon.new(icon: :"alert-fill", color: :danger)

app/components/open_project/common/inplace_edit_fields/display_fields/display_field_component.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,22 @@ def custom_field_values
193193
def dialog_controller_actions
194194
return "" unless writable? || @has_comment
195195

196-
"click->inplace-edit#openDialog " \
197-
"keydown.enter->inplace-edit#openDialog " \
198-
"keydown.space->inplace-edit#openDialog " \
196+
[
197+
"click->inplace-edit#openDialog",
198+
"keydown.enter->inplace-edit#openDialog",
199+
"keydown.space->inplace-edit#openDialog",
199200
"inplace-edit:open-dialog->async-dialog#handleOpenDialog"
201+
].join(" ")
200202
end
201203

202204
def inline_controller_actions
203205
return "" unless writable?
204206

205-
"click->inplace-edit#request " \
206-
"keydown.enter->inplace-edit#request " \
207+
[
208+
"click->inplace-edit#request",
209+
"keydown.enter->inplace-edit#request",
207210
"keydown.space->inplace-edit#request"
211+
].join(" ")
208212
end
209213
end
210214
end

app/components/open_project/common/inplace_edit_fields/display_fields/select_list_component.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@ def render_display_value
4141
value = model.public_send(attribute)
4242

4343
if value.present? && value != [nil]
44-
if custom_field?
45-
formatted_custom_field_values.presence || t("placeholders.default")
46-
else
47-
value.is_a?(Array) ? value.map(&:to_s).join(", ") : value.to_s
48-
end
44+
render_value(value)
4945
else
5046
t("placeholders.default")
5147
end
5248
end
5349

50+
private
51+
52+
def render_value(value)
53+
if custom_field?
54+
formatted_custom_field_values.presence || t("placeholders.default")
55+
else
56+
value.is_a?(Array) ? value.join(", ") : value.to_s
57+
end
58+
end
59+
5460
def formatted_custom_field_values
5561
return @formatted_custom_field_values if defined?(@formatted_custom_field_values)
5662

app/components/open_project/common/inplace_edit_fields/rich_text_area_component.rb

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,36 @@ def initialize(form:, attribute:, model:, show_action_buttons: true, **system_ar
5454

5555
def call
5656
form.rich_text_area(name: attribute,
57-
wrapper_data_attributes: {
58-
controller: "ckeditor-focus",
59-
ckeditor_focus_target: "editor",
60-
ckeditor_focus_autofocus_value: true
61-
},
57+
wrapper_data_attributes: ckeditor_wrapper_data,
6258
**@system_arguments)
6359

6460
comment_field_if_enabled(form)
61+
render_action_buttons if show_action_buttons
62+
end
63+
64+
private
65+
66+
def ckeditor_wrapper_data
67+
{
68+
controller: "ckeditor-focus",
69+
ckeditor_focus_target: "editor",
70+
ckeditor_focus_autofocus_value: true
71+
}
72+
end
6573

66-
if show_action_buttons
67-
form.group(layout: :horizontal, justify_content: :flex_end) do |button_group|
68-
button_group.submit(name: :reset,
69-
type: :submit,
70-
label: I18n.t(:button_cancel),
71-
scheme: :default,
72-
formaction: inplace_edit_field_reset_path(model: model.class.name, id: model.id, attribute:),
73-
formmethod: :get,
74-
test_selector: "op-inplace-edit-field--textarea-cancel")
75-
button_group.submit(name: :submit,
76-
label: I18n.t(:button_save),
77-
scheme: :primary,
78-
test_selector: "op-inplace-edit-field--textarea-save")
79-
end
74+
def render_action_buttons
75+
form.group(layout: :horizontal, justify_content: :flex_end) do |button_group|
76+
button_group.submit(name: :reset,
77+
type: :submit,
78+
label: I18n.t(:button_cancel),
79+
scheme: :default,
80+
formaction: inplace_edit_field_reset_path(model: model.class.name, id: model.id, attribute:),
81+
formmethod: :get,
82+
test_selector: "op-inplace-edit-field--textarea-cancel")
83+
button_group.submit(name: :submit,
84+
label: I18n.t(:button_save),
85+
scheme: :primary,
86+
test_selector: "op-inplace-edit-field--textarea-save")
8087
end
8188
end
8289
end

app/components/open_project/common/inplace_edit_fields/select_list_component.rb

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ def initialize(form:, attribute:, model:, show_action_buttons: true, **system_ar
4040
super
4141

4242
@system_arguments[:autocomplete_options] ||= {}
43-
@system_arguments[:autocomplete_options][:model] ||= { id: model.id, name: model.name }
44-
@system_arguments[:autocomplete_options][:inputName] ||= attribute
45-
@system_arguments[:autocomplete_options][:wrapper_id] ||= @system_arguments[:wrapper_id]
46-
if @system_arguments[:autocomplete_options][:focusDirectly].nil?
47-
@system_arguments[:autocomplete_options][:focusDirectly] =
48-
true
49-
end
50-
if @system_arguments[:autocomplete_options][:closeOnSelect].nil?
51-
@system_arguments[:autocomplete_options][:closeOnSelect] =
52-
false
53-
end
43+
set_autocomplete_defaults(model, attribute)
5444
end
5545

5646
def call
@@ -61,24 +51,34 @@ def call
6151
end
6252

6353
comment_field_if_enabled(form)
64-
65-
if show_action_buttons
66-
form.group(layout: :horizontal, justify_content: :flex_end) do |button_group|
67-
button_group.submit(name: :reset,
68-
type: :submit,
69-
label: I18n.t(:button_cancel),
70-
scheme: :default,
71-
formaction: inplace_edit_field_reset_path(model: model.class.name, id: model.id, attribute:),
72-
formmethod: :get)
73-
button_group.submit(name: :submit,
74-
label: I18n.t(:button_save),
75-
scheme: :primary)
76-
end
77-
end
54+
render_action_buttons if show_action_buttons
7855
end
7956

8057
private
8158

59+
def set_autocomplete_defaults(model, attribute)
60+
opts = @system_arguments[:autocomplete_options]
61+
opts[:model] ||= { id: model.id, name: model.name }
62+
opts[:inputName] ||= attribute
63+
opts[:wrapper_id] ||= @system_arguments[:wrapper_id]
64+
opts[:focusDirectly] = true if opts[:focusDirectly].nil?
65+
opts[:closeOnSelect] = false if opts[:closeOnSelect].nil?
66+
end
67+
68+
def render_action_buttons
69+
form.group(layout: :horizontal, justify_content: :flex_end) do |button_group|
70+
button_group.submit(name: :reset,
71+
type: :submit,
72+
label: I18n.t(:button_cancel),
73+
scheme: :default,
74+
formaction: inplace_edit_field_reset_path(model: model.class.name, id: model.id, attribute:),
75+
formmethod: :get)
76+
button_group.submit(name: :submit,
77+
label: I18n.t(:button_save),
78+
scheme: :primary)
79+
end
80+
end
81+
8282
def render_custom_field_input
8383
input_class = if custom_field.multi_value?
8484
CustomFields::Inputs::MultiSelectList

0 commit comments

Comments
 (0)