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

47 lines
1.3 KiB
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';
2020-03-13 15:44:24 +05:30
export const findDefaultOption = options => {
const item = options.find(o => o.default);
return item ? item.key : null;
};
export const mapComputedToEvent = (list, root) => {
const result = {};
list.forEach(e => {
result[e] = {
get() {
return this[root][e];
},
set(value) {
2020-07-28 23:09:34 +05:30
this.$emit('input', { newValue: { ...this[root], [e]: value }, modified: e });
2020-03-13 15:44:24 +05:30
},
};
});
return result;
};
2021-01-03 14:25:43 +05:30
export const olderThanTranslationGenerator = variable =>
n__(
'%d day until tags are automatically removed',
'%d days until tags are automatically removed',
variable,
);
export const keepNTranslationGenerator = variable =>
n__('%d tag per image name', '%d tags per image name', variable);
export const optionLabelGenerator = (collection, translationFn) =>
collection.map(option => ({
...option,
label: translationFn(option.variable),
}));
export const formOptionsGenerator = () => {
return {
olderThan: optionLabelGenerator(OLDER_THAN_OPTIONS, olderThanTranslationGenerator),
cadence: CADENCE_OPTIONS,
keepN: optionLabelGenerator(KEEP_N_OPTIONS, keepNTranslationGenerator),
};
};