You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/hooks/useEnvironmentId.ts

26 lines
679 B

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);
}