AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(builder): a step shows its saved dropdown value when that value is no longer offered (#16018)
Hazem Adelbcbfac14e846
diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.jsonindex 61018db1bec..6f799548b61 100644--- a/packages/web/public/locales/en/translation.json+++ b/packages/web/public/locales/en/translation.json@@ -3157,5 +3157,6 @@"Pick the default model for each AI capability": "Pick the default model for each AI capability","Pay your provider directly, with no model markup": "Pay your provider directly, with no model markup","Add an AI provider before uploading. Files are indexed when uploaded so agents can search them.": "Add an AI provider before uploading. Files are indexed when uploaded so agents can search them.",- "This file has no text that can be searched.": "This file has no text that can be searched."+ "This file has no text that can be searched.": "This file has no text that can be searched.",+ "{value} (not in the list)": "{value} (not in the list)"}diff --git a/packages/web/src/app/builder/piece-properties/dynamic-dropdown-piece-property.tsx b/packages/web/src/app/builder/piece-properties/dynamic-dropdown-piece-property.tsxindex 5705161704b..f42d9fc02b4 100644--- a/packages/web/src/app/builder/piece-properties/dynamic-dropdown-piece-property.tsx+++ b/packages/web/src/app/builder/piece-properties/dynamic-dropdown-piece-property.tsx@@ -171,6 +171,11 @@ const DynamicDropdownPiecePropertyImplementation = React.memo(label: option.label,value: option.value,}));+ const singleSelectOptions = withSavedValueNotInList({+ options: selectOptions,+ value: props.value,+ loadsOptionsOnSearch: props.shouldRefreshOnSearch === true,+ });const isDisabled = dropdownState.disabled || props.disabled;return props.multiple ? (<MultiSelectPieceProperty@@ -194,7 +199,7 @@ const DynamicDropdownPiecePropertyImplementation = React.memo(/>) : (<SearchableSelect- options={selectOptions}+ options={singleSelectOptions}disabled={dropdownState.disabled || props.disabled}loading={isPending}placeholder={dropdownState.placeholder ?? t('Select an option')}@@ -225,6 +230,36 @@ DynamicDropdownPieceProperty.displayName = 'DynamicDropdownPieceProperty';DynamicDropdownPiecePropertyImplementation.displayName ='DynamicDropdownPiecePropertyImplementation';export { DynamicDropdownPieceProperty };++function withSavedValueNotInList({+ options,+ value,+ loadsOptionsOnSearch,+}: {+ options: SelectOption[];+ value: unknown;+ loadsOptionsOnSearch: boolean;+}): SelectOption[] {+ const isReadableValue =+ (typeof value === 'string' && value !== '') || typeof value === 'number';+ const isNotInList =+ isReadableValue &&+ !loadsOptionsOnSearch &&+ options.length > 0 &&+ !options.some((option) => deepEqual(option.value, value));+ return isNotInList+ ? [+ {+ label: t('{value} (not in the list)', { value: String(value) }),+ value,+ },+ ...options,+ ]+ : options;+}++type SelectOption = { label: string; value: unknown };+type DynamicDropdownProps = {refreshers: string[];propertyName: string;diff --git a/packages/web/test/app/builder/piece-properties/dynamic-dropdown-piece-property.test.tsx b/packages/web/test/app/builder/piece-properties/dynamic-dropdown-piece-property.test.tsxindex 9c49336ac34..6b44fd9a171 100644--- a/packages/web/test/app/builder/piece-properties/dynamic-dropdown-piece-property.test.tsx+++ b/packages/web/test/app/builder/piece-properties/dynamic-dropdown-piece-property.test.tsx@@ -14,7 +14,10 @@ import {} from 'react-hook-form';import { afterEach, describe, expect, it, vi } from 'vitest';-vi.mock('i18next', () => ({ t: (key: string) => key }));+vi.mock('i18next', () => ({+ t: (key: string, params?: Record<string, string>) =>+ key.replace(/\{(\w+)\}/g, (match, name) => params?.[name] ?? match),+}));vi.mock('@/lib/authentication-session', () => ({authenticationSession: { getProjectId: () => 'test-project' },@@ -39,16 +42,20 @@ vi.mock();const searchCalls: ((term: string) => void)[] = [];+const selectRenders: { label: string; value: unknown }[][] = [];vi.mock('@/components/custom/searchable-select', () => ({SearchableSelect: ({refreshOnSearch,+ options,}: {refreshOnSearch?: (term: string) => void;+ options: { label: string; value: unknown }[];}) => {if (refreshOnSearch) {searchCalls.push(refreshOnSearch);}+ selectRenders.push(options);return null;},}));@@ -216,6 +223,7 @@ describe('DynamicDropdownPieceProperty refresher change', () => {container?.remove();mutateCalls.length = 0;searchCalls.length = 0;+ selectRenders.length = 0;multiSelectRenders.length = 0;formInstance = undefined;});@@ -425,4 +433,48 @@ describe('DynamicDropdownPieceProperty refresher change', () => {expect(formInstance!.getValues(DROPDOWN_PATH)).toBeNull();});++ describe('a saved value that is not among the options', () => {+ const lastOptions = () => selectRenders[selectRenders.length - 1];++ it('is shown by name instead of leaving the field looking empty', () => {+ mount();+ resolveOptions(['fast', 'deep']);+ act(() => formInstance!.setValue(DROPDOWN_PATH, 'openai/gpt-4.1-nano'));++ expect(lastOptions()).toEqual([+ { label: 'openai/gpt-4.1-nano (not in the list)', value: 'openai/gpt-4.1-nano' },+ { label: 'fast', value: 'fast' },+ { label: 'deep', value: 'deep' },+ ]);+ expect(formInstance!.getValues(DROPDOWN_PATH)).toBe('openai/gpt-4.1-nano');+ });++ it('adds nothing when the saved value is still offered', () => {+ mount();+ resolveOptions(['fast', 'deep']);+ act(() => formInstance!.setValue(DROPDOWN_PATH, 'deep'));++ expect(lastOptions()).toEqual([+ { label: 'fast', value: 'fast' },+ { label: 'deep', value: 'deep' },+ ]);+ });++ it('adds nothing for a dropdown that loads its options as you search, where the first list may be one page', () => {+ mount({ multiple: false, refreshOnSearch: true });+ resolveOptions(['sheet-a']);+ act(() => formInstance!.setValue(DROPDOWN_PATH, 'sheet-z'));++ expect(lastOptions()).toEqual([{ label: 'sheet-a', value: 'sheet-a' }]);+ });++ it('adds nothing while there are no options to compare against', () => {+ mount();+ resolveOptions([]);+ act(() => formInstance!.setValue(DROPDOWN_PATH, 'openai/gpt-4.1-nano'));++ expect(lastOptions()).toEqual([]);+ });+ });});