Skip to content

Commit

Permalink
Filter estimations history by label
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaherrera07 committed Jan 15, 2024
1 parent b92be8c commit 7ec0fe1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
7 changes: 6 additions & 1 deletion app/controllers/concerns/epic_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def epic_presenter
epic: epic,
issues: epic_issues,
expected_average: expected_average,
uncertainty_level: uncertainty_level
uncertainty_level: uncertainty_level,
labels_filter: labels_filter
)
end

Expand Down Expand Up @@ -56,4 +57,8 @@ def project_key
def uncertainty_level
params[:uncertainty_level]
end

def labels_filter
params[:labels]
end
end
9 changes: 6 additions & 3 deletions app/presenters/epic_estimation_history_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# frozen_string_literal: true

class EpicEstimationHistoryPresenter
def initialize(epic_id:)
def initialize(epic_id:, labels_filter: nil)
@epic_id = epic_id
@labels_filter = labels_filter
end

def estimation_items
Estimation.where(epic_id: epic_id).order(created_at: :desc).to_dto(
items = Estimation.where(epic_id: epic_id).order(created_at: :desc)
items = items.where("filters_applied->>'labels' = ?", labels_filter) if labels_filter.present?
items.to_dto(
methods: %i[estimated_finish_date estimated_finish_date_with_uncertainty label]
)
end

private

attr_reader :epic_id
attr_reader :epic_id, :labels_filter
end
10 changes: 7 additions & 3 deletions app/presenters/epic_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
class EpicPresenter
attr_reader :epic, :issues

def initialize(epic:, issues:, expected_average: nil, uncertainty_level: nil)
def initialize(epic:, issues:, expected_average: nil, uncertainty_level: nil, labels_filter: nil)
@epic = epic
@issues = issues
@expected_average = expected_average
@uncertainty_level = uncertainty_level
@labels_filter = labels_filter
end

delegate :key, :labels, :project_key, :summary, to: :epic
Expand All @@ -34,7 +35,10 @@ def estimation_presenter
end

def estimation_history_presenter
@estimation_history_presenter ||= EpicEstimationHistoryPresenter.new(epic_id: epic.key)
@estimation_history_presenter ||= EpicEstimationHistoryPresenter.new(
epic_id: epic.key,
labels_filter: labels_filter
)
end

def earned_value_presenter
Expand All @@ -54,5 +58,5 @@ def weekly_earned_value_presenter

private

attr_reader :expected_average, :uncertainty_level
attr_reader :expected_average, :uncertainty_level, :labels_filter
end
25 changes: 24 additions & 1 deletion spec/presenters/epic_estimation_history_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

RSpec.describe EpicEstimationHistoryPresenter do
describe '#estimation_items' do
subject { described_class.new(epic_id: epic_id).estimation_items }
subject { described_class.new(epic_id: epic_id, labels_filter: labels_filter).estimation_items }

let(:epic_id) { build(:epic).key }
let(:labels_filter) { nil }

context 'when no estimations exist' do
it { is_expected.to be_empty }
Expand All @@ -24,5 +25,27 @@
expect(subject).to eq([estimation2.to_dto, estimation1.to_dto])
end
end

context 'when filtering by label' do
let!(:estimation1) do
create(:estimation, epic_id: epic_id, created_at: '2022-09-11', filters_applied: { labels: 'scope1' })
end
let!(:estimation2) do
create(:estimation, epic_id: epic_id, created_at: '2022-10-18', filters_applied: { labels: 'scope1' })
end
let(:labels_filter) { 'scope1' }

before do
create(:estimation, epic_id: epic_id, created_at: '2022-10-18', filters_applied: { labels: 'scope2' })
end

it 'returns EstimationDTOs' do
expect(subject).to all(be_a(EstimationDTO))
end

it 'returns estimations ordered by created_at descending' do
expect(subject).to eq([estimation2.to_dto, estimation1.to_dto])
end
end
end
end

0 comments on commit 7ec0fe1

Please sign in to comment.