Skip to content

Commit

Permalink
feat: make label values matching URLs clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMac committed Nov 21, 2024
1 parent 8154b6b commit e652910
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/fakedata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func run(ctx context.Context) error {
fdStagingPhase, err := phases.New(
glu.Name("staging",
glu.Label("environment", "staging"),
glu.Label("domain", "stage.billing.mycorp.com"),
glu.Label("domain", "http://stage.billing.mycorp.com"),
),
fdPipeline,
fdStagingSource,
Expand All @@ -134,7 +134,7 @@ func run(ctx context.Context) error {
phases.New(
glu.Name("production",
glu.Label("environment", "production"),
glu.Label("domain", "prod.billing.mycorp.com"),
glu.Label("domain", "https://prod.billing.mycorp.com"),
glu.Label("ssl", "enabled"),
),
fdPipeline,
Expand Down
25 changes: 25 additions & 0 deletions ui/src/components/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getLabelColor } from '@/lib/utils';
import { Badge } from './ui/badge';

interface LabelProps {
labelKey: string;
value: string;
}

export function Label({ labelKey, value }: LabelProps) {
return (
<Badge
key={`${labelKey}-${value}`}
className={`whitespace-nowrap text-xs font-light ${getLabelColor(labelKey, value)}`}
>
{labelKey}:{' '}
{value.match('^https?://.*') ? (
<a className="ml-1 hover:underline" href={value} target="_blank">
{value}
</a>
) : (
value
)}
</Badge>
);
}
8 changes: 2 additions & 6 deletions ui/src/components/node-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Package, GitBranch, ChevronDown, ChevronUp } from 'lucide-react';
import { getLabelColor } from '@/lib/utils';
import { Button } from './ui/button';
import { cn } from '@/lib/utils';
import { Label } from './label';

interface NodePanelProps {
node: PhaseNode | null;
Expand Down Expand Up @@ -68,12 +69,7 @@ export function NodePanel({ node, isExpanded, onToggle }: NodePanelProps) {
<div className="mt-2 flex flex-wrap gap-2">
{node.data.labels &&
Object.entries(node.data.labels).map(([key, value]) => (
<Badge
key={`${key}-${value}`}
className={`whitespace-nowrap text-xs font-light ${getLabelColor(key, value)}`}
>
{key}: {value}
</Badge>
<Label labelKey={key} value={value} />
))}
</div>
</div>
Expand Down
8 changes: 2 additions & 6 deletions ui/src/components/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Button } from '@/components/ui/button';
import { useState } from 'react';
import { ANNOTATION_OCI_IMAGE_URL } from '@/types/metadata';
import { getLabelColor } from '@/lib/utils';
import { Label } from './label';

const PhaseNode = ({ data }: NodeProps<PhaseNodeType>) => {
const getIcon = () => {
Expand Down Expand Up @@ -90,12 +91,7 @@ const PhaseNode = ({ data }: NodeProps<PhaseNodeType>) => {
Object.entries(data.labels).length > 0 &&
Object.entries(data.labels).map(([key, value]) => (
<div key={`${key}-${value}`} className="mb-2 flex">
<Badge
key={`${key}-${value}`}
className={`whitespace-nowrap text-xs font-light ${getLabelColor(key, value)}`}
>
{key}: {value}
</Badge>
<Label labelKey={key} value={value} />
</div>
))}
</div>
Expand Down

0 comments on commit e652910

Please sign in to comment.