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 11, 2024
1 parent 3d0c160 commit 43366b9
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 132 deletions.
32 changes: 0 additions & 32 deletions packages/twenty-front/src/hooks/usePreventOverlapCallback.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const useTextVariableEditor = ({
const { tr } = state;

// Insert hard break using the view's state and dispatch
if (isDefined(state.schema.nodes.hardBreak)) {
if (multiline) {
const transaction = tr.replaceSelectionWith(
state.schema.nodes.hardBreak.create(),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import { join } from 'path';

export const INDEX_FILE_PATH = join('src', 'index.ts');
export const INDEX_FILE_PATH = 'src/index.ts';
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useExecuteOneServerlessFunction } from '@/settings/serverless-functions/hooks/useExecuteOneServerlessFunction';
import { useRecoilState } from 'recoil';
import { serverlessFunctionTestDataFamilyState } from '@/workflow/states/serverlessFunctionTestDataFamilyState';
Expand All @@ -15,48 +14,39 @@ export const useTestServerlessFunction = (
useRecoilState(serverlessFunctionTestDataFamilyState(serverlessFunctionId));

const testServerlessFunction = async () => {
try {
const result = await executeOneServerlessFunction({
id: serverlessFunctionId,
payload: serverlessFunctionTestData.input,
version: 'draft',
});
const result = await executeOneServerlessFunction({
id: serverlessFunctionId,
payload: serverlessFunctionTestData.input,
version: 'draft',
});

if (isDefined(result?.data?.executeOneServerlessFunction?.data)) {
callback?.(result?.data?.executeOneServerlessFunction?.data);
}

setServerlessFunctionTestData((prev) => ({
...prev,
language: 'json',
height: 300,
output: {
data: result?.data?.executeOneServerlessFunction?.data
? JSON.stringify(
result?.data?.executeOneServerlessFunction?.data,
null,
4,
)
: undefined,
duration: result?.data?.executeOneServerlessFunction?.duration,
status: result?.data?.executeOneServerlessFunction?.status,
error: result?.data?.executeOneServerlessFunction?.error
? JSON.stringify(
result?.data?.executeOneServerlessFunction?.error,
null,
4,
)
: undefined,
},
}));
} catch (err) {
enqueueSnackBar(
(err as Error)?.message || 'An error occurred while executing function',
{
variant: SnackBarVariant.Error,
},
);
if (isDefined(result?.data?.executeOneServerlessFunction?.data)) {
callback?.(result?.data?.executeOneServerlessFunction?.data);
}

setServerlessFunctionTestData((prev) => ({
...prev,
language: 'json',
height: 300,
output: {
data: result?.data?.executeOneServerlessFunction?.data
? JSON.stringify(
result?.data?.executeOneServerlessFunction?.data,
null,
4,
)
: undefined,
duration: result?.data?.executeOneServerlessFunction?.duration,
status: result?.data?.executeOneServerlessFunction?.status,
error: result?.data?.executeOneServerlessFunction?.error
? JSON.stringify(
result?.data?.executeOneServerlessFunction?.error,
null,
4,
)
: undefined,
},
}));
};

return { testServerlessFunction };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export const getFunctionInputFromSourceCode = (
sourceCode?: string,
): FunctionInput => {
if (!isDefined(sourceCode)) {
throw Error('Source code is not defined');
throw new Error('Source code is not defined');
}

const functionInputSchema = getFunctionInputSchema(sourceCode);

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

const result = getDefaultFunctionInputFromInputSchema(functionInputSchema)[0];

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

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ export const ShowPageSubContainer = ({

const visibleTabs = tabs.filter((tab) => !tab.hide);

const displaySummaryAndFields =
layout && !layout.hideSummaryAndFields && !isMobile && !isInRightDrawer;

return (
<>
{layout &&
!layout.hideSummaryAndFields &&
!isMobile &&
!isInRightDrawer && (
<ShowPageLeftContainer forceMobile={isMobile}>
{summaryCard}
{fieldsCard}
</ShowPageLeftContainer>
)}
{displaySummaryAndFields && (
<ShowPageLeftContainer forceMobile={isMobile}>
{summaryCard}
{fieldsCard}
</ShowPageLeftContainer>
)}
<StyledShowPageRightContainer isMobile={isMobile}>
<StyledTabListContainer shouldDisplay={visibleTabs.length > 1}>
<TabList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useGetAvailablePackages } from '@/settings/serverless-functions/hooks/useGetAvailablePackages';
import { useServerlessFunctionUpdateFormState } from '@/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState';
import { useUpdateOneServerlessFunction } from '@/settings/serverless-functions/hooks/useUpdateOneServerlessFunction';
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { WorkflowStepHeader } from '@/workflow/components/WorkflowStepHeader';
import { useGetUpdatableWorkflowVersion } from '@/workflow/hooks/useGetUpdatableWorkflowVersion';
Expand All @@ -19,7 +18,6 @@ import { useEffect, useState } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';
import { CodeEditor, IconCode, isDefined, IconPlayerPlay } from 'twenty-ui';
import { useDebouncedCallback } from 'use-debounce';
import { usePreventOverlapCallback } from '~/hooks/usePreventOverlapCallback';
import { WorkflowStepBody } from '@/workflow/components/WorkflowStepBody';
import { TabList } from '@/ui/layout/tab/components/TabList';
import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
Expand Down Expand Up @@ -107,22 +105,13 @@ export const WorkflowEditActionFormServerlessFunction = ({
updateOutputSchemaFromTestResult,
);

const handleSave = usePreventOverlapCallback(async () => {
try {
await updateOneServerlessFunction({
id: serverlessFunctionId,
name: formValues.name,
description: formValues.description,
code: formValues.code,
});
} catch (err) {
enqueueSnackBar(
(err as Error)?.message || 'An error occurred while updating function',
{
variant: SnackBarVariant.Error,
},
);
}
const handleSave = useDebouncedCallback(async () => {
await updateOneServerlessFunction({
id: serverlessFunctionId,
name: formValues.name,
description: formValues.description,
code: formValues.code,
});
}, 1_000);

const onCodeChange = async (newCode: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const StyledContainer = styled.div`
flex-direction: column;
`;

const StyledInputContainer = styled.div`
const StyledFormNestedFieldInputContainer = styled.div`
background: ${({ theme }) => theme.background.secondary};
border: 1px solid ${({ theme }) => theme.border.color.medium};
border-radius: ${({ theme }) => theme.border.radius.md};
Expand Down Expand Up @@ -55,14 +55,14 @@ export const WorkflowEditActionFormServerlessFunctionFields = ({
return (
<StyledContainer key={pathKey}>
<InputLabel>{inputKey}</InputLabel>
<StyledInputContainer>
<StyledFormNestedFieldInputContainer>
{renderFields({
functionInput: inputValue,
path: currentPath,
VariablePicker,
onInputChange,
})}
</StyledInputContainer>
</StyledFormNestedFieldInputContainer>
</StyledContainer>
);
} else {
Expand Down
4 changes: 3 additions & 1 deletion packages/twenty-front/src/pages/auth/PasswordReset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export const PasswordReset = () => {
} catch (err) {
logError(err);
enqueueSnackBar(
(err as Error)?.message || 'An error occurred while updating password',
err instanceof Error
? err.message
: 'An error occurred while updating password',
{
variant: SnackBarVariant.Error,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { IconCode, IconGauge, IconSettings, IconTestPipe } from 'twenty-ui';
import { usePreventOverlapCallback } from '~/hooks/usePreventOverlapCallback';
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { isDefined } from '~/utils/isDefined';
import { useTestServerlessFunction } from '@/serverless-functions/hooks/useTestServerlessFunction';
import { useDebouncedCallback } from 'use-debounce';

const TAB_LIST_COMPONENT_ID = 'serverless-function-detail';

Expand All @@ -43,25 +43,14 @@ export const SettingsServerlessFunctionDetail = () => {
version: 'latest',
});

const save = async () => {
try {
await updateOneServerlessFunction({
id: serverlessFunctionId,
name: formValues.name,
description: formValues.description,
code: formValues.code,
});
} catch (err) {
enqueueSnackBar(
(err as Error)?.message || 'An error occurred while updating function',
{
variant: SnackBarVariant.Error,
},
);
}
};

const handleSave = usePreventOverlapCallback(save, 1000);
const handleSave = useDebouncedCallback(async () => {
await updateOneServerlessFunction({
id: serverlessFunctionId,
name: formValues.name,
description: formValues.description,
code: formValues.code,
});
}, 1_000);

const onChange = (key: string) => {
return async (value: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BaseGraphQLError extends GraphQLError {
}

if (extensions?.extensions) {
throw Error(
throw new Error(
'Pass extensions directly as the third argument of the ApolloError constructor: `new ' +
'ApolloError(message, code, {myExt: value})`, not `new ApolloError(message, code, ' +
'{extensions: {myExt: value}})`',
Expand Down

0 comments on commit 43366b9

Please sign in to comment.