8726 workflow add a test button in workflow code step (#9016)
- add test button to workflow code step - add test tab to workflow code step https://github.com/user-attachments/assets/e180a827-7321-49a2-8026-88490c557da2  
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import {
|
||||
DEFAULT_OUTPUT_VALUE,
|
||||
settingsServerlessFunctionOutputState,
|
||||
} from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
|
||||
import styled from '@emotion/styled';
|
||||
import { IconSquareRoundedCheck } from 'twenty-ui';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import { ServerlessFunctionExecutionStatus } from '~/generated-metadata/graphql';
|
||||
|
||||
const StyledOutput = styled.div<{ status?: ServerlessFunctionExecutionStatus }>`
|
||||
align-items: center;
|
||||
gap: ${({ theme }) => theme.spacing(1)};
|
||||
color: ${({ theme, status }) =>
|
||||
status === ServerlessFunctionExecutionStatus.Success
|
||||
? theme.color.turquoise
|
||||
: theme.color.red};
|
||||
display: flex;
|
||||
`;
|
||||
|
||||
export const SettingsServerlessFunctionsOutputMetadataInfo = () => {
|
||||
const theme = useTheme();
|
||||
const settingsServerlessFunctionOutput = useRecoilValue(
|
||||
settingsServerlessFunctionOutputState,
|
||||
);
|
||||
return settingsServerlessFunctionOutput.data === DEFAULT_OUTPUT_VALUE ? (
|
||||
'Output'
|
||||
) : (
|
||||
<StyledOutput status={settingsServerlessFunctionOutput.status}>
|
||||
<IconSquareRoundedCheck size={theme.icon.size.md} />
|
||||
{settingsServerlessFunctionOutput.status ===
|
||||
ServerlessFunctionExecutionStatus.Success
|
||||
? '200 OK'
|
||||
: '500 Error'}
|
||||
{' - '}
|
||||
{settingsServerlessFunctionOutput.duration}ms
|
||||
</StyledOutput>
|
||||
);
|
||||
};
|
||||
@ -11,7 +11,6 @@ import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
|
||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||
import styled from '@emotion/styled';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { Key } from 'ts-key-enum';
|
||||
import {
|
||||
Button,
|
||||
@ -47,10 +46,9 @@ export const SettingsServerlessFunctionCodeEditorTab = ({
|
||||
onChange: (filePath: string, value: string) => void;
|
||||
setIsCodeValid: (isCodeValid: boolean) => void;
|
||||
}) => {
|
||||
const { activeTabIdState } = useTabList(
|
||||
const { activeTabId } = useTabList(
|
||||
SETTINGS_SERVERLESS_FUNCTION_TAB_LIST_COMPONENT_ID,
|
||||
);
|
||||
const activeTabId = useRecoilValue(activeTabIdState);
|
||||
const TestButton = (
|
||||
<Button
|
||||
title="Test"
|
||||
|
||||
@ -7,20 +7,17 @@ import {
|
||||
Section,
|
||||
} from 'twenty-ui';
|
||||
|
||||
import { LightCopyIconButton } from '@/object-record/record-field/components/LightCopyIconButton';
|
||||
import { SettingsServerlessFunctionsOutputMetadataInfo } from '@/settings/serverless-functions/components/SettingsServerlessFunctionsOutputMetadataInfo';
|
||||
import { settingsServerlessFunctionCodeEditorOutputParamsState } from '@/settings/serverless-functions/states/settingsServerlessFunctionCodeEditorOutputParamsState';
|
||||
import { settingsServerlessFunctionInputState } from '@/settings/serverless-functions/states/settingsServerlessFunctionInputState';
|
||||
import { settingsServerlessFunctionOutputState } from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
|
||||
import { SettingsServerlessFunctionHotkeyScope } from '@/settings/serverless-functions/types/SettingsServerlessFunctionHotKeyScope';
|
||||
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
|
||||
import { SettingsPath } from '@/types/SettingsPath';
|
||||
import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
|
||||
import styled from '@emotion/styled';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { useRecoilState } from 'recoil';
|
||||
import { Key } from 'ts-key-enum';
|
||||
import { useHotkeyScopeOnMount } from '~/hooks/useHotkeyScopeOnMount';
|
||||
import { ServerlessFunctionExecutionResult } from '@/serverless-functions/components/ServerlessFunctionExecutionResult';
|
||||
import { serverlessFunctionTestDataFamilyState } from '@/workflow/states/serverlessFunctionTestDataFamilyState';
|
||||
|
||||
const StyledInputsContainer = styled.div`
|
||||
display: flex;
|
||||
@ -28,24 +25,27 @@ const StyledInputsContainer = styled.div`
|
||||
gap: ${({ theme }) => theme.spacing(4)};
|
||||
`;
|
||||
|
||||
const StyledCodeEditorContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
`;
|
||||
|
||||
export const SettingsServerlessFunctionTestTab = ({
|
||||
handleExecute,
|
||||
serverlessFunctionId,
|
||||
}: {
|
||||
handleExecute: () => void;
|
||||
serverlessFunctionId: string;
|
||||
}) => {
|
||||
const settingsServerlessFunctionCodeEditorOutputParams = useRecoilValue(
|
||||
settingsServerlessFunctionCodeEditorOutputParamsState,
|
||||
);
|
||||
const settingsServerlessFunctionOutput = useRecoilValue(
|
||||
settingsServerlessFunctionOutputState,
|
||||
);
|
||||
const [settingsServerlessFunctionInput, setSettingsServerlessFunctionInput] =
|
||||
useRecoilState(settingsServerlessFunctionInputState);
|
||||
const [serverlessFunctionTestData, setServerlessFunctionTestData] =
|
||||
useRecoilState(serverlessFunctionTestDataFamilyState(serverlessFunctionId));
|
||||
|
||||
const result =
|
||||
settingsServerlessFunctionOutput.data ||
|
||||
settingsServerlessFunctionOutput.error ||
|
||||
'';
|
||||
const onChange = (newInput: string) => {
|
||||
setServerlessFunctionTestData((prev) => ({
|
||||
...prev,
|
||||
input: JSON.parse(newInput),
|
||||
}));
|
||||
};
|
||||
|
||||
const navigate = useNavigate();
|
||||
useHotkeyScopeOnMount(
|
||||
@ -67,7 +67,7 @@ export const SettingsServerlessFunctionTestTab = ({
|
||||
description='Insert a JSON input, then press "Run" to test your function.'
|
||||
/>
|
||||
<StyledInputsContainer>
|
||||
<div>
|
||||
<StyledCodeEditorContainer>
|
||||
<CoreEditorHeader
|
||||
title={'Input'}
|
||||
rightNodes={[
|
||||
@ -82,26 +82,16 @@ export const SettingsServerlessFunctionTestTab = ({
|
||||
]}
|
||||
/>
|
||||
<CodeEditor
|
||||
value={settingsServerlessFunctionInput}
|
||||
value={JSON.stringify(serverlessFunctionTestData.input, null, 4)}
|
||||
language="json"
|
||||
height={200}
|
||||
onChange={setSettingsServerlessFunctionInput}
|
||||
onChange={onChange}
|
||||
withHeader
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<CoreEditorHeader
|
||||
leftNodes={[<SettingsServerlessFunctionsOutputMetadataInfo />]}
|
||||
rightNodes={[<LightCopyIconButton copyText={result} />]}
|
||||
/>
|
||||
<CodeEditor
|
||||
value={result}
|
||||
language={settingsServerlessFunctionCodeEditorOutputParams.language}
|
||||
height={settingsServerlessFunctionCodeEditorOutputParams.height}
|
||||
options={{ readOnly: true, domReadOnly: true }}
|
||||
withHeader
|
||||
/>
|
||||
</div>
|
||||
</StyledCodeEditorContainer>
|
||||
<ServerlessFunctionExecutionResult
|
||||
serverlessFunctionTestData={serverlessFunctionTestData}
|
||||
/>
|
||||
</StyledInputsContainer>
|
||||
</Section>
|
||||
);
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import {
|
||||
DEFAULT_OUTPUT_VALUE,
|
||||
settingsServerlessFunctionOutputState,
|
||||
} from '@/settings/serverless-functions/states/settingsServerlessFunctionOutputState';
|
||||
import { settingsServerlessFunctionCodeEditorOutputParamsState } from '@/settings/serverless-functions/states/settingsServerlessFunctionCodeEditorOutputParamsState';
|
||||
|
||||
export const SettingsServerlessFunctionTestTabEffect = () => {
|
||||
const settingsServerlessFunctionOutput = useRecoilValue(
|
||||
settingsServerlessFunctionOutputState,
|
||||
);
|
||||
const setSettingsServerlessFunctionCodeEditorOutputParams = useSetRecoilState(
|
||||
settingsServerlessFunctionCodeEditorOutputParamsState,
|
||||
);
|
||||
useEffect(() => {
|
||||
if (settingsServerlessFunctionOutput.data !== DEFAULT_OUTPUT_VALUE) {
|
||||
setSettingsServerlessFunctionCodeEditorOutputParams({
|
||||
language: 'json',
|
||||
height: 300,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
settingsServerlessFunctionOutput.data,
|
||||
setSettingsServerlessFunctionCodeEditorOutputParams,
|
||||
]);
|
||||
return <></>;
|
||||
};
|
||||
Reference in New Issue
Block a user