The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Fix test data disapear (#10846)
martmull3f7315c2dc37
diff --git a/packages/twenty-front/src/modules/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState.ts b/packages/twenty-front/src/modules/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState.tsindex dc84a7ec1d8..7ce04866551 100644--- a/packages/twenty-front/src/modules/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState.ts+++ b/packages/twenty-front/src/modules/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState.ts@@ -3,7 +3,7 @@ import { useGetOneServerlessFunctionSourceCode } from '@/settings/serverless-funimport { Dispatch, SetStateAction, useState } from 'react';import { FindOneServerlessFunctionSourceCodeQuery } from '~/generated-metadata/graphql';import { serverlessFunctionTestDataFamilyState } from '@/workflow/states/serverlessFunctionTestDataFamilyState';-import { useSetRecoilState } from 'recoil';+import { useRecoilState } from 'recoil';import { getFunctionInputFromSourceCode } from '@/serverless-functions/utils/getFunctionInputFromSourceCode';import { INDEX_FILE_PATH } from '@/serverless-functions/constants/IndexFilePath';@@ -37,9 +37,8 @@ export const useServerlessFunctionUpdateFormState = ({code: undefined,});- const setServerlessFunctionTestData = useSetRecoilState(- serverlessFunctionTestDataFamilyState(serverlessFunctionId),- );+ const [serverlessFunctionTestData, setServerlessFunctionTestData] =+ useRecoilState(serverlessFunctionTestDataFamilyState(serverlessFunctionId));const { serverlessFunction } = useGetOneServerlessFunction({id: serverlessFunctionId,@@ -54,16 +53,22 @@ export const useServerlessFunctionUpdateFormState = ({name: serverlessFunction?.name || '',description: serverlessFunction?.description || '',};+setFormValues((prevState) => ({...prevState,...newState,}));- const sourceCode =- data?.getServerlessFunctionSourceCode?.[INDEX_FILE_PATH];- setServerlessFunctionTestData((prev) => ({- ...prev,- input: getFunctionInputFromSourceCode(sourceCode),- }));++ if (serverlessFunctionTestData.shouldInitInput) {+ const sourceCode =+ data?.getServerlessFunctionSourceCode?.[INDEX_FILE_PATH];++ setServerlessFunctionTestData((prev) => ({+ ...prev,+ input: getFunctionInputFromSourceCode(sourceCode),+ shouldInitInput: false,+ }));+ }},});diff --git a/packages/twenty-front/src/modules/workflow/states/serverlessFunctionTestDataFamilyState.ts b/packages/twenty-front/src/modules/workflow/states/serverlessFunctionTestDataFamilyState.tsindex a59accd0d3d..3ce8742bf82 100644--- a/packages/twenty-front/src/modules/workflow/states/serverlessFunctionTestDataFamilyState.ts+++ b/packages/twenty-front/src/modules/workflow/states/serverlessFunctionTestDataFamilyState.ts@@ -3,6 +3,7 @@ import { ServerlessFunctionExecutionStatus } from '~/generated-metadata/graphql'export type ServerlessFunctionTestData = {input: { [field: string]: any };+ shouldInitInput: boolean;output: {data?: string;logs: string;@@ -29,6 +30,7 @@ export const serverlessFunctionTestDataFamilyState = createFamilyState<language: 'plaintext',height: 64,input: {},+ shouldInitInput: true,output: DEFAULT_OUTPUT_VALUE,},});diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionServerlessFunction.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionServerlessFunction.tsxindex 4e2a67c7053..63fda868f6d 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionServerlessFunction.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionServerlessFunction.tsx@@ -337,16 +337,18 @@ export const WorkflowEditActionServerlessFunction = ({isTesting={isTesting}/></StyledCodeEditorContainer>- <StyledCodeEditorContainer>- <InputLabel>Logs</InputLabel>- <TextArea- value={- isTesting ? '' : serverlessFunctionTestData.output.logs- }- maxRows={20}- disabled- />- </StyledCodeEditorContainer>+ {serverlessFunctionTestData.output.logs.length > 0 && (+ <StyledCodeEditorContainer>+ <InputLabel>Logs</InputLabel>+ <TextArea+ value={+ isTesting ? '' : serverlessFunctionTestData.output.logs+ }+ maxRows={20}+ disabled+ />+ </StyledCodeEditorContainer>+ )}</>)}</WorkflowStepBody>