feat(Evaluation Metrics Node): Add Evaluation Metrics node (no-changelog) (#14050)

This commit is contained in:
oleg
2025-03-25 14:45:20 +01:00
committed by GitHub
parent 8aad7dbaf6
commit 22e6569f7e
10 changed files with 319 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ interface Props {
modelValue: AssignmentValue;
issues: string[];
hideType?: boolean;
disableType?: boolean;
isReadOnly?: boolean;
index?: number;
}
@@ -163,7 +164,7 @@ const onBlur = (): void => {
<TypeSelect
:class="$style.select"
:model-value="assignment.type ?? 'string'"
:is-read-only="isReadOnly"
:is-read-only="disableType || isReadOnly"
@update:model-value="onAssignmentTypeChange"
>
</TypeSelect>

View File

@@ -151,4 +151,69 @@ describe('AssignmentCollection.vue', () => {
expect(getAssignmentType(assignments[3])).toEqual('Object');
expect(getAssignmentType(assignments[4])).toEqual('Array');
});
describe('defaultType prop', () => {
it('should use string as default type when no defaultType is specified', async () => {
const { getByTestId, findAllByTestId } = renderComponent();
await userEvent.click(getByTestId('assignment-collection-drop-area'));
const assignments = await findAllByTestId('assignment');
expect(assignments.length).toBe(1);
expect(getAssignmentType(assignments[0])).toEqual('String');
});
it('should use specified defaultType when adding a new assignment manually', async () => {
const { getByTestId, findAllByTestId } = renderComponent({
props: {
defaultType: 'number',
},
});
await userEvent.click(getByTestId('assignment-collection-drop-area'));
const assignments = await findAllByTestId('assignment');
expect(assignments.length).toBe(1);
expect(getAssignmentType(assignments[0])).toEqual('Number');
});
it('should use defaultType for drag and drop when disableType is true', async () => {
const { getByTestId, findAllByTestId } = renderComponent({
props: {
defaultType: 'number',
disableType: true,
},
});
const dropArea = getByTestId('drop-area');
// Even though we're dropping a string value, it should use number type because of defaultType
await dropAssignment({ key: 'stringKey', value: 'stringValue', dropArea });
const assignments = await findAllByTestId('assignment');
expect(assignments.length).toBe(1);
expect(getAssignmentType(assignments[0])).toEqual('Number');
});
it('should respect defaultType for all assignments when provided', async () => {
const { getByTestId, findAllByTestId } = renderComponent({
props: {
defaultType: 'boolean',
},
});
const dropArea = getByTestId('drop-area');
await userEvent.click(getByTestId('assignment-collection-drop-area'));
await dropAssignment({ key: 'stringKey', value: 'stringValue', dropArea });
await dropAssignment({ key: 'numberKey', value: 25, dropArea });
const assignments = await findAllByTestId('assignment');
expect(assignments.length).toBe(3);
expect(getAssignmentType(assignments[0])).toEqual('Boolean');
expect(getAssignmentType(assignments[1])).toEqual('Boolean');
expect(getAssignmentType(assignments[2])).toEqual('Boolean');
});
});
});

View File

@@ -5,6 +5,7 @@ import { useNDVStore } from '@/stores/ndv.store';
import type {
AssignmentCollectionValue,
AssignmentValue,
FieldTypeMap,
INode,
INodeProperties,
} from 'n8n-workflow';
@@ -20,11 +21,17 @@ interface Props {
parameter: INodeProperties;
value: AssignmentCollectionValue;
path: string;
defaultType?: keyof FieldTypeMap;
disableType?: boolean;
node: INode | null;
isReadOnly?: boolean;
}
const props = withDefaults(defineProps<Props>(), { isReadOnly: false });
const props = withDefaults(defineProps<Props>(), {
isReadOnly: false,
defaultType: undefined,
disableType: false,
});
const emit = defineEmits<{
valueChanged: [value: { name: string; node: string; value: AssignmentCollectionValue }];
@@ -82,7 +89,7 @@ function addAssignment(): void {
id: crypto.randomUUID(),
name: '',
value: '',
type: 'string',
type: props.defaultType ?? 'string',
});
}
@@ -91,7 +98,7 @@ function dropAssignment(expression: string): void {
id: crypto.randomUUID(),
name: propertyNameFromExpression(expression),
value: `=${expression}`,
type: typeFromExpression(expression),
type: props.defaultType ?? typeFromExpression(expression),
});
}
@@ -157,6 +164,7 @@ function optionSelected(action: string) {
:issues="getIssues(index)"
:class="$style.assignment"
:is-read-only="isReadOnly"
:disable-type="disableType"
@update:model-value="(value) => onAssignmentUpdate(index, value)"
@remove="() => onAssignmentRemove(index)"
>

View File

@@ -665,6 +665,8 @@ function getParameterValue<T extends NodeParameterValueType = NodeParameterValue
:path="getPath(parameter.name)"
:node="node"
:is-read-only="isReadOnly"
:default-type="parameter.typeOptions?.assignment?.defaultType"
:disable-type="parameter.typeOptions?.assignment?.disableType"
@value-changed="valueChanged"
/>
<div v-else-if="credentialsParameterIndex !== index" class="parameter-item">

View File

@@ -29,6 +29,7 @@ import {
faChartBar,
faCheck,
faCheckCircle,
faCheckDouble,
faCheckSquare,
faChevronDown,
faChevronUp,
@@ -225,6 +226,7 @@ export const FontAwesomePlugin: Plugin = {
addIcon(faChartBar);
addIcon(faCheck);
addIcon(faCheckCircle);
addIcon(faCheckDouble);
addIcon(faCheckSquare);
addIcon(faChevronLeft);
addIcon(faChevronRight);