All files / app/assets/javascripts/packages_and_registries/settings/project utils.js

80% Statements 12/15
0% Branches 0/2
71.43% Functions 5/7
83.33% Lines 10/12

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      3x         42x   3x 48x   3x 90x       17x 17x     3x 8x            
import { n__ } from '~/locale';
import { KEEP_N_OPTIONS, CADENCE_OPTIONS, OLDER_THAN_OPTIONS } from './constants';
 
export const findDefaultOption = (options) => {
  const item = options.find((o) => o.default);
  return item ? item.key : null;
};
 
export const olderThanTranslationGenerator = (variable) => n__('%d day', '%d days', variable);
 
export const keepNTranslationGenerator = (variable) =>
  n__('%d tag per image name', '%d tags per image name', variable);
 
export const optionLabelGenerator = (collection, translationFn) => {
  const result = collection.map((option) => ({
    ...option,
    label: translationFn(option.variable),
  }));
  result.unshift({ key: null, label: '' });
  return result;
};
 
export const formOptionsGenerator = () => {
  return {
    olderThan: optionLabelGenerator(OLDER_THAN_OPTIONS, olderThanTranslationGenerator),
    cadence: CADENCE_OPTIONS,
    keepN: optionLabelGenerator(KEEP_N_OPTIONS, keepNTranslationGenerator),
  };
};