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
50
51
52
53
54
55
56
57
58
59
60
|
import { DEFAULT_I18N } from './constants';
function convertToListBoxItems(items) {
return items.map((item) => ({
text: item.name,
value: item.value || item.name,
default: item.default,
}));
}
/**
* Format multiple lists to array of group options for listbox
* @param branches list of branches
* @param tags list of tags
* @param commits list of commits
* @returns {*[]} array of group items with header and options
*/
export const formatListBoxItems = (branches, tags, commits) => {
const listBoxItems = [];
const addToFinalResult = (items, header) => {
if (items && items.length > 0) {
listBoxItems.push({
text: header,
options: convertToListBoxItems(items),
});
}
};
addToFinalResult(branches, DEFAULT_I18N.branches);
addToFinalResult(tags, DEFAULT_I18N.tags);
addToFinalResult(commits, DEFAULT_I18N.commits);
return listBoxItems;
};
/**
* Check error existence and add to final array
* @param branches list of branches
* @param tags list of tags
* @param commits list of commits
* @returns {*[]} array of error messages
*/
export const formatErrors = (branches, tags, commits) => {
const errorsList = [];
if (branches && branches.error) {
errorsList.push(DEFAULT_I18N.branchesErrorMessage);
}
if (tags && tags.error) {
errorsList.push(DEFAULT_I18N.tagsErrorMessage);
}
if (commits && commits.error) {
errorsList.push(DEFAULT_I18N.commitsErrorMessage);
}
return errorsList;
};
|