MCPcopy
hub / github.com/deepops-ai/deepops / replaceWithVariablesHasMultiValues

Function replaceWithVariablesHasMultiValues

ui/src/utils/variable.ts:73–104  ·  view source on GitHub ↗
(s: string, replaceAllWith?)

Source from the content-addressed store, hash-verified

71// replace ${xxx} format in s with every possible value of the variable
72// if s doesn't contain any variable, return [s]
73export const replaceWithVariablesHasMultiValues = (s: string, replaceAllWith?): string[] => {
74 const vars = $variables.get()
75 let res = []
76 const formats = parseVariableFormat(s);
77 for (const f of formats) {
78 const v = (vars.length > 0 ? vars : gvariables).find(v => v.name ==f)
79 if (v) {
80
81 let selected = []
82 if (v.selected == VarialbeAllOption) {
83 if (replaceAllWith) {
84 selected.push(replaceAllWith)
85 } else {
86 selected = v.values?.filter(v1 => v1 != VarialbeAllOption )??[]
87 }
88 } else {
89 selected = isEmpty(v.selected) ? [] : v.selected.split(VariableSplitChar)
90 }
91
92
93 res = selected.map(v => s.replaceAll(`\${${f}}`, v))
94 }
95 }
96
97 if (res.length == 0) {
98 res.push(s)
99 }
100
101 // console.log("here333333:",s, res)
102
103 return res
104}
105
106

Callers 8

queryPrometheusLabelsFunction · 0.90
queryLokiVariableValuesFunction · 0.90
onSearchFunction · 0.90
TraceSearchPanelFunction · 0.90
loadOperationsFunction · 0.90

Calls 4

parseVariableFormatFunction · 0.90
isEmptyFunction · 0.90
getMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected