Commit 62cf2cc2 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska Committed by Paul Slaughter

Avoid code duplication in CE&EE for projects services initialization

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28819
parent 054e3740
import IntegrationSettingsForm from '~/integrations/integration_settings_form'; import IntegrationSettingsForm from '~/integrations/integration_settings_form';
import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics'; import PrometheusMetrics from 'ee_else_ce/prometheus_metrics/prometheus_metrics';
import PrometheusAlerts from '~/prometheus_alerts'; import PrometheusAlerts from '~/prometheus_alerts';
import initAlertsSettings from '~/alerts_service_settings'; import initAlertsSettings from '~/alerts_service_settings';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const prometheusSettingsWrapper = document.querySelector('.js-prometheus-metrics-monitoring');
const integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form'); const integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
integrationSettingsForm.init(); integrationSettingsForm.init();
const prometheusSettingsSelector = '.js-prometheus-metrics-monitoring';
const prometheusSettingsWrapper = document.querySelector(prometheusSettingsSelector);
if (prometheusSettingsWrapper) { if (prometheusSettingsWrapper) {
const prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring'); const prometheusMetrics = new PrometheusMetrics(prometheusSettingsSelector);
prometheusMetrics.loadActiveMetrics(); prometheusMetrics.init();
} }
PrometheusAlerts(); PrometheusAlerts();
......
...@@ -28,6 +28,10 @@ export default class PrometheusMetrics { ...@@ -28,6 +28,10 @@ export default class PrometheusMetrics {
this.$panelToggle.on('click', e => this.handlePanelToggle(e)); this.$panelToggle.on('click', e => this.handlePanelToggle(e));
} }
init() {
this.loadActiveMetrics();
}
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this */
handlePanelToggle(e) { handlePanelToggle(e) {
const $toggleBtn = $(e.currentTarget); const $toggleBtn = $(e.currentTarget);
......
import PrometheusMetrics from 'ee/prometheus_metrics/prometheus_metrics';
import PrometheusAlerts from '~/prometheus_alerts';
import IntegrationSettingsForm from '~/integrations/integration_settings_form';
import initAlertsSettings from '~/alerts_service_settings';
document.addEventListener('DOMContentLoaded', () => {
const integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
integrationSettingsForm.init();
const prometheusSettingsWrapper = document.querySelector('.js-prometheus-metrics-monitoring');
if (prometheusSettingsWrapper) {
const prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
if (prometheusMetrics.isServiceActive) {
prometheusMetrics.loadActiveCustomMetrics();
} else {
prometheusMetrics.setNoIntegrationActiveState();
}
}
PrometheusAlerts();
initAlertsSettings(document.querySelector('.js-alerts-service-settings'));
});
...@@ -55,6 +55,14 @@ export default class EEPrometheusMetrics extends PrometheusMetrics { ...@@ -55,6 +55,14 @@ export default class EEPrometheusMetrics extends PrometheusMetrics {
this.isServiceActive = this.$monitoredCustomMetricsPanel.data('service-active'); this.isServiceActive = this.$monitoredCustomMetricsPanel.data('service-active');
} }
init() {
if (this.isServiceActive) {
this.loadActiveCustomMetrics();
} else {
this.setNoIntegrationActiveState();
}
}
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
setHidden(els) { setHidden(els) {
els.forEach(el => el.addClass('hidden')); els.forEach(el => el.addClass('hidden'));
......
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