Commit b1165c3f authored by Mikolaj Wawrzyniak's avatar Mikolaj Wawrzyniak

Use snake case in EnvironmentsHelper

FE is normaly expects camel cased data, and has better tooling to
accept snake case data and convert it to camel case
parent 9f729d7c
...@@ -12,8 +12,8 @@ module EnvironmentsHelper ...@@ -12,8 +12,8 @@ module EnvironmentsHelper
def environments_folder_list_view_data def environments_folder_list_view_data
{ {
"endpoint" => folder_project_environments_path(@project, @folder, format: :json), "endpoint" => folder_project_environments_path(@project, @folder, format: :json),
"folder-name" => @folder, "folder_name" => @folder,
"can-read-environment" => can?(current_user, :read_environment, @project).to_s "can_read_environment" => can?(current_user, :read_environment, @project).to_s
} }
end end
...@@ -33,11 +33,11 @@ module EnvironmentsHelper ...@@ -33,11 +33,11 @@ module EnvironmentsHelper
def environment_logs_data(project, environment) def environment_logs_data(project, environment)
{ {
"environment-name": environment.name, "environment_name": environment.name,
"environments-path": project_environments_path(project, format: :json), "environments_path": project_environments_path(project, format: :json),
"environment-id": environment.id, "environment_id": environment.id,
"cluster-applications-documentation-path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'), "cluster_applications_documentation_path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'),
"clusters-path": project_clusters_path(project, format: :json) "clusters_path": project_clusters_path(project, format: :json)
} }
end end
...@@ -51,18 +51,18 @@ module EnvironmentsHelper ...@@ -51,18 +51,18 @@ module EnvironmentsHelper
return {} unless project return {} unless project
{ {
'settings-path' => edit_project_service_path(project, 'prometheus'), 'settings_path' => edit_project_service_path(project, 'prometheus'),
'clusters-path' => project_clusters_path(project), 'clusters_path' => project_clusters_path(project),
'dashboards-endpoint' => project_performance_monitoring_dashboards_path(project, format: :json), 'dashboards_endpoint' => project_performance_monitoring_dashboards_path(project, format: :json),
'default-branch' => project.default_branch, 'default_branch' => project.default_branch,
'project-path' => project_path(project), 'project_path' => project_path(project),
'tags-path' => project_tags_path(project), 'tags_path' => project_tags_path(project),
'external-dashboard-url' => project.metrics_setting_external_dashboard_url, 'external_dashboard_url' => project.metrics_setting_external_dashboard_url,
'custom-metrics-path' => project_prometheus_metrics_path(project), 'custom_metrics_path' => project_prometheus_metrics_path(project),
'validate-query-path' => validate_query_project_prometheus_metrics_path(project), 'validate_query_path' => validate_query_project_prometheus_metrics_path(project),
'custom-metrics-available' => "#{custom_metrics_available?(project)}", 'custom_metrics_available' => "#{custom_metrics_available?(project)}",
'prometheus-alerts-available' => "#{can?(current_user, :read_prometheus_alerts, project)}", 'prometheus_alerts_available' => "#{can?(current_user, :read_prometheus_alerts, project)}",
'dashboard-timezone' => project.metrics_setting_dashboard_timezone.to_s.upcase 'dashboard_timezone' => project.metrics_setting_dashboard_timezone.to_s.upcase
} }
end end
...@@ -70,11 +70,11 @@ module EnvironmentsHelper ...@@ -70,11 +70,11 @@ module EnvironmentsHelper
return {} unless environment return {} unless environment
{ {
'metrics-dashboard-base-path' => metrics_dashboard_base_path(environment, project), 'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project),
'current-environment-name' => environment.name, 'current_environment_name' => environment.name,
'has-metrics' => "#{environment.has_metrics?}", 'has_metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}", 'prometheus_status' => "#{environment.prometheus_status}",
'environment-state' => "#{environment.state}" 'environment_state' => "#{environment.state}"
} }
end end
...@@ -93,26 +93,26 @@ module EnvironmentsHelper ...@@ -93,26 +93,26 @@ module EnvironmentsHelper
return {} unless project && environment return {} unless project && environment
{ {
'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json), 'metrics_endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
'dashboard-endpoint' => metrics_dashboard_project_environment_path(project, environment, format: :json), 'dashboard_endpoint' => metrics_dashboard_project_environment_path(project, environment, format: :json),
'deployments-endpoint' => project_environment_deployments_path(project, environment, format: :json), 'deployments_endpoint' => project_environment_deployments_path(project, environment, format: :json),
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), 'alerts_endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'operations-settings-path' => project_settings_operations_path(project), 'operations_settings_path' => project_settings_operations_path(project),
'can-access-operations-settings' => can?(current_user, :admin_operations, project).to_s, 'can_access_operations_settings' => can?(current_user, :admin_operations, project).to_s,
'panel-preview-endpoint' => project_metrics_dashboards_builder_path(project, format: :json) 'panel_preview_endpoint' => project_metrics_dashboards_builder_path(project, format: :json)
} }
end end
def static_metrics_data def static_metrics_data
{ {
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'), 'documentation_path' => help_page_path('administration/monitoring/prometheus/index.md'),
'add-dashboard-documentation-path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), 'add_dashboard_documentation_path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'),
'empty-getting-started-svg-path' => image_path('illustrations/monitoring/getting_started.svg'), 'empty_getting_started_svg_path' => image_path('illustrations/monitoring/getting_started.svg'),
'empty-loading-svg-path' => image_path('illustrations/monitoring/loading.svg'), 'empty_loading_svg_path' => image_path('illustrations/monitoring/loading.svg'),
'empty-no-data-svg-path' => image_path('illustrations/monitoring/no_data.svg'), 'empty_no_data_svg_path' => image_path('illustrations/monitoring/no_data.svg'),
'empty-no-data-small-svg-path' => image_path('illustrations/chart-empty-state-small.svg'), 'empty_no_data_small_svg_path' => image_path('illustrations/chart-empty-state-small.svg'),
'empty-unable-to-connect-svg-path' => image_path('illustrations/monitoring/unable_to_connect.svg'), 'empty_unable_to_connect_svg_path' => image_path('illustrations/monitoring/unable_to_connect.svg'),
'custom-dashboard-base-path' => Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT 'custom_dashboard_base_path' => Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT
} }
end end
end end
......
...@@ -8,10 +8,10 @@ module EE ...@@ -8,10 +8,10 @@ module EE
def environments_list_data def environments_list_data
ee_environments_list_data = { ee_environments_list_data = {
"canary_deployment_feature_id" => UserCalloutsHelper::CANARY_DEPLOYMENT, "canary_deployment_feature_id" => UserCalloutsHelper::CANARY_DEPLOYMENT,
"show-canary-deployment-callout" => show_canary_deployment_callout?(@project).to_s, "show_canary_deployment_callout" => show_canary_deployment_callout?(@project).to_s,
"user-callouts-path" => user_callouts_path, "user_callouts_path" => user_callouts_path,
"lock-promotion-svg-path" => image_path('illustrations/lock_promotion.svg'), "lock_promotion_svg_path" => image_path('illustrations/lock_promotion.svg'),
"help-canary-deployments-path" => help_page_path('user/project/canary_deployments') "help_canary_deployments_path" => help_page_path('user/project/canary_deployments')
} }
super.merge(ee_environments_list_data) super.merge(ee_environments_list_data)
...@@ -21,10 +21,10 @@ module EE ...@@ -21,10 +21,10 @@ module EE
def environments_folder_list_view_data def environments_folder_list_view_data
ee_environments_folder_list_view_data = { ee_environments_folder_list_view_data = {
"canary_deployment_feature_id" => UserCalloutsHelper::CANARY_DEPLOYMENT, "canary_deployment_feature_id" => UserCalloutsHelper::CANARY_DEPLOYMENT,
"show-canary-deployment-callout" => show_canary_deployment_callout?(@project).to_s, "show_canary_deployment_callout" => show_canary_deployment_callout?(@project).to_s,
"user-callouts-path" => user_callouts_path, "user_callouts_path" => user_callouts_path,
"lock-promotion-svg-path" => image_path('illustrations/lock_promotion.svg'), "lock_promotion_svg_path" => image_path('illustrations/lock_promotion.svg'),
"help-canary-deployments-path" => help_page_path('user/project/canary_deployments') "help_canary_deployments_path" => help_page_path('user/project/canary_deployments')
} }
super.merge(ee_environments_folder_list_view_data) super.merge(ee_environments_folder_list_view_data)
......
...@@ -60,14 +60,14 @@ RSpec.describe EnvironmentsHelper do ...@@ -60,14 +60,14 @@ RSpec.describe EnvironmentsHelper do
it 'returns environment parameters data' do it 'returns environment parameters data' do
expect(subject).to include( expect(subject).to include(
"environment-name": environment.name, "environment_name": environment.name,
"environments-path": project_environments_path(project, format: :json) "environments_path": project_environments_path(project, format: :json)
) )
end end
it 'returns parameters for forming the pod logs API URL' do it 'returns parameters for forming the pod logs API URL' do
expect(subject).to include( expect(subject).to include(
"environment-id": environment.id "environment_id": environment.id
) )
end end
end end
......
import { stateAndPropsFromDataset } from '~/monitoring/utils'; import { stateAndPropsFromDataset } from '~/monitoring/utils';
import { mapToDashboardViewModel } from '~/monitoring/stores/utils'; import { mapToDashboardViewModel } from '~/monitoring/stores/utils';
import { metricStates } from '~/monitoring/constants'; import { metricStates } from '~/monitoring/constants';
import { convertObjectProps } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { convertToCamelCase } from '~/lib/utils/text_utility';
import { metricsResult } from './mock_data'; import { metricsResult } from './mock_data';
...@@ -14,13 +13,7 @@ export const metricsDashboardResponse = getJSONFixture( ...@@ -14,13 +13,7 @@ export const metricsDashboardResponse = getJSONFixture(
export const metricsDashboardPayload = metricsDashboardResponse.dashboard; export const metricsDashboardPayload = metricsDashboardResponse.dashboard;
const datasetState = stateAndPropsFromDataset( const datasetState = stateAndPropsFromDataset(
// It's preferable to have props in snake_case, this will be addressed at: convertObjectPropsToCamelCase(metricsDashboardResponse.metrics_data),
// https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33574
convertObjectProps(
// Some props use kebab-case, convert to snake_case first
key => convertToCamelCase(key.replace(/-/g, '_')),
metricsDashboardResponse.metrics_data,
),
); );
// new properties like addDashboardDocumentationPath prop and alertsEndpoint // new properties like addDashboardDocumentationPath prop and alertsEndpoint
......
...@@ -18,34 +18,34 @@ RSpec.describe EnvironmentsHelper do ...@@ -18,34 +18,34 @@ RSpec.describe EnvironmentsHelper do
it 'returns data' do it 'returns data' do
expect(metrics_data).to include( expect(metrics_data).to include(
'settings-path' => edit_project_service_path(project, 'prometheus'), 'settings_path' => edit_project_service_path(project, 'prometheus'),
'clusters-path' => project_clusters_path(project), 'clusters_path' => project_clusters_path(project),
'metrics-dashboard-base-path' => environment_metrics_path(environment), 'metrics_dashboard_base_path' => environment_metrics_path(environment),
'current-environment-name' => environment.name, 'current_environment_name' => environment.name,
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'), 'documentation_path' => help_page_path('administration/monitoring/prometheus/index.md'),
'add-dashboard-documentation-path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), 'add_dashboard_documentation_path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'),
'empty-getting-started-svg-path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'), 'empty_getting_started_svg_path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'),
'empty-loading-svg-path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'), 'empty_loading_svg_path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'),
'empty-no-data-svg-path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'), 'empty_no_data_svg_path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'),
'empty-unable-to-connect-svg-path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'), 'empty_unable_to_connect_svg_path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'),
'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json), 'metrics_endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
'deployments-endpoint' => project_environment_deployments_path(project, environment, format: :json), 'deployments_endpoint' => project_environment_deployments_path(project, environment, format: :json),
'default-branch' => 'master', 'default_branch' => 'master',
'project-path' => project_path(project), 'project_path' => project_path(project),
'tags-path' => project_tags_path(project), 'tags_path' => project_tags_path(project),
'has-metrics' => "#{environment.has_metrics?}", 'has_metrics' => "#{environment.has_metrics?}",
'prometheus-status' => "#{environment.prometheus_status}", 'prometheus_status' => "#{environment.prometheus_status}",
'external-dashboard-url' => nil, 'external_dashboard_url' => nil,
'environment-state' => environment.state, 'environment_state' => environment.state,
'custom-metrics-path' => project_prometheus_metrics_path(project), 'custom_metrics_path' => project_prometheus_metrics_path(project),
'validate-query-path' => validate_query_project_prometheus_metrics_path(project), 'validate_query_path' => validate_query_project_prometheus_metrics_path(project),
'custom-metrics-available' => 'true', 'custom_metrics_available' => 'true',
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json), 'alerts_endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
'prometheus-alerts-available' => 'true', 'prometheus_alerts_available' => 'true',
'custom-dashboard-base-path' => Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT, 'custom_dashboard_base_path' => Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT,
'operations-settings-path' => project_settings_operations_path(project), 'operations_settings_path' => project_settings_operations_path(project),
'can-access-operations-settings' => 'true', 'can_access_operations_settings' => 'true',
'panel-preview-endpoint' => project_metrics_dashboards_builder_path(project, format: :json) 'panel_preview_endpoint' => project_metrics_dashboards_builder_path(project, format: :json)
) )
end end
...@@ -58,7 +58,7 @@ RSpec.describe EnvironmentsHelper do ...@@ -58,7 +58,7 @@ RSpec.describe EnvironmentsHelper do
specify do specify do
expect(metrics_data).to include( expect(metrics_data).to include(
'can-access-operations-settings' => 'false' 'can_access_operations_settings' => 'false'
) )
end end
end end
...@@ -72,7 +72,7 @@ RSpec.describe EnvironmentsHelper do ...@@ -72,7 +72,7 @@ RSpec.describe EnvironmentsHelper do
it 'returns false' do it 'returns false' do
expect(metrics_data).to include( expect(metrics_data).to include(
'prometheus-alerts-available' => 'false' 'prometheus_alerts_available' => 'false'
) )
end end
end end
...@@ -83,7 +83,7 @@ RSpec.describe EnvironmentsHelper do ...@@ -83,7 +83,7 @@ RSpec.describe EnvironmentsHelper do
end end
it 'adds external_dashboard_url' do it 'adds external_dashboard_url' do
expect(metrics_data['external-dashboard-url']).to eq('http://gitlab.com') expect(metrics_data['external_dashboard_url']).to eq('http://gitlab.com')
end end
end end
...@@ -94,7 +94,7 @@ RSpec.describe EnvironmentsHelper do ...@@ -94,7 +94,7 @@ RSpec.describe EnvironmentsHelper do
subject { metrics_data } subject { metrics_data }
it { is_expected.to include('environment-state' => 'stopped') } it { is_expected.to include('environment_state' => 'stopped') }
end end
context 'when request is from project scoped metrics path' do context 'when request is from project scoped metrics path' do
...@@ -107,16 +107,16 @@ RSpec.describe EnvironmentsHelper do ...@@ -107,16 +107,16 @@ RSpec.describe EnvironmentsHelper do
context '/:namespace/:project/-/metrics' do context '/:namespace/:project/-/metrics' do
let(:path) { project_metrics_dashboard_path(project) } let(:path) { project_metrics_dashboard_path(project) }
it 'uses correct path for metrics-dashboard-base-path' do it 'uses correct path for metrics_dashboard_base_path' do
expect(metrics_data['metrics-dashboard-base-path']).to eq(project_metrics_dashboard_path(project)) expect(metrics_data['metrics_dashboard_base_path']).to eq(project_metrics_dashboard_path(project))
end end
end end
context '/:namespace/:project/-/metrics/some_custom_dashboard.yml' do context '/:namespace/:project/-/metrics/some_custom_dashboard.yml' do
let(:path) { "#{project_metrics_dashboard_path(project)}/some_custom_dashboard.yml" } let(:path) { "#{project_metrics_dashboard_path(project)}/some_custom_dashboard.yml" }
it 'uses correct path for metrics-dashboard-base-path' do it 'uses correct path for metrics_dashboard_base_path' do
expect(metrics_data['metrics-dashboard-base-path']).to eq(project_metrics_dashboard_path(project)) expect(metrics_data['metrics_dashboard_base_path']).to eq(project_metrics_dashboard_path(project))
end end
end end
end end
...@@ -143,11 +143,11 @@ RSpec.describe EnvironmentsHelper do ...@@ -143,11 +143,11 @@ RSpec.describe EnvironmentsHelper do
describe '#environment_logs_data' do describe '#environment_logs_data' do
it 'returns logs data' do it 'returns logs data' do
expected_data = { expected_data = {
"environment-name": environment.name, "environment_name": environment.name,
"environments-path": project_environments_path(project, format: :json), "environments_path": project_environments_path(project, format: :json),
"environment-id": environment.id, "environment_id": environment.id,
"cluster-applications-documentation-path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'), "cluster_applications_documentation_path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'),
"clusters-path": project_clusters_path(project, format: :json) "clusters_path": project_clusters_path(project, format: :json)
} }
expect(helper.environment_logs_data(project, environment)).to eq(expected_data) expect(helper.environment_logs_data(project, environment)).to eq(expected_data)
......
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