Skip to content

The open alternative to Salesforce, designed for AI.

fix(workflow): flag a trigger filter whose field reference is broken (#24377)

Thomas Trompetteb109ddbe7e07
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/WorkflowStepFilterFieldSelect.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/WorkflowStepFilterFieldSelect.tsx
index 9baac32abda..b22bc4f8238 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/WorkflowStepFilterFieldSelect.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/WorkflowStepFilterFieldSelect.tsx
@@ -11,14 +11,17 @@ import { useSearchVariable } from '@/workflow/workflow-variables/hooks/useSearch
import { type StepOutputSchemaV2 } from '@/workflow/workflow-variables/types/StepOutputSchemaV2';
import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
import { useContext, useState } from 'react';
import { type StepFilter } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import {
extractRawVariableNamePart,
+ isStandaloneVariableString,
TRIGGER_STEP_ID,
} from 'twenty-shared/workflow';
import { useIcons } from 'twenty-ui/icon';
+import { InputHint } from 'twenty-ui/input';
import { FieldMetadataType } from '~/generated-metadata/graphql';
type WorkflowStepFilterFieldSelectProps = {
@@ -92,12 +95,23 @@ export const WorkflowStepFilterFieldSelect = ({
};
const isSelectedFieldNotFound = !isDefined(variableLabel);
+
+ const isStepOutputKeyBroken =
+ isNonEmptyString(stepFilter.stepOutputKey) &&
+ !isStandaloneVariableString(stepFilter.stepOutputKey);
+
const label = isSelectedFieldNotFound
? currentStepId === TRIGGER_STEP_ID
? t`Select a field`
: t`Select a field from a previous step`
: variableLabel;
+ const brokenFieldReferenceHint = isStepOutputKeyBroken ? (
+ <InputHint danger>
+ {t`Broken field reference. Select the field again to fix this condition.`}
+ </InputHint>
+ ) : null;
+
const fullRecordIconProps = stepFilter.isFullRecord
? isDefined(filterObjectMetadataItem)
? getSelectIconPropsFromObjectMetadataItem(filterObjectMetadataItem)
@@ -118,62 +132,68 @@ export const WorkflowStepFilterFieldSelect = ({
: label;
return (
+ <>
+ <Dropdown
+ dropdownId={dropdownId}
+ clickableComponent={
+ <SelectControl
+ selectedOption={{
+ value: stepFilter.stepOutputKey,
+ label: disabledLabel,
+ fullLabel: variablePathLabel,
+ Icon: icon,
+ iconThemeColor,
+ }}
+ isDisabled={true}
+ />
+ }
+ dropdownComponents={[]}
+ />
+ {brokenFieldReferenceHint}
+ </>
+ );
+ }
+
+ return (
+ <>
<Dropdown
dropdownId={dropdownId}
clickableComponent={
<SelectControl
selectedOption={{
- value: stepFilter.stepOutputKey,
- label: disabledLabel,
+ label,
fullLabel: variablePathLabel,
+ value: stepFilter.stepOutputKey,
Icon: icon,
iconThemeColor,
}}
- isDisabled={true}
+ textAccent={isSelectedFieldNotFound ? 'placeholder' : 'default'}
+ isDisabled={readonly}
/>
}
- dropdownComponents={[]}
+ dropdownComponents={
+ !isDefined(selectedStep) ? (
+ <WorkflowVariablesDropdownSteps
+ dropdownId={dropdownId}
+ steps={availableVariablesInWorkflowStep}
+ onSelect={handleStepSelect}
+ />
+ ) : (
+ <WorkflowDropdownStepOutputItems
+ stepFilter={stepFilter}
+ step={selectedStep}
+ onSelect={handleSubItemSelect}
+ onBack={handleBack}
+ />
+ )
+ }
+ dropdownPlacement="bottom-end"
+ dropdownOffset={{
+ x: 2,
+ y: 4,
+ }}
/>
- );
- }
-
- return (
- <Dropdown
- dropdownId={dropdownId}
- clickableComponent={
- <SelectControl
- selectedOption={{
- label,
- fullLabel: variablePathLabel,
- value: stepFilter.stepOutputKey,
- Icon: icon,
- iconThemeColor,
- }}
- textAccent={isSelectedFieldNotFound ? 'placeholder' : 'default'}
- isDisabled={readonly}
- />
- }
- dropdownComponents={
- !isDefined(selectedStep) ? (
- <WorkflowVariablesDropdownSteps
- dropdownId={dropdownId}
- steps={availableVariablesInWorkflowStep}
- onSelect={handleStepSelect}
- />
- ) : (
- <WorkflowDropdownStepOutputItems
- stepFilter={stepFilter}
- step={selectedStep}
- onSelect={handleSubItemSelect}
- onBack={handleBack}
- />
- )
- }
- dropdownPlacement="bottom-end"
- dropdownOffset={{
- x: 2,
- y: 4,
- }}
- />
+ {brokenFieldReferenceHint}
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterColumn.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterColumn.stories.tsx
index 0440629f772..6dd7cfc5f85 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterColumn.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterColumn.stories.tsx
@@ -1,6 +1,7 @@
import { WorkflowStepFilterColumn } from '@/workflow/workflow-steps/filters/components/WorkflowStepFilterColumn';
import { WorkflowStepFilterDecorator } from '@/workflow/workflow-steps/workflow-actions/filter-action/components/decorators/WorkflowStepFilterDecorator';
import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, within } from 'storybook/test';
import {
type StepFilter,
type StepFilterGroup,
@@ -23,12 +24,17 @@ const STEP_FILTER_GROUP: StepFilterGroup = {
const TEXT_STEP_FILTER: StepFilter = {
id: 'filter-1',
stepFilterGroupId: 'filter-group-1',
- stepOutputKey: 'company.name',
+ stepOutputKey: '{{company.name}}',
type: 'text',
value: 'Acme',
operand: ViewFilterOperand.CONTAINS,
};
+const BROKEN_FIELD_REFERENCE_STEP_FILTER: StepFilter = {
+ ...TEXT_STEP_FILTER,
+ stepOutputKey: 'company.name',
+};
+
const meta: Meta<typeof WorkflowStepFilterColumn> = {
title: 'Modules/Workflow/Actions/Filter/WorkflowStepFilterColumn',
component: WorkflowStepFilterColumn,
@@ -53,4 +59,29 @@ const meta: Meta<typeof WorkflowStepFilterColumn> = {
export default meta;
type Story = StoryObj<typeof WorkflowStepFilterColumn>;
-export const Default: Story = {};
+export const Default: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await expect(
+ canvas.queryByText(
+ 'Broken field reference. Select the field again to fix this condition.',
+ ),
+ ).toBeNull();
+ },
+};
+
+export const WithBrokenFieldReference: Story = {
+ args: {
+ stepFilter: BROKEN_FIELD_REFERENCE_STEP_FILTER,
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await expect(
+ await canvas.findByText(
+ 'Broken field reference. Select the field again to fix this condition.',
+ ),
+ ).toBeVisible();
+ },
+};
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterOperandSelect.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterOperandSelect.stories.tsx
index b952c8440e2..e8e937b530f 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterOperandSelect.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterOperandSelect.stories.tsx
@@ -12,7 +12,7 @@ import { graphqlMocks } from '~/testing/graphqlMocks';
const DEFAULT_STEP_FILTER: StepFilter = {
id: 'filter-1',
stepFilterGroupId: 'filter-group-1',
- stepOutputKey: 'company.name',
+ stepOutputKey: '{{company.name}}',
type: 'text',
operand: ViewFilterOperand.CONTAINS,
value: '',
@@ -22,7 +22,7 @@ const DEFAULT_STEP_FILTER: StepFilter = {
const GREATER_THAN_FILTER: StepFilter = {
id: 'filter-1',
stepFilterGroupId: 'filter-group-1',
- stepOutputKey: 'company.employees',
+ stepOutputKey: '{{company.employees}}',
type: 'number',
operand: ViewFilterOperand.GREATER_THAN_OR_EQUAL,
value: '100',
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterValueInput.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterValueInput.stories.tsx
index c1772947d9f..562b262cd64 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterValueInput.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/filters/components/__stories__/WorkflowStepFilterValueInput.stories.tsx
@@ -13,7 +13,7 @@ import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorato
const TEXT_FILTER: StepFilter = {
id: 'filter-1',
stepFilterGroupId: 'filter-group-1',
- stepOutputKey: 'company.name',
+ stepOutputKey: '{{company.name}}',
type: 'text',
operand: ViewFilterOperand.CONTAINS,
value: 'Acme',
@@ -23,7 +23,7 @@ const TEXT_FILTER: StepFilter = {
const NUMBER_FILTER: StepFilter = {
id: 'filter-2',
stepFilterGroupId: 'filter-group-1',
- stepOutputKey: 'company.employees',
+ stepOutputKey: '{{company.employees}}',
type: 'number',
operand: ViewFilterOperand.GREATER_THAN_OR_EQUAL,
value: '100',
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/filter-action/components/__stories__/WorkflowEditActionFilter.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/filter-action/components/__stories__/WorkflowEditActionFilter.stories.tsx
index 7b650ed9210..f677828b36a 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/filter-action/components/__stories__/WorkflowEditActionFilter.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/filter-action/components/__stories__/WorkflowEditActionFilter.stories.tsx
@@ -50,7 +50,7 @@ const CONFIGURED_ACTION: WorkflowFilterAction = {
{
id: 'filter-1',
stepFilterGroupId: 'filter-group-1',
- stepOutputKey: 'company.name',
+ stepOutputKey: '{{company.name}}',
operand: ViewFilterOperand.CONTAINS,
value: 'Acme',
type: 'string',