diff options
Diffstat (limited to 'app/assets/javascripts/helpers')
4 files changed, 28 insertions, 7 deletions
diff --git a/app/assets/javascripts/helpers/event_hub_factory.js b/app/assets/javascripts/helpers/event_hub_factory.js index a9c301e3a93..62af67d3ef3 100644 --- a/app/assets/javascripts/helpers/event_hub_factory.js +++ b/app/assets/javascripts/helpers/event_hub_factory.js @@ -45,7 +45,7 @@ class EventHub { $off(type, handler) { const handlers = this.$_all.get(type) || []; - const newHandlers = handler ? handlers.filter(x => x !== handler) : []; + const newHandlers = handler ? handlers.filter((x) => x !== handler) : []; if (newHandlers.length) { this.$_all.set(type, newHandlers); @@ -77,7 +77,7 @@ class EventHub { $emit(type, ...args) { const handlers = this.$_all.get(type) || []; - handlers.forEach(handler => { + handlers.forEach((handler) => { handler(...args); }); } diff --git a/app/assets/javascripts/helpers/help_page_helper.js b/app/assets/javascripts/helpers/help_page_helper.js new file mode 100644 index 00000000000..0e824548646 --- /dev/null +++ b/app/assets/javascripts/helpers/help_page_helper.js @@ -0,0 +1,21 @@ +import { joinPaths, setUrlFragment } from '~/lib/utils/url_utility'; + +const HELP_PAGE_URL_ROOT = '/help/'; + +/** + * Generate link to a GitLab documentation page. + * + * This is designed to mirror the Ruby `help_page_path` helper function, so that + * the two can be used interchangeably. + * @param {String} path - Path to doc file relative to the doc/ directory in the GitLab repository. + * Optionally, including `.md` or `.html` prefix + * @param {String} options.anchor - Name of the anchor to scroll to on the documentation page. + */ +export const helpPagePath = (path, { anchor = '' } = {}) => { + let helpPath = joinPaths(gon.relative_url_root || '/', HELP_PAGE_URL_ROOT, path); + if (anchor) { + helpPath = setUrlFragment(helpPath, anchor); + } + + return helpPath; +}; diff --git a/app/assets/javascripts/helpers/monitor_helper.js b/app/assets/javascripts/helpers/monitor_helper.js index 5e345321013..7c6a6d6a433 100644 --- a/app/assets/javascripts/helpers/monitor_helper.js +++ b/app/assets/javascripts/helpers/monitor_helper.js @@ -38,7 +38,7 @@ const templatedLabel = (queryLabel, metricAttributes) => { * @example * multiMetricLabel('', {__name__: "up", app: "prometheus"}) -> "__name__: up, app: prometheus" */ -const multiMetricLabel = metricAttributes => { +const multiMetricLabel = (metricAttributes) => { return Object.entries(metricAttributes) .map(([templateVar, label]) => `${templateVar}: ${label}`) .join(', '); @@ -64,7 +64,7 @@ export const getSeriesLabel = (queryLabel, metricAttributes) => { * @returns {Array} The formatted values */ export const makeDataSeries = (queryResults, defaultConfig) => - queryResults.map(result => { + queryResults.map((result) => { return { ...defaultConfig, data: result.values, diff --git a/app/assets/javascripts/helpers/startup_css_helper.js b/app/assets/javascripts/helpers/startup_css_helper.js index d41a6209898..6e19979721c 100644 --- a/app/assets/javascripts/helpers/startup_css_helper.js +++ b/app/assets/javascripts/helpers/startup_css_helper.js @@ -22,14 +22,14 @@ const handleStartupEvents = () => { /* For `waitForCSSLoaded` methods, see docs.gitlab.com/ee/development/fe_guide/performance.html#important-considerations */ export const waitForCSSLoaded = (action = () => {}) => { - if (!gon?.features?.startupCss || allLinksLoaded()) { - return new Promise(resolve => { + if (allLinksLoaded()) { + return new Promise((resolve) => { action(); resolve(); }); } - return new Promise(resolve => { + return new Promise((resolve) => { document.addEventListener(CSS_LOADED_EVENT, resolve, { once: true }); document.addEventListener(STARTUP_LINK_LOADED_EVENT, handleStartupEvents); }).then(action); |