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