chore: Refactor nodeValues back to NodeSettings (no-changelog) (#17300)

This commit is contained in:
Charlie Kolb
2025-07-15 11:14:07 +02:00
committed by GitHub
parent fc3129e378
commit ec69bcc3fd
6 changed files with 157 additions and 130 deletions

View File

@@ -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,