mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
chore: Refactor nodeValues back to NodeSettings (no-changelog) (#17300)
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
isINodePropertyOptionsList,
|
||||
displayParameter,
|
||||
isResourceLocatorValue,
|
||||
deepCopy,
|
||||
} from 'n8n-workflow';
|
||||
import type { INodeUi, IUpdateInformation } from '@/Interface';
|
||||
import { CUSTOM_API_CALL_KEY, SWITCH_NODE_TYPE } from '@/constants';
|
||||
@@ -27,6 +28,84 @@ import unset from 'lodash/unset';
|
||||
|
||||
import { captureException } from '@sentry/vue';
|
||||
import { isPresent } from './typesUtils';
|
||||
import type { Ref } from 'vue';
|
||||
import { omitKey } from './objectUtils';
|
||||
|
||||
export function setValue(
|
||||
nodeValues: Ref<INodeParameters>,
|
||||
name: string,
|
||||
value: NodeParameterValue,
|
||||
) {
|
||||
const nameParts = name.split('.');
|
||||
let lastNamePart: string | undefined = nameParts.pop();
|
||||
|
||||
let isArray = false;
|
||||
if (lastNamePart?.includes('[')) {
|
||||
// It includes an index so we have to extract it
|
||||
const lastNameParts = lastNamePart.match(/(.*)\[(\d+)\]$/);
|
||||
if (lastNameParts) {
|
||||
nameParts.push(lastNameParts[1]);
|
||||
lastNamePart = lastNameParts[2];
|
||||
isArray = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the value so that everything updates correctly in the UI
|
||||
if (nameParts.length === 0) {
|
||||
// Data is on top level
|
||||
if (value === null) {
|
||||
// Property should be deleted
|
||||
if (lastNamePart) {
|
||||
nodeValues.value = omitKey(nodeValues.value, lastNamePart);
|
||||
}
|
||||
} else {
|
||||
// Value should be set
|
||||
nodeValues.value = {
|
||||
...nodeValues.value,
|
||||
[lastNamePart as string]: value,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// Data is on lower level
|
||||
if (value === null) {
|
||||
// Property should be deleted
|
||||
let tempValue = get(nodeValues.value, nameParts.join('.')) as
|
||||
| INodeParameters
|
||||
| INodeParameters[];
|
||||
|
||||
if (lastNamePart && !Array.isArray(tempValue)) {
|
||||
tempValue = omitKey(tempValue, lastNamePart);
|
||||
}
|
||||
|
||||
if (isArray && Array.isArray(tempValue) && tempValue.length === 0) {
|
||||
// If a value from an array got delete and no values are left
|
||||
// delete also the parent
|
||||
lastNamePart = nameParts.pop();
|
||||
tempValue = get(nodeValues.value, nameParts.join('.')) as INodeParameters;
|
||||
if (lastNamePart) {
|
||||
tempValue = omitKey(tempValue, lastNamePart);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Value should be set
|
||||
if (typeof value === 'object') {
|
||||
set(
|
||||
get(nodeValues.value, nameParts.join('.')) as Record<string, unknown>,
|
||||
lastNamePart as string,
|
||||
deepCopy(value),
|
||||
);
|
||||
} else {
|
||||
set(
|
||||
get(nodeValues.value, nameParts.join('.')) as Record<string, unknown>,
|
||||
lastNamePart as string,
|
||||
value,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nodeValues.value = { ...nodeValues.value };
|
||||
}
|
||||
|
||||
export function updateDynamicConnections(
|
||||
node: INodeUi,
|
||||
|
||||
Reference in New Issue
Block a user