Commit 71030f46 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '32571-cleaner-translation-approach-in-vsa-stage-presenter' into 'master'

Eliminate usage of lambdas when translating VSA stage data

Closes #32571

See merge request gitlab-org/gitlab!34277
parents 8fcba2ee 1e1f3084
......@@ -3,37 +3,6 @@
module Analytics
module CycleAnalytics
class StagePresenter < Gitlab::View::Presenter::Delegated
DEFAULT_STAGE_ATTRIBUTES = {
issue: {
title: -> { s_('CycleAnalyticsStage|Issue') },
description: -> { _('Time before an issue gets scheduled') }
}.freeze,
plan: {
title: -> { s_('CycleAnalyticsStage|Plan') },
description: -> { _('Time before an issue starts implementation') }
}.freeze,
code: {
title: -> { s_('CycleAnalyticsStage|Code') },
description: -> { _('Time until first merge request') }
}.freeze,
test: {
title: -> { s_('CycleAnalyticsStage|Test') },
description: -> { _('Total test time for all commits/merges') }
}.freeze,
review: {
title: -> { s_('CycleAnalyticsStage|Review') },
description: -> { _('Time between merge request creation and merge/close') }
}.freeze,
staging: {
title: -> { s_('CycleAnalyticsStage|Staging') },
description: -> { _('From merge request merge until deploy to production') }
}.freeze,
production: {
title: -> { s_('CycleAnalyticsStage|Total') },
description: -> { _('From issue creation until deploy to production') }
}.freeze
}.freeze
def title
extract_default_stage_attribute(:title) || name
end
......@@ -49,7 +18,40 @@ module Analytics
private
def extract_default_stage_attribute(attribute)
DEFAULT_STAGE_ATTRIBUTES.dig(name.to_sym, attribute.to_sym)&.call
default_stage_attributes.dig(name.to_sym, attribute.to_sym)
end
def default_stage_attributes
@default_stage_attributes ||= {
issue: {
title: s_('CycleAnalyticsStage|Issue'),
description: _('Time before an issue gets scheduled')
},
plan: {
title: s_('CycleAnalyticsStage|Plan'),
description: _('Time before an issue starts implementation')
},
code: {
title: s_('CycleAnalyticsStage|Code'),
description: _('Time until first merge request')
},
test: {
title: s_('CycleAnalyticsStage|Test'),
description: _('Total test time for all commits/merges')
},
review: {
title: s_('CycleAnalyticsStage|Review'),
description: _('Time between merge request creation and merge/close')
},
staging: {
title: s_('CycleAnalyticsStage|Staging'),
description: _('From merge request merge until deploy to production')
},
production: {
title: s_('CycleAnalyticsStage|Total'),
description: _('From issue creation until deploy to production')
}
}.freeze
end
end
end
......
......@@ -964,10 +964,12 @@ RSpec.describe 'Group Value Stream Analytics', :js do
context 'Duration chart' do
let(:duration_chart_dropdown) { page.find('.js-dropdown-stages') }
default_stages = Analytics::CycleAnalytics::StagePresenter::DEFAULT_STAGE_ATTRIBUTES
.each_value
.map { |value| value[:title].call }
.freeze
let_it_be(:translated_default_stage_names) do
Gitlab::Analytics::CycleAnalytics::DefaultStages.names.map do |name|
stage = Analytics::CycleAnalytics::GroupStage.new(name: name)
Analytics::CycleAnalytics::StagePresenter.new(stage).title
end.freeze
end
def duration_chart_stages
duration_chart_dropdown.all('.dropdown-item').collect(&:text)
......@@ -984,7 +986,7 @@ RSpec.describe 'Group Value Stream Analytics', :js do
it 'has all the default stages' do
toggle_duration_chart_dropdown
expect(duration_chart_stages).to eq(default_stages)
expect(duration_chart_stages).to eq(translated_default_stage_names)
end
context 'hidden stage' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment