2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div v-if="dialogVisible" @keydown.stop>
|
2021-12-15 04:16:53 -08:00
|
|
|
<el-dialog :visible="dialogVisible" custom-class="expression-dialog classic" append-to-body width="80%" :title="$locale.baseText('expressionEdit.editExpression')" :before-close="closeDialog">
|
2019-06-23 03:35:23 -07:00
|
|
|
<el-row>
|
|
|
|
<el-col :span="8">
|
|
|
|
<div class="header-side-menu">
|
|
|
|
<div class="headline">
|
2021-12-15 04:16:53 -08:00
|
|
|
{{ $locale.baseText('expressionEdit.editExpression') }}
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
<div class="sub-headline">
|
2021-12-15 04:16:53 -08:00
|
|
|
{{ $locale.baseText('expressionEdit.variableSelector') }}
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="variable-selector">
|
|
|
|
<variable-selector :path="path" @itemSelected="itemSelected"></variable-selector>
|
|
|
|
</div>
|
|
|
|
</el-col>
|
|
|
|
<el-col :span="16" class="right-side">
|
|
|
|
<div class="expression-editor-wrapper">
|
|
|
|
<div class="editor-description">
|
2021-12-15 04:16:53 -08:00
|
|
|
{{ $locale.baseText('expressionEdit.expression') }}
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
<div class="expression-editor">
|
|
|
|
<expression-input :parameter="parameter" ref="inputFieldExpression" rows="8" :value="value" :path="path" @change="valueChanged" @keydown.stop="noOp"></expression-input>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="expression-result-wrapper">
|
|
|
|
<div class="editor-description">
|
2021-12-15 04:16:53 -08:00
|
|
|
{{ $locale.baseText('expressionEdit.result') }}
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
2021-05-29 19:08:41 -07:00
|
|
|
<expression-input :parameter="parameter" resolvedValue="true" ref="expressionResult" rows="8" :value="displayValue" :path="path"></expression-input>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
</el-dialog>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import ExpressionInput from '@/components/ExpressionInput.vue';
|
|
|
|
import VariableSelector from '@/components/VariableSelector.vue';
|
|
|
|
|
|
|
|
import { IVariableItemSelected } from '@/Interface';
|
|
|
|
|
2021-05-11 20:12:53 -07:00
|
|
|
import { externalHooks } from '@/components/mixins/externalHooks';
|
2021-05-29 19:08:41 -07:00
|
|
|
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
2021-05-11 20:12:53 -07:00
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
|
2022-05-23 08:56:15 -07:00
|
|
|
const MAPPING_PARAMS = [`$evaluateExpression`, `$item`, `$jmespath`, `$node`, `$binary`, `$data`, `$env`, `$json`, `$now`, `$parameters`, `$position`, `$resumeWebhookUrl`, `$runIndex`, `$today`, `$workflow`];
|
|
|
|
|
2021-05-29 19:08:41 -07:00
|
|
|
export default mixins(
|
|
|
|
externalHooks,
|
|
|
|
genericHelpers,
|
|
|
|
).extend({
|
2019-06-23 03:35:23 -07:00
|
|
|
name: 'ExpressionEdit',
|
|
|
|
props: [
|
|
|
|
'dialogVisible',
|
|
|
|
'parameter',
|
|
|
|
'path',
|
|
|
|
'value',
|
2022-05-23 08:56:15 -07:00
|
|
|
'eventSource',
|
2019-06-23 03:35:23 -07:00
|
|
|
],
|
|
|
|
components: {
|
|
|
|
ExpressionInput,
|
|
|
|
VariableSelector,
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2021-05-29 19:08:41 -07:00
|
|
|
displayValue: '',
|
|
|
|
latestValue: '',
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2021-05-31 10:59:45 -07:00
|
|
|
valueChanged (value: string, forceUpdate = false) {
|
2021-05-29 19:08:41 -07:00
|
|
|
this.latestValue = value;
|
2021-05-31 10:59:45 -07:00
|
|
|
|
|
|
|
if (forceUpdate === true) {
|
|
|
|
this.updateDisplayValue();
|
|
|
|
this.$emit('valueChanged', this.latestValue);
|
|
|
|
} else {
|
2022-03-04 08:28:03 -08:00
|
|
|
this.callDebounced('updateDisplayValue', { debounceTime: 500 });
|
2021-05-31 10:59:45 -07:00
|
|
|
}
|
2021-05-29 19:08:41 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
updateDisplayValue () {
|
|
|
|
this.displayValue = this.latestValue;
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
closeDialog () {
|
|
|
|
// Handle the close externally as the visible parameter is an external prop
|
|
|
|
// and is so not allowed to be changed here.
|
2021-05-29 19:08:41 -07:00
|
|
|
this.$emit('valueChanged', this.latestValue);
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$emit('closeDialog');
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
itemSelected (eventData: IVariableItemSelected) {
|
|
|
|
(this.$refs.inputFieldExpression as any).itemSelected(eventData); // tslint:disable-line:no-any
|
2021-05-11 20:12:53 -07:00
|
|
|
this.$externalHooks().run('expressionEdit.itemSelected', { parameter: this.parameter, value: this.value, selectedItem: eventData });
|
2022-07-09 23:53:04 -07:00
|
|
|
|
|
|
|
const trackProperties: {
|
|
|
|
event_version: string;
|
|
|
|
node_type_dest: string;
|
|
|
|
node_type_source?: string;
|
|
|
|
parameter_name_dest: string;
|
|
|
|
parameter_name_source?: string;
|
|
|
|
variable_type?: string;
|
|
|
|
is_immediate_input: boolean;
|
|
|
|
variable_expression: string;
|
|
|
|
node_name: string;
|
|
|
|
} = {
|
|
|
|
event_version: '2',
|
|
|
|
node_type_dest: this.$store.getters.activeNode.type,
|
|
|
|
parameter_name_dest: this.parameter.displayName,
|
|
|
|
is_immediate_input: false,
|
|
|
|
variable_expression: eventData.variable,
|
|
|
|
node_name: this.$store.getters.activeNode.name,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (eventData.variable) {
|
|
|
|
let splitVar = eventData.variable.split('.');
|
|
|
|
|
|
|
|
if (eventData.variable.startsWith('Object.keys')) {
|
|
|
|
splitVar = eventData.variable.split('(')[1].split(')')[0].split('.');
|
|
|
|
trackProperties.variable_type = 'Keys';
|
|
|
|
} else if (eventData.variable.startsWith('Object.values')) {
|
|
|
|
splitVar = eventData.variable.split('(')[1].split(')')[0].split('.');
|
|
|
|
trackProperties.variable_type = 'Values';
|
|
|
|
} else {
|
|
|
|
trackProperties.variable_type = 'Raw value';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (splitVar[0].startsWith('$node')) {
|
|
|
|
const sourceNodeName = splitVar[0].split('"')[1];
|
|
|
|
trackProperties.node_type_source = this.$store.getters.getNodeByName(sourceNodeName).type;
|
|
|
|
const nodeConnections: Array<Array<{ node: string }>> = this.$store.getters.outgoingConnectionsByNodeName(sourceNodeName).main;
|
|
|
|
trackProperties.is_immediate_input = (nodeConnections && nodeConnections[0] && !!nodeConnections[0].find(({ node }) => node === this.$store.getters.activeNode.name)) ? true : false;
|
|
|
|
|
|
|
|
if (splitVar[1].startsWith('parameter')) {
|
|
|
|
trackProperties.parameter_name_source = splitVar[1].split('"')[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
trackProperties.is_immediate_input = true;
|
|
|
|
|
|
|
|
if(splitVar[0].startsWith('$parameter')) {
|
|
|
|
trackProperties.parameter_name_source = splitVar[0].split('"')[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$telemetry.track('User inserted item from Expression Editor variable selector', trackProperties);
|
2021-05-11 20:12:53 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
dialogVisible (newValue) {
|
2021-05-29 20:41:54 -07:00
|
|
|
this.displayValue = this.value;
|
|
|
|
this.latestValue = this.value;
|
|
|
|
|
2021-05-11 20:12:53 -07:00
|
|
|
const resolvedExpressionValue = this.$refs.expressionResult && (this.$refs.expressionResult as any).getValue() || undefined; // tslint:disable-line:no-any
|
|
|
|
this.$externalHooks().run('expressionEdit.dialogVisibleChanged', { dialogVisible: newValue, parameter: this.parameter, value: this.value, resolvedExpressionValue });
|
2021-10-18 20:57:49 -07:00
|
|
|
|
|
|
|
if (!newValue) {
|
2022-05-23 08:56:15 -07:00
|
|
|
this.$telemetry.track('User closed Expression Editor', {
|
|
|
|
empty_expression: (this.value === '=') || (this.value === '={{}}') || !this.value,
|
|
|
|
workflow_id: this.$store.getters.workflowId,
|
|
|
|
source: this.eventSource,
|
|
|
|
session_id: this.$store.getters['ui/ndvSessionId'],
|
|
|
|
has_parameter: this.value.includes('$parameter'),
|
|
|
|
has_mapping: !!MAPPING_PARAMS.find((param) => this.value.includes(param)),
|
|
|
|
});
|
2021-10-18 20:57:49 -07:00
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.editor-description {
|
2021-08-29 04:36:17 -07:00
|
|
|
line-height: 1.5;
|
2019-06-23 03:35:23 -07:00
|
|
|
font-weight: bold;
|
|
|
|
padding: 0 0 0.5em 0.2em;;
|
|
|
|
}
|
|
|
|
|
|
|
|
.expression-result-wrapper,
|
|
|
|
.expression-editor-wrapper {
|
|
|
|
padding: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.expression-result-wrapper {
|
|
|
|
margin-top: 1em;
|
|
|
|
}
|
|
|
|
|
2020-02-07 08:36:23 -08:00
|
|
|
::v-deep .expression-dialog {
|
2019-06-23 03:35:23 -07:00
|
|
|
.el-dialog__header {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
.el-dialog__title {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.el-dialog__body {
|
|
|
|
padding: 0;
|
2021-10-27 12:55:37 -07:00
|
|
|
font-size: var(--font-size-s);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.right-side {
|
|
|
|
background-color: #f9f9f9;
|
2021-09-11 01:15:36 -07:00
|
|
|
border-top-right-radius: 8px;
|
|
|
|
border-bottom-right-radius: 8px;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.header-side-menu {
|
|
|
|
padding: 1em 0 0.5em 1.8em;
|
2021-09-11 01:15:36 -07:00
|
|
|
border-top-left-radius: 8px;
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-04-11 06:12:13 -07:00
|
|
|
background-color: var(--color-background-base);
|
2019-06-23 03:35:23 -07:00
|
|
|
color: #555;
|
|
|
|
border-bottom: 1px solid $--color-primary;
|
|
|
|
margin-bottom: 1em;
|
|
|
|
|
|
|
|
.headline {
|
|
|
|
font-size: 1.35em;
|
|
|
|
font-weight: 600;
|
2021-08-29 04:36:17 -07:00
|
|
|
line-height: 1.5;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.sub-headline {
|
|
|
|
font-weight: 600;
|
|
|
|
font-size: 1.1em;
|
|
|
|
text-align: center;
|
2021-08-29 04:36:17 -07:00
|
|
|
line-height: 1.5;
|
2019-06-23 03:35:23 -07:00
|
|
|
padding-top: 1.5em;
|
|
|
|
color: $--color-primary;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.variable-selector {
|
|
|
|
margin: 0 1em;
|
|
|
|
}
|
|
|
|
</style>
|