Skip to content

Commit

Permalink
feat: Set or Create raw value if not exists (#2571)
Browse files Browse the repository at this point in the history
  • Loading branch information
riccefarias authored Oct 9, 2023
1 parent 47872c4 commit be0b70b
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions lib/Internal/CustomVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class CustomVariables extends CoreBase {
constructor(registry, internalModule) {
super(registry, 'internal', 'Internal/CustomVariables')

// this.internalModule = internalModule
//this.internalModule = internalModule
}

getActionDefinitions() {
Expand All @@ -44,6 +44,22 @@ export default class CustomVariables extends CoreBase {
},
],
},
custom_variable_create_value: {
label: 'Custom Variable: Set or Create raw value if not exists',
options: [
{
type: 'textinput',
label: 'Custom variable',
id: 'name',
},
{
type: 'textinput',
label: 'Value',
id: 'value',
default: '',
},
],
},
custom_variable_set_expression: {
label: 'Custom Variable: Set with expression',
options: [
Expand Down Expand Up @@ -199,7 +215,7 @@ export default class CustomVariables extends CoreBase {
const wrappedVariable = `\${$(${action.options.variable})}`

action.options.expression =
action.options.order == 'variable_value'
action.options.order === 'variable_value'
? `\`${wrappedVariable}${wrappedValue}\``
: `\`${wrappedValue}${wrappedVariable}\``

Expand All @@ -210,7 +226,7 @@ export default class CustomVariables extends CoreBase {
delete action.options.result

return action
} else if (action.action == 'custom_variable_string_substring_operation') {
} else if (action.action === 'custom_variable_string_substring_operation') {
action.action = 'custom_variable_set_expression'

action.options.expression = `substr($(${action.options.variable}), ${wrapValue(
Expand All @@ -231,6 +247,13 @@ export default class CustomVariables extends CoreBase {
if (action.action === 'custom_variable_set_value') {
this.instance.variable.custom.setValue(action.options.name, action.options.value)
return true
} else if (action.action === 'custom_variable_create_value') {
if (this.instance.variable.custom.custom_variables[action.options.name]) {
this.instance.variable.custom.setValue(action.options.name, action.options.value)
} else {
this.instance.variable.custom.createVariable(action.options.name, action.options.value)
}
return true
} else if (action.action === 'custom_variable_set_expression') {
this.instance.variable.custom.setValueToExpression(action.options.name, action.options.expression)
return true
Expand Down Expand Up @@ -281,10 +304,10 @@ export default class CustomVariables extends CoreBase {
this.instance.variable.custom.setValue(action.options.targetVariable, valueToSet)

return true
} else if (action.action == 'custom_variable_reset_to_default') {
} else if (action.action === 'custom_variable_reset_to_default') {
this.instance.variable.custom.resetValueToDefault(action.options.name)
return true
} else if (action.action == 'custom_variable_sync_to_default') {
} else if (action.action === 'custom_variable_sync_to_default') {
this.instance.variable.custom.syncValueToDefault(action.options.name)
return true
}
Expand Down

0 comments on commit be0b70b

Please sign in to comment.