Fix test data disapear (#10846)
As title. Init input from source code only once.
This commit is contained in:
@ -3,7 +3,7 @@ import { useGetOneServerlessFunctionSourceCode } from '@/settings/serverless-fun
|
|||||||
import { Dispatch, SetStateAction, useState } from 'react';
|
import { Dispatch, SetStateAction, useState } from 'react';
|
||||||
import { FindOneServerlessFunctionSourceCodeQuery } from '~/generated-metadata/graphql';
|
import { FindOneServerlessFunctionSourceCodeQuery } from '~/generated-metadata/graphql';
|
||||||
import { serverlessFunctionTestDataFamilyState } from '@/workflow/states/serverlessFunctionTestDataFamilyState';
|
import { serverlessFunctionTestDataFamilyState } from '@/workflow/states/serverlessFunctionTestDataFamilyState';
|
||||||
import { useSetRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
import { getFunctionInputFromSourceCode } from '@/serverless-functions/utils/getFunctionInputFromSourceCode';
|
import { getFunctionInputFromSourceCode } from '@/serverless-functions/utils/getFunctionInputFromSourceCode';
|
||||||
import { INDEX_FILE_PATH } from '@/serverless-functions/constants/IndexFilePath';
|
import { INDEX_FILE_PATH } from '@/serverless-functions/constants/IndexFilePath';
|
||||||
|
|
||||||
@ -37,9 +37,8 @@ export const useServerlessFunctionUpdateFormState = ({
|
|||||||
code: undefined,
|
code: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const setServerlessFunctionTestData = useSetRecoilState(
|
const [serverlessFunctionTestData, setServerlessFunctionTestData] =
|
||||||
serverlessFunctionTestDataFamilyState(serverlessFunctionId),
|
useRecoilState(serverlessFunctionTestDataFamilyState(serverlessFunctionId));
|
||||||
);
|
|
||||||
|
|
||||||
const { serverlessFunction } = useGetOneServerlessFunction({
|
const { serverlessFunction } = useGetOneServerlessFunction({
|
||||||
id: serverlessFunctionId,
|
id: serverlessFunctionId,
|
||||||
@ -54,16 +53,22 @@ export const useServerlessFunctionUpdateFormState = ({
|
|||||||
name: serverlessFunction?.name || '',
|
name: serverlessFunction?.name || '',
|
||||||
description: serverlessFunction?.description || '',
|
description: serverlessFunction?.description || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
setFormValues((prevState) => ({
|
setFormValues((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
...newState,
|
...newState,
|
||||||
}));
|
}));
|
||||||
const sourceCode =
|
|
||||||
data?.getServerlessFunctionSourceCode?.[INDEX_FILE_PATH];
|
if (serverlessFunctionTestData.shouldInitInput) {
|
||||||
setServerlessFunctionTestData((prev) => ({
|
const sourceCode =
|
||||||
...prev,
|
data?.getServerlessFunctionSourceCode?.[INDEX_FILE_PATH];
|
||||||
input: getFunctionInputFromSourceCode(sourceCode),
|
|
||||||
}));
|
setServerlessFunctionTestData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
input: getFunctionInputFromSourceCode(sourceCode),
|
||||||
|
shouldInitInput: false,
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { ServerlessFunctionExecutionStatus } from '~/generated-metadata/graphql'
|
|||||||
|
|
||||||
export type ServerlessFunctionTestData = {
|
export type ServerlessFunctionTestData = {
|
||||||
input: { [field: string]: any };
|
input: { [field: string]: any };
|
||||||
|
shouldInitInput: boolean;
|
||||||
output: {
|
output: {
|
||||||
data?: string;
|
data?: string;
|
||||||
logs: string;
|
logs: string;
|
||||||
@ -29,6 +30,7 @@ export const serverlessFunctionTestDataFamilyState = createFamilyState<
|
|||||||
language: 'plaintext',
|
language: 'plaintext',
|
||||||
height: 64,
|
height: 64,
|
||||||
input: {},
|
input: {},
|
||||||
|
shouldInitInput: true,
|
||||||
output: DEFAULT_OUTPUT_VALUE,
|
output: DEFAULT_OUTPUT_VALUE,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -337,16 +337,18 @@ export const WorkflowEditActionServerlessFunction = ({
|
|||||||
isTesting={isTesting}
|
isTesting={isTesting}
|
||||||
/>
|
/>
|
||||||
</StyledCodeEditorContainer>
|
</StyledCodeEditorContainer>
|
||||||
<StyledCodeEditorContainer>
|
{serverlessFunctionTestData.output.logs.length > 0 && (
|
||||||
<InputLabel>Logs</InputLabel>
|
<StyledCodeEditorContainer>
|
||||||
<TextArea
|
<InputLabel>Logs</InputLabel>
|
||||||
value={
|
<TextArea
|
||||||
isTesting ? '' : serverlessFunctionTestData.output.logs
|
value={
|
||||||
}
|
isTesting ? '' : serverlessFunctionTestData.output.logs
|
||||||
maxRows={20}
|
}
|
||||||
disabled
|
maxRows={20}
|
||||||
/>
|
disabled
|
||||||
</StyledCodeEditorContainer>
|
/>
|
||||||
|
</StyledCodeEditorContainer>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</WorkflowStepBody>
|
</WorkflowStepBody>
|
||||||
|
|||||||
Reference in New Issue
Block a user