Skip to content
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
10 changes: 7 additions & 3 deletions modules/grids/app/components/grids/widgets/project_timeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ def title
end

def phases_data
project.phases.active
active_project_phases
.eager_load(definition: :color)
.order("project_phase_definitions.position")
.map { |phase| phase_data(phase) }
.to_json
end

def any_phases?
project.phases.active.with_timeline_content.exists?
active_project_phases.with_timeline_content.exists?
end

def render?
User.current.allowed_in_project?(:view_project_phases, project)
User.current.allowed_in_project?(:view_project_phases, project) && active_project_phases.any?
end

def wrapper_arguments
Expand All @@ -78,6 +78,10 @@ def phase_data(phase) # rubocop:disable Metrics/AbcSize
finishGateName: phase.definition.finish_gate_name
}
end

def active_project_phases
@active_project_phases ||= project.phases.active
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@

describe "#render?" do
context "with view_project_phases permission" do
before { create(:member, user:, project:, roles: [role]) }
before do
create(:member, user:, project:, roles: [role])
create(:project_phase, project:)
end

it { expect(component.render?).to be(true) }
end

context "without permission" do
before { create(:project_phase, project:) }

it { expect(component.render?).to be(false) }
end

context "with only inactive phases" do
before do
create(:member, user:, project:, roles: [role])
create(:project_phase, :inactive, project:)
end

it { expect(component.render?).to be(false) }
end
end
Expand Down Expand Up @@ -108,7 +122,9 @@
describe "rendering" do
before { create(:member, user:, project:, roles: [role]) }

context "with no phases" do
context "with phases without dates" do
before { create(:project_phase, project:, finish_date: nil, start_date: nil) }

it "renders a blankslate" do
render_inline(component)
expect(page).to have_test_selector("project-timeline-widget-empty")
Expand Down
Loading