Commit 4111c635 authored by Denys Mishunov's avatar Denys Mishunov

Merge branch '214271-reuse-payload-previwer-start' into 'master'

Refactor PayloadPreviewer to avoid CE/EE split

See merge request gitlab-org/gitlab!40508
parents 94e7a6c4 6b478ad6
import PayloadPreviewer from '~/pages/admin/application_settings/payload_previewer'; import PayloadPreviewer from '~/pages/admin/application_settings/payload_previewer';
export default () => { export default () => {
new PayloadPreviewer( Array.from(document.querySelectorAll('.js-payload-preview-trigger')).forEach(trigger => {
document.querySelector('.js-usage-ping-payload-trigger'), new PayloadPreviewer(trigger).init();
document.querySelector('.js-usage-ping-payload'), });
).init();
}; };
import setup from 'ee_else_ce/admin/application_settings/setup_metrics_and_profiling'; import setup from '~/admin/application_settings/setup_metrics_and_profiling';
document.addEventListener('DOMContentLoaded', setup); document.addEventListener('DOMContentLoaded', setup);
...@@ -3,9 +3,9 @@ import { __ } from '../../../locale'; ...@@ -3,9 +3,9 @@ import { __ } from '../../../locale';
import { deprecatedCreateFlash as flash } from '../../../flash'; import { deprecatedCreateFlash as flash } from '../../../flash';
export default class PayloadPreviewer { export default class PayloadPreviewer {
constructor(trigger, container) { constructor(trigger) {
this.trigger = trigger; this.trigger = trigger;
this.container = container; this.container = document.querySelector(trigger.dataset.payloadSelector);
this.isVisible = false; this.isVisible = false;
this.isInserted = false; this.isInserted = false;
} }
......
- payload_class = 'js-usage-ping-payload'
= form_for @application_setting, url: metrics_and_profiling_admin_application_settings_path(anchor: 'js-usage-settings'), html: { class: 'fieldset-form' } do |f| = form_for @application_setting, url: metrics_and_profiling_admin_application_settings_path(anchor: 'js-usage-settings'), html: { class: 'fieldset-form' } do |f|
= form_errors(@application_setting) = form_errors(@application_setting)
...@@ -25,10 +27,10 @@ ...@@ -25,10 +27,10 @@
- usage_ping_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: usage_ping_path } - usage_ping_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: usage_ping_path }
%p.mb-2= s_('%{usage_ping_link_start}Learn more%{usage_ping_link_end} about what information is shared with GitLab Inc.').html_safe % { usage_ping_link_start: usage_ping_link_start, usage_ping_link_end: '</a>'.html_safe } %p.mb-2= s_('%{usage_ping_link_start}Learn more%{usage_ping_link_end} about what information is shared with GitLab Inc.').html_safe % { usage_ping_link_start: usage_ping_link_start, usage_ping_link_end: '</a>'.html_safe }
%button.btn.js-usage-ping-payload-trigger{ type: 'button' } %button.btn.js-payload-preview-trigger{ type: 'button', data: { payload_selector: ".#{payload_class}" } }
.spinner.js-spinner.d-none .spinner.js-spinner.d-none
.js-text.d-inline= _('Preview payload') .js-text.d-inline= _('Preview payload')
%pre.usage-data.js-usage-ping-payload.js-syntax-highlight.code.highlight.mt-2.d-none{ data: { endpoint: usage_data_admin_application_settings_path(format: :html) } } %pre.usage-data.js-syntax-highlight.code.highlight.mt-2.d-none{ class: payload_class, data: { endpoint: usage_data_admin_application_settings_path(format: :html) } }
- else - else
= _('The usage ping is disabled, and cannot be configured through this form.') = _('The usage ping is disabled, and cannot be configured through this form.')
- deactivating_usage_ping_path = help_page_path('development/telemetry/usage_ping', anchor: 'disable-usage-ping') - deactivating_usage_ping_path = help_page_path('development/telemetry/usage_ping', anchor: 'disable-usage-ping')
......
import PayloadPreviewer from '~/pages/admin/application_settings/payload_previewer';
import baseSetup from '~/admin/application_settings/setup_metrics_and_profiling';
export default () => {
baseSetup();
new PayloadPreviewer(
document.querySelector('.js-seat-link-payload-trigger'),
document.querySelector('.js-seat-link-payload'),
).init();
};
- payload_class = 'js-seat-link-payload'
= form_for @application_setting, url: metrics_and_profiling_admin_application_settings_path(anchor: 'js-seat-link-settings'), html: { class: 'fieldset-form' } do |f| = form_for @application_setting, url: metrics_and_profiling_admin_application_settings_path(anchor: 'js-seat-link-settings'), html: { class: 'fieldset-form' } do |f|
= form_errors(@application_setting) = form_errors(@application_setting)
...@@ -16,10 +18,10 @@ ...@@ -16,10 +18,10 @@
- link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: link_path } - link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: link_path }
%p.mb-2= s_('%{link_start}Learn more%{link_end} about what information is shared with GitLab Inc.').html_safe % { link_start: link_start, link_end: '</a>'.html_safe } %p.mb-2= s_('%{link_start}Learn more%{link_end} about what information is shared with GitLab Inc.').html_safe % { link_start: link_start, link_end: '</a>'.html_safe }
%button.btn.js-seat-link-payload-trigger{ type: 'button' } %button.btn.js-payload-preview-trigger{ type: 'button', data: { payload_selector: ".#{payload_class}" } }
.spinner.js-spinner.d-none .spinner.js-spinner.d-none
.js-text.d-inline= _('Preview payload') .js-text.d-inline= _('Preview payload')
%pre.usage-data.js-seat-link-payload.js-syntax-highlight.code.highlight.mt-2.d-none{ data: { endpoint: seat_link_payload_admin_application_settings_path(format: :html) } } %pre.usage-data.js-syntax-highlight.code.highlight.mt-2.d-none{ class: payload_class, data: { endpoint: seat_link_payload_admin_application_settings_path(format: :html) } }
- else - else
= _('Seat Link is disabled, and cannot be configured through this form.') = _('Seat Link is disabled, and cannot be configured through this form.')
- link_path = help_page_path('subscriptions/index', anchor: 'disable-seat-link') - link_path = help_page_path('subscriptions/index', anchor: 'disable-seat-link')
......
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