@skyhook-io/k8s-ui 1.5.10 → 1.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/dock/BottomDock.tsx +21 -10
- package/src/components/resources/get-pod-phase-display.test.ts +254 -0
- package/src/components/resources/renderers/AWSManagedMachinePoolRenderer.tsx +2 -4
- package/src/components/resources/renderers/ArgoApplicationRenderer.tsx +3 -2
- package/src/components/resources/renderers/AzureManagedMachinePoolRenderer.tsx +3 -8
- package/src/components/resources/renderers/ChallengeRenderer.tsx +2 -1
- package/src/components/resources/renderers/ClusterComplianceReportRenderer.tsx +2 -1
- package/src/components/resources/renderers/ConfigAuditReportRenderer.tsx +2 -1
- package/src/components/resources/renderers/ExposedSecretReportRenderer.tsx +2 -1
- package/src/components/resources/renderers/GatewayClassRenderer.tsx +2 -1
- package/src/components/resources/renderers/GatewayRenderer.tsx +5 -4
- package/src/components/resources/renderers/IngressClassRenderer.tsx +2 -1
- package/src/components/resources/renderers/IstioAuthorizationPolicyRenderer.tsx +2 -1
- package/src/components/resources/renderers/IstioGatewayRenderer.tsx +3 -2
- package/src/components/resources/renderers/IstioPeerAuthenticationRenderer.tsx +2 -1
- package/src/components/resources/renderers/KarpenterNodeClaimRenderer.tsx +2 -2
- package/src/components/resources/renderers/OrderRenderer.tsx +2 -1
- package/src/components/resources/renderers/PodRenderer.tsx +23 -2
- package/src/components/resources/renderers/RoleBindingRenderer.tsx +3 -2
- package/src/components/resources/renderers/RolloutRenderer.tsx +2 -1
- package/src/components/resources/renderers/SecretRenderer.tsx +15 -6
- package/src/components/resources/renderers/aws-capi-cells.tsx +2 -4
- package/src/components/resources/renderers/azure-capi-cells.tsx +3 -8
- package/src/components/resources/renderers/istio-cells.tsx +3 -2
- package/src/components/resources/renderers/karpenter-cells.tsx +1 -1
- package/src/components/resources/resource-utils-karpenter.ts +0 -6
- package/src/components/resources/resource-utils.ts +108 -0
- package/src/components/timeline/shared.tsx +5 -6
- package/src/components/ui/Tooltip.tsx +73 -40
- package/src/components/ui/tooltip-position.test.ts +132 -0
- package/src/components/ui/tooltip-position.ts +86 -0
- package/src/components/workload/WorkloadView.tsx +6 -6
- package/src/utils/badge-colors.ts +19 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/validators.test.ts +207 -0
- package/src/utils/validators.ts +178 -0
- package/src/utils/view-transition.test.ts +81 -0
- package/src/utils/view-transition.ts +62 -0
|
@@ -2,7 +2,7 @@ import { useState, type ReactNode, type JSX } from 'react'
|
|
|
2
2
|
import { Server, HardDrive, Terminal as TerminalIcon, FileText, Activity, CirclePlay, FolderOpen, List, Eye, EyeOff } from 'lucide-react'
|
|
3
3
|
import { clsx } from 'clsx'
|
|
4
4
|
import { Section, PropertyList, Property, ConditionsSection, CopyHandler, AlertBanner, ResourceLink } from '../../ui/drawer-components'
|
|
5
|
-
import { formatResources, formatDuration, getPodProblems, SEVERITY_DOT_COLOR } from '../resource-utils'
|
|
5
|
+
import { formatResources, formatDuration, getPodProblems, getPodPhaseDisplay, healthColors, SEVERITY_DOT_COLOR } from '../resource-utils'
|
|
6
6
|
import { getResourceStatusColor, SEVERITY_BADGE_BORDERED } from '../../../utils/badge-colors'
|
|
7
7
|
import type { ResolvedEnvFrom } from '../../../types'
|
|
8
8
|
import { Tooltip } from '../../ui/Tooltip'
|
|
@@ -333,7 +333,28 @@ export function PodRenderer({
|
|
|
333
333
|
{/* Status section */}
|
|
334
334
|
<Section title="Status" icon={Server}>
|
|
335
335
|
<PropertyList>
|
|
336
|
-
|
|
336
|
+
{(() => {
|
|
337
|
+
const phaseDisplay = getPodPhaseDisplay(data)
|
|
338
|
+
const node = (
|
|
339
|
+
<span className={clsx(healthColors[phaseDisplay.level])}>
|
|
340
|
+
{phaseDisplay.text}
|
|
341
|
+
</span>
|
|
342
|
+
)
|
|
343
|
+
return (
|
|
344
|
+
<Property
|
|
345
|
+
label="Phase"
|
|
346
|
+
value={
|
|
347
|
+
phaseDisplay.hint ? (
|
|
348
|
+
<Tooltip content={phaseDisplay.hint} position="right">
|
|
349
|
+
{node}
|
|
350
|
+
</Tooltip>
|
|
351
|
+
) : (
|
|
352
|
+
node
|
|
353
|
+
)
|
|
354
|
+
}
|
|
355
|
+
/>
|
|
356
|
+
)
|
|
357
|
+
})()}
|
|
337
358
|
<Property label="Node" value={
|
|
338
359
|
data.spec?.nodeName ? <ResourceLink name={data.spec.nodeName} kind="nodes" onNavigate={onNavigate} /> : undefined
|
|
339
360
|
} copyable onCopy={onCopy} copied={copied} />
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Shield, Users } from 'lucide-react'
|
|
2
2
|
import { clsx } from 'clsx'
|
|
3
3
|
import { Section, PropertyList, Property, ResourceLink, AlertBanner } from '../../ui/drawer-components'
|
|
4
|
+
import { BADGE_INACTIVE } from '../../../utils/badge-colors'
|
|
4
5
|
|
|
5
6
|
interface RoleBindingRendererProps {
|
|
6
7
|
data: any
|
|
@@ -16,7 +17,7 @@ function getSubjectKindBadgeClass(kind: string): string {
|
|
|
16
17
|
case 'Group':
|
|
17
18
|
return 'bg-purple-500/20 text-purple-400'
|
|
18
19
|
default:
|
|
19
|
-
return
|
|
20
|
+
return BADGE_INACTIVE
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -27,7 +28,7 @@ function getRoleRefKindBadgeClass(kind: string): string {
|
|
|
27
28
|
case 'ClusterRole':
|
|
28
29
|
return 'bg-purple-500/20 text-purple-400'
|
|
29
30
|
default:
|
|
30
|
-
return
|
|
31
|
+
return BADGE_INACTIVE
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -2,6 +2,7 @@ import { Server, GitBranch, AlertTriangle, Network } from 'lucide-react'
|
|
|
2
2
|
import { clsx } from 'clsx'
|
|
3
3
|
import { Section, PropertyList, Property, ConditionsSection, PodTemplateSection } from '../../ui/drawer-components'
|
|
4
4
|
import { formatAge } from '../resource-utils'
|
|
5
|
+
import { BADGE_INACTIVE } from '../../../utils/badge-colors'
|
|
5
6
|
|
|
6
7
|
interface RolloutRendererProps {
|
|
7
8
|
data: any
|
|
@@ -292,7 +293,7 @@ export function RolloutRenderer({ data }: RolloutRendererProps) {
|
|
|
292
293
|
'w-5 h-5 rounded-full flex items-center justify-center text-xs shrink-0',
|
|
293
294
|
isCompleted && 'bg-green-500/20 text-green-400',
|
|
294
295
|
isCurrent && 'bg-blue-500/20 text-blue-400',
|
|
295
|
-
isPending &&
|
|
296
|
+
isPending && BADGE_INACTIVE
|
|
296
297
|
)}
|
|
297
298
|
>
|
|
298
299
|
{isCompleted ? '\u2713' : isCurrent ? '\u25CF' : '\u25CB'}
|
|
@@ -34,7 +34,11 @@ export function SecretRenderer({ data, certificateInfo, resourceData, onSaveSecr
|
|
|
34
34
|
function toggleReveal(key: string) {
|
|
35
35
|
setRevealed(prev => {
|
|
36
36
|
const next = new Set(prev)
|
|
37
|
-
next.has(key)
|
|
37
|
+
if (next.has(key)) {
|
|
38
|
+
next.delete(key)
|
|
39
|
+
} else {
|
|
40
|
+
next.add(key)
|
|
41
|
+
}
|
|
38
42
|
return next
|
|
39
43
|
})
|
|
40
44
|
}
|
|
@@ -153,6 +157,16 @@ export function SecretRenderer({ data, certificateInfo, resourceData, onSaveSecr
|
|
|
153
157
|
</>
|
|
154
158
|
)}
|
|
155
159
|
|
|
160
|
+
{dataKeys.length > 0 && (
|
|
161
|
+
<div className="flex items-center gap-2 p-3 bg-amber-500/10 border border-amber-500/30 rounded text-amber-400 text-sm">
|
|
162
|
+
<AlertTriangle className="w-4 h-4 flex-shrink-0" />
|
|
163
|
+
<span>
|
|
164
|
+
Secret values are sensitive. Reveal carefully — anyone who can see your
|
|
165
|
+
screen will see the plaintext.
|
|
166
|
+
</span>
|
|
167
|
+
</div>
|
|
168
|
+
)}
|
|
169
|
+
|
|
156
170
|
<Section title="Data" defaultExpanded>
|
|
157
171
|
<div className="space-y-2">
|
|
158
172
|
{dataKeys.map((key) => {
|
|
@@ -250,11 +264,6 @@ export function SecretRenderer({ data, certificateInfo, resourceData, onSaveSecr
|
|
|
250
264
|
</div>
|
|
251
265
|
</Section>
|
|
252
266
|
|
|
253
|
-
<div className="flex items-center gap-2 p-3 bg-red-500/10 border border-red-500/30 rounded text-red-400 text-sm">
|
|
254
|
-
<AlertTriangle className="w-4 h-4" />
|
|
255
|
-
Secret values are sensitive. Be careful when revealing.
|
|
256
|
-
</div>
|
|
257
|
-
|
|
258
267
|
{editingKey && (
|
|
259
268
|
<ConfirmDialog
|
|
260
269
|
open={showSaveConfirm}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { clsx } from 'clsx'
|
|
4
4
|
import { Tooltip } from '../../ui/Tooltip'
|
|
5
|
+
import { CAPACITY_TYPE_BADGE } from '../../../utils/badge-colors'
|
|
5
6
|
import {
|
|
6
7
|
getAWSMCPStatus, getAWSMCPEKSClusterName, getAWSMCPRegion, getAWSMCPVersion,
|
|
7
8
|
getAWSMMPStatus, getAWSMMPInstanceType, getAWSMMPReplicas, getAWSMMPCapacityType,
|
|
@@ -57,10 +58,7 @@ export function AWSManagedMachinePoolCell({ resource, column }: { resource: any;
|
|
|
57
58
|
case 'capacityType': {
|
|
58
59
|
const ct = getAWSMMPCapacityType(resource)
|
|
59
60
|
return (
|
|
60
|
-
<span className={clsx('badge badge-sm', ct === 'spot'
|
|
61
|
-
? 'bg-amber-100 text-amber-800 border-amber-300 dark:bg-amber-950/50 dark:text-amber-400 dark:border-amber-700/40'
|
|
62
|
-
: 'bg-sky-100 text-sky-700 border-sky-300 dark:bg-sky-950/50 dark:text-sky-400 dark:border-sky-700/40'
|
|
63
|
-
)}>{ct === 'onDemand' ? 'On-Demand' : ct}</span>
|
|
61
|
+
<span className={clsx('badge badge-sm', ct === 'spot' ? CAPACITY_TYPE_BADGE.spot : CAPACITY_TYPE_BADGE.onDemand)}>{ct === 'onDemand' ? 'On-Demand' : ct}</span>
|
|
64
62
|
)
|
|
65
63
|
}
|
|
66
64
|
default:
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Tooltip } from '../../ui/Tooltip'
|
|
4
4
|
import { clsx } from 'clsx'
|
|
5
|
+
import { CAPACITY_TYPE_BADGE, NODEPOOL_MODE_BADGE } from '../../../utils/badge-colors'
|
|
5
6
|
import {
|
|
6
7
|
getAzureMCPStatus, getAzureMCPLocation, getAzureMCPVersion, getAzureMCPResourceGroup,
|
|
7
8
|
getAzureMMPStatus, getAzureMMPSKU, getAzureMMPMode, getAzureMMPReplicas, getAzureMMPScaleSetPriority,
|
|
@@ -40,20 +41,14 @@ export function AzureManagedMachinePoolCell({ resource, column }: { resource: an
|
|
|
40
41
|
case 'mode': {
|
|
41
42
|
const mode = getAzureMMPMode(resource)
|
|
42
43
|
return (
|
|
43
|
-
<span className={clsx('badge badge-sm', mode
|
|
44
|
-
? 'bg-purple-100 text-purple-800 border-purple-300 dark:bg-purple-950/50 dark:text-purple-400 dark:border-purple-700/40'
|
|
45
|
-
: 'bg-sky-100 text-sky-700 border-sky-300 dark:bg-sky-950/50 dark:text-sky-400 dark:border-sky-700/40'
|
|
46
|
-
)}>{mode}</span>
|
|
44
|
+
<span className={clsx('badge badge-sm', NODEPOOL_MODE_BADGE[mode] || NODEPOOL_MODE_BADGE.User)}>{mode}</span>
|
|
47
45
|
)
|
|
48
46
|
}
|
|
49
47
|
case 'replicas': return <TextCell value={getAzureMMPReplicas(resource)} />
|
|
50
48
|
case 'priority': {
|
|
51
49
|
const p = getAzureMMPScaleSetPriority(resource)
|
|
52
50
|
return (
|
|
53
|
-
<span className={clsx('badge badge-sm', p === 'Spot'
|
|
54
|
-
? 'bg-amber-100 text-amber-800 border-amber-300 dark:bg-amber-950/50 dark:text-amber-400 dark:border-amber-700/40'
|
|
55
|
-
: 'bg-sky-100 text-sky-700 border-sky-300 dark:bg-sky-950/50 dark:text-sky-400 dark:border-sky-700/40'
|
|
56
|
-
)}>{p}</span>
|
|
51
|
+
<span className={clsx('badge badge-sm', p === 'Spot' ? CAPACITY_TYPE_BADGE.spot : CAPACITY_TYPE_BADGE.regular)}>{p}</span>
|
|
57
52
|
)
|
|
58
53
|
}
|
|
59
54
|
default: return <span className="text-sm text-theme-text-tertiary">-</span>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Istio cell components for ResourcesView table
|
|
2
2
|
|
|
3
3
|
import { clsx } from 'clsx'
|
|
4
|
+
import { BADGE_INACTIVE } from '../../../utils/badge-colors'
|
|
4
5
|
import {
|
|
5
6
|
getVirtualServiceStatus,
|
|
6
7
|
getVirtualServiceHosts,
|
|
@@ -164,7 +165,7 @@ export function PeerAuthenticationCell({ resource, column }: { resource: any; co
|
|
|
164
165
|
return (
|
|
165
166
|
<span className={clsx(
|
|
166
167
|
'badge',
|
|
167
|
-
modeColors[mode] ||
|
|
168
|
+
modeColors[mode] || BADGE_INACTIVE
|
|
168
169
|
)}>
|
|
169
170
|
{mode}
|
|
170
171
|
</span>
|
|
@@ -194,7 +195,7 @@ export function AuthorizationPolicyCell({ resource, column }: { resource: any; c
|
|
|
194
195
|
return (
|
|
195
196
|
<span className={clsx(
|
|
196
197
|
'badge',
|
|
197
|
-
actionColors[action] ||
|
|
198
|
+
actionColors[action] || BADGE_INACTIVE
|
|
198
199
|
)}>
|
|
199
200
|
{action}
|
|
200
201
|
</span>
|
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
import type { StatusBadge } from './resource-utils'
|
|
4
4
|
import { healthColors } from './resource-utils'
|
|
5
5
|
|
|
6
|
-
// Shared capacity type badge colors for NodeClaim renderer and table cells
|
|
7
|
-
export const CAPACITY_TYPE_BADGE: Record<string, string> = {
|
|
8
|
-
spot: 'bg-amber-100 text-amber-800 border-amber-300 dark:bg-amber-950/50 dark:text-amber-400 dark:border-amber-700/40',
|
|
9
|
-
'on-demand': 'bg-sky-100 text-sky-700 border-sky-300 dark:bg-sky-950/50 dark:text-sky-400 dark:border-sky-700/40',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
6
|
// ============================================================================
|
|
13
7
|
// KARPENTER NODEPOOL UTILITIES
|
|
14
8
|
// ============================================================================
|
|
@@ -130,6 +130,114 @@ export function getPodStatus(pod: any): StatusBadge {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Pod phase enriched with readiness/restart/crash signals so the Phase
|
|
135
|
+
* row doesn't show a bare "Running" on a 0/1 or crash-looping pod.
|
|
136
|
+
*/
|
|
137
|
+
export interface PodPhaseDisplay {
|
|
138
|
+
/** Verbatim `pod.status.phase` (or "Unknown") — never lost. */
|
|
139
|
+
phase: string
|
|
140
|
+
/** Phase + derived qualifier, e.g. "Running — Not Ready (0/1)". */
|
|
141
|
+
text: string
|
|
142
|
+
/** Severity tier for tinting / icon choice, mirrors getPodStatus. */
|
|
143
|
+
level: HealthLevel
|
|
144
|
+
/** Optional one-line explanation surfaced as a tooltip / muted suffix. */
|
|
145
|
+
hint?: string
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const RESTART_CYCLING_THRESHOLD = 5
|
|
149
|
+
|
|
150
|
+
export function getPodPhaseDisplay(pod: any): PodPhaseDisplay {
|
|
151
|
+
const phase: string = pod?.status?.phase || 'Unknown'
|
|
152
|
+
const containerStatuses: any[] = pod?.status?.containerStatuses || []
|
|
153
|
+
const totalContainers = containerStatuses.length
|
|
154
|
+
const readyContainers = containerStatuses.filter((c) => c?.ready).length
|
|
155
|
+
const restartTotal = containerStatuses.reduce(
|
|
156
|
+
(sum, c) => sum + (c?.restartCount || 0),
|
|
157
|
+
0
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
if (pod?.metadata?.deletionTimestamp) {
|
|
161
|
+
return {
|
|
162
|
+
phase,
|
|
163
|
+
text: `${phase} — Terminating`,
|
|
164
|
+
level: 'degraded',
|
|
165
|
+
hint: 'Pod has a deletionTimestamp set; awaiting graceful termination.',
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Container-state failures take precedence over phase: a CrashLoopBackOff
|
|
170
|
+
// pod can still report phase: Running. Skip for Succeeded — a Job pod whose
|
|
171
|
+
// sidecar was OOMKilled before the main container completed should not be
|
|
172
|
+
// shown as unhealthy after the pod has reached terminal success.
|
|
173
|
+
if (phase !== 'Succeeded') {
|
|
174
|
+
for (const cs of containerStatuses) {
|
|
175
|
+
const waitingReason = cs?.state?.waiting?.reason
|
|
176
|
+
if (
|
|
177
|
+
waitingReason === 'CrashLoopBackOff' ||
|
|
178
|
+
waitingReason === 'ImagePullBackOff' ||
|
|
179
|
+
waitingReason === 'ErrImagePull' ||
|
|
180
|
+
waitingReason === 'CreateContainerConfigError'
|
|
181
|
+
) {
|
|
182
|
+
return {
|
|
183
|
+
phase,
|
|
184
|
+
text: `${phase} — ${waitingReason}`,
|
|
185
|
+
level: 'unhealthy',
|
|
186
|
+
hint: `Container "${cs.name}" is stuck in ${waitingReason}.`,
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (cs?.state?.terminated?.reason === 'OOMKilled') {
|
|
190
|
+
return {
|
|
191
|
+
phase,
|
|
192
|
+
text: `${phase} — OOMKilled`,
|
|
193
|
+
level: 'unhealthy',
|
|
194
|
+
hint: `Container "${cs.name}" was OOMKilled.`,
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
switch (phase) {
|
|
201
|
+
case 'Running': {
|
|
202
|
+
const notReady = totalContainers > 0 && readyContainers < totalContainers
|
|
203
|
+
const cycling = restartTotal > RESTART_CYCLING_THRESHOLD
|
|
204
|
+
if (notReady && cycling) {
|
|
205
|
+
return {
|
|
206
|
+
phase,
|
|
207
|
+
text: `Running — Not Ready (${readyContainers}/${totalContainers}), ${restartTotal} restarts`,
|
|
208
|
+
level: 'unhealthy',
|
|
209
|
+
hint: 'Containers report not-ready and have restarted many times — likely crash-looping.',
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (notReady) {
|
|
213
|
+
return {
|
|
214
|
+
phase,
|
|
215
|
+
text: `Running — Not Ready (${readyContainers}/${totalContainers})`,
|
|
216
|
+
level: 'degraded',
|
|
217
|
+
hint: 'Pod is in the Running phase but at least one container is not ready (probes failing or still starting).',
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (cycling) {
|
|
221
|
+
return {
|
|
222
|
+
phase,
|
|
223
|
+
text: `Running — Restarting (${restartTotal} restarts)`,
|
|
224
|
+
level: 'degraded',
|
|
225
|
+
hint: 'Containers are ready right now but have restarted many times — investigate stability.',
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return { phase, text: 'Running', level: 'healthy' }
|
|
229
|
+
}
|
|
230
|
+
case 'Succeeded':
|
|
231
|
+
return { phase, text: 'Completed', level: 'neutral' }
|
|
232
|
+
case 'Pending':
|
|
233
|
+
return { phase, text: 'Pending', level: 'degraded' }
|
|
234
|
+
case 'Failed':
|
|
235
|
+
return { phase, text: 'Failed', level: 'unhealthy' }
|
|
236
|
+
default:
|
|
237
|
+
return { phase, text: phase, level: 'unknown' }
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
133
241
|
export function getPodProblems(pod: any): PodProblem[] {
|
|
134
242
|
const problems: PodProblem[] = []
|
|
135
243
|
const containerStatuses = pod.status?.containerStatuses || []
|
|
@@ -244,21 +244,20 @@ export function EventMarker({ event, x, selected, onClick, dimmed, small }: Even
|
|
|
244
244
|
return 'bg-theme-hover/30 border-2 border-dashed border-theme-border-light'
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
const opacity = dimmed ? '/50' : ''
|
|
248
247
|
if (isProblematic) {
|
|
249
|
-
return
|
|
248
|
+
return dimmed ? 'bg-amber-500/50' : 'bg-amber-500'
|
|
250
249
|
}
|
|
251
250
|
if (isChange) {
|
|
252
251
|
switch (event.eventType) {
|
|
253
252
|
case 'add':
|
|
254
|
-
return
|
|
253
|
+
return dimmed ? 'bg-green-500/50' : 'bg-green-500'
|
|
255
254
|
case 'delete':
|
|
256
|
-
return
|
|
255
|
+
return dimmed ? 'bg-red-500/50' : 'bg-red-500'
|
|
257
256
|
case 'update':
|
|
258
|
-
return
|
|
257
|
+
return dimmed ? 'bg-blue-500/50' : 'bg-blue-500'
|
|
259
258
|
}
|
|
260
259
|
}
|
|
261
|
-
return
|
|
260
|
+
return dimmed ? 'bg-theme-text-tertiary/50' : 'bg-theme-text-tertiary'
|
|
262
261
|
}
|
|
263
262
|
|
|
264
263
|
const getOperationLabel = () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactNode, useState, useRef, useEffect, useCallback } from 'react'
|
|
2
2
|
import { createPortal } from 'react-dom'
|
|
3
3
|
import { clsx } from 'clsx'
|
|
4
|
+
import { computeTooltipPosition } from './tooltip-position'
|
|
4
5
|
|
|
5
6
|
// Module-level singleton coordinator: only one Tooltip can be visible
|
|
6
7
|
// at a time across the whole app. Without this, two Tooltip instances
|
|
@@ -45,53 +46,43 @@ export function Tooltip({
|
|
|
45
46
|
wrapperStyle,
|
|
46
47
|
}: TooltipProps) {
|
|
47
48
|
const [isVisible, setIsVisible] = useState(false)
|
|
48
|
-
|
|
49
|
+
// null until measured. Portal renders with visibility:hidden until coords
|
|
50
|
+
// resolve so the user never sees a frame painted at default (0,0).
|
|
51
|
+
const [coords, setCoords] = useState<{ top: number; left: number } | null>(
|
|
52
|
+
null
|
|
53
|
+
)
|
|
49
54
|
const triggerRef = useRef<HTMLSpanElement>(null)
|
|
50
55
|
const tooltipRef = useRef<HTMLSpanElement>(null)
|
|
51
56
|
const timeoutRef = useRef<number | null>(null)
|
|
57
|
+
const rafRef = useRef<number | null>(null)
|
|
52
58
|
|
|
53
59
|
const updatePosition = useCallback(() => {
|
|
54
60
|
if (!triggerRef.current) return
|
|
55
61
|
|
|
56
|
-
const
|
|
62
|
+
const triggerRect = triggerRef.current.getBoundingClientRect()
|
|
57
63
|
const tooltipRect = tooltipRef.current?.getBoundingClientRect()
|
|
58
|
-
const tooltipWidth = tooltipRect?.width || 0
|
|
59
|
-
const tooltipHeight = tooltipRect?.height || 0
|
|
60
|
-
|
|
61
|
-
let top = 0
|
|
62
|
-
let left = 0
|
|
63
|
-
|
|
64
|
-
switch (position) {
|
|
65
|
-
case 'top':
|
|
66
|
-
top = rect.top - tooltipHeight - 6
|
|
67
|
-
left = rect.left + rect.width / 2 - tooltipWidth / 2
|
|
68
|
-
break
|
|
69
|
-
case 'bottom':
|
|
70
|
-
top = rect.bottom + 6
|
|
71
|
-
left = rect.left + rect.width / 2 - tooltipWidth / 2
|
|
72
|
-
break
|
|
73
|
-
case 'left':
|
|
74
|
-
top = rect.top + rect.height / 2 - tooltipHeight / 2
|
|
75
|
-
left = rect.left - tooltipWidth - 6
|
|
76
|
-
break
|
|
77
|
-
case 'right':
|
|
78
|
-
top = rect.top + rect.height / 2 - tooltipHeight / 2
|
|
79
|
-
left = rect.right + 6
|
|
80
|
-
break
|
|
81
|
-
}
|
|
82
64
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
65
|
+
const next = computeTooltipPosition({
|
|
66
|
+
triggerRect: {
|
|
67
|
+
top: triggerRect.top,
|
|
68
|
+
left: triggerRect.left,
|
|
69
|
+
width: triggerRect.width,
|
|
70
|
+
height: triggerRect.height,
|
|
71
|
+
},
|
|
72
|
+
tooltipSize: {
|
|
73
|
+
width: tooltipRect?.width ?? 0,
|
|
74
|
+
height: tooltipRect?.height ?? 0,
|
|
75
|
+
},
|
|
76
|
+
position,
|
|
77
|
+
viewport: {
|
|
78
|
+
width: window.innerWidth,
|
|
79
|
+
height: window.innerHeight,
|
|
80
|
+
},
|
|
81
|
+
})
|
|
93
82
|
|
|
94
|
-
|
|
83
|
+
if (next) {
|
|
84
|
+
setCoords(next)
|
|
85
|
+
}
|
|
95
86
|
}, [position])
|
|
96
87
|
|
|
97
88
|
// Stable hide function for the singleton registry — useRef so the
|
|
@@ -104,6 +95,7 @@ export function Tooltip({
|
|
|
104
95
|
timeoutRef.current = null
|
|
105
96
|
}
|
|
106
97
|
setIsVisible(false)
|
|
98
|
+
setCoords(null)
|
|
107
99
|
}
|
|
108
100
|
|
|
109
101
|
const showTooltip = () => {
|
|
@@ -128,12 +120,22 @@ export function Tooltip({
|
|
|
128
120
|
activeHide = null
|
|
129
121
|
}
|
|
130
122
|
setIsVisible(false)
|
|
123
|
+
setCoords(null)
|
|
131
124
|
}
|
|
132
125
|
|
|
133
126
|
useEffect(() => {
|
|
134
127
|
if (isVisible) {
|
|
135
|
-
//
|
|
136
|
-
|
|
128
|
+
// Second rAF re-centers using the measured tooltip size; without
|
|
129
|
+
// it the first frame centers against size 0 and visibly jumps.
|
|
130
|
+
const id1 = requestAnimationFrame(() => {
|
|
131
|
+
updatePosition()
|
|
132
|
+
const id2 = requestAnimationFrame(updatePosition)
|
|
133
|
+
rafRef.current = id2
|
|
134
|
+
})
|
|
135
|
+
rafRef.current = id1
|
|
136
|
+
return () => {
|
|
137
|
+
if (rafRef.current !== null) cancelAnimationFrame(rafRef.current)
|
|
138
|
+
}
|
|
137
139
|
}
|
|
138
140
|
}, [isVisible, updatePosition])
|
|
139
141
|
|
|
@@ -142,6 +144,9 @@ export function Tooltip({
|
|
|
142
144
|
if (timeoutRef.current) {
|
|
143
145
|
clearTimeout(timeoutRef.current)
|
|
144
146
|
}
|
|
147
|
+
if (rafRef.current !== null) {
|
|
148
|
+
cancelAnimationFrame(rafRef.current)
|
|
149
|
+
}
|
|
145
150
|
// Clear from singleton registry on unmount — otherwise a Tooltip
|
|
146
151
|
// that unmounts while visible (e.g. row removed during hover)
|
|
147
152
|
// would leave a stale entry in activeHide pointing at a torn-down
|
|
@@ -165,9 +170,27 @@ export function Tooltip({
|
|
|
165
170
|
timeoutRef.current = null
|
|
166
171
|
}
|
|
167
172
|
setIsVisible(false)
|
|
173
|
+
setCoords(null)
|
|
168
174
|
}
|
|
169
175
|
}, [disabled])
|
|
170
176
|
|
|
177
|
+
// Mouseleave doesn't fire when the trigger stays mounted across a
|
|
178
|
+
// navigation and the cursor is still over it; popstate + Escape give
|
|
179
|
+
// a deterministic dismissal path for those cases.
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!isVisible) return
|
|
182
|
+
const onPop = () => hideRef.current()
|
|
183
|
+
const onKey = (e: KeyboardEvent) => {
|
|
184
|
+
if (e.key === 'Escape') hideRef.current()
|
|
185
|
+
}
|
|
186
|
+
window.addEventListener('popstate', onPop)
|
|
187
|
+
window.addEventListener('keydown', onKey)
|
|
188
|
+
return () => {
|
|
189
|
+
window.removeEventListener('popstate', onPop)
|
|
190
|
+
window.removeEventListener('keydown', onKey)
|
|
191
|
+
}
|
|
192
|
+
}, [isVisible])
|
|
193
|
+
|
|
171
194
|
if (disabled || !content) {
|
|
172
195
|
return <>{children}</>
|
|
173
196
|
}
|
|
@@ -182,6 +205,10 @@ export function Tooltip({
|
|
|
182
205
|
onMouseLeave={hideTooltip}
|
|
183
206
|
onFocus={showTooltip}
|
|
184
207
|
onBlur={hideTooltip}
|
|
208
|
+
// pointerdown fires before click, so the tooltip is gone before
|
|
209
|
+
// the trigger's action runs. Required when the child handles
|
|
210
|
+
// navigation/state changes that don't unmount the trigger.
|
|
211
|
+
onPointerDown={hideTooltip}
|
|
185
212
|
>
|
|
186
213
|
{children}
|
|
187
214
|
</span>
|
|
@@ -194,8 +221,14 @@ export function Tooltip({
|
|
|
194
221
|
'whitespace-nowrap pointer-events-none',
|
|
195
222
|
className
|
|
196
223
|
)}
|
|
197
|
-
style={{
|
|
224
|
+
style={{
|
|
225
|
+
top: coords?.top ?? 0,
|
|
226
|
+
left: coords?.left ?? 0,
|
|
227
|
+
// Hide until first measurement so we never paint at (0,0).
|
|
228
|
+
visibility: coords ? 'visible' : 'hidden',
|
|
229
|
+
}}
|
|
198
230
|
role="tooltip"
|
|
231
|
+
aria-hidden={coords ? undefined : true}
|
|
199
232
|
>
|
|
200
233
|
{content}
|
|
201
234
|
</span>,
|