);
}
function getOwnershipTooltip(
ownership: ResourceControlOwnership,
resourceName: string
) {
switch (ownership) {
case ResourceControlOwnership.PRIVATE:
return `Management of this ${resourceName} is restricted to a single user.`;
case ResourceControlOwnership.RESTRICTED:
return `This ${resourceName} can be managed by a restricted set of users and/or teams.`;
case ResourceControlOwnership.PUBLIC:
return `This ${resourceName} can be managed by any user with access to this environment.`;
case ResourceControlOwnership.ADMINISTRATORS:
default:
return `This ${resourceName} can only be managed by administrators.`;
}
}
function getInheritanceMessage(
resourceType: ResourceControlType | undefined,
resourceControl?: ResourceControlViewModel
) {
if (!resourceControl || resourceControl.Type === resourceType) {
return null;
}
const parentType = resourceControl.Type;
const resourceId = resourceControl.ResourceId;
if (
resourceType === ResourceControlType.Container &&
parentType === ResourceControlType.Service
) {
return (
Access control on this resource is inherited from the following service:
{truncate(resourceId)}
);
}
if (
resourceType === ResourceControlType.Volume &&
parentType === ResourceControlType.Container
) {
return (
Access control on this resource is inherited from the following
container:
{truncate(resourceId)}
);
}
if (parentType === ResourceControlType.Stack) {
return (
Access control on this resource is inherited from the following stack:
{removeEndpointIdFromStackResourceId(resourceId)}
);
}
return null;
}
function removeEndpointIdFromStackResourceId(stackName: ResourceId) {
if (!stackName || typeof stackName !== 'string') {
return stackName;
}
const firstUnderlineIndex = stackName.indexOf('_');
if (firstUnderlineIndex < 0) {
return stackName;
}
return stackName.substring(firstUnderlineIndex + 1);
}
interface InheritanceMessageProps {
tooltip: string;
}
function InheritanceMessage({
children,
tooltip,
}: PropsWithChildren) {
return (