From 0ce645d8934e2b9ca2e2fc67d8dabff07d06ad79 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Fri, 28 Mar 2025 13:49:19 -0600 Subject: [PATCH] update delete endpoints --- web/src/api/buster_rest/api_keys/requests.ts | 2 +- web/src/api/buster_rest/chats/requests.ts | 4 ++-- web/src/api/buster_rest/collections/requests.ts | 10 ++++++---- web/src/api/buster_rest/dashboards/requests.ts | 4 ++-- .../api/buster_rest/dataset_groups/requests.ts | 4 ++-- .../ChatHeaderOptions/ChatHeaderDropdown.tsx | 16 +++++++++++++--- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/web/src/api/buster_rest/api_keys/requests.ts b/web/src/api/buster_rest/api_keys/requests.ts index b17c8b8e6..d256352ab 100644 --- a/web/src/api/buster_rest/api_keys/requests.ts +++ b/web/src/api/buster_rest/api_keys/requests.ts @@ -10,7 +10,7 @@ export const createApiKey = async (name: string) => { }; export const deleteApiKey = async (id: string) => { - return mainApi.delete(`/api_keys/${id}`).then(() => {}); + return mainApi.delete(`/api_keys/${id}`).then((res) => res.data); }; export const getApiKey = async (id: string) => { diff --git a/web/src/api/buster_rest/chats/requests.ts b/web/src/api/buster_rest/chats/requests.ts index c1e913044..a19b133c5 100644 --- a/web/src/api/buster_rest/chats/requests.ts +++ b/web/src/api/buster_rest/chats/requests.ts @@ -60,8 +60,8 @@ export const updateChat = async ({ return mainApi.put(`${CHATS_BASE}/${id}`, data).then((res) => res.data); }; -export const deleteChat = async (ids: string[]): Promise => { - return mainApi.delete(`${CHATS_BASE}`, { data: { ids } }).then((res) => res.data); +export const deleteChat = async (data: string[]): Promise => { + return mainApi.delete(`${CHATS_BASE}`, { data }).then((res) => res.data); }; export const duplicateChat = async ({ diff --git a/web/src/api/buster_rest/collections/requests.ts b/web/src/api/buster_rest/collections/requests.ts index f0099f0c5..9b6896a9f 100644 --- a/web/src/api/buster_rest/collections/requests.ts +++ b/web/src/api/buster_rest/collections/requests.ts @@ -64,13 +64,15 @@ export const collectionsUpdateCollection = async (params: { .then((res) => res.data); }; -export const collectionsDeleteCollection = async (params: { +export const collectionsDeleteCollection = async (data: { /** Array of collection IDs to be deleted */ ids: string[]; }) => { - return await mainApi.delete('/collections', { - data: { ids: params.ids } - }).then((res) => res.data); + return await mainApi + .delete('/collections', { + data + }) + .then((res) => res.data); }; // share collections diff --git a/web/src/api/buster_rest/dashboards/requests.ts b/web/src/api/buster_rest/dashboards/requests.ts index 4fbfecab9..c329a582a 100644 --- a/web/src/api/buster_rest/dashboards/requests.ts +++ b/web/src/api/buster_rest/dashboards/requests.ts @@ -72,8 +72,8 @@ export const dashboardsUpdateDashboard = async (params: { .then((res) => res.data); }; -export const dashboardsDeleteDashboard = async ({ ids }: { ids: string[] }) => { - return await mainApi.delete(`/dashboards`, { data: { ids } }).then((res) => res.data); +export const dashboardsDeleteDashboard = async (data: { ids: string[] }) => { + return await mainApi.delete(`/dashboards`, { data }).then((res) => res.data); }; // share dashboards diff --git a/web/src/api/buster_rest/dataset_groups/requests.ts b/web/src/api/buster_rest/dataset_groups/requests.ts index f12154147..292060c2b 100644 --- a/web/src/api/buster_rest/dataset_groups/requests.ts +++ b/web/src/api/buster_rest/dataset_groups/requests.ts @@ -25,8 +25,8 @@ export const updateDatasetGroup = async ( return mainApi.put(`/dataset_groups`, data).then((res) => res.data); }; -export const deleteDatasetGroup = async (ids: string[]) => { - return mainApi.delete(`/dataset_groups`, { data: { ids } }).then((res) => res.data); +export const deleteDatasetGroup = async (data: string[]) => { + return mainApi.delete(`/dataset_groups`, { data }).then((res) => res.data); }; export const getDatasetGroup = async (id: string) => { diff --git a/web/src/layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx b/web/src/layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx index 2dea9ad0b..dd6f98d55 100644 --- a/web/src/layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx +++ b/web/src/layouts/ChatLayout/ChatContainer/ChatHeader/ChatHeaderOptions/ChatHeaderDropdown.tsx @@ -5,12 +5,15 @@ import { Copy, Trash, Pencil } from '@/components/ui/icons'; import { useDeleteChat, useDuplicateChat } from '@/api/buster_rest/chats'; import { CHAT_HEADER_TITLE_ID } from '../ChatHeaderTitle'; import { timeout } from '@/lib'; +import { useRouter } from 'next/navigation'; +import { BusterRoutes, createBusterRoute } from '@/routes'; export const ChatContainerHeaderDropdown: React.FC<{ children: React.ReactNode; }> = React.memo(({ children }) => { const chatId = useChatIndividualContextSelector((state) => state.chatId); - const { mutate: deleteChat } = useDeleteChat(); + const router = useRouter(); + const { mutate: deleteChat, isPending: isDeleting } = useDeleteChat(); const { mutate: duplicateChat } = useDuplicateChat(); const currentMessageId = useChatIndividualContextSelector((state) => state.currentMessageId); @@ -20,7 +23,14 @@ export const ChatContainerHeaderDropdown: React.FC<{ label: 'Delete chat', value: 'delete', icon: , - onClick: () => chatId && deleteChat([chatId]) + loading: isDeleting, + onClick: () => + chatId && + deleteChat([chatId], { + onSuccess: () => { + router.push(createBusterRoute({ route: BusterRoutes.APP_CHAT })); + } + }) }, { label: 'Duplicate chat', @@ -44,7 +54,7 @@ export const ChatContainerHeaderDropdown: React.FC<{ } } ]; - }, [chatId, currentMessageId, deleteChat, duplicateChat]); + }, [chatId, isDeleting, currentMessageId, deleteChat, duplicateChat]); return (