Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(formatting): consolidate duration formatting into shared utility#3118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7386d2212409f5567f392c69d6bfa529db147cb0a2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,11 +6,11 @@ import Link from 'next/link' | ||
| import { List, type RowComponentProps, useListRef } from 'react-window' | ||
| import { Badge, buttonVariants } from '@/components/emcn' | ||
| import { cn } from '@/lib/core/utils/cn' | ||
| import { formatDuration } from '@/lib/core/utils/formatting' | ||
| import { | ||
| DELETED_WORKFLOW_COLOR, | ||
| DELETED_WORKFLOW_LABEL, | ||
| formatDate, | ||
| formatDuration, | ||
| getDisplayStatus, | ||
| LOG_COLUMNS, | ||
| StatusBadge, | ||
| @@ -113,7 +113,7 @@ const LogRow = memo( | ||
| <div className={`${LOG_COLUMNS.duration.width} ${LOG_COLUMNS.duration.minWidth}`}> | ||
| <Badge variant='default' className='rounded-[6px] px-[9px] py-[2px] text-[12px]'> | ||
| {formatDuration(log.duration) || '—'} | ||
| {formatDuration(log.duration, { precision: 2 }) || '—'} | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| </Badge> | ||
| </div> | ||
| </div> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,7 @@ | ||
| import { memo, useEffect, useMemo, useRef, useState } from 'react' | ||
| import clsx from 'clsx' | ||
| import { ChevronUp } from 'lucide-react' | ||
| import { formatDuration } from '@/lib/core/utils/formatting' | ||
| import { CopilotMarkdownRenderer } from '../markdown-renderer' | ||
| /** Removes thinking tags (raw or escaped) and special tags from streamed content */ | ||
| @@ -241,15 +242,11 @@ export function ThinkingBlock({ | ||
| return () => window.clearInterval(intervalId) | ||
| }, [isStreaming, isExpanded, userHasScrolledAway]) | ||
| /** Formats duration in milliseconds to seconds (minimum 1s) */ | ||
| const formatDuration = (ms: number) => { | ||
| const seconds = Math.max(1, Math.round(ms / 1000)) | ||
| return `${seconds}s` | ||
| } | ||
| const hasContent = cleanContent.length > 0 | ||
| const isThinkingDone = !isStreaming || hasFollowingContent || hasSpecialTags | ||
| const durationText = `${label} for ${formatDuration(duration)}` | ||
| // Round to nearest second (minimum 1s) to match original behavior | ||
| const roundedMs = Math.max(1000, Math.round(duration / 1000) * 1000) | ||
| const durationText = `${label} for ${formatDuration(roundedMs)}` | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const getStreamingLabel = (lbl: string) => { | ||
| if (lbl === 'Thought') return 'Thinking' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -53,17 +53,6 @@ export function getBlockColor(blockType: string): string { | ||
| return '#6b7280' | ||
| } | ||
| /** | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| * Formats duration from milliseconds to readable format | ||
| */ | ||
| export function formatDuration(ms?: number): string { | ||
| if (ms === undefined || ms === null) return '-' | ||
| if (ms < 1000) { | ||
| return `${Math.round(ms)}ms` | ||
| } | ||
| return `${(ms / 1000).toFixed(2)}s` | ||
| } | ||
| /** | ||
| * Determines if a keyboard event originated from a text-editable element | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -30,6 +30,7 @@ import { | ||
| Textarea, | ||
| } from '@/components/emcn' | ||
| import { cn } from '@/lib/core/utils/cn' | ||
| import { formatDuration } from '@/lib/core/utils/formatting' | ||
| import { sanitizeForCopilot } from '@/lib/workflows/sanitization/json-sanitizer' | ||
| import { formatEditSequence } from '@/lib/workflows/training/compute-edit-sequence' | ||
| import { useCurrentWorkflow } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-current-workflow' | ||
| @@ -575,7 +576,9 @@ export function TrainingModal() { | ||
| <span className='text-[var(--text-muted)]'>Duration:</span>{' '} | ||
| <span className='text-[var(--text-secondary)]'> | ||
| {dataset.metadata?.duration | ||
| ? `${(dataset.metadata.duration / 1000).toFixed(1)}s` | ||
| ? formatDuration(dataset.metadata.duration, { | ||
| precision: 1, | ||
| }) | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| : 'N/A'} | ||
| </span> | ||
| </div> | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.