From 57b827f0e7452849c026ccea1ee29926f2574635 Mon Sep 17 00:00:00 2001 From: Jamie Knight Date: Thu, 8 Aug 2024 10:14:28 -0600 Subject: [PATCH] remove all onSuccessCallback params --- src/components/modals/CreateCatalogModal.tsx | 17 ++++++++----- src/components/modals/CreateSchemaModal.tsx | 17 ++++++++----- src/components/modals/DeleteCatalogModal.tsx | 13 +++++----- src/components/modals/DeleteFunctionModal.tsx | 13 ++++++---- src/components/modals/DeleteSchemaModal.tsx | 10 ++++---- src/components/modals/DeleteTableModal.tsx | 25 ++++++++++++------- src/components/modals/DeleteVolumeModal.tsx | 10 ++++---- src/hooks/catalog.tsx | 22 +++------------- src/hooks/functions.tsx | 8 +----- src/hooks/schemas.tsx | 18 +++---------- src/hooks/tables.tsx | 10 ++------ src/hooks/volumes.tsx | 8 +----- 12 files changed, 73 insertions(+), 98 deletions(-) diff --git a/src/components/modals/CreateCatalogModal.tsx b/src/components/modals/CreateCatalogModal.tsx index 0192f5b..515d7a0 100644 --- a/src/components/modals/CreateCatalogModal.tsx +++ b/src/components/modals/CreateCatalogModal.tsx @@ -6,6 +6,7 @@ import { import { useCallback, useRef } from 'react'; import TextArea from 'antd/es/input/TextArea'; import { useNavigate } from 'react-router-dom'; +import { useNotification } from '../../utils/NotificationContext'; interface CreateCatalogModalProps { open: boolean; @@ -17,11 +18,8 @@ export function CreateCatalogModal({ closeModal, }: CreateCatalogModalProps) { const navigate = useNavigate(); - const mutation = useCreateCatalog({ - onSuccessCallback: (catalog) => { - navigate(`/data/${catalog.name}`); - }, - }); + const mutation = useCreateCatalog(); + const { setNotification } = useNotification(); const submitRef = useRef(null); const handleSubmit = useCallback(() => { @@ -45,7 +43,14 @@ export function CreateCatalogModal({ layout="vertical" onFinish={(values) => { - mutation.mutate(values); + mutation.mutate(values, { + onError: (error: Error) => { + setNotification(error.message, 'error'); + }, + onSuccess: (catalog) => { + navigate(`/data/${catalog.name}`); + }, + }); }} name="Create catalog form" > diff --git a/src/components/modals/CreateSchemaModal.tsx b/src/components/modals/CreateSchemaModal.tsx index 015b979..32810c2 100644 --- a/src/components/modals/CreateSchemaModal.tsx +++ b/src/components/modals/CreateSchemaModal.tsx @@ -6,6 +6,7 @@ import { CreateSchemaMutationParams, useCreateSchema, } from '../../hooks/schemas'; +import { useNotification } from '../../utils/NotificationContext'; interface CreateSchemaModalProps { open: boolean; @@ -19,11 +20,8 @@ export default function CreateSchemaModal({ catalog, }: CreateSchemaModalProps) { const navigate = useNavigate(); - const mutation = useCreateSchema({ - onSuccessCallback: (schema) => { - navigate(`/data/${schema.catalog_name}/${schema.name}`); - }, - }); + const mutation = useCreateSchema(); + const { setNotification } = useNotification(); const submitRef = useRef(null); const handleSubmit = useCallback(() => { @@ -47,7 +45,14 @@ export default function CreateSchemaModal({ layout="vertical" onFinish={(values) => { - mutation.mutate(values); + mutation.mutate(values, { + onError: (error) => { + setNotification(error.message, 'error'); + }, + onSuccess: (schema) => { + navigate(`/data/${schema.catalog_name}/${schema.name}`); + }, + }); }} name="Create schema form" initialValues={{ catalog_name: catalog }} diff --git a/src/components/modals/DeleteCatalogModal.tsx b/src/components/modals/DeleteCatalogModal.tsx index 46d55e4..894ef7e 100644 --- a/src/components/modals/DeleteCatalogModal.tsx +++ b/src/components/modals/DeleteCatalogModal.tsx @@ -17,12 +17,7 @@ export function DeleteCatalogModal({ }: DeleteCatalogModalProps) { const navigate = useNavigate(); const { setNotification } = useNotification(); - const mutation = useDeleteCatalog({ - onSuccessCallback: () => { - setNotification(`${catalog} catalog successfully deleted`, 'success'); - navigate(`/`); - }, - }); + const mutation = useDeleteCatalog(); const handleSubmit = useCallback(() => { mutation.mutate( @@ -31,9 +26,13 @@ export function DeleteCatalogModal({ onError: (error: Error) => { setNotification(error.message, 'error'); }, + onSuccess: () => { + setNotification(`${catalog} catalog successfully deleted`, 'success'); + navigate(`/`); + }, }, ); - }, [mutation, catalog, setNotification]); + }, [mutation, catalog, setNotification, navigate]); return ( { - setNotification(`${ucFunction} function successfully deleted`, 'success'); - navigate(`/data/${catalog}/${schema}`); - }, catalog, schema, }); @@ -37,9 +33,16 @@ export function DeleteFunctionModal({ onError: (error: Error) => { setNotification(error.message, 'error'); }, + onSuccess: () => { + setNotification( + `${ucFunction} function successfully deleted`, + 'success', + ); + navigate(`/data/${catalog}/${schema}`); + }, }, ); - }, [mutation, ucFunction, setNotification]); + }, [mutation, ucFunction, setNotification, navigate]); return ( { - setNotification(`${schema} schema successfully deleted`, 'success'); - navigate(`/data/${catalog}`); - }, catalog, }); @@ -34,9 +30,13 @@ export function DeleteSchemaModal({ onError: (error: Error) => { setNotification(error.message, 'error'); }, + onSuccess: () => { + setNotification(`${schema} schema successfully deleted`, 'success'); + navigate(`/data/${catalog}`); + }, }, ); - }, [mutation, catalog, schema, setNotification]); + }, [mutation, catalog, schema, setNotification, navigate]); return ( { - setNotification(`${table} table successfully deleted`, 'success'); - navigate(`/data/${catalog}/${schema}`); - }, catalog, schema, }); @@ -34,11 +30,22 @@ export function DeleteTableModal({ [catalog, schema, table], ); const handleSubmit = useCallback(() => { - mutation.mutate({ - catalog_name: catalog, - schema_name: schema, - name: table, - }); + mutation.mutate( + { + catalog_name: catalog, + schema_name: schema, + name: table, + }, + { + onError: (error: Error) => { + setNotification(error.message, 'error'); + }, + onSuccess: () => { + setNotification(`${table} table successfully deleted`, 'success'); + navigate(`/data/${catalog}/${schema}`); + }, + }, + ); }, [mutation, catalog, schema, table]); return ( diff --git a/src/components/modals/DeleteVolumeModal.tsx b/src/components/modals/DeleteVolumeModal.tsx index b521c93..f3d709b 100644 --- a/src/components/modals/DeleteVolumeModal.tsx +++ b/src/components/modals/DeleteVolumeModal.tsx @@ -22,10 +22,6 @@ export function DeleteVolumeModal({ const navigate = useNavigate(); const { setNotification } = useNotification(); const mutation = useDeleteVolume({ - onSuccessCallback: () => { - setNotification(`${volume} volume successfully deleted`, 'success'); - navigate(`/data/${catalog}/${schema}`); - }, catalog, schema, }); @@ -37,9 +33,13 @@ export function DeleteVolumeModal({ onError: (error: Error) => { setNotification(error.message, 'error'); }, + onSuccess: () => { + setNotification(`${volume} volume successfully deleted`, 'success'); + navigate(`/data/${catalog}/${schema}`); + }, }, ); - }, [mutation, volume, setNotification]); + }, [mutation, volume, setNotification, navigate]); return ( {} -interface CreateCatalogParams { - onSuccessCallback?: (catalog: CatalogInterface) => void; -} - // Create a new catalog -export function useCreateCatalog({ - onSuccessCallback, -}: CreateCatalogParams = {}) { +export function useCreateCatalog() { const queryClient = useQueryClient(); - return useMutation({ + return useMutation({ mutationFn: async (params: CreateCatalogMutationParams) => { const response = await fetch(`${UC_API_PREFIX}/catalogs`, { method: 'POST', @@ -74,11 +68,10 @@ export function useCreateCatalog({ } return response.json(); }, - onSuccess: (catalog) => { + onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['listCatalogs'], }); - onSuccessCallback?.(catalog); }, }); } @@ -86,14 +79,8 @@ export function useCreateCatalog({ export interface DeleteCatalogMutationParams extends Pick {} -interface DeleteCatalogParams { - onSuccessCallback?: () => void; -} - // Delete a catalog -export function useDeleteCatalog({ - onSuccessCallback, -}: DeleteCatalogParams = {}) { +export function useDeleteCatalog() { const queryClient = useQueryClient(); return useMutation({ @@ -110,7 +97,6 @@ export function useDeleteCatalog({ queryClient.invalidateQueries({ queryKey: ['listCatalogs'], }); - onSuccessCallback?.(); }, }); } diff --git a/src/hooks/functions.tsx b/src/hooks/functions.tsx index 2cbf365..eef7cf4 100644 --- a/src/hooks/functions.tsx +++ b/src/hooks/functions.tsx @@ -81,17 +81,12 @@ export interface DeleteFunctionMutationParams extends Pick {} interface DeleteFunctionParams { - onSuccessCallback?: () => void; catalog: string; schema: string; } // Delete a function -export function useDeleteFunction({ - onSuccessCallback, - catalog, - schema, -}: DeleteFunctionParams) { +export function useDeleteFunction({ catalog, schema }: DeleteFunctionParams) { const queryClient = useQueryClient(); return useMutation({ @@ -118,7 +113,6 @@ export function useDeleteFunction({ queryClient.invalidateQueries({ queryKey: ['listFunctions', catalog, schema], }); - onSuccessCallback?.(); }, }); } diff --git a/src/hooks/schemas.tsx b/src/hooks/schemas.tsx index 0e768f2..c03b9d9 100644 --- a/src/hooks/schemas.tsx +++ b/src/hooks/schemas.tsx @@ -58,16 +58,10 @@ export function useGetSchema({ catalog, schema }: GetSchemaParams) { export interface CreateSchemaMutationParams extends Pick {} -interface CreateSchemaParams { - onSuccessCallback?: (catalog: SchemaInterface) => void; -} - -export function useCreateSchema({ - onSuccessCallback, -}: CreateSchemaParams = {}) { +export function useCreateSchema() { const queryClient = useQueryClient(); - return useMutation({ + return useMutation({ mutationFn: async (params: CreateSchemaMutationParams) => { const response = await fetch(`${UC_API_PREFIX}/schemas`, { method: 'POST', @@ -86,7 +80,6 @@ export function useCreateSchema({ queryClient.invalidateQueries({ queryKey: ['listSchemas', schema.catalog_name], }); - onSuccessCallback?.(schema); }, }); } @@ -95,14 +88,10 @@ export interface DeleteSchemaMutationParams extends Pick {} interface DeleteSchemaParams { - onSuccessCallback?: () => void; catalog: string; } -export function useDeleteSchema({ - onSuccessCallback, - catalog, -}: DeleteSchemaParams) { +export function useDeleteSchema({ catalog }: DeleteSchemaParams) { const queryClient = useQueryClient(); return useMutation({ @@ -122,7 +111,6 @@ export function useDeleteSchema({ queryClient.invalidateQueries({ queryKey: ['listSchemas', catalog], }); - onSuccessCallback?.(); }, }); } diff --git a/src/hooks/tables.tsx b/src/hooks/tables.tsx index 89f41f6..b1ff716 100644 --- a/src/hooks/tables.tsx +++ b/src/hooks/tables.tsx @@ -76,19 +76,14 @@ export interface DeleteTableMutationParams extends Pick {} interface DeleteTableParams { - onSuccessCallback?: () => void; catalog: string; schema: string; } -export function useDeleteTable({ - onSuccessCallback, - catalog, - schema, -}: DeleteTableParams) { +export function useDeleteTable({ catalog, schema }: DeleteTableParams) { const queryClient = useQueryClient(); - return useMutation({ + return useMutation({ mutationFn: async ({ catalog_name, schema_name, @@ -111,7 +106,6 @@ export function useDeleteTable({ queryClient.invalidateQueries({ queryKey: ['listTables', catalog, schema], }); - onSuccessCallback?.(); }, }); } diff --git a/src/hooks/volumes.tsx b/src/hooks/volumes.tsx index 6a63e4e..dbfb853 100644 --- a/src/hooks/volumes.tsx +++ b/src/hooks/volumes.tsx @@ -74,17 +74,12 @@ export interface DeleteVolumeMutationParams extends Pick {} interface DeleteVolumeParams { - onSuccessCallback?: () => void; catalog: string; schema: string; } // Delete a volume -export function useDeleteVolume({ - onSuccessCallback, - catalog, - schema, -}: DeleteVolumeParams) { +export function useDeleteVolume({ catalog, schema }: DeleteVolumeParams) { const queryClient = useQueryClient(); return useMutation({ @@ -111,7 +106,6 @@ export function useDeleteVolume({ queryClient.invalidateQueries({ queryKey: ['listVolumes', catalog, schema], }); - onSuccessCallback?.(); }, }); }