mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 06:19:41 +02:00
fix showing namespaces for standard user (#7917)
This commit is contained in:
parent
446febb0f6
commit
a550bfaedb
6 changed files with 77 additions and 7 deletions
|
@ -2,13 +2,29 @@ import { useQuery } from 'react-query';
|
|||
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
import { error as notifyError } from '@/portainer/services/notifications';
|
||||
import { getIngresses } from '@/kubernetes/react/views/networks/ingresses/service';
|
||||
|
||||
import { getNamespaces, getNamespace } from './service';
|
||||
import { Namespaces } from './types';
|
||||
|
||||
export function useNamespaces(environmentId: EnvironmentId) {
|
||||
return useQuery(
|
||||
['environments', environmentId, 'kubernetes', 'namespaces'],
|
||||
() => getNamespaces(environmentId),
|
||||
async () => {
|
||||
const namespaces = await getNamespaces(environmentId);
|
||||
const settledNamespacesPromise = await Promise.allSettled(
|
||||
Object.keys(namespaces).map((namespace) =>
|
||||
getIngresses(environmentId, namespace).then(() => namespace)
|
||||
)
|
||||
);
|
||||
const ns: Namespaces = {};
|
||||
settledNamespacesPromise.forEach((namespace) => {
|
||||
if (namespace.status === 'fulfilled') {
|
||||
ns[namespace.value] = namespaces[namespace.value];
|
||||
}
|
||||
});
|
||||
return ns;
|
||||
},
|
||||
{
|
||||
onError: (err) => {
|
||||
notifyError('Failure', err as Error, 'Unable to get namespaces.');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue