mirror of https://github.com/portainer/portainer
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { useQuery } from 'react-query';
|
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
import { error as notifyError } from '@/portainer/services/notifications';
|
|
import { withError } from '@/react-tools/react-query';
|
|
|
|
import { getConfigurations, getConfigMapsForCluster } from './service';
|
|
|
|
// returns a usequery hook for the formatted list of configmaps and secrets
|
|
export function useConfigurations(
|
|
environmentId: EnvironmentId,
|
|
namespace?: string
|
|
) {
|
|
return useQuery(
|
|
[
|
|
'environments',
|
|
environmentId,
|
|
'kubernetes',
|
|
'namespaces',
|
|
namespace,
|
|
'configurations',
|
|
],
|
|
() => (namespace ? getConfigurations(environmentId, namespace) : []),
|
|
{
|
|
onError: (err) => {
|
|
notifyError('Failure', err as Error, 'Unable to get configurations');
|
|
},
|
|
enabled: !!namespace,
|
|
}
|
|
);
|
|
}
|
|
|
|
export function useConfigurationsForCluster(
|
|
environemtId: EnvironmentId,
|
|
namespaces?: string[]
|
|
) {
|
|
return useQuery(
|
|
['environments', environemtId, 'kubernetes', 'configmaps'],
|
|
() => namespaces && getConfigMapsForCluster(environemtId, namespaces),
|
|
{
|
|
...withError('Unable to retrieve applications'),
|
|
enabled: !!namespaces,
|
|
}
|
|
);
|
|
}
|