mirror of
https://github.com/stablyai/orca.git
synced 2026-10-27 16:02:42 +00:00
fix(ai-vault): split SessionTime out to pass max-lines lint
AiVaultSessionDetails exceeded the 400-line oxlint limit after adding first-prompt UI; move SessionTime into its own module.
This commit is contained in:
@@ -333,77 +333,6 @@ function SessionDetailEmptyState({ message }: { message: string }): React.JSX.El
|
||||
)
|
||||
}
|
||||
|
||||
export function SessionTime({
|
||||
value,
|
||||
className
|
||||
}: {
|
||||
value: string
|
||||
className?: string
|
||||
}): React.JSX.Element {
|
||||
const timestamp = Date.parse(value)
|
||||
if (!Number.isFinite(timestamp)) {
|
||||
return (
|
||||
<span className={cn('shrink-0 text-[11px] text-muted-foreground', className)}>
|
||||
{translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.unknownTime',
|
||||
'Unknown time'
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const date = new Date(timestamp)
|
||||
return (
|
||||
<span className={cn('shrink-0 text-[11px] text-muted-foreground', className)}>
|
||||
<time dateTime={date.toISOString()}>{formatTimeAgo(timestamp)}</time>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function formatTimeAgo(timestamp: number): string {
|
||||
const diffMs = Date.now() - timestamp
|
||||
if (diffMs < 60_000) {
|
||||
return translate('auto.components.right.sidebar.AiVaultSessionDetails.justNow', 'Just now')
|
||||
}
|
||||
const minutes = Math.floor(diffMs / 60_000)
|
||||
if (minutes < 60) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.minutesAgo',
|
||||
'{{value0}}m ago',
|
||||
{ value0: minutes }
|
||||
)
|
||||
}
|
||||
const hours = Math.floor(minutes / 60)
|
||||
if (hours < 24) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.hoursAgo',
|
||||
'{{value0}}h ago',
|
||||
{ value0: hours }
|
||||
)
|
||||
}
|
||||
const days = Math.floor(hours / 24)
|
||||
if (days < 30) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.daysAgo',
|
||||
'{{value0}}d ago',
|
||||
{ value0: days }
|
||||
)
|
||||
}
|
||||
const months = Math.floor(days / 30)
|
||||
if (months < 12) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.monthsAgo',
|
||||
'{{value0}}mo ago',
|
||||
{ value0: months }
|
||||
)
|
||||
}
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.yearsAgo',
|
||||
'{{value0}}y ago',
|
||||
{ value0: Math.floor(months / 12) }
|
||||
)
|
||||
}
|
||||
|
||||
function conversationRoleLabel(role: AiVaultSession['previewMessages'][number]['role']): string {
|
||||
if (role === 'user') {
|
||||
return translate('auto.components.right.sidebar.AiVaultSessionDetails.userRole', 'You')
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
type AiVaultSession
|
||||
} from '../../../../shared/ai-vault-types'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { SessionTime } from './AiVaultSessionDetails'
|
||||
import { SessionTime } from './ai-vault-session-time'
|
||||
import { sessionModelLabel } from './ai-vault-session-display'
|
||||
import { agentLabel } from './ai-vault-session-filters'
|
||||
import {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import type React from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
|
||||
export function SessionTime({
|
||||
value,
|
||||
className
|
||||
}: {
|
||||
value: string
|
||||
className?: string
|
||||
}): React.JSX.Element {
|
||||
const timestamp = Date.parse(value)
|
||||
if (!Number.isFinite(timestamp)) {
|
||||
return (
|
||||
<span className={cn('shrink-0 text-[11px] text-muted-foreground', className)}>
|
||||
{translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.unknownTime',
|
||||
'Unknown time'
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const date = new Date(timestamp)
|
||||
return (
|
||||
<span className={cn('shrink-0 text-[11px] text-muted-foreground', className)}>
|
||||
<time dateTime={date.toISOString()}>{formatTimeAgo(timestamp)}</time>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function formatTimeAgo(timestamp: number): string {
|
||||
const diffMs = Date.now() - timestamp
|
||||
if (diffMs < 60_000) {
|
||||
return translate('auto.components.right.sidebar.AiVaultSessionDetails.justNow', 'Just now')
|
||||
}
|
||||
const minutes = Math.floor(diffMs / 60_000)
|
||||
if (minutes < 60) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.minutesAgo',
|
||||
'{{value0}}m ago',
|
||||
{ value0: minutes }
|
||||
)
|
||||
}
|
||||
const hours = Math.floor(minutes / 60)
|
||||
if (hours < 24) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.hoursAgo',
|
||||
'{{value0}}h ago',
|
||||
{ value0: hours }
|
||||
)
|
||||
}
|
||||
const days = Math.floor(hours / 24)
|
||||
if (days < 30) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.daysAgo',
|
||||
'{{value0}}d ago',
|
||||
{ value0: days }
|
||||
)
|
||||
}
|
||||
const months = Math.floor(days / 30)
|
||||
if (months < 12) {
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.monthsAgo',
|
||||
'{{value0}}mo ago',
|
||||
{ value0: months }
|
||||
)
|
||||
}
|
||||
return translate(
|
||||
'auto.components.right.sidebar.AiVaultSessionDetails.yearsAgo',
|
||||
'{{value0}}y ago',
|
||||
{ value0: Math.floor(months / 12) }
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user