Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function InclusionScopeCard({
scope.namespaceLabel ? 'label' : 'name'
);

const clusterName = clusters.find((cluster) => cluster.id === scope.cluster)?.name;

const clusterOptions: TypeaheadSelectOption[] = clusters.map((cluster) => ({
value: cluster.id,
label: cluster.name,
Expand All @@ -60,7 +62,12 @@ function InclusionScopeCard({
}

return (
<PolicyScopeCardBase title="Inclusion scope" onDelete={onDelete}>
<PolicyScopeCardBase
title="Inclusion scope"
onDelete={onDelete}
scope={scope}
clusterName={clusterName}
>
<Form>
<FormGroup label="Cluster" role="radiogroup">
<Flex direction={{ default: 'row' }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
import type { ReactElement, ReactNode } from 'react';
import { Button, Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core';
import {
Button,
Card,
CardBody,
CardFooter,
CardHeader,
CardTitle,
CodeBlock,
CodeBlockCode,
} from '@patternfly/react-core';
import { TrashIcon } from '@patternfly/react-icons';
import type { PolicyScope } from 'types/policy.proto';

type PolicyScopeCardBaseProps = {
title: string;
onDelete: () => void;
children: ReactNode;
scope: PolicyScope | undefined;
clusterName?: string;
};

function PolicyScopeCardBase({
title,
onDelete,
scope,
clusterName,
children,
}: PolicyScopeCardBaseProps): ReactElement {
let clusterDisplay = 'Cluster: all';
if (scope?.clusterLabel?.key) {
const { key, value } = scope.clusterLabel;
clusterDisplay = `Cluster label: ${key}${value ? `=${value}` : ''}`;
} else if (scope?.cluster) {
clusterDisplay = `Cluster: ${clusterName ?? scope.cluster}`;
}

let namespaceDisplay = 'Namespace: all';
if (scope?.namespaceLabel?.key) {
const { key, value } = scope.namespaceLabel;
namespaceDisplay = `Namespace label: ${key}${value ? `=${value}` : ''}`;
} else if (scope?.namespace) {
namespaceDisplay = `Namespace: ${scope.namespace}`;
}

let deploymentDisplay = 'Deployment: all';
if (scope?.label) {
const { label } = scope;
deploymentDisplay = `Deployment label: ${label.key}${label.value ? `=${label.value}` : ''}`;
}

return (
<Card isCompact>
<CardHeader
Expand All @@ -27,6 +63,18 @@ function PolicyScopeCardBase({
<CardTitle>{title}</CardTitle>
</CardHeader>
<CardBody>{children}</CardBody>
<CardFooter>
Applies to:
<CodeBlock>
<CodeBlockCode>
{[
`(${clusterDisplay})`,
`AND (${namespaceDisplay})`,
`AND (${deploymentDisplay})`,
].join('\n')}
</CodeBlockCode>
</CodeBlock>
</CardFooter>
</Card>
);
}
Expand Down
Loading