The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Support optional labels on logic-function input schema fields (#20471)
Abdul Rahman1adb59f7f8e2
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsxindex deb44af1785..ed90400e8c8 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsx@@ -10,7 +10,7 @@ import { getWorkflowCodeFieldsEnumSelectOptions } from '@/workflow/workflow-stepimport { getWorkflowCodeFieldsLeafKind } from '@/workflow/workflow-steps/workflow-actions/code-action/utils/getWorkflowCodeFieldsLeafKind';import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';-import { isNonEmptyArray, isObject } from '@sniptt/guards';+import { isNonEmptyArray, isNonEmptyString, isObject } from '@sniptt/guards';import { isDefined } from 'twenty-shared/utils';import { type FunctionInput, type InputSchema } from 'twenty-shared/workflow';import { themeCssVariables } from 'twenty-ui/theme-constants';@@ -51,10 +51,18 @@ export const WorkflowEditActionCodeFields = ({const currentPath = [...path, inputKey];const pathKey = currentPath.join('.');+ const schemaProperty = getInputSchemaPropertyAtPath(+ inputSchema,+ currentPath,+ );+ const displayLabel = isNonEmptyString(schemaProperty?.label)+ ? schemaProperty.label+ : inputKey;+if (inputValue !== null && isObject(inputValue)) {return (<div key={pathKey}>- <InputLabel>{inputKey}</InputLabel>+ <InputLabel>{displayLabel}</InputLabel><FormNestedFieldInputContainer><WorkflowEditActionCodeFieldsfunctionInput={inputValue}@@ -70,17 +78,13 @@ export const WorkflowEditActionCodeFields = ({);}- const schemaProperty = getInputSchemaPropertyAtPath(- inputSchema,- currentPath,- );const leafKind = getWorkflowCodeFieldsLeafKind(schemaProperty);if (leafKind === 'boolean') {return (<FormBooleanFieldInputkey={pathKey}- label={inputKey}+ label={displayLabel}defaultValue={!isDefined(inputValue)? undefined@@ -100,7 +104,7 @@ export const WorkflowEditActionCodeFields = ({return (<FormNumberFieldInputkey={pathKey}- label={inputKey}+ label={displayLabel}defaultValue={!isDefined(inputValue)? undefined@@ -124,7 +128,7 @@ export const WorkflowEditActionCodeFields = ({return (<FormSelectFieldInputkey={pathKey}- label={inputKey}+ label={displayLabel}defaultValue={!isDefined(inputValue)? undefined@@ -144,7 +148,7 @@ export const WorkflowEditActionCodeFields = ({return (<FormTextFieldInputkey={pathKey}- label={inputKey}+ label={displayLabel}placeholder={t`Enter value`}defaultValue={inputValue ? `${inputValue}` : ''}readonly={readonly}diff --git a/packages/twenty-shared/src/logic-function/__tests__/json-schema-to-input-schema.test.ts b/packages/twenty-shared/src/logic-function/__tests__/json-schema-to-input-schema.test.tsindex 5225ae41be1..5ab321f62c8 100644--- a/packages/twenty-shared/src/logic-function/__tests__/json-schema-to-input-schema.test.ts+++ b/packages/twenty-shared/src/logic-function/__tests__/json-schema-to-input-schema.test.ts@@ -108,4 +108,48 @@ describe('jsonSchemaToInputSchema', () => {expect(result[0].properties?.title).toEqual({ type: 'string' });expect(result[0].properties?.other).toEqual({ type: 'string' });});++ it('preserves label on top-level and nested properties', () => {+ const result = jsonSchemaToInputSchema({+ type: 'object',+ label: 'Slack Message',+ properties: {+ slackChannelId: { type: 'string', label: 'Channel' },+ messageText: { type: 'string', label: 'Message text' },+ meta: {+ type: 'object',+ properties: {+ count: { type: 'integer', label: 'Count' },+ },+ },+ },+ });++ expect(result[0].label).toBe('Slack Message');+ expect(result[0].properties?.slackChannelId).toEqual({+ type: 'string',+ label: 'Channel',+ });+ expect(result[0].properties?.messageText).toEqual({+ type: 'string',+ label: 'Message text',+ });+ expect(result[0].properties?.meta?.properties?.count).toEqual({+ type: 'number',+ label: 'Count',+ });+ });++ it('does not set label when empty or omitted', () => {+ const result = jsonSchemaToInputSchema({+ type: 'object',+ properties: {+ empty: { type: 'string', label: '' },+ missing: { type: 'string' },+ },+ });++ expect(result[0].properties?.empty).toEqual({ type: 'string' });+ expect(result[0].properties?.missing).toEqual({ type: 'string' });+ });});diff --git a/packages/twenty-shared/src/logic-function/input-json-schema.type.ts b/packages/twenty-shared/src/logic-function/input-json-schema.type.tsindex ec0f8179862..782764eeded 100644--- a/packages/twenty-shared/src/logic-function/input-json-schema.type.ts+++ b/packages/twenty-shared/src/logic-function/input-json-schema.type.ts@@ -16,4 +16,5 @@ export type InputJsonSchema = {minimum?: number;maximum?: number;multiline?: boolean;+ label?: string;};diff --git a/packages/twenty-shared/src/logic-function/json-schema-to-input-schema.ts b/packages/twenty-shared/src/logic-function/json-schema-to-input-schema.tsindex dd2bb5cda18..2c0a17633a0 100644--- a/packages/twenty-shared/src/logic-function/json-schema-to-input-schema.ts+++ b/packages/twenty-shared/src/logic-function/json-schema-to-input-schema.ts@@ -3,6 +3,7 @@ import {type InputSchema,type InputSchemaProperty,} from '@/workflow/types/InputSchema';+import { isNonEmptyString } from '@sniptt/guards';const convertProperty = (jsonSchema: InputJsonSchema): InputSchemaProperty => {const property: InputSchemaProperty = { type: 'unknown' };@@ -50,6 +51,10 @@ const convertProperty = (jsonSchema: InputJsonSchema): InputSchemaProperty => {property.multiline = true;}+ if (isNonEmptyString(jsonSchema.label)) {+ property.label = jsonSchema.label;+ }+return property;};diff --git a/packages/twenty-shared/src/workflow/types/InputSchema.ts b/packages/twenty-shared/src/workflow/types/InputSchema.tsindex 83cffd9a5c2..10328993236 100644--- a/packages/twenty-shared/src/workflow/types/InputSchema.ts+++ b/packages/twenty-shared/src/workflow/types/InputSchema.ts@@ -9,6 +9,7 @@ export type InputSchemaProperty = {items?: InputSchemaProperty;properties?: Properties;multiline?: boolean;+ label?: string;};type Properties = {