2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
2021-10-27 12:55:37 -07:00
|
|
|
<n8n-input-label
|
2022-12-14 01:04:10 -08:00
|
|
|
:label="hideLabel ? '' : $locale.nodeText().inputLabelDisplayName(parameter, path)"
|
|
|
|
:tooltipText="hideLabel ? '' : $locale.nodeText().inputLabelDescription(parameter, path)"
|
2021-10-27 12:55:37 -07:00
|
|
|
:showTooltip="focused"
|
2022-07-20 04:32:51 -07:00
|
|
|
:showOptions="menuExpanded || focused || forceShowExpression"
|
2021-10-27 12:55:37 -07:00
|
|
|
:bold="false"
|
|
|
|
size="small"
|
2022-10-12 05:06:28 -07:00
|
|
|
color="text-dark"
|
2021-10-27 12:55:37 -07:00
|
|
|
>
|
2022-07-20 04:32:51 -07:00
|
|
|
<template #options>
|
|
|
|
<parameter-options
|
|
|
|
:parameter="parameter"
|
|
|
|
:value="value"
|
|
|
|
:isReadOnly="isReadOnly"
|
|
|
|
:showOptions="displayOptions"
|
2022-09-21 06:44:45 -07:00
|
|
|
:showExpressionSelector="showExpressionSelector"
|
2022-07-20 04:32:51 -07:00
|
|
|
@optionSelected="optionSelected"
|
|
|
|
@menu-expanded="onMenuExpanded"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template>
|
2022-09-21 06:44:45 -07:00
|
|
|
<draggable-target
|
|
|
|
type="mapping"
|
|
|
|
:disabled="isDropDisabled"
|
|
|
|
:sticky="true"
|
2022-12-14 05:43:02 -08:00
|
|
|
:stickyOffset="isValueExpression ? [26, 3] : [3, 3]"
|
2022-09-21 06:44:45 -07:00
|
|
|
@drop="onDrop"
|
|
|
|
>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #default="{ droppable, activeDrop }">
|
2022-10-06 06:03:55 -07:00
|
|
|
<n8n-tooltip
|
|
|
|
placement="left"
|
|
|
|
:manual="true"
|
|
|
|
:value="showMappingTooltip"
|
|
|
|
:buttons="dataMappingTooltipButtons"
|
|
|
|
>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
2022-12-14 01:04:10 -08:00
|
|
|
<span
|
|
|
|
v-html="
|
|
|
|
$locale.baseText(`dataMapping.${displayMode}Hint`, {
|
|
|
|
interpolate: { name: parameter.displayName },
|
|
|
|
})
|
|
|
|
"
|
|
|
|
/>
|
2022-11-18 05:59:31 -08:00
|
|
|
</template>
|
2022-10-12 05:06:28 -07:00
|
|
|
<parameter-input-wrapper
|
2022-10-06 06:03:55 -07:00
|
|
|
ref="param"
|
|
|
|
:parameter="parameter"
|
|
|
|
:value="value"
|
|
|
|
:path="path"
|
|
|
|
:isReadOnly="isReadOnly"
|
|
|
|
:droppable="droppable"
|
|
|
|
:activeDrop="activeDrop"
|
|
|
|
:forceShowExpression="forceShowExpression"
|
2022-10-12 05:06:28 -07:00
|
|
|
:hint="hint"
|
2022-10-06 06:03:55 -07:00
|
|
|
@valueChanged="valueChanged"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@drop="onDrop"
|
|
|
|
inputSize="small"
|
|
|
|
/>
|
|
|
|
</n8n-tooltip>
|
2022-07-20 04:32:51 -07:00
|
|
|
</template>
|
2022-09-21 06:44:45 -07:00
|
|
|
</draggable-target>
|
2022-07-20 04:32:51 -07:00
|
|
|
</template>
|
2021-10-27 12:55:37 -07:00
|
|
|
</n8n-input-label>
|
2019-06-23 03:35:23 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-11-03 05:04:53 -07:00
|
|
|
import Vue, { PropType } from 'vue';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
import { IN8nButton, INodeUi, IRunDataDisplayMode, IUpdateInformation } from '@/Interface';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-11-03 05:04:53 -07:00
|
|
|
import ParameterOptions from '@/components/ParameterOptions.vue';
|
2022-07-20 04:32:51 -07:00
|
|
|
import DraggableTarget from '@/components/DraggableTarget.vue';
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { showMessage } from '@/mixins/showMessage';
|
2022-07-20 04:32:51 -07:00
|
|
|
import { LOCAL_STORAGE_MAPPING_FLAG } from '@/constants';
|
2022-12-14 05:43:02 -08:00
|
|
|
import {
|
|
|
|
hasExpressionMapping,
|
|
|
|
isResourceLocatorValue,
|
|
|
|
hasOnlyListMode,
|
|
|
|
isValueExpression,
|
|
|
|
} from '@/utils';
|
2022-11-03 05:04:53 -07:00
|
|
|
import ParameterInputWrapper from '@/components/ParameterInputWrapper.vue';
|
|
|
|
import { INodeParameters, INodeProperties, INodePropertyMode } from 'n8n-workflow';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { BaseTextKey } from '@/plugins/i18n';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
|
|
|
import { useNDVStore } from '@/stores/ndv';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
export default mixins(showMessage).extend({
|
|
|
|
name: 'parameter-input-full',
|
|
|
|
components: {
|
|
|
|
ParameterOptions,
|
|
|
|
DraggableTarget,
|
|
|
|
ParameterInputWrapper,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
focused: false,
|
|
|
|
menuExpanded: false,
|
|
|
|
forceShowExpression: false,
|
|
|
|
dataMappingTooltipButtons: [] as IN8nButton[],
|
|
|
|
mappingTooltipEnabled: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
displayOptions: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
isReadOnly: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
hideLabel: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
2022-11-03 05:04:53 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
parameter: {
|
|
|
|
type: Object as PropType<INodeProperties>,
|
2022-10-06 06:03:55 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
path: {
|
|
|
|
type: String,
|
2022-07-20 04:32:51 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
value: {
|
|
|
|
type: [Number, String, Boolean, Array, Object] as PropType<INodeParameters>,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
const mappingTooltipDismissHandler = this.onMappingTooltipDismissed.bind(this);
|
|
|
|
this.dataMappingTooltipButtons = [
|
|
|
|
{
|
|
|
|
attrs: {
|
|
|
|
label: this.$locale.baseText('_reusableBaseText.dismiss' as BaseTextKey),
|
|
|
|
},
|
|
|
|
listeners: {
|
|
|
|
click: mappingTooltipDismissHandler,
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
];
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapStores(useNDVStore),
|
|
|
|
node(): INodeUi | null {
|
|
|
|
return this.ndvStore.activeNode;
|
|
|
|
},
|
|
|
|
hint(): string | null {
|
|
|
|
return this.$locale.nodeText().hint(this.parameter, this.path);
|
|
|
|
},
|
|
|
|
isInputTypeString(): boolean {
|
|
|
|
return this.parameter.type === 'string';
|
|
|
|
},
|
|
|
|
isResourceLocator(): boolean {
|
|
|
|
return this.parameter.type === 'resourceLocator';
|
|
|
|
},
|
|
|
|
isDropDisabled(): boolean {
|
|
|
|
return this.parameter.noDataExpression || this.isReadOnly || this.isResourceLocator;
|
|
|
|
},
|
2022-12-14 05:43:02 -08:00
|
|
|
isValueExpression(): boolean {
|
|
|
|
return isValueExpression(this.parameter, this.value);
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
showExpressionSelector(): boolean {
|
|
|
|
return this.isResourceLocator ? !hasOnlyListMode(this.parameter) : true;
|
|
|
|
},
|
|
|
|
isInputDataEmpty(): boolean {
|
|
|
|
return this.ndvStore.isDNVDataEmpty('input');
|
|
|
|
},
|
|
|
|
displayMode(): IRunDataDisplayMode {
|
|
|
|
return this.ndvStore.inputPanelDisplayMode;
|
|
|
|
},
|
|
|
|
showMappingTooltip(): boolean {
|
|
|
|
return (
|
|
|
|
this.mappingTooltipEnabled &&
|
|
|
|
this.focused &&
|
|
|
|
this.isInputTypeString &&
|
|
|
|
!this.isInputDataEmpty &&
|
|
|
|
window.localStorage.getItem(LOCAL_STORAGE_MAPPING_FLAG) !== 'true'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onFocus() {
|
|
|
|
this.focused = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.mappingTooltipEnabled = true;
|
|
|
|
}, 500);
|
|
|
|
if (!this.parameter.noDataExpression) {
|
|
|
|
this.ndvStore.setMappableNDVInputFocus(this.parameter.displayName);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onBlur() {
|
|
|
|
this.focused = false;
|
|
|
|
this.mappingTooltipEnabled = false;
|
|
|
|
if (!this.parameter.noDataExpression) {
|
|
|
|
this.ndvStore.setMappableNDVInputFocus('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onMenuExpanded(expanded: boolean) {
|
|
|
|
this.menuExpanded = expanded;
|
|
|
|
},
|
|
|
|
optionSelected(command: string) {
|
|
|
|
if (this.$refs.param) {
|
|
|
|
(this.$refs.param as Vue).$emit('optionSelected', command);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
valueChanged(parameterData: IUpdateInformation) {
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
|
|
|
onDrop(data: string) {
|
|
|
|
this.forceShowExpression = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
if (this.node) {
|
|
|
|
const prevValue = this.isResourceLocator ? this.value.value : this.value;
|
|
|
|
let updatedValue: string;
|
|
|
|
if (typeof prevValue === 'string' && prevValue.startsWith('=') && prevValue.length > 1) {
|
|
|
|
updatedValue = `${prevValue} ${data}`;
|
|
|
|
} else {
|
|
|
|
updatedValue = `=${data}`;
|
|
|
|
}
|
2022-09-21 06:44:45 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
let parameterData;
|
|
|
|
if (this.isResourceLocator) {
|
|
|
|
if (!isResourceLocatorValue(this.value)) {
|
|
|
|
parameterData = {
|
|
|
|
node: this.node.name,
|
|
|
|
name: this.path,
|
|
|
|
value: { __rl: true, value: updatedValue, mode: '' },
|
|
|
|
};
|
|
|
|
} else if (
|
|
|
|
this.value.mode === 'list' &&
|
|
|
|
this.parameter.modes &&
|
|
|
|
this.parameter.modes.length > 1
|
|
|
|
) {
|
|
|
|
let mode =
|
|
|
|
this.parameter.modes.find((mode: INodePropertyMode) => mode.name === 'id') || null;
|
|
|
|
if (!mode) {
|
|
|
|
mode = this.parameter.modes.filter(
|
|
|
|
(mode: INodePropertyMode) => mode.name !== 'list',
|
|
|
|
)[0];
|
2022-09-21 06:44:45 -07:00
|
|
|
}
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
parameterData = {
|
|
|
|
node: this.node.name,
|
|
|
|
name: this.path,
|
|
|
|
value: { __rl: true, value: updatedValue, mode: mode ? mode.name : '' },
|
|
|
|
};
|
2022-09-21 06:44:45 -07:00
|
|
|
} else {
|
|
|
|
parameterData = {
|
|
|
|
node: this.node.name,
|
|
|
|
name: this.path,
|
2022-12-14 01:04:10 -08:00
|
|
|
value: { __rl: true, value: updatedValue, mode: this.value.mode },
|
2022-09-21 06:44:45 -07:00
|
|
|
};
|
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
} else {
|
|
|
|
parameterData = {
|
|
|
|
node: this.node.name,
|
|
|
|
name: this.path,
|
|
|
|
value: updatedValue,
|
|
|
|
};
|
|
|
|
}
|
2022-07-20 04:32:51 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
this.$emit('valueChanged', parameterData);
|
2022-07-20 04:32:51 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
if (window.localStorage.getItem(LOCAL_STORAGE_MAPPING_FLAG) !== 'true') {
|
|
|
|
this.$showMessage({
|
|
|
|
title: this.$locale.baseText('dataMapping.success.title'),
|
|
|
|
message: this.$locale.baseText('dataMapping.success.moreInfo'),
|
|
|
|
type: 'success',
|
2022-07-20 04:32:51 -07:00
|
|
|
});
|
2022-12-14 01:04:10 -08:00
|
|
|
|
|
|
|
window.localStorage.setItem(LOCAL_STORAGE_MAPPING_FLAG, 'true');
|
2022-07-20 04:32:51 -07:00
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
|
|
|
|
this.ndvStore.setMappingTelemetry({
|
|
|
|
dest_node_type: this.node.type,
|
|
|
|
dest_parameter: this.path,
|
|
|
|
dest_parameter_mode:
|
|
|
|
typeof prevValue === 'string' && prevValue.startsWith('=') ? 'expression' : 'fixed',
|
|
|
|
dest_parameter_empty: prevValue === '' || prevValue === undefined,
|
|
|
|
dest_parameter_had_mapping:
|
|
|
|
typeof prevValue === 'string' &&
|
|
|
|
prevValue.startsWith('=') &&
|
|
|
|
hasExpressionMapping(prevValue),
|
|
|
|
success: true,
|
|
|
|
});
|
2022-10-06 06:03:55 -07:00
|
|
|
}
|
2022-12-14 01:04:10 -08:00
|
|
|
this.forceShowExpression = false;
|
|
|
|
}, 200);
|
|
|
|
},
|
|
|
|
onMappingTooltipDismissed() {
|
|
|
|
window.localStorage.setItem(LOCAL_STORAGE_MAPPING_FLAG, 'true');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
showMappingTooltip(newValue: boolean) {
|
|
|
|
if (!newValue) {
|
|
|
|
this.$telemetry.track('User viewed data mapping tooltip', { type: 'param focus' });
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
});
|
2019-06-23 03:35:23 -07:00
|
|
|
</script>
|