mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat: Add assignment component with drag and drop to Set node (#8283)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
:model-value="modelValue"
|
||||
:path="path"
|
||||
:is-read-only="isReadOnly"
|
||||
:is-assignment="isAssignment"
|
||||
:droppable="droppable"
|
||||
:active-drop="activeDrop"
|
||||
:force-show-expression="forceShowExpression"
|
||||
@@ -15,10 +16,10 @@
|
||||
:error-highlight="errorHighlight"
|
||||
:is-for-credential="isForCredential"
|
||||
:event-source="eventSource"
|
||||
:expression-evaluated="expressionValueComputed"
|
||||
:expression-evaluated="evaluatedExpressionValue"
|
||||
:additional-expression-data="resolvedAdditionalExpressionData"
|
||||
:label="label"
|
||||
:is-single-line="isSingleLine"
|
||||
:rows="rows"
|
||||
:data-test-id="`parameter-input-${parsedParameterName}`"
|
||||
:event-bus="eventBus"
|
||||
@focus="onFocus"
|
||||
@@ -45,28 +46,29 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import type { PropType } from 'vue';
|
||||
import { mapStores } from 'pinia';
|
||||
import type { PropType } from 'vue';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
import type { INodeUi, IUpdateInformation, TargetItem } from '@/Interface';
|
||||
import ParameterInput from '@/components/ParameterInput.vue';
|
||||
import InputHint from '@/components/ParameterInputHint.vue';
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
import { useEnvironmentsStore } from '@/stores/environments.ee.store';
|
||||
import { useExternalSecretsStore } from '@/stores/externalSecrets.ee.store';
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { isValueExpression, parseResourceMapperFieldName } from '@/utils/nodeTypesUtils';
|
||||
import type {
|
||||
IDataObject,
|
||||
INodeProperties,
|
||||
INodePropertyMode,
|
||||
IParameterLabel,
|
||||
NodeParameterValue,
|
||||
NodeParameterValueType,
|
||||
Result,
|
||||
} from 'n8n-workflow';
|
||||
import { isResourceLocatorValue } from 'n8n-workflow';
|
||||
import type { INodeUi, IUpdateInformation, TargetItem } from '@/Interface';
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
import { isValueExpression, parseResourceMapperFieldName } from '@/utils/nodeTypesUtils';
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { useEnvironmentsStore } from '@/stores/environments.ee.store';
|
||||
import { useExternalSecretsStore } from '@/stores/externalSecrets.ee.store';
|
||||
|
||||
import { get } from 'lodash-es';
|
||||
import type { EventBus } from 'n8n-design-system/utils';
|
||||
import { createEventBus } from 'n8n-design-system/utils';
|
||||
|
||||
@@ -85,7 +87,11 @@ export default defineComponent({
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
},
|
||||
isSingleLine: {
|
||||
rows: {
|
||||
type: Number,
|
||||
default: 5,
|
||||
},
|
||||
isAssignment: {
|
||||
type: Boolean,
|
||||
},
|
||||
parameter: {
|
||||
@@ -183,15 +189,14 @@ export default defineComponent({
|
||||
isInputParentOfActiveNode(): boolean {
|
||||
return this.ndvStore.isInputParentOfActiveNode;
|
||||
},
|
||||
expressionValueComputed(): string | null {
|
||||
evaluatedExpression(): Result<unknown, unknown> {
|
||||
const value = isResourceLocatorValue(this.modelValue)
|
||||
? this.modelValue.value
|
||||
: this.modelValue;
|
||||
if (!this.activeNode || !this.isValueExpression || typeof value !== 'string') {
|
||||
return null;
|
||||
return { ok: false, error: '' };
|
||||
}
|
||||
|
||||
let computedValue: NodeParameterValue;
|
||||
try {
|
||||
let opts;
|
||||
if (this.ndvStore.isInputParentOfActiveNode) {
|
||||
@@ -204,24 +209,39 @@ export default defineComponent({
|
||||
};
|
||||
}
|
||||
|
||||
computedValue = this.resolveExpression(value, undefined, opts);
|
||||
|
||||
if (computedValue === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof computedValue === 'string' && computedValue.length === 0) {
|
||||
return this.$locale.baseText('parameterInput.emptyString');
|
||||
}
|
||||
return { ok: true, result: this.resolveExpression(value, undefined, opts) };
|
||||
} catch (error) {
|
||||
computedValue = `[${this.$locale.baseText('parameterInput.error')}: ${error.message}]`;
|
||||
return { ok: false, error };
|
||||
}
|
||||
},
|
||||
evaluatedExpressionValue(): unknown {
|
||||
const evaluated = this.evaluatedExpression;
|
||||
return evaluated.ok ? evaluated.result : null;
|
||||
},
|
||||
evaluatedExpressionString(): string | null {
|
||||
const evaluated = this.evaluatedExpression;
|
||||
|
||||
if (!evaluated.ok) {
|
||||
return `[${this.$locale.baseText('parameterInput.error')}: ${get(
|
||||
evaluated.error,
|
||||
'message',
|
||||
)}]`;
|
||||
}
|
||||
|
||||
return typeof computedValue === 'string' ? computedValue : JSON.stringify(computedValue);
|
||||
if (evaluated.result === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof evaluated.result === 'string' && evaluated.result.length === 0) {
|
||||
return this.$locale.baseText('parameterInput.emptyString');
|
||||
}
|
||||
return typeof evaluated.result === 'string'
|
||||
? evaluated.result
|
||||
: JSON.stringify(evaluated.result);
|
||||
},
|
||||
expressionOutput(): string | null {
|
||||
if (this.isValueExpression && this.expressionValueComputed) {
|
||||
return this.expressionValueComputed;
|
||||
if (this.isValueExpression && this.evaluatedExpressionString) {
|
||||
return this.evaluatedExpressionString;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user