refactor(ui): use external/system badge where applicable [EE-6952] (#11475)

pull/11453/head
Chaim Lev-Ari 2024-04-10 08:56:02 +03:00 committed by GitHub
parent 0b62456236
commit 3cad13388c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 49 additions and 76 deletions

View File

@ -6,6 +6,7 @@ import { getValueAsArrayOfStrings } from '@/portainer/helpers/array';
import { ImagesListResponse } from '@/react/docker/images/queries/useImages'; import { ImagesListResponse } from '@/react/docker/images/queries/useImages';
import { MultipleSelectionFilter } from '@@/datatables/Filter'; import { MultipleSelectionFilter } from '@@/datatables/Filter';
import { UnusedBadge } from '@@/Badge/UnusedBadge';
import { columnHelper } from './helper'; import { columnHelper } from './helper';
@ -76,9 +77,7 @@ function Cell({
<a href={linkProps.href} onClick={linkProps.onClick} title={name}> <a href={linkProps.href} onClick={linkProps.onClick} title={name}>
{truncate(name, 40)} {truncate(name, 40)}
</a> </a>
{!image.used && ( {!image.used && <UnusedBadge />}
<span className="label label-warning image-tag ml-2">Unused</span>
)}
</> </>
); );
} }

View File

@ -8,6 +8,7 @@ import { Authorized } from '@/react/hooks/useUser';
import { Button } from '@@/buttons'; import { Button } from '@@/buttons';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { MultipleSelectionFilter } from '@@/datatables/Filter'; import { MultipleSelectionFilter } from '@@/datatables/Filter';
import { UnusedBadge } from '@@/Badge/UnusedBadge';
import { DecoratedVolume } from '../../types'; import { DecoratedVolume } from '../../types';
import { getTableMeta } from '../tableMeta'; import { getTableMeta } from '../tableMeta';
@ -76,7 +77,7 @@ function Cell({
const name = getValue(); const name = getValue();
return ( return (
<> <div className="flex gap-2">
<Link <Link
to=".volume" to=".volume"
params={{ params={{
@ -107,11 +108,7 @@ function Cell({
</Button> </Button>
</Authorized> </Authorized>
)} )}
{item.dangling && ( {item.dangling && <UnusedBadge />}
<span className="label label-warning image-tag ml-2" role="status"> </div>
Unused
</span>
)}
</>
); );
} }

View File

@ -10,13 +10,14 @@ import { usePublicSettings } from '@/react/portainer/settings/queries';
import { GlobalDeploymentOptions } from '@/react/portainer/settings/types'; import { GlobalDeploymentOptions } from '@/react/portainer/settings/types';
import { DetailsTable } from '@@/DetailsTable'; import { DetailsTable } from '@@/DetailsTable';
import { Badge } from '@@/Badge';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { LoadingButton } from '@@/buttons'; import { LoadingButton } from '@@/buttons';
import { WidgetBody, Widget } from '@@/Widget'; import { WidgetBody, Widget } from '@@/Widget';
import { InlineLoader } from '@@/InlineLoader'; import { InlineLoader } from '@@/InlineLoader';
import { Icon } from '@@/Icon'; import { Icon } from '@@/Icon';
import { Note } from '@@/Note'; import { Note } from '@@/Note';
import { ExternalBadge } from '@@/Badge/ExternalBadge';
import { SystemBadge } from '@@/Badge/SystemBadge';
import { import {
appStackNameLabel, appStackNameLabel,
@ -127,7 +128,7 @@ export function ApplicationSummaryWidget() {
> >
{name} {name}
{externalApplication && !isSystemNamespace && ( {externalApplication && !isSystemNamespace && (
<Badge type="info">external</Badge> <ExternalBadge />
)} )}
</div> </div>
</td> </td>
@ -156,7 +157,7 @@ export function ApplicationSummaryWidget() {
> >
{namespace} {namespace}
</Link> </Link>
{isSystemNamespace && <Badge type="info">system</Badge>} {isSystemNamespace && <SystemBadge />}
</div> </div>
</td> </td>
</tr> </tr>

View File

@ -4,6 +4,7 @@ import KubernetesApplicationHelper from '@/kubernetes/helpers/application';
import KubernetesNamespaceHelper from '@/kubernetes/helpers/namespaceHelper'; import KubernetesNamespaceHelper from '@/kubernetes/helpers/namespaceHelper';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { ExternalBadge } from '@@/Badge/ExternalBadge';
import { KubernetesStack } from '../../types'; import { KubernetesStack } from '../../types';
@ -26,6 +27,7 @@ export function SubRows({
> >
<td /> <td />
<td colSpan={span - 1}> <td colSpan={span - 1}>
<div className="flex gap-2">
<Link <Link
to="kubernetes.applications.application" to="kubernetes.applications.application"
params={{ name: app.Name, namespace: app.ResourcePool }} params={{ name: app.Name, namespace: app.ResourcePool }}
@ -34,10 +36,9 @@ export function SubRows({
</Link> </Link>
{KubernetesNamespaceHelper.isSystemNamespace(app.ResourcePool) && {KubernetesNamespaceHelper.isSystemNamespace(app.ResourcePool) &&
KubernetesApplicationHelper.isExternalApplication(app) && ( KubernetesApplicationHelper.isExternalApplication(app) && (
<span className="space-left label label-primary image-tag"> <ExternalBadge />
external
</span>
)} )}
</div>
</td> </td>
</tr> </tr>
))} ))}

View File

@ -6,6 +6,7 @@ import KubernetesNamespaceHelper from '@/kubernetes/helpers/namespaceHelper';
import { buildExpandColumn } from '@@/datatables/expand-column'; import { buildExpandColumn } from '@@/datatables/expand-column';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { Icon } from '@@/Icon'; import { Icon } from '@@/Icon';
import { SystemBadge } from '@@/Badge/SystemBadge';
import { KubernetesStack } from '../../types'; import { KubernetesStack } from '../../types';
@ -23,7 +24,7 @@ export const columns = [
cell: ({ getValue }) => { cell: ({ getValue }) => {
const value = getValue(); const value = getValue();
return ( return (
<> <div className="flex gap-2">
<Link <Link
to="kubernetes.resourcePools.resourcePool" to="kubernetes.resourcePools.resourcePool"
params={{ id: value }} params={{ id: value }}
@ -31,11 +32,9 @@ export const columns = [
{value} {value}
</Link> </Link>
{KubernetesNamespaceHelper.isSystemNamespace(value) && ( {KubernetesNamespaceHelper.isSystemNamespace(value) && (
<span className="label label-info image-tag label-margins"> <SystemBadge />
system
</span>
)} )}
</> </div>
); );
}, },
}), }),

View File

@ -3,8 +3,10 @@ import { CellContext } from '@tanstack/react-table';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants'; import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { ExternalBadge } from '@@/Badge/ExternalBadge';
import { SystemBadge } from '@@/Badge/SystemBadge';
import { UnusedBadge } from '@@/Badge/UnusedBadge';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { Badge } from '@@/Badge';
import { ConfigMapRowData } from '../types'; import { ConfigMapRowData } from '../types';
import { configurationOwnerUsernameLabel } from '../../../constants'; import { configurationOwnerUsernameLabel } from '../../../constants';
@ -47,7 +49,7 @@ function Cell({ row }: CellContext<ConfigMapRowData, string>) {
return ( return (
<Authorized authorizations="K8sConfigMapsR" childrenUnauthorized={name}> <Authorized authorizations="K8sConfigMapsR" childrenUnauthorized={name}>
<div className="flex"> <div className="flex gap-2">
<Link <Link
to="kubernetes.configmaps.configmap" to="kubernetes.configmaps.configmap"
params={{ params={{
@ -59,19 +61,9 @@ function Cell({ row }: CellContext<ConfigMapRowData, string>) {
> >
{name} {name}
</Link> </Link>
{isSystemConfigMap && ( {isSystemConfigMap && <SystemBadge />}
<Badge type="success" className="ml-2"> {!isSystemToken && !hasConfigurationOwner && <ExternalBadge />}
System {!row.original.inUse && !isSystemConfigMap && <UnusedBadge />}
</Badge>
)}
{!isSystemToken && !hasConfigurationOwner && (
<Badge className="ml-2">External</Badge>
)}
{!row.original.inUse && !isSystemConfigMap && (
<Badge type="warn" className="ml-2">
Unused
</Badge>
)}
</div> </div>
</Authorized> </Authorized>
); );

View File

@ -3,8 +3,10 @@ import { CellContext } from '@tanstack/react-table';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants'; import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { SystemBadge } from '@@/Badge/SystemBadge';
import { ExternalBadge } from '@@/Badge/ExternalBadge';
import { UnusedBadge } from '@@/Badge/UnusedBadge';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { Badge } from '@@/Badge';
import { SecretRowData } from '../types'; import { SecretRowData } from '../types';
import { configurationOwnerUsernameLabel } from '../../../constants'; import { configurationOwnerUsernameLabel } from '../../../constants';
@ -60,19 +62,10 @@ function Cell({ row }: CellContext<SecretRowData, string>) {
> >
{name} {name}
</Link> </Link>
{isSystemSecret && (
<Badge type="success" className="ml-2"> {isSystemSecret && <SystemBadge />}
System {!isSystemToken && !hasConfigurationOwner && <ExternalBadge />}
</Badge> {!row.original.inUse && !isSystemSecret && <UnusedBadge />}
)}
{!isSystemToken && !hasConfigurationOwner && (
<Badge className="ml-2">External</Badge>
)}
{!row.original.inUse && !isSystemSecret && (
<Badge type="warn" className="ml-2">
Unused
</Badge>
)}
</div> </div>
</Authorized> </Authorized>
); );

View File

@ -2,8 +2,8 @@ import { CellContext } from '@tanstack/react-table';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { SystemBadge } from '@@/Badge/SystemBadge';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { Badge } from '@@/Badge';
import { Ingress } from '../../types'; import { Ingress } from '../../types';
@ -20,7 +20,7 @@ function Cell({ row, getValue }: CellContext<Ingress, string>) {
const namespace = row.original.Namespace; const namespace = row.original.Namespace;
return ( return (
<div className="flex flex-nowrap whitespace-nowrap"> <div className="flex flex-nowrap whitespace-nowrap gap-2">
<Authorized authorizations="K8sIngressesW" childrenUnauthorized={name}> <Authorized authorizations="K8sIngressesW" childrenUnauthorized={name}>
<Link <Link
to="kubernetes.ingresses.edit" to="kubernetes.ingresses.edit"
@ -34,11 +34,7 @@ function Cell({ row, getValue }: CellContext<Ingress, string>) {
{name} {name}
</Link> </Link>
</Authorized> </Authorized>
{row.original.IsSystem && ( {row.original.IsSystem && <SystemBadge />}
<Badge type="success" className="ml-2">
System
</Badge>
)}
</div> </div>
); );
} }

View File

@ -1,6 +1,7 @@
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { Badge } from '@@/Badge'; import { SystemBadge } from '@@/Badge/SystemBadge';
import { ExternalBadge } from '@@/Badge/ExternalBadge';
import { columnHelper } from './helper'; import { columnHelper } from './helper';
@ -31,19 +32,13 @@ export const name = columnHelper.accessor(
!row.original.Labels['io.portainer.kubernetes.application.owner']; !row.original.Labels['io.portainer.kubernetes.application.owner'];
return ( return (
<div className="flex"> <div className="flex gap-2">
<Authorized authorizations="K8sServiceW" childrenUnauthorized={name}> <Authorized authorizations="K8sServiceW" childrenUnauthorized={name}>
{name} {name}
{row.original.IsSystem && ( {row.original.IsSystem && <SystemBadge />}
<Badge type="success" className="ml-2">
System
</Badge>
)}
{isExternal && !row.original.IsSystem && ( {isExternal && !row.original.IsSystem && <ExternalBadge />}
<Badge className="ml-2">External</Badge>
)}
</Authorized> </Authorized>
</div> </div>
); );