Variables not coming from a Record step should be available in Record Picker (#12708)

We want code and webhook variables available in Record Picker since
those can contains uuid.

This PR:
- update `WorkflowVariablesDropdownObjectItems.tsx` so it manages fields
properly
- factorise both dropdown into a commun hook
- update filterOutputSchema.ts so it does not filter fields that are not
FieldMetadata types
- set relation fields as record object in variable schema so those can
be selected as full record

Before


https://github.com/user-attachments/assets/f4f85402-c056-4fd8-8474-d86bef9d4bc3

After


https://github.com/user-attachments/assets/c6589e18-7dfa-4fc8-a525-3a580e265896
This commit is contained in:
Thomas Trompette
2025-06-19 11:33:21 +02:00
committed by GitHub
parent c16b625752
commit 07cf1ed71d
16 changed files with 229 additions and 159 deletions
@@ -1,4 +1,5 @@
import { OutputSchema } from '@/workflow/workflow-variables/types/StepOutputSchema';
import { FieldMetadataType } from 'twenty-shared/types';
import { filterOutputSchema } from '../filterOutputSchema';
describe('filterOutputSchema', () => {
@@ -85,9 +86,10 @@ describe('filterOutputSchema', () => {
expect(filterOutputSchema(inputSchema, 'person')).toEqual(expectedSchema);
});
it('should ignore leaf fields', () => {
it('should ignore leaf fields that are field metadata types', () => {
const inputSchema = createRecordSchema('company', {
name: { isLeaf: true, value: 'string' },
id: { isLeaf: true, type: FieldMetadataType.UUID },
employee: {
isLeaf: false,
value: createRecordSchema('person'),
@@ -97,6 +99,7 @@ describe('filterOutputSchema', () => {
const expectedSchema = {
_outputSchemaType: 'RECORD',
fields: {
name: { isLeaf: true, value: 'string' },
employee: {
isLeaf: false,
value: createRecordSchema('person'),
@@ -117,6 +120,7 @@ describe('filterOutputSchema', () => {
const inputSchema = createBaseSchema({
field1: {
isLeaf: true,
type: FieldMetadataType.TEXT,
value: 'string',
},
});
@@ -4,6 +4,7 @@ import {
RecordOutputSchema,
} from '@/workflow/workflow-variables/types/StepOutputSchema';
import { isBaseOutputSchema } from '@/workflow/workflow-variables/utils/isBaseOutputSchema';
import { isFieldTypeCompatibleWithRecordId } from '@/workflow/workflow-variables/utils/isFieldTypeCompatibleWithRecordId';
import { isLinkOutputSchema } from '@/workflow/workflow-variables/utils/isLinkOutputSchema';
import { isRecordOutputSchema } from '@/workflow/workflow-variables/utils/isRecordOutputSchema';
import { isDefined } from 'twenty-shared/utils';
@@ -33,6 +34,10 @@ const filterRecordOutputSchema = (
const field = outputSchema.fields[key];
if (field.isLeaf) {
if (isFieldTypeCompatibleWithRecordId(field.type)) {
filteredFields[key] = field;
hasValidFields = true;
}
continue;
}
@@ -75,6 +80,10 @@ const filterBaseOutputSchema = (
const field = outputSchema[key];
if (field.isLeaf) {
if (isFieldTypeCompatibleWithRecordId(field.type)) {
filteredSchema[key] = field;
hasValidFields = true;
}
continue;
}
@@ -0,0 +1,7 @@
import { InputSchemaPropertyType } from '@/workflow/types/InputSchema';
export const isFieldTypeCompatibleWithRecordId = (
type?: InputSchemaPropertyType,
): boolean => {
return !type || type === 'string' || type === 'unknown';
};
@@ -94,12 +94,13 @@ const searchCurrentStepOutputSchema = ({
}
return {
variableLabel: isFullRecord
? getDisplayedSubStepObjectLabel(currentSubStep)
: getDisplayedSubStepFieldLabel(
isSelectedFieldInNextKey ? nextKey : selectedField,
currentSubStep,
),
variableLabel:
isFullRecord && isRecordOutputSchema(currentSubStep)
? getDisplayedSubStepObjectLabel(currentSubStep)
: getDisplayedSubStepFieldLabel(
isSelectedFieldInNextKey ? nextKey : selectedField,
currentSubStep,
),
variablePathLabel,
};
};