diff --git a/odd-platform-ui/src/components/Management/Integrations/IntegrationPreviewList/IntegrationPreviewList.tsx b/odd-platform-ui/src/components/Management/Integrations/IntegrationPreviewList/IntegrationPreviewList.tsx index d244f0c94..4e1bb7cd6 100644 --- a/odd-platform-ui/src/components/Management/Integrations/IntegrationPreviewList/IntegrationPreviewList.tsx +++ b/odd-platform-ui/src/components/Management/Integrations/IntegrationPreviewList/IntegrationPreviewList.tsx @@ -26,7 +26,7 @@ const IntegrationPreviewList: FC = () => { const filteredIntegrations = data?.items.filter(integration => integration.name.toLowerCase().includes(query.toLowerCase()) - ) || []; + ) ?? []; return ( diff --git a/odd-platform-ui/src/lib/hooks/api/dataEntity.ts b/odd-platform-ui/src/lib/hooks/api/dataEntity.ts index c5d221355..89d77a7c7 100644 --- a/odd-platform-ui/src/lib/hooks/api/dataEntity.ts +++ b/odd-platform-ui/src/lib/hooks/api/dataEntity.ts @@ -24,7 +24,7 @@ export function useDataEntityMetrics({ }: UseDataEntityMetricsProps) { return useQuery({ queryKey: ['dataEntityMetrics', dataEntityId], - queryFn: () => + queryFn: async () => dataEntityApi.getDataEntityMetrics({ dataEntityId }).catch(err => { showServerErrorToast(err as Response, { additionalMessage: 'while loading metrics', @@ -143,12 +143,9 @@ export function useGetDataEntityGroupItems({ } export function useUpdateDataEntityStatus() { - return useMutation( - (params: DataEntityApiUpdateStatusRequest) => dataEntityApi.updateStatus(params), - { - onSuccess: () => { - showSuccessToast({ message: 'Status successfully updated!' }); - }, - } - ); + return useMutation({ + mutationFn: async (params: DataEntityApiUpdateStatusRequest) => + dataEntityApi.updateStatus(params), + onSuccess: () => showSuccessToast({ message: 'Status successfully updated!' }), + }); } diff --git a/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityFiles.ts b/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityFiles.ts index 0d2c4e553..cc3507b2c 100644 --- a/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityFiles.ts +++ b/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityFiles.ts @@ -52,8 +52,8 @@ interface UseSaveDataEntityFileParams { export function useSaveDataEntityFile() { const client = useQueryClient(); - return useMutation( - async ({ dataEntityId, file }: UseSaveDataEntityFileParams) => { + return useMutation({ + mutationFn: async ({ dataEntityId, file }: UseSaveDataEntityFileParams) => { const dataEntityUploadFormData = { fileName: file.name }; const initialUploadParams = { dataEntityId, dataEntityUploadFormData }; const { id: uploadId } = await dataEntityAttachmentApi.initiateFileUpload( @@ -74,13 +74,11 @@ export function useSaveDataEntityFile() { uploadId, }); }, - { - onSuccess: () => { - showSuccessToast({ message: 'File successfully saved!' }); - client.invalidateQueries(['dataEntityAttachments']); - }, - } - ); + onSuccess: async () => { + showSuccessToast({ message: 'File successfully saved!' }); + await client.invalidateQueries(['dataEntityAttachments']); + }, + }); } export function useDownloadDataEntityFile({ @@ -97,16 +95,14 @@ export function useDownloadDataEntityFile({ export function useDeleteDataEntityFile() { const client = useQueryClient(); - return useMutation( - (params: DataEntityAttachmentApiDeleteFileRequest) => + return useMutation({ + mutationFn: (params: DataEntityAttachmentApiDeleteFileRequest) => dataEntityAttachmentApi.deleteFile(params), - { - onSuccess: () => { - showSuccessToast({ message: 'File successfully deleted!' }); - client.invalidateQueries(['dataEntityAttachments']); - }, - } - ); + onSuccess: async () => { + showSuccessToast({ message: 'File successfully deleted!' }); + await client.invalidateQueries(['dataEntityAttachments']); + }, + }); } export function useGetUploadOptions({ diff --git a/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityLinks.ts b/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityLinks.ts index 03eed98dd..3056fb348 100644 --- a/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityLinks.ts +++ b/odd-platform-ui/src/lib/hooks/api/dataEntityAttachments/dataEntityLinks.ts @@ -19,56 +19,48 @@ export function useDataEntityAttachments({ DataEntityAttachments, ErrorState, Array - >( - ['dataEntityAttachments'], - () => dataEntityAttachmentApi.getAttachments({ dataEntityId }), - { - select: data => [...data.files, ...data.links], - } - ); + >({ + queryKey: ['dataEntityAttachments'], + queryFn: () => dataEntityAttachmentApi.getAttachments({ dataEntityId }), + select: data => [...data.files, ...data.links], + }); } export function useSaveDataEntityLinks() { const client = useQueryClient(); - return useMutation( - (params: DataEntityAttachmentApiSaveLinksRequest) => - dataEntityAttachmentApi.saveLinks(params), - { - onSuccess: () => { - showSuccessToast({ message: 'Links successfully saved!' }); - client.invalidateQueries(['dataEntityAttachments']); - }, - } - ); + return useMutation({ + mutationFn: async (params: DataEntityAttachmentApiSaveLinksRequest) => + await dataEntityAttachmentApi.saveLinks(params), + onSuccess: async () => { + showSuccessToast({ message: 'Links successfully saved!' }); + await client.invalidateQueries(['dataEntityAttachments']); + }, + }); } export function useUpdateDataEntityLink() { const client = useQueryClient(); - return useMutation( - (params: DataEntityAttachmentApiUpdateLinkRequest) => - dataEntityAttachmentApi.updateLink(params), - { - onSuccess: () => { - showSuccessToast({ message: 'Link successfully updated!' }); - client.invalidateQueries(['dataEntityAttachments']); - }, - } - ); + return useMutation({ + mutationFn: async (params: DataEntityAttachmentApiUpdateLinkRequest) => + await dataEntityAttachmentApi.updateLink(params), + onSuccess: async () => { + showSuccessToast({ message: 'Link successfully updated!' }); + await client.invalidateQueries(['dataEntityAttachments']); + }, + }); } export function useDeleteDataEntityLink() { const client = useQueryClient(); - return useMutation( - (params: DataEntityAttachmentApiDeleteLinkRequest) => + return useMutation({ + mutationFn: (params: DataEntityAttachmentApiDeleteLinkRequest) => dataEntityAttachmentApi.deleteLink(params), - { - onSuccess: () => { - showSuccessToast({ message: 'Link successfully deleted!' }); - client.invalidateQueries(['dataEntityAttachments']); - }, - } - ); + onSuccess: async () => { + showSuccessToast({ message: 'Link successfully deleted!' }); + await client.invalidateQueries(['dataEntityAttachments']); + }, + }); } diff --git a/odd-platform-ui/src/lib/hooks/api/datasetField.ts b/odd-platform-ui/src/lib/hooks/api/datasetField.ts index 46e48248c..64c0406fa 100644 --- a/odd-platform-ui/src/lib/hooks/api/datasetField.ts +++ b/odd-platform-ui/src/lib/hooks/api/datasetField.ts @@ -13,12 +13,12 @@ interface UseDataEntityMetricsProps { export function useDataSetFieldMetrics({ datasetFieldId }: UseDataEntityMetricsProps) { return useQuery({ queryKey: ['dataSetFieldMetrics', datasetFieldId], - queryFn: () => - datasetFieldApiClient.getDatasetFieldMetrics({ datasetFieldId }).catch(err => { - showServerErrorToast(err as Response, { - additionalMessage: 'while loading field metrics', - }); - }), + queryFn: async () => + datasetFieldApiClient + .getDatasetFieldMetrics({ datasetFieldId }) + .catch((err: Response) => { + showServerErrorToast(err, { additionalMessage: 'while loading field metrics' }); + }), retry: false, refetchOnWindowFocus: false, }); @@ -30,43 +30,31 @@ interface UseAddDatasetFieldTermParams { } export function useAddDatasetFieldTerm() { - return useMutation( - ({ datasetFieldId, termId }: UseAddDatasetFieldTermParams) => { - const params = { datasetFieldId, datasetFieldTermFormData: { termId } }; - - return datasetFieldApiClient.addDatasetFieldTerm(params); - }, - { - onSuccess: () => { - showSuccessToast({ message: 'Term successfully added!' }); - }, - } - ); + return useMutation({ + mutationFn: async ({ termId, datasetFieldId }: UseAddDatasetFieldTermParams) => + datasetFieldApiClient.addDatasetFieldTerm({ + datasetFieldId, + datasetFieldTermFormData: { termId }, + }), + onSuccess: () => showSuccessToast({ message: 'Term successfully added!' }), + }); } export function useDeleteDatasetFieldTerm() { - return useMutation( - async (params: DatasetFieldApiDeleteTermFromDatasetFieldRequest) => { + return useMutation({ + mutationFn: async (params: DatasetFieldApiDeleteTermFromDatasetFieldRequest) => { await datasetFieldApiClient.deleteTermFromDatasetField(params); return params.termId; }, - { - onSuccess: () => { - showSuccessToast({ message: 'Term successfully deleted!' }); - }, - } - ); + onSuccess: () => showSuccessToast({ message: 'Term successfully deleted!' }), + }); } export function useUpdateDatasetFieldInternalName() { - return useMutation( - async (params: DatasetFieldApiUpdateDatasetFieldInternalNameRequest) => + return useMutation({ + mutationFn: async (params: DatasetFieldApiUpdateDatasetFieldInternalNameRequest) => datasetFieldApiClient.updateDatasetFieldInternalName(params), - { - onSuccess: () => { - showSuccessToast({ message: 'Internal name successfully updated!' }); - }, - } - ); + onSuccess: () => showSuccessToast({ message: 'Internal name successfully updated!' }), + }); } diff --git a/odd-platform-ui/src/lib/hooks/api/integration.ts b/odd-platform-ui/src/lib/hooks/api/integration.ts index ebf78e0e8..9954a8488 100644 --- a/odd-platform-ui/src/lib/hooks/api/integration.ts +++ b/odd-platform-ui/src/lib/hooks/api/integration.ts @@ -13,33 +13,34 @@ export function useIntegrationPreviews() { { items: GeneratedIntegrationPreview[] }, ErrorState, { items: IntegrationPreview[] } - >(['integrationPreviews'], () => integrationApi.getIntegrationPreviews()); + >({ + queryKey: ['integrationPreviews'], + queryFn: () => integrationApi.getIntegrationPreviews(), + }); } export function useIntegration({ integrationId }: IntegrationApiGetIntegrationRequest) { - return useQuery( - ['integration', integrationId], - () => integrationApi.getIntegration({ integrationId }), - { - select: ({ id, installed, name, description, contentBlocks }) => { - const contentByTitle = contentBlocks.reduce( - (memo, block) => { - const lowerCasedTitle = block.title.toLowerCase(); + return useQuery({ + queryKey: ['integration', integrationId], + queryFn: () => integrationApi.getIntegration({ integrationId }), + select: ({ id, installed, name, description, contentBlocks }) => { + const contentByTitle = contentBlocks.reduce( + (memo, block) => { + const lowerCasedTitle = block.title.toLowerCase(); - return { - ...memo, - [lowerCasedTitle]: { - ...memo[lowerCasedTitle], - content: block.content, - codeSnippets: block.codeSnippets, - }, - }; - }, - {} - ); + return { + ...memo, + [lowerCasedTitle]: { + ...memo[lowerCasedTitle], + content: block.content, + codeSnippets: block.codeSnippets, + }, + }; + }, + {} + ); - return { id: id as DatasourceName, name, description, installed, contentByTitle }; - }, - } - ); + return { id: id as DatasourceName, name, description, installed, contentByTitle }; + }, + }); }