-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathDocBadges.tsx
More file actions
162 lines (152 loc) · 5.96 KB
/
DocBadges.tsx
File metadata and controls
162 lines (152 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* DocBadges — repo / branch / plan-diff / demo / archive / linked-doc badge cluster.
*
* Extracted from Viewer.tsx so the same markup can render in two places:
* - layout="column": original location at the top-left of the plan card (absolute)
* - layout="row": inside the sticky header lane when the user scrolls
*
* In row layout, the demo badge and linked-doc breadcrumb are dropped — the
* sticky lane hides entirely in linked-doc mode, and the demo badge is purely
* decorative top-of-doc context.
*/
import React from 'react';
import { PlanDiffBadge } from './plan-diff/PlanDiffBadge';
import type { PlanDiffStats } from '../utils/planDiffEngine';
export interface DocBadgesProps {
layout: 'column' | 'row';
repoInfo?: { display: string; branch?: string } | null;
planDiffStats?: PlanDiffStats | null;
isPlanDiffActive?: boolean;
hasPreviousVersion?: boolean;
onPlanDiffToggle?: () => void;
showDemoBadge?: boolean;
archiveInfo?: { status: 'approved' | 'denied' | 'unknown'; timestamp: string; title: string } | null;
linkedDocInfo?: { filepath: string; onBack: () => void; label?: string; backLabel?: string } | null;
}
export const DocBadges: React.FC<DocBadgesProps> = ({
layout,
repoInfo,
planDiffStats,
isPlanDiffActive,
hasPreviousVersion,
onPlanDiffToggle,
showDemoBadge,
archiveInfo,
linkedDocInfo,
}) => {
const anything =
repoInfo || hasPreviousVersion || showDemoBadge || linkedDocInfo || archiveInfo;
if (!anything) return null;
const isRow = layout === 'row';
// Row layout: single horizontal line. Column layout: stacked rows.
const outerClass = isRow
? 'flex flex-row items-center gap-1.5 text-[9px] text-muted-foreground/70 font-mono'
: 'flex flex-col items-start gap-1 text-[9px] text-muted-foreground/50 font-mono';
return (
<div className={outerClass}>
{repoInfo && !linkedDocInfo && (
<div className="flex items-center gap-1.5">
<span
className="px-1.5 py-0.5 bg-muted/50 rounded truncate max-w-[140px]"
title={repoInfo.display}
>
{repoInfo.display}
</span>
{repoInfo.branch && (
<span
className="px-1.5 py-0.5 bg-muted/30 rounded max-w-[120px] flex items-center gap-1 overflow-hidden"
title={repoInfo.branch}
>
<svg className="w-2.5 h-2.5 flex-shrink-0" viewBox="0 0 16 16" fill="currentColor">
<path d="M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z" />
</svg>
<span className="truncate">{repoInfo.branch}</span>
</span>
)}
</div>
)}
{onPlanDiffToggle && !linkedDocInfo && (
<PlanDiffBadge
stats={planDiffStats ?? null}
isActive={isPlanDiffActive ?? false}
onToggle={onPlanDiffToggle}
hasPreviousVersion={hasPreviousVersion ?? false}
/>
)}
{/* Demo badge: only in column (top-of-doc) layout */}
{!isRow && showDemoBadge && !linkedDocInfo && (
<span className="px-1.5 py-0.5 rounded text-[9px] font-mono bg-amber-500/15 text-amber-600 dark:text-amber-400">
Demo
</span>
)}
{archiveInfo && !linkedDocInfo && (
<div className="flex items-center gap-1.5">
<span
className={`px-1.5 py-0.5 rounded ${
archiveInfo.status === 'approved'
? 'bg-green-500/15 text-green-600 dark:text-green-400'
: archiveInfo.status === 'denied'
? 'bg-red-500/15 text-red-600 dark:text-red-400'
: 'bg-muted/50 text-muted-foreground'
}`}
>
{archiveInfo.status === 'approved'
? 'Approved'
: archiveInfo.status === 'denied'
? 'Denied'
: 'Unknown'}
</span>
{archiveInfo.timestamp && (
<span
className="px-1.5 py-0.5 bg-muted/50 rounded"
title={archiveInfo.timestamp}
>
{new Date(archiveInfo.timestamp).toLocaleDateString(undefined, {
month: 'short',
day: 'numeric',
year: 'numeric',
})}{' '}
{new Date(archiveInfo.timestamp).toLocaleTimeString(undefined, {
hour: 'numeric',
minute: '2-digit',
})}
</span>
)}
</div>
)}
{/* Linked-doc breadcrumb: only in column layout (sticky lane is hidden in linked-doc mode) */}
{!isRow && linkedDocInfo && (
<div className="flex items-center gap-1.5">
<button
onClick={linkedDocInfo.onBack}
className="px-1.5 py-0.5 bg-primary/10 text-primary rounded hover:bg-primary/20 transition-colors flex items-center gap-1"
>
<svg
className="w-2.5 h-2.5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2.5}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"
/>
</svg>
{linkedDocInfo.backLabel || 'plan'}
</button>
<span className="px-1.5 py-0.5 bg-primary/10 text-primary/80 rounded">
{linkedDocInfo.label || 'Linked File'}
</span>
<span
className="px-1.5 py-0.5 bg-muted/50 text-muted-foreground rounded truncate max-w-[200px]"
title={linkedDocInfo.filepath}
>
{linkedDocInfo.filepath.split('/').pop()}
</span>
</div>
)}
</div>
);
};