diff --git a/packages/twenty-front/src/hooks/usePreventOverlapCallback.ts b/packages/twenty-front/src/hooks/usePreventOverlapCallback.ts deleted file mode 100644 index 0cd1c5b89845..000000000000 --- a/packages/twenty-front/src/hooks/usePreventOverlapCallback.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { useEffect, useState } from 'react'; -import { useDebouncedCallback } from 'use-debounce'; - -export const usePreventOverlapCallback = ( - callback: () => Promise, - wait?: number, -) => { - const [isRunning, setIsRunning] = useState(false); - const [pendingRun, setPendingRun] = useState(false); - - const handleCallback = async () => { - if (isRunning) { - setPendingRun(true); - return; - } - setIsRunning(true); - try { - await callback(); - } finally { - setIsRunning(false); - } - }; - - useEffect(() => { - if (!isRunning && pendingRun) { - setPendingRun(false); - callback(); - } - }, [callback, isRunning, pendingRun, setPendingRun]); - - return useDebouncedCallback(handleCallback, wait); -}; diff --git a/packages/twenty-front/src/modules/object-record/record-field/form-types/hooks/useTextVariableEditor.ts b/packages/twenty-front/src/modules/object-record/record-field/form-types/hooks/useTextVariableEditor.ts index af9def8ac05e..d89600483499 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/form-types/hooks/useTextVariableEditor.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/form-types/hooks/useTextVariableEditor.ts @@ -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(), ); diff --git a/packages/twenty-front/src/modules/serverless-functions/constants/IndexFilePath.ts b/packages/twenty-front/src/modules/serverless-functions/constants/IndexFilePath.ts index 467d6a7b0ac7..7a5671d7eae5 100644 --- a/packages/twenty-front/src/modules/serverless-functions/constants/IndexFilePath.ts +++ b/packages/twenty-front/src/modules/serverless-functions/constants/IndexFilePath.ts @@ -1,3 +1 @@ -import { join } from 'path'; - -export const INDEX_FILE_PATH = join('src', 'index.ts'); +export const INDEX_FILE_PATH = 'src/index.ts'; diff --git a/packages/twenty-front/src/modules/serverless-functions/hooks/useTestServerlessFunction.ts b/packages/twenty-front/src/modules/serverless-functions/hooks/useTestServerlessFunction.ts index 5891f8ba16e2..29e64cf8dab2 100644 --- a/packages/twenty-front/src/modules/serverless-functions/hooks/useTestServerlessFunction.ts +++ b/packages/twenty-front/src/modules/serverless-functions/hooks/useTestServerlessFunction.ts @@ -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'; @@ -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 }; diff --git a/packages/twenty-front/src/modules/serverless-functions/utils/getFunctionInputFromSourceCode.ts b/packages/twenty-front/src/modules/serverless-functions/utils/getFunctionInputFromSourceCode.ts index d898ff483fb0..f21998eec4e8 100644 --- a/packages/twenty-front/src/modules/serverless-functions/utils/getFunctionInputFromSourceCode.ts +++ b/packages/twenty-front/src/modules/serverless-functions/utils/getFunctionInputFromSourceCode.ts @@ -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; diff --git a/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSubContainer.tsx b/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSubContainer.tsx index e8bebf30193e..80c69b86a8b6 100644 --- a/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSubContainer.tsx +++ b/packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageSubContainer.tsx @@ -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 && ( - - {summaryCard} - {fieldsCard} - - )} + {displaySummaryAndFields && ( + + {summaryCard} + {fieldsCard} + + )} 1}> { - 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) => { diff --git a/packages/twenty-front/src/modules/workflow/workflow-actions/components/WorkflowEditActionFormServerlessFunctionFields.tsx b/packages/twenty-front/src/modules/workflow/workflow-actions/components/WorkflowEditActionFormServerlessFunctionFields.tsx index 7a26d0998c17..640cd8c47e78 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-actions/components/WorkflowEditActionFormServerlessFunctionFields.tsx +++ b/packages/twenty-front/src/modules/workflow/workflow-actions/components/WorkflowEditActionFormServerlessFunctionFields.tsx @@ -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}; @@ -55,14 +55,14 @@ export const WorkflowEditActionFormServerlessFunctionFields = ({ return ( {inputKey} - + {renderFields({ functionInput: inputValue, path: currentPath, VariablePicker, onInputChange, })} - + ); } else { diff --git a/packages/twenty-front/src/pages/auth/PasswordReset.tsx b/packages/twenty-front/src/pages/auth/PasswordReset.tsx index dd47cb8962a3..3b896d30688e 100644 --- a/packages/twenty-front/src/pages/auth/PasswordReset.tsx +++ b/packages/twenty-front/src/pages/auth/PasswordReset.tsx @@ -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, }, diff --git a/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx b/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx index 256021aadc54..ef2fa9a9a901 100644 --- a/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx +++ b/packages/twenty-front/src/pages/settings/serverless-functions/SettingsServerlessFunctionDetail.tsx @@ -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'; @@ -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) => { diff --git a/packages/twenty-server/src/engine/core-modules/graphql/utils/graphql-errors.util.ts b/packages/twenty-server/src/engine/core-modules/graphql/utils/graphql-errors.util.ts index 613225796cb3..799ccedc4f8d 100644 --- a/packages/twenty-server/src/engine/core-modules/graphql/utils/graphql-errors.util.ts +++ b/packages/twenty-server/src/engine/core-modules/graphql/utils/graphql-errors.util.ts @@ -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}})`',