blob: 009e56469d16666e74d249cc193a2c2405c64875 (
plain)
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
|
import { uniq } from 'lodash';
import { allEnvironments } from './constants';
/**
* This function takes aa list of variable and environments
* and create a new Array that concatenate the environment list
* with the environment scopes find in the variable list. This is
* useful for variable settings so that we can render a list of all
* environment scopes available based on both the list of envs and what
* is found under each variable.
* @param {Array} variables
* @param {Array} environments
* @returns {Array} - Array of environments
*/
export const createJoinedEnvironments = (variables = [], environments = []) => {
const scopesFromVariables = variables.map((variable) => variable.environmentScope);
return uniq(environments.concat(scopesFromVariables)).sort();
};
/**
* This function job is to convert the * wildcard to text when applicable
* in the UI. It uses a constants to compare the incoming value to that
* of the * and then apply the corresponding label if applicable. If there
* is no scope, then we return the default value as well.
* @param {String} scope
* @returns {String} - Converted value if applicable
*/
export const convertEnvironmentScope = (environmentScope = '') => {
if (environmentScope === allEnvironments.type || !environmentScope) {
return allEnvironments.text;
}
return environmentScope;
};
/**
* Gives us an array of all the environments by name
* @param {Array} nodes
* @return {Array<String>} - Array of environments strings
*/
export const mapEnvironmentNames = (nodes = []) => {
return nodes.map((env) => env.name);
};
|