Skip to content

Commit

Permalink
Code review returns
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed Dec 12, 2024
1 parent 1c19366 commit 2a938f1
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export const getFunctionInputFromSourceCode = (
const functionInputSchema = getFunctionInputSchema(sourceCode);

if (functionInputSchema.length !== 1) {
throw new Error('Function should have one object parameter');
return {};
}

const result = getDefaultFunctionInputFromInputSchema(functionInputSchema)[0];

if (!isObject(result)) {
throw new Error('Function should have one object parameter');
return {};
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const StyledInputsContainer = styled.div`
gap: ${({ theme }) => theme.spacing(4)};
`;

const StyledCodeEditorContainer = styled.div`
display: flex;
flex-direction: column;
`;

export const SettingsServerlessFunctionTestTab = ({
handleExecute,
serverlessFunctionId,
Expand Down Expand Up @@ -62,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={[
Expand All @@ -83,7 +88,7 @@ export const SettingsServerlessFunctionTestTab = ({
onChange={onChange}
withHeader
/>
</div>
</StyledCodeEditorContainer>
<ServerlessFunctionExecutionResult
serverlessFunctionTestData={serverlessFunctionTestData}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const StyledContainer = styled.div`
justify-content: flex-end;
padding: ${({ theme }) => theme.spacing(2)} ${({ theme }) => theme.spacing(3)};
gap: ${({ theme }) => theme.spacing(2)};
position: fixed;
width: 100%;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const StyledWorkflowStepBody = styled.div`
overflow-y: scroll;
padding: ${({ theme }) => theme.spacing(6)};
row-gap: ${({ theme }) => theme.spacing(6)};
flex: 1 1 auto;
`;

export { StyledWorkflowStepBody as WorkflowStepBody };
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,30 @@ export const WorkflowStepHeader = ({
};

return (
<>
<StyledHeader>
<StyledHeaderIconContainer>
{
<Icon
color={iconColor}
stroke={theme.icon.stroke.sm}
size={theme.icon.size.lg}
/>
}
</StyledHeaderIconContainer>
<StyledHeaderInfo>
<StyledHeaderTitle>
<TextInput
value={title}
copyButton={false}
hotkeyScope="workflow-step-title"
onEnter={onTitleChange}
onEscape={onTitleChange}
onChange={handleChange}
shouldTrim={false}
/>
</StyledHeaderTitle>
<StyledHeaderType>{headerType}</StyledHeaderType>
</StyledHeaderInfo>
</StyledHeader>
</>
<StyledHeader>
<StyledHeaderIconContainer>
{
<Icon
color={iconColor}
stroke={theme.icon.stroke.sm}
size={theme.icon.size.lg}
/>
}
</StyledHeaderIconContainer>
<StyledHeaderInfo>
<StyledHeaderTitle>
<TextInput
value={title}
copyButton={false}
hotkeyScope="workflow-step-title"
onEnter={onTitleChange}
onEscape={onTitleChange}
onChange={handleChange}
shouldTrim={false}
/>
</StyledHeaderTitle>
<StyledHeaderType>{headerType}</StyledHeaderType>
</StyledHeaderInfo>
</StyledHeader>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ import { getFunctionInputFromSourceCode } from '@/serverless-functions/utils/get
import { mergeDefaultFunctionInputAndFunctionInput } from '@/serverless-functions/utils/mergeDefaultFunctionInputAndFunctionInput';
import { WorkflowEditActionFormServerlessFunctionFields } from '@/workflow/workflow-actions/components/WorkflowEditActionFormServerlessFunctionFields';

const StyledContainer = styled.div`
display: flex;
flex-direction: column;
height: 100%;
`;

const StyledCodeEditorContainer = styled.div`
display: flex;
flex-direction: column;
`;

const StyledTabList = styled(TabList)`
background: ${({ theme }) => theme.background.secondary};
padding-left: ${({ theme }) => theme.spacing(2)};
padding-right: ${({ theme }) => theme.spacing(2)};
`;
Expand Down Expand Up @@ -92,7 +99,7 @@ export const WorkflowEditActionFormServerlessFunction = ({
return;
}
const newOutputSchema = getFunctionOutputSchema(testResult);
await updateAction({
updateAction({
...action,
settings: { ...action.settings, outputSchema: newOutputSchema },
});
Expand Down Expand Up @@ -124,50 +131,53 @@ export const WorkflowEditActionFormServerlessFunction = ({
await handleUpdateFunctionInputSchema(newCode);
};

const handleUpdateFunctionInputSchema = async (sourceCode: string) => {
if (actionOptions.readonly === true) {
return;
}
const handleUpdateFunctionInputSchema = useDebouncedCallback(
async (sourceCode: string) => {
if (actionOptions.readonly === true) {
return;
}

if (!isDefined(sourceCode)) {
return;
}
if (!isDefined(sourceCode)) {
return;
}

const newFunctionInput = getFunctionInputFromSourceCode(sourceCode);
const newMergedInput = mergeDefaultFunctionInputAndFunctionInput({
newInput: newFunctionInput,
oldInput: action.settings.input.serverlessFunctionInput,
});
const newMergedTestInput = mergeDefaultFunctionInputAndFunctionInput({
newInput: newFunctionInput,
oldInput: serverlessFunctionTestData.input,
});
const newFunctionInput = getFunctionInputFromSourceCode(sourceCode);
const newMergedInput = mergeDefaultFunctionInputAndFunctionInput({
newInput: newFunctionInput,
oldInput: action.settings.input.serverlessFunctionInput,
});
const newMergedTestInput = mergeDefaultFunctionInputAndFunctionInput({
newInput: newFunctionInput,
oldInput: serverlessFunctionTestData.input,
});

setFunctionInput(newMergedInput);
setServerlessFunctionTestData((prev) => ({
...prev,
input: newMergedTestInput,
}));
setFunctionInput(newMergedInput);
setServerlessFunctionTestData((prev) => ({
...prev,
input: newMergedTestInput,
}));

await updateAction({
...action,
settings: {
...action.settings,
outputSchema: {},
input: {
...action.settings.input,
serverlessFunctionInput: newMergedInput,
updateAction({
...action,
settings: {
...action.settings,
outputSchema: {},
input: {
...action.settings.input,
serverlessFunctionInput: newMergedInput,
},
},
},
});
};
});
},
1_000,
);

const handleInputChange = async (value: any, path: string[]) => {
const updatedFunctionInput = setNestedValue(functionInput, path, value);

setFunctionInput(updatedFunctionInput);

await updateAction({
updateAction({
...action,
settings: {
...action.settings,
Expand Down Expand Up @@ -200,10 +210,6 @@ export const WorkflowEditActionFormServerlessFunction = ({
editor: editor.IStandaloneCodeEditor,
monaco: Monaco,
) => {
editor.addCommand(
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter,
handleRunFunction,
);
await AutoTypings.create(editor, {
monaco,
preloadPackages: true,
Expand All @@ -219,7 +225,7 @@ export const WorkflowEditActionFormServerlessFunction = ({
return;
}

actionOptions?.onActionUpdate({
actionOptions.onActionUpdate({
...action,
...actionUpdate,
});
Expand All @@ -246,7 +252,7 @@ export const WorkflowEditActionFormServerlessFunction = ({

return (
!loading && (
<>
<StyledContainer>
<StyledTabList
tabListInstanceId={TAB_LIST_COMPONENT_ID}
tabs={tabs}
Expand Down Expand Up @@ -302,12 +308,14 @@ export const WorkflowEditActionFormServerlessFunction = ({
</>
)}
</WorkflowStepBody>
<RightDrawerFooter
actions={[
<CmdEnterActionButton title="Test" onClick={handleRunFunction} />,
]}
/>
</>
{activeTabId === 'test' && (
<RightDrawerFooter
actions={[
<CmdEnterActionButton title="Test" onClick={handleRunFunction} />,
]}
/>
)}
</StyledContainer>
)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ export type RecordOutputSchema = {
};

export type OutputSchema = BaseOutputSchema | RecordOutputSchema;

export type StepOutputSchema = {
id: string;
name: string;
outputSchema: OutputSchema;
};

0 comments on commit 2a938f1

Please sign in to comment.