1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 05:19:39 +02:00
portainer/app/react/hooks/useEnvironmentId.ts
Ali 32e94d4e4e
Some checks failed
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
feat(podman): support add podman envs in the wizard [r8s-20] (#12056)
2024-09-25 11:55:07 +12:00

25 lines
679 B
TypeScript

import { useCurrentStateAndParams } from '@uirouter/react';
import { EnvironmentId } from '@/react/portainer/environments/types';
/**
* useEnvironmentId is a hook that returns the environmentId from the url params.
* use only when endpointId is set in the path.
* for example: /kubernetes/clusters/:endpointId
* for `:id` paths, use a different hook
*/
export function useEnvironmentId(force = true): EnvironmentId {
const {
params: { endpointId: environmentId },
} = useCurrentStateAndParams();
if (!environmentId) {
if (!force) {
return 0;
}
throw new Error('endpointId url param is required');
}
return parseInt(environmentId, 10);
}