Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
remove all onSuccessCallback params
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieknight-db committed Aug 8, 2024
1 parent c8d6ec6 commit 57b827f
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 98 deletions.
17 changes: 11 additions & 6 deletions src/components/modals/CreateCatalogModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<HTMLButtonElement>(null);

const handleSubmit = useCallback(() => {
Expand All @@ -45,7 +43,14 @@ export function CreateCatalogModal({
<Form<CreateCatalogMutationParams>
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"
>
Expand Down
17 changes: 11 additions & 6 deletions src/components/modals/CreateSchemaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CreateSchemaMutationParams,
useCreateSchema,
} from '../../hooks/schemas';
import { useNotification } from '../../utils/NotificationContext';

interface CreateSchemaModalProps {
open: boolean;
Expand All @@ -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<HTMLButtonElement>(null);

const handleSubmit = useCallback(() => {
Expand All @@ -47,7 +45,14 @@ export default function CreateSchemaModal({
<Form<CreateSchemaMutationParams>
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 }}
Expand Down
13 changes: 6 additions & 7 deletions src/components/modals/DeleteCatalogModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 (
<Modal
Expand Down
13 changes: 8 additions & 5 deletions src/components/modals/DeleteFunctionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export function DeleteFunctionModal({
const navigate = useNavigate();
const { setNotification } = useNotification();
const mutation = useDeleteFunction({
onSuccessCallback: () => {
setNotification(`${ucFunction} function successfully deleted`, 'success');
navigate(`/data/${catalog}/${schema}`);
},
catalog,
schema,
});
Expand All @@ -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]);

Check warning on line 45 in src/components/modals/DeleteFunctionModal.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'catalog' and 'schema'. Either include them or remove the dependency array

return (
<Modal
Expand Down
10 changes: 5 additions & 5 deletions src/components/modals/DeleteSchemaModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export function DeleteSchemaModal({
const navigate = useNavigate();
const { setNotification } = useNotification();
const mutation = useDeleteSchema({
onSuccessCallback: () => {
setNotification(`${schema} schema successfully deleted`, 'success');
navigate(`/data/${catalog}`);
},
catalog,
});

Expand All @@ -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 (
<Modal
Expand Down
25 changes: 16 additions & 9 deletions src/components/modals/DeleteTableModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export function DeleteTableModal({
const navigate = useNavigate();
const { setNotification } = useNotification();
const mutation = useDeleteTable({
onSuccessCallback: () => {
setNotification(`${table} table successfully deleted`, 'success');
navigate(`/data/${catalog}/${schema}`);
},
catalog,
schema,
});
Expand All @@ -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]);

Check warning on line 49 in src/components/modals/DeleteTableModal.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'navigate' and 'setNotification'. Either include them or remove the dependency array

return (
Expand Down
10 changes: 5 additions & 5 deletions src/components/modals/DeleteVolumeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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]);

Check warning on line 42 in src/components/modals/DeleteVolumeModal.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has missing dependencies: 'catalog' and 'schema'. Either include them or remove the dependency array

return (
<Modal
Expand Down
22 changes: 4 additions & 18 deletions src/hooks/catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ export function useGetCatalog({ catalog }: GetCatalogParams) {
export interface CreateCatalogMutationParams
extends Pick<CatalogInterface, 'name' | 'comment'> {}

interface CreateCatalogParams {
onSuccessCallback?: (catalog: CatalogInterface) => void;
}

// Create a new catalog
export function useCreateCatalog({
onSuccessCallback,
}: CreateCatalogParams = {}) {
export function useCreateCatalog() {
const queryClient = useQueryClient();

return useMutation<CatalogInterface, unknown, CreateCatalogMutationParams>({
return useMutation<CatalogInterface, Error, CreateCatalogMutationParams>({
mutationFn: async (params: CreateCatalogMutationParams) => {
const response = await fetch(`${UC_API_PREFIX}/catalogs`, {
method: 'POST',
Expand All @@ -74,26 +68,19 @@ export function useCreateCatalog({
}
return response.json();
},
onSuccess: (catalog) => {
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['listCatalogs'],
});
onSuccessCallback?.(catalog);
},
});
}

export interface DeleteCatalogMutationParams
extends Pick<CatalogInterface, 'name'> {}

interface DeleteCatalogParams {
onSuccessCallback?: () => void;
}

// Delete a catalog
export function useDeleteCatalog({
onSuccessCallback,
}: DeleteCatalogParams = {}) {
export function useDeleteCatalog() {
const queryClient = useQueryClient();

return useMutation<void, Error, DeleteCatalogMutationParams>({
Expand All @@ -110,7 +97,6 @@ export function useDeleteCatalog({
queryClient.invalidateQueries({
queryKey: ['listCatalogs'],
});
onSuccessCallback?.();
},
});
}
8 changes: 1 addition & 7 deletions src/hooks/functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,12 @@ export interface DeleteFunctionMutationParams
extends Pick<FunctionInterface, 'catalog_name' | 'schema_name' | 'name'> {}

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<void, Error, DeleteFunctionMutationParams>({
Expand All @@ -118,7 +113,6 @@ export function useDeleteFunction({
queryClient.invalidateQueries({
queryKey: ['listFunctions', catalog, schema],
});
onSuccessCallback?.();
},
});
}
18 changes: 3 additions & 15 deletions src/hooks/schemas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ export function useGetSchema({ catalog, schema }: GetSchemaParams) {
export interface CreateSchemaMutationParams
extends Pick<SchemaInterface, 'name' | 'catalog_name' | 'comment'> {}

interface CreateSchemaParams {
onSuccessCallback?: (catalog: SchemaInterface) => void;
}

export function useCreateSchema({
onSuccessCallback,
}: CreateSchemaParams = {}) {
export function useCreateSchema() {
const queryClient = useQueryClient();

return useMutation<SchemaInterface, unknown, CreateSchemaMutationParams>({
return useMutation<SchemaInterface, Error, CreateSchemaMutationParams>({
mutationFn: async (params: CreateSchemaMutationParams) => {
const response = await fetch(`${UC_API_PREFIX}/schemas`, {
method: 'POST',
Expand All @@ -86,7 +80,6 @@ export function useCreateSchema({
queryClient.invalidateQueries({
queryKey: ['listSchemas', schema.catalog_name],
});
onSuccessCallback?.(schema);
},
});
}
Expand All @@ -95,14 +88,10 @@ export interface DeleteSchemaMutationParams
extends Pick<SchemaInterface, 'catalog_name' | 'name'> {}

interface DeleteSchemaParams {
onSuccessCallback?: () => void;
catalog: string;
}

export function useDeleteSchema({
onSuccessCallback,
catalog,
}: DeleteSchemaParams) {
export function useDeleteSchema({ catalog }: DeleteSchemaParams) {
const queryClient = useQueryClient();

return useMutation<void, Error, DeleteSchemaMutationParams>({
Expand All @@ -122,7 +111,6 @@ export function useDeleteSchema({
queryClient.invalidateQueries({
queryKey: ['listSchemas', catalog],
});
onSuccessCallback?.();
},
});
}
10 changes: 2 additions & 8 deletions src/hooks/tables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,14 @@ export interface DeleteTableMutationParams
extends Pick<TableInterface, 'catalog_name' | 'schema_name' | 'name'> {}

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<void, unknown, DeleteTableMutationParams>({
return useMutation<void, Error, DeleteTableMutationParams>({
mutationFn: async ({
catalog_name,
schema_name,
Expand All @@ -111,7 +106,6 @@ export function useDeleteTable({
queryClient.invalidateQueries({
queryKey: ['listTables', catalog, schema],
});
onSuccessCallback?.();
},
});
}
Loading

0 comments on commit 57b827f

Please sign in to comment.