2021-02-16 04:09:36 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module LearnGitlabHelper
|
|
|
|
def learn_gitlab_experiment_enabled?(project)
|
|
|
|
return false unless current_user
|
2021-04-20 11:09:24 -04:00
|
|
|
return false unless continous_onboarding_experiment_enabled_for_user?
|
2021-02-16 04:09:36 -05:00
|
|
|
|
|
|
|
learn_gitlab_onboarding_available?(project)
|
|
|
|
end
|
|
|
|
|
2021-04-30 17:10:23 -04:00
|
|
|
def learn_gitlab_experiment_tracking_category
|
|
|
|
return unless current_user
|
|
|
|
|
|
|
|
if Gitlab::Experimentation.in_experiment_group?(:learn_gitlab_a, subject: current_user)
|
|
|
|
Gitlab::Experimentation.get_experiment(:learn_gitlab_a).tracking_category
|
|
|
|
elsif Gitlab::Experimentation.in_experiment_group?(:learn_gitlab_b, subject: current_user)
|
|
|
|
Gitlab::Experimentation.get_experiment(:learn_gitlab_b).tracking_category
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-16 04:09:36 -05:00
|
|
|
def onboarding_actions_data(project)
|
|
|
|
attributes = onboarding_progress(project).attributes.symbolize_keys
|
|
|
|
|
2021-03-28 11:09:30 -04:00
|
|
|
action_urls.to_h do |action, url|
|
2021-02-16 04:09:36 -05:00
|
|
|
[
|
|
|
|
action,
|
|
|
|
url: url,
|
2021-02-23 13:10:40 -05:00
|
|
|
completed: attributes[OnboardingProgress.column_name(action)].present?,
|
|
|
|
svg: image_path("learn_gitlab/#{action}.svg")
|
2021-02-16 04:09:36 -05:00
|
|
|
]
|
2021-03-28 11:09:30 -04:00
|
|
|
end
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
2021-04-20 11:09:24 -04:00
|
|
|
def continous_onboarding_experiment_enabled_for_user?
|
|
|
|
Gitlab::Experimentation.in_experiment_group?(:learn_gitlab_a, subject: current_user) ||
|
|
|
|
Gitlab::Experimentation.in_experiment_group?(:learn_gitlab_b, subject: current_user)
|
|
|
|
end
|
|
|
|
|
2021-05-06 14:10:06 -04:00
|
|
|
def onboarding_sections_data
|
|
|
|
{
|
|
|
|
workspace: {
|
|
|
|
svg: image_path("learn_gitlab/section_workspace.svg")
|
|
|
|
},
|
|
|
|
plan: {
|
|
|
|
svg: image_path("learn_gitlab/section_plan.svg")
|
|
|
|
},
|
|
|
|
deploy: {
|
|
|
|
svg: image_path("learn_gitlab/section_deploy.svg")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-05-10 11:10:24 -04:00
|
|
|
def learn_gitlab_onboarding_available?(project)
|
|
|
|
OnboardingProgress.onboarding?(project.namespace) &&
|
|
|
|
LearnGitlab::Project.new(current_user).available?
|
|
|
|
end
|
|
|
|
|
2021-02-16 04:09:36 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def action_urls
|
2021-04-30 08:12:30 -04:00
|
|
|
LearnGitlab::Onboarding::ACTION_ISSUE_IDS.transform_values { |id| project_issue_url(learn_gitlab_project, id) }
|
|
|
|
.merge(LearnGitlab::Onboarding::ACTION_DOC_URLS)
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def learn_gitlab_project
|
2021-04-30 08:12:30 -04:00
|
|
|
@learn_gitlab_project ||= LearnGitlab::Project.new(current_user).project
|
2021-02-16 04:09:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def onboarding_progress(project)
|
|
|
|
OnboardingProgress.find_by(namespace: project.namespace) # rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
end
|
|
|
|
end
|