Filter dropdown by types (#13703)
Allow to filter types in variable dropdown. This will avoid unsupported types for filters (RICH_TEXT, ACTOR) <img width="579" height="505" alt="Capture d’écran 2025-08-07 à 09 58 42" src="https://github.com/user-attachments/assets/c3fbeb3f-61ab-4c2c-bb2c-6f2c6292ef9e" />
This commit is contained in:
+40
@@ -225,4 +225,44 @@ describe('filterOutputSchema', () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('fieldTypesToExclude', () => {
|
||||
it('should filter out the types', () => {
|
||||
const inputSchema = createRecordSchema('person', {
|
||||
name: { isLeaf: true, type: undefined, value: 'toto' },
|
||||
age: { isLeaf: true, type: FieldMetadataType.NUMBER },
|
||||
id: { isLeaf: true, type: FieldMetadataType.UUID },
|
||||
});
|
||||
|
||||
const expectedSchema = createRecordSchema('person', {
|
||||
name: { isLeaf: true, type: undefined, value: 'toto' },
|
||||
age: { isLeaf: true, type: FieldMetadataType.NUMBER },
|
||||
});
|
||||
|
||||
expect(
|
||||
filterOutputSchema({
|
||||
shouldDisplayRecordFields: true,
|
||||
shouldDisplayRecordObjects: false,
|
||||
outputSchema: inputSchema,
|
||||
fieldTypesToExclude: [FieldMetadataType.UUID],
|
||||
}),
|
||||
).toEqual(expectedSchema);
|
||||
});
|
||||
|
||||
it('should return the same schema if no types to filter', () => {
|
||||
const inputSchema = createRecordSchema('person', {
|
||||
name: { isLeaf: true, value: 'string' },
|
||||
id: { isLeaf: true, type: FieldMetadataType.UUID },
|
||||
});
|
||||
|
||||
expect(
|
||||
filterOutputSchema({
|
||||
shouldDisplayRecordFields: true,
|
||||
shouldDisplayRecordObjects: false,
|
||||
outputSchema: inputSchema,
|
||||
fieldTypesToExclude: [],
|
||||
}),
|
||||
).toEqual(inputSchema);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+41
-5
@@ -1,3 +1,4 @@
|
||||
import { InputSchemaPropertyType } from '@/workflow/types/InputSchema';
|
||||
import {
|
||||
BaseOutputSchema,
|
||||
OutputSchema,
|
||||
@@ -128,20 +129,55 @@ const filterBaseOutputSchema = ({
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const filterRecordOutputSchemaFieldsByType = ({
|
||||
outputSchema,
|
||||
fieldTypesToExclude,
|
||||
}: {
|
||||
outputSchema: RecordOutputSchema;
|
||||
fieldTypesToExclude: InputSchemaPropertyType[];
|
||||
}) => {
|
||||
const filteredFields: BaseOutputSchema = {};
|
||||
|
||||
for (const key in outputSchema.fields) {
|
||||
const field = outputSchema.fields[key];
|
||||
|
||||
if (isDefined(field.type) && fieldTypesToExclude.includes(field.type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
filteredFields[key] = field;
|
||||
}
|
||||
|
||||
return {
|
||||
...outputSchema,
|
||||
// Relations could be filtered recursively but this util requires a global simplification first
|
||||
fields: filteredFields,
|
||||
};
|
||||
};
|
||||
|
||||
export const filterOutputSchema = ({
|
||||
shouldDisplayRecordFields,
|
||||
shouldDisplayRecordObjects,
|
||||
outputSchema,
|
||||
fieldTypesToExclude,
|
||||
}: {
|
||||
shouldDisplayRecordFields: boolean;
|
||||
shouldDisplayRecordObjects: boolean;
|
||||
outputSchema?: OutputSchema;
|
||||
fieldTypesToExclude?: InputSchemaPropertyType[];
|
||||
}): OutputSchema | undefined => {
|
||||
if (
|
||||
!shouldDisplayRecordObjects ||
|
||||
shouldDisplayRecordFields ||
|
||||
!outputSchema
|
||||
) {
|
||||
if (!isDefined(outputSchema)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!shouldDisplayRecordObjects || shouldDisplayRecordFields) {
|
||||
if (isRecordOutputSchema(outputSchema) && isDefined(fieldTypesToExclude)) {
|
||||
return filterRecordOutputSchemaFieldsByType({
|
||||
outputSchema,
|
||||
fieldTypesToExclude,
|
||||
});
|
||||
}
|
||||
|
||||
return outputSchema;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user