All files / app/assets/javascripts/notes utils.js

100% Statements 17/17
100% Branches 8/8
100% Functions 4/4
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                        48x             48x   48x 22x     48x 12x   12x 8x 5x     3x     4x     48x 7x   7x 4x     3x    
import { marked } from 'marked';
import markedBidi from 'marked-bidi';
import { sanitize } from '~/lib/dompurify';
import { markdownConfig } from '~/lib/utils/text_utility';
import { HTTP_STATUS_UNPROCESSABLE_ENTITY } from '~/lib/utils/http_status';
import { sprintf } from '~/locale';
import { UPDATE_COMMENT_FORM, COMMENT_FORM } from './i18n';
 
/**
 * Tracks snowplow event when User toggles timeline view
 * @param {Boolean} enabled that will be send as a property for the event
 */
export const trackToggleTimelineView = (enabled) => ({
  category: 'Incident Management', // eslint-disable-line @gitlab/require-i18n-strings
  action: 'toggle_incident_comments_into_timeline_view',
  label: 'Status', // eslint-disable-line @gitlab/require-i18n-strings
  property: enabled,
});
 
marked.use(markedBidi());
 
export const renderMarkdown = (rawMarkdown) => {
  return sanitize(marked(rawMarkdown), markdownConfig);
};
 
export const createNoteErrorMessages = (data, status) => {
  const errors = data?.errors;
 
  if (errors && status === HTTP_STATUS_UNPROCESSABLE_ENTITY) {
    if (errors.commands_only?.length) {
      return errors.commands_only;
    }
 
    return [sprintf(COMMENT_FORM.error, { reason: errors.toLowerCase() }, false)];
  }
 
  return [COMMENT_FORM.GENERIC_UNSUBMITTABLE_NETWORK];
};
 
export const updateNoteErrorMessage = (e) => {
  const errors = e?.response?.data?.errors;
 
  if (errors) {
    return sprintf(UPDATE_COMMENT_FORM.error, { reason: errors.toLowerCase() });
  }
 
  return UPDATE_COMMENT_FORM.defaultError;
};