Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[22360] Edit lag to follow-precedes-relations #17299

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,44 @@ flex_layout do |flex|
end
end

if should_display_start_and_end_dates?
flex.with_row(flex_layout: true, align_items: :center, mb: 2) do |start_and_end_dates_row|
start_and_end_dates_row.with_column(mr: 1) do
icon = if follows?
:calendar
elsif precedes?
:pin
end
if should_display_dates_row?
flex.with_row(flex_layout: true, align_items: :center, color: :muted, mb: 2) do |dates_row|
if precedes? && lag_present?
dates_row.with_column(mr: 1) do
render(Primer::Beta::Octicon.new(icon: "arrow-both"))
end
dates_row.with_column(mr: 3) do
render(Primer::Beta::Text.new) do
lag_as_text(relation.lag)
end
end
end

if related_work_package.start_date.present? || related_work_package.due_date.present?
dates_row.with_column(mr: 1) do
icon = if follows?
:calendar
elsif precedes?
:pin
end

render(Primer::Beta::Octicon.new(icon:, color: :muted))
render(Primer::Beta::Octicon.new(icon:))
end
dates_row.with_column do
render(Primer::Beta::Text.new) do
"#{format_date(related_work_package.start_date)} - #{format_date(related_work_package.due_date)}"
end
end
end
start_and_end_dates_row.with_column do
render(Primer::Beta::Text.new(color: :muted)) do
"#{format_date(related_work_package.start_date)} - #{format_date(related_work_package.due_date)}"

if follows? && lag_present?
dates_row.with_column(ml: 3, mr: 1) do
render(Primer::Beta::Octicon.new(icon: "arrow-both"))
end
dates_row.with_column(mr: 1) do
render(Primer::Beta::Text.new) do
lag_as_text(relation.lag)
end
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion app/components/work_package_relations_tab/relation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def should_display_description?
relation.description.present?
end

def should_display_start_and_end_dates?
def lag_present?
relation.lag.present? && relation.lag != 0
end

def should_display_dates_row?
return false if parent_child_relationship?

relation.follows? || relation.precedes?
Expand Down Expand Up @@ -91,6 +95,10 @@ def destroy_path
end
end

def lag_as_text(lag)
"#{I18n.t('work_package_relations_tab.lag.subject')}: #{I18n.t('datetime.distance_in_words.x_days', count: lag)}"
end

def action_menu_test_selector
"op-relation-row-#{underlying_resource_id}-action-menu"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# These are not available inside the render_inline_form block
# so we need to re-define them here. Figure out solution for this.
relation = @relation
lag_shown = show_lag?
to_id_field_value = relation.to.present? ? "#{related_work_package.type.name.upcase} ##{related_work_package.id} - #{related_work_package.subject}" : nil
url = ::API::V3::Utilities::PathHelper::ApiV3Path.work_package_available_relation_candidates(@work_package.id, type: relation.relation_type_for(@work_package))
render_inline_form(f) do |my_form|
Expand Down Expand Up @@ -58,6 +59,17 @@
label: Relation.human_attribute_name(:description),
autofocus: relation.persisted?
)

if lag_shown
my_form.text_field(
name: :lag,
type: :number,
min: 0,
label: I18n.t("work_package_relations_tab.lag.title"),
caption: I18n.t("work_package_relations_tab.lag.caption"),
input_width: :small,
)
end
end
end
end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ def submit_url_options
url: work_package_relations_path(@work_package) }
end
end

def show_lag?
@relation.relation_type == Relation::TYPE_PRECEDES || @relation.relation_type == Relation::TYPE_FOLLOWS
end
end
4 changes: 2 additions & 2 deletions app/controllers/work_package_relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def set_relation

def create_relation_params
params.require(:relation)
.permit(:relation_type, :to_id, :description)
.permit(:relation_type, :to_id, :description, :lag)
.merge(from_id: @work_package.id)
end

def update_relation_params
params.require(:relation)
.permit(:description)
.permit(:description, :lag)
end
end
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ en:
label_add_x: "Add %{x}"
label_edit_x: "Edit %{x}"
label_add_description: "Add description"
lag:
subject: "Lag"
title: "Lag (in days)"
caption: "The gap in number of working days in between the two work packages"
relations:
label_relates_singular: "related to"
label_relates_plural: "related to"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ def label_for_relation_type(relation_type)

relation_row = relations_tab.expect_relation(relation_follows)

relations_tab.add_description_to_relation(relation_follows, "Discovered relations have descriptions!")
relations_tab.edit_relation_description(relation_follows, "Discovered relations have descriptions!")

# Reflects new description
relations_tab.edit_lag_of_relation(relation_follows, 5)

# Reflects new description and lag
expect(relation_row).to have_text("Discovered relations have descriptions!")
expect(relation_row).to have_text("5 days")

# Unchanged
tabs.expect_counter("relations", 4)
Expand All @@ -171,6 +174,17 @@ def label_for_relation_type(relation_type)
end
end

it "does not show the lag field for all relation types" do
scroll_to_element relations_panel

relations_tab.open_relation_dialog(relation_relates)

within "##{WorkPackageRelationsTab::WorkPackageRelationDialogComponent::DIALOG_ID}" do
expect(page).to have_field("Work package", readonly: true)
expect(page).to have_no_field("Lag")
end
end

context "with the shown WorkPackage being the 'to' relation part" do
let(:another_wp) { create(:work_package, type: type2, subject: "related to main") }

Expand Down
8 changes: 4 additions & 4 deletions spec/support/components/work_packages/relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def add_relation(type:, relatable:, description: nil)
find_row(target_wp)
end

def add_description_to_relation(relatable, description)
def edit_relation_description(relatable, description)
open_relation_dialog(relatable)

within "##{WorkPackageRelationsTab::WorkPackageRelationDialogComponent::DIALOG_ID}" do
Expand All @@ -183,14 +183,14 @@ def add_description_to_relation(relatable, description)
end
end

def edit_relation_description(relatable, description)
def edit_lag_of_relation(relatable, lag)
open_relation_dialog(relatable)

within "##{WorkPackageRelationsTab::WorkPackageRelationDialogComponent::DIALOG_ID}" do
expect(page).to have_field("Work package", readonly: true)
expect(page).to have_field("Description")
expect(page).to have_field("Lag")

fill_in "Description", with: description
fill_in "Lag", with: lag

click_link_or_button "Save"

Expand Down
Loading