From 32d51b69e86a5d96b5499aef8fe7b40c971235c5 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira <62335616+lucaseduoli@users.noreply.github.com> Date: Thu, 29 Aug 2024 16:31:03 -0300 Subject: [PATCH] refactor: custom api code generator and fix chat locking when saving (#3618) * Removed saveLoading from the chat * Fixed initialSetup that couldnt be null * Added types for get codes type * Added new types for getCodes and initialSetup on Tweaks store * Created a use custom api code to return all code * Passed the getCodes from the custom hook into initialSetup * Updated tabs array to receive object * Update every code to get correct props * Update tweaks store to handle refactored getCodes and createTabsArray * Added custom api generator component on top of the codetabscomponent --- .../components/custom-api-generator.tsx | 3 + .../hooks/use-custom-api-code.ts | 19 +++++ .../components/buttonSendWrapper/index.tsx | 13 +--- .../components/textAreaWrapper/index.tsx | 20 +++-- .../components/chatView/chatInput/index.tsx | 11 +-- src/frontend/src/modals/apiModal/index.tsx | 7 +- .../modals/apiModal/utils/get-curl-code.tsx | 19 ++--- .../modals/apiModal/utils/get-js-api-code.tsx | 14 ++-- .../apiModal/utils/get-python-api-code.tsx | 13 ++-- .../modals/apiModal/utils/get-python-code.tsx | 10 ++- .../modals/apiModal/utils/get-widget-code.tsx | 12 +-- .../src/modals/apiModal/utils/tabs-array.tsx | 64 ++++++++------- src/frontend/src/stores/tweaksStore.ts | 77 ++++++++++--------- src/frontend/src/types/tweaks/index.ts | 16 ++++ .../src/types/zustand/tweaks/index.ts | 8 +- 15 files changed, 178 insertions(+), 128 deletions(-) create mode 100644 src/frontend/src/customization/components/custom-api-generator.tsx create mode 100644 src/frontend/src/customization/hooks/use-custom-api-code.ts create mode 100644 src/frontend/src/types/tweaks/index.ts diff --git a/src/frontend/src/customization/components/custom-api-generator.tsx b/src/frontend/src/customization/components/custom-api-generator.tsx new file mode 100644 index 000000000000..d6d6bb6971bf --- /dev/null +++ b/src/frontend/src/customization/components/custom-api-generator.tsx @@ -0,0 +1,3 @@ +export function CustomAPIGenerator() { + return <>; +} diff --git a/src/frontend/src/customization/hooks/use-custom-api-code.ts b/src/frontend/src/customization/hooks/use-custom-api-code.ts new file mode 100644 index 000000000000..034f8f6f0335 --- /dev/null +++ b/src/frontend/src/customization/hooks/use-custom-api-code.ts @@ -0,0 +1,19 @@ +import { + getCurlRunCode, + getCurlWebhookCode, +} from "@/modals/apiModal/utils/get-curl-code"; +import getJsApiCode from "@/modals/apiModal/utils/get-js-api-code"; +import getPythonApiCode from "@/modals/apiModal/utils/get-python-api-code"; +import getPythonCode from "@/modals/apiModal/utils/get-python-code"; +import getWidgetCode from "@/modals/apiModal/utils/get-widget-code"; + +export function useCustomAPICode() { + return { + getCurlRunCode, + getCurlWebhookCode, + getJsApiCode, + getPythonApiCode, + getPythonCode, + getWidgetCode, + }; +} diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx index 81f42675c2a5..4c148575cddc 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/buttonSendWrapper/index.tsx @@ -8,7 +8,6 @@ type ButtonSendWrapperProps = { send: () => void; lockChat: boolean; noInput: boolean; - saveLoading: boolean; chatValue: string; files: FilePreviewType[]; }; @@ -17,7 +16,6 @@ const ButtonSendWrapper = ({ send, lockChat, noInput, - saveLoading, chatValue, files, }: ButtonSendWrapperProps) => { @@ -31,15 +29,11 @@ const ButtonSendWrapper = ({ ? "text-primary" : "bg-chat-send text-background", )} - disabled={lockChat || saveLoading} + disabled={lockChat} onClick={(): void => send()} unstyled > - file.loading) - } - > + file.loading)}> file.loading)) && - !noInput + !(lockChat || files.some((file) => file.loading)) && !noInput } > 0 @@ -45,10 +43,10 @@ const TextAreaWrapper = ({ const additionalClassNames = "form-modal-lockchat pl-14"; useEffect(() => { - if (!lockChat && !noInput && !saveLoading) { + if (!lockChat && !noInput) { inputRef.current?.focus(); } - }, [lockChat, noInput, saveLoading]); + }, [lockChat, noInput]); return (