debian-mirror-gitlab/app/assets/javascripts/registry/settings/utils.js

27 lines
890 B
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { n__ } from '~/locale';
import { KEEP_N_OPTIONS, CADENCE_OPTIONS, OLDER_THAN_OPTIONS } from './constants';
2021-03-08 18:12:59 +05:30
export const findDefaultOption = (options) => {
const item = options.find((o) => o.default);
2020-03-13 15:44:24 +05:30
return item ? item.key : null;
};
2021-03-08 18:12:59 +05:30
export const olderThanTranslationGenerator = (variable) => n__('%d day', '%d days', variable);
2021-01-03 14:25:43 +05:30
2021-03-08 18:12:59 +05:30
export const keepNTranslationGenerator = (variable) =>
2021-01-03 14:25:43 +05:30
n__('%d tag per image name', '%d tags per image name', variable);
export const optionLabelGenerator = (collection, translationFn) =>
2021-03-08 18:12:59 +05:30
collection.map((option) => ({
2021-01-03 14:25:43 +05:30
...option,
label: translationFn(option.variable),
}));
export const formOptionsGenerator = () => {
return {
olderThan: optionLabelGenerator(OLDER_THAN_OPTIONS, olderThanTranslationGenerator),
cadence: CADENCE_OPTIONS,
keepN: optionLabelGenerator(KEEP_N_OPTIONS, keepNTranslationGenerator),
};
};