1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

refactor(access-control): create access-control-panel component [EE-2345] (#6486)

This commit is contained in:
Chaim Lev-Ari 2022-03-16 08:35:32 +02:00 committed by GitHub
parent 07294c19bb
commit f63b07bbb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 2053 additions and 1518 deletions

View file

@ -1,12 +1,29 @@
import { ReactQueryDevtools } from 'react-query/devtools';
import { QueryClient, QueryClientProvider } from 'react-query';
import {
MutationCache,
QueryCache,
QueryClient,
QueryClientProvider,
} from 'react-query';
import { UIRouterContextComponent } from '@uirouter/react-hybrid';
import { PropsWithChildren, StrictMode, useState, useEffect } from 'react';
import { UserProvider } from '@/portainer/hooks/useUser';
import { UIStateProvider } from '@/portainer/hooks/UIStateProvider';
import { notifyError } from '@/portainer/services/notifications';
const queryClient = new QueryClient();
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);
},
}),
});
export function RootProvider({ children }: PropsWithChildren<unknown>) {
const [showReactQueryDevtools, setShowReactQueryDevtools] = useState(false);
@ -29,3 +46,20 @@ 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);
}
}
}