mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
refactor(app): add rq mutation helpers [EE-3176] (#6923)
This commit is contained in:
parent
b01180bb29
commit
0ffb84aaa6
2 changed files with 102 additions and 43 deletions
|
@ -1,37 +1,18 @@
|
|||
import { ReactQueryDevtools } from 'react-query/devtools';
|
||||
import {
|
||||
MutationCache,
|
||||
QueryCache,
|
||||
QueryClient,
|
||||
QueryClientProvider,
|
||||
} from 'react-query';
|
||||
import { QueryClientProvider } from 'react-query';
|
||||
import { UIRouterContextComponent } from '@uirouter/react-hybrid';
|
||||
import { PropsWithChildren, StrictMode, useState, useEffect } from 'react';
|
||||
import { PropsWithChildren, StrictMode } from 'react';
|
||||
|
||||
import { UserProvider } from '@/portainer/hooks/useUser';
|
||||
import { UIStateProvider } from '@/portainer/hooks/UIStateProvider';
|
||||
import { notifyError } from '@/portainer/services/notifications';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
mutationCache: new MutationCache({
|
||||
onError: (error, variable, context, mutation) => {
|
||||
handleError(error, mutation.meta?.error);
|
||||
},
|
||||
}),
|
||||
queryCache: new QueryCache({
|
||||
onError: (error, mutation) => {
|
||||
handleError(error, mutation.meta?.error);
|
||||
},
|
||||
}),
|
||||
});
|
||||
import { createQueryClient } from './react-query';
|
||||
|
||||
const queryClient = createQueryClient();
|
||||
|
||||
export function RootProvider({ children }: PropsWithChildren<unknown>) {
|
||||
const [showReactQueryDevtools, setShowReactQueryDevtools] = useState(false);
|
||||
useEffect(() => {
|
||||
if (process.env.SHOW_REACT_QUERY_DEV_TOOLS === 'true') {
|
||||
setShowReactQueryDevtools(true);
|
||||
}
|
||||
}, []);
|
||||
const showReactQueryDevtools =
|
||||
process.env.SHOW_REACT_QUERY_DEV_TOOLS === 'true';
|
||||
|
||||
return (
|
||||
<StrictMode>
|
||||
|
@ -46,20 +27,3 @@ export function RootProvider({ children }: PropsWithChildren<unknown>) {
|
|||
</StrictMode>
|
||||
);
|
||||
}
|
||||
|
||||
function handleError(error: unknown, errorMeta?: unknown) {
|
||||
if (errorMeta && typeof errorMeta === 'object') {
|
||||
if (!('title' in errorMeta)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { title, message } = errorMeta as {
|
||||
title: unknown;
|
||||
message?: unknown;
|
||||
};
|
||||
|
||||
if (typeof title === 'string') {
|
||||
notifyError(title, error as Error, message as string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue