Manage composite fields in step filters (#13407)
- add to step output schema the information that field is a composite sub field - from output schema, when selecting the variable, copy all info required to stepFilter - from stepFilter, when selecting a value, display a special component for composites
This commit is contained in:
+2
@@ -8,6 +8,7 @@ type Leaf = {
|
||||
description?: string;
|
||||
value: any;
|
||||
fieldMetadataId?: string;
|
||||
isCompositeSubField?: boolean;
|
||||
};
|
||||
|
||||
type Node = {
|
||||
@@ -18,6 +19,7 @@ type Node = {
|
||||
value: OutputSchema;
|
||||
description?: string;
|
||||
fieldMetadataId?: string;
|
||||
isCompositeSubField?: boolean;
|
||||
};
|
||||
|
||||
type Link = {
|
||||
|
||||
+45
-30
@@ -8,6 +8,14 @@ import { isLinkOutputSchema } from '@/workflow/workflow-variables/utils/isLinkOu
|
||||
import { isRecordOutputSchema } from '@/workflow/workflow-variables/utils/isRecordOutputSchema';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
type VariableInfo = {
|
||||
variableLabel: string | undefined;
|
||||
variablePathLabel: string | undefined;
|
||||
variableType?: string | undefined;
|
||||
fieldMetadataId?: string | undefined;
|
||||
compositeFieldSubFieldName?: string | undefined;
|
||||
};
|
||||
|
||||
const getDisplayedSubStepObjectLabel = (outputSchema: OutputSchema) => {
|
||||
if (!isRecordOutputSchema(outputSchema)) {
|
||||
return;
|
||||
@@ -54,6 +62,17 @@ const getFieldMetadataId = (
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const isCompositeSubField = (
|
||||
key: string,
|
||||
outputSchema: OutputSchema,
|
||||
): boolean => {
|
||||
if (isBaseOutputSchema(outputSchema) && outputSchema[key]?.isLeaf) {
|
||||
return outputSchema[key]?.isCompositeSubField ?? false;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const searchCurrentStepOutputSchema = ({
|
||||
stepOutputSchema,
|
||||
path,
|
||||
@@ -70,6 +89,7 @@ const searchCurrentStepOutputSchema = ({
|
||||
let nextKey = path[nextKeyIndex];
|
||||
let variablePathLabel = stepOutputSchema.name;
|
||||
let isSelectedFieldInNextKey = false;
|
||||
let parentFieldMetadataId: string | undefined;
|
||||
|
||||
const handleFieldNotFound = () => {
|
||||
if (nextKeyIndex + 1 < path.length) {
|
||||
@@ -94,6 +114,7 @@ const searchCurrentStepOutputSchema = ({
|
||||
currentSubStep = currentField.value;
|
||||
nextKey = path[nextKeyIndex + 1];
|
||||
variablePathLabel = `${variablePathLabel} > ${currentField.label}`;
|
||||
parentFieldMetadataId = currentField.fieldMetadataId;
|
||||
} else {
|
||||
handleFieldNotFound();
|
||||
}
|
||||
@@ -103,6 +124,7 @@ const searchCurrentStepOutputSchema = ({
|
||||
currentSubStep = currentField.value;
|
||||
nextKey = path[nextKeyIndex + 1];
|
||||
variablePathLabel = `${variablePathLabel} > ${currentField.label}`;
|
||||
parentFieldMetadataId = currentField.fieldMetadataId;
|
||||
} else {
|
||||
handleFieldNotFound();
|
||||
}
|
||||
@@ -118,23 +140,24 @@ const searchCurrentStepOutputSchema = ({
|
||||
};
|
||||
}
|
||||
|
||||
const variableName = isSelectedFieldInNextKey ? nextKey : selectedField;
|
||||
const variableLabel =
|
||||
isFullRecord && isRecordOutputSchema(currentSubStep)
|
||||
? getDisplayedSubStepObjectLabel(currentSubStep)
|
||||
: getDisplayedSubStepFieldLabel(variableName, currentSubStep);
|
||||
|
||||
return {
|
||||
variableLabel:
|
||||
isFullRecord && isRecordOutputSchema(currentSubStep)
|
||||
? getDisplayedSubStepObjectLabel(currentSubStep)
|
||||
: getDisplayedSubStepFieldLabel(
|
||||
isSelectedFieldInNextKey ? nextKey : selectedField,
|
||||
currentSubStep,
|
||||
),
|
||||
variablePathLabel,
|
||||
variableType: getVariableType(
|
||||
isSelectedFieldInNextKey ? nextKey : selectedField,
|
||||
variableLabel,
|
||||
variablePathLabel: `${variablePathLabel} > ${variableLabel}`,
|
||||
variableType: getVariableType(variableName, currentSubStep),
|
||||
fieldMetadataId:
|
||||
getFieldMetadataId(variableName, currentSubStep) ?? parentFieldMetadataId,
|
||||
compositeFieldSubFieldName: isCompositeSubField(
|
||||
variableName,
|
||||
currentSubStep,
|
||||
),
|
||||
fieldMetadataId: getFieldMetadataId(
|
||||
isSelectedFieldInNextKey ? nextKey : selectedField,
|
||||
currentSubStep,
|
||||
),
|
||||
)
|
||||
? variableName
|
||||
: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -146,7 +169,7 @@ export const searchVariableThroughOutputSchema = ({
|
||||
stepOutputSchema: StepOutputSchema;
|
||||
rawVariableName: string;
|
||||
isFullRecord?: boolean;
|
||||
}) => {
|
||||
}): VariableInfo => {
|
||||
if (!isDefined(stepOutputSchema)) {
|
||||
return {
|
||||
variableLabel: undefined,
|
||||
@@ -175,18 +198,10 @@ export const searchVariableThroughOutputSchema = ({
|
||||
};
|
||||
}
|
||||
|
||||
const { variableLabel, variablePathLabel, variableType, fieldMetadataId } =
|
||||
searchCurrentStepOutputSchema({
|
||||
stepOutputSchema,
|
||||
path,
|
||||
isFullRecord,
|
||||
selectedField,
|
||||
});
|
||||
|
||||
return {
|
||||
variableLabel,
|
||||
variablePathLabel: `${variablePathLabel} > ${variableLabel}`,
|
||||
variableType,
|
||||
fieldMetadataId,
|
||||
};
|
||||
return searchCurrentStepOutputSchema({
|
||||
stepOutputSchema,
|
||||
path,
|
||||
isFullRecord,
|
||||
selectedField,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user