-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(web): display '—' for missing data instead of NaN% or 0% #678
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
Merged
hzb1115
merged 2 commits into
NoFxAiOS:dev
from
the-dev-z:fix/competition-missing-data-display
Nov 11, 2025
Merged
fix(web): display '—' for missing data instead of NaN% or 0% #678
hzb1115
merged 2 commits into
NoFxAiOS:dev
from
the-dev-z:fix/competition-missing-data-display
Nov 11, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…S#633) - Add hasValidData validation for null/undefined/NaN - Display '—' for invalid trader.total_pnl_pct - Only show gap calculations when both values are valid - Prevents misleading users with 0% when data is missing Fixes NoFxAiOS#633
Closed
xqliu
reviewed
Nov 7, 2025
| : '—'} | ||
| </div> | ||
| {isWinning && gap > 0 && ( | ||
| {hasValidData && isWinning && gap > 0 && ( |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的模式可以抽取可复用函数的,辛苦看下怎么处理比较好?
boolean && component 方式
Contributor
代码审查报告 - PR #678审查结果:✅ 通过(数据显示改进)业务层面审查✅ 需求验证
✅ 功能完整性
技术层面审查✅ 数据验证逻辑验证条件: const hasValidData =
trader.total_pnl_pct != null && // 不是 null 或 undefined
opponent.total_pnl_pct != null &&
!isNaN(trader.total_pnl_pct) && // 不是 NaN
!isNaN(opponent.total_pnl_pct)优点:
✅ 条件渲染修改前: {/* 总是显示,可能是 NaN% 或 0.00% */}
{(trader.total_pnl ?? 0) >= 0 ? '+' : ''}
{trader.total_pnl_pct?.toFixed(2) || '0.00'}%修改后: {trader.total_pnl_pct != null && !isNaN(trader.total_pnl_pct)
? `${trader.total_pnl_pct >= 0 ? '+' : ''}${trader.total_pnl_pct.toFixed(2)}%`
: '—'}改进:
✅ Gap 计算逻辑修改前: const gap = trader.total_pnl_pct - opponent.total_pnl_pct
// 可能计算出 NaN修改后: const gap = hasValidData
? trader.total_pnl_pct - opponent.total_pnl_pct
: NaN改进:
✅ 领先/落后显示修改: // Before: 可能显示 "NaN%" 的差距
{isWinning && gap > 0 && (...)}
// After: 仅在有效数据时显示
{hasValidData && isWinning && gap > 0 && (...)}新增缺失数据提示: {!hasValidData && (
<div className="text-xs font-semibold" style={{ color: '#848E9C' }}>
—
</div>
)}E2E 验证报告✅ 测试场景1:正常数据✅ 测试场景2:null 数据✅ 测试场景3:NaN 数据✅ 测试场景4:undefined 数据✅ 测试场景5:负数代码质量审查✅ 代码清晰度
✅ 一致性
✅ 错误处理
UI/UX 设计验证✅ 视觉一致性缺失数据标识:
✅ 用户体验Before:
After:
🟡 改进建议(非 BLOCKING)建议1:提取验证函数// 提取为独立函数,便于复用
const isValidNumber = (value: number | null | undefined): boolean => {
return value != null && !isNaN(value)
}
// 使用
const hasValidData =
isValidNumber(trader.total_pnl_pct) &&
isValidNumber(opponent.total_pnl_pct)建议2:添加 Tooltip// 对于缺失数据,提供悬停提示
{!hasValidData && (
<Tooltip content="数据暂不可用">
<div className="text-xs font-semibold" style={{ color: '#848E9C' }}>
—
</div>
</Tooltip>
)}建议3:类型安全// 在 TypeScript 类型定义中明确可选性
interface Trader {
total_pnl?: number | null // 明确可以是 undefined 或 null
total_pnl_pct?: number | null
}建议4:单元测试describe('CompetitionPage data display', () => {
it('displays "—" for null data', () => {
const trader = { total_pnl_pct: null }
render(<CompetitionPage traders={[trader, ...]} />)
expect(screen.getByText('—')).toBeInTheDocument()
})
it('displays "—" for NaN data', () => {
const trader = { total_pnl_pct: NaN }
render(<CompetitionPage traders={[trader, ...]} />)
expect(screen.getByText('—')).toBeInTheDocument()
})
it('displays percentage for valid data', () => {
const trader = { total_pnl_pct: 10.5 }
render(<CompetitionPage traders={[trader, ...]} />)
expect(screen.getByText('+10.50%')).toBeInTheDocument()
})
})总结这是一个高质量的数据显示改进 PR: 优点
改进空间(非 BLOCKING)
审查结论:✅ 通过,建议合并 重要性:
影响范围:
|
Collaborator
Author
|
此 PR 已獲批准 ✅ 可以合併了嗎?謝謝!🙏 |
- Test data validation logic (null/undefined/NaN detection) - Test gap calculation with valid and invalid data - Test display formatting (shows '—' instead of 'NaN%') - Test leading/trailing message display conditions - Test edge cases (Infinity, very small/large numbers) All 25 test cases passed, covering: 1. hasValidData check (7 cases): valid/null/undefined/NaN/zero/negative 2. gap calculation (3 cases): valid data, invalid data, negative gap 3. display formatting (6 cases): positive/negative/null/undefined/NaN/zero 4. leading/trailing messages (5 cases): conditional display logic 5. edge cases (4 cases): Infinity, -Infinity, very small/large numbers Related to PR NoFxAiOS#678 - ensures missing data displays as '—' instead of 'NaN%'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
sparrow211
pushed a commit
to sparrow211/nofx
that referenced
this pull request
Nov 11, 2025
…S#678) * fix(web): display '—' for missing data instead of NaN% or 0% (NoFxAiOS#633) - Add hasValidData validation for null/undefined/NaN - Display '—' for invalid trader.total_pnl_pct - Only show gap calculations when both values are valid - Prevents misleading users with 0% when data is missing Fixes NoFxAiOS#633 * test(web): add comprehensive unit tests for CompetitionPage NaN handling - Test data validation logic (null/undefined/NaN detection) - Test gap calculation with valid and invalid data - Test display formatting (shows '—' instead of 'NaN%') - Test leading/trailing message display conditions - Test edge cases (Infinity, very small/large numbers) All 25 test cases passed, covering: 1. hasValidData check (7 cases): valid/null/undefined/NaN/zero/negative 2. gap calculation (3 cases): valid data, invalid data, negative gap 3. display formatting (6 cases): positive/negative/null/undefined/NaN/zero 4. leading/trailing messages (5 cases): conditional display logic 5. edge cases (4 cases): Infinity, -Infinity, very small/large numbers Related to PR NoFxAiOS#678 - ensures missing data displays as '—' instead of 'NaN%'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: ZhouYongyou <[email protected]> Co-authored-by: Claude <[email protected]>
bebest2010
pushed a commit
to bebest2010/nofx
that referenced
this pull request
Nov 18, 2025
…S#678) * fix(web): display '—' for missing data instead of NaN% or 0% (NoFxAiOS#633) - Add hasValidData validation for null/undefined/NaN - Display '—' for invalid trader.total_pnl_pct - Only show gap calculations when both values are valid - Prevents misleading users with 0% when data is missing Fixes NoFxAiOS#633 * test(web): add comprehensive unit tests for CompetitionPage NaN handling - Test data validation logic (null/undefined/NaN detection) - Test gap calculation with valid and invalid data - Test display formatting (shows '—' instead of 'NaN%') - Test leading/trailing message display conditions - Test edge cases (Infinity, very small/large numbers) All 25 test cases passed, covering: 1. hasValidData check (7 cases): valid/null/undefined/NaN/zero/negative 2. gap calculation (3 cases): valid data, invalid data, negative gap 3. display formatting (6 cases): positive/negative/null/undefined/NaN/zero 4. leading/trailing messages (5 cases): conditional display logic 5. edge cases (4 cases): Infinity, -Infinity, very small/large numbers Related to PR NoFxAiOS#678 - ensures missing data displays as '—' instead of 'NaN%'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: ZhouYongyou <[email protected]> Co-authored-by: Claude <[email protected]>
tinkle-community
added a commit
that referenced
this pull request
Nov 26, 2025
* fix(web): display '—' for missing data instead of NaN% or 0% (#633) - Add hasValidData validation for null/undefined/NaN - Display '—' for invalid trader.total_pnl_pct - Only show gap calculations when both values are valid - Prevents misleading users with 0% when data is missing Fixes #633 * test(web): add comprehensive unit tests for CompetitionPage NaN handling - Test data validation logic (null/undefined/NaN detection) - Test gap calculation with valid and invalid data - Test display formatting (shows '—' instead of 'NaN%') - Test leading/trailing message display conditions - Test edge cases (Infinity, very small/large numbers) All 25 test cases passed, covering: 1. hasValidData check (7 cases): valid/null/undefined/NaN/zero/negative 2. gap calculation (3 cases): valid data, invalid data, negative gap 3. display formatting (6 cases): positive/negative/null/undefined/NaN/zero 4. leading/trailing messages (5 cases): conditional display logic 5. edge cases (4 cases): Infinity, -Infinity, very small/large numbers Related to PR #678 - ensures missing data displays as '—' instead of 'NaN%'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: tinkle-community <[email protected]> --------- Co-authored-by: ZhouYongyou <[email protected]> Co-authored-by: tinkle-community <[email protected]>
tinkle-community
added a commit
that referenced
this pull request
Nov 26, 2025
* fix(web): display '—' for missing data instead of NaN% or 0% (#633) - Add hasValidData validation for null/undefined/NaN - Display '—' for invalid trader.total_pnl_pct - Only show gap calculations when both values are valid - Prevents misleading users with 0% when data is missing Fixes #633 * test(web): add comprehensive unit tests for CompetitionPage NaN handling - Test data validation logic (null/undefined/NaN detection) - Test gap calculation with valid and invalid data - Test display formatting (shows '—' instead of 'NaN%') - Test leading/trailing message display conditions - Test edge cases (Infinity, very small/large numbers) All 25 test cases passed, covering: 1. hasValidData check (7 cases): valid/null/undefined/NaN/zero/negative 2. gap calculation (3 cases): valid data, invalid data, negative gap 3. display formatting (6 cases): positive/negative/null/undefined/NaN/zero 4. leading/trailing messages (5 cases): conditional display logic 5. edge cases (4 cases): Infinity, -Infinity, very small/large numbers Related to PR #678 - ensures missing data displays as '—' instead of 'NaN%'. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: tinkle-community <[email protected]> --------- Co-authored-by: ZhouYongyou <[email protected]> Co-authored-by: tinkle-community <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request - Frontend
Summary
This PR fixes issue #633 by properly handling missing data in the competition page's head-to-head comparison.
Problem
The original code would display
NaN%when trader data was missing or invalid. The first attempted fix (PR #633, later reverted in #676) used null coalescing to default to0%, but this was misleading as it suggested traders had equal performance when data was actually unavailable.Solution
hasValidDatavalidation that checks fornull,undefined, andNaNvalues—(em dash) for invalidtrader.total_pnl_pctinstead of0%orNaN%leadingBy,behindBy) when both traders have valid data—placeholder when data is unavailableWhy This Approach?
Testing
—)—)Closes #633
🎯 Type of Change | 變更類型
🔗 Related Issues | 相關 Issue
🧪 Testing | 測試
Test Environment | 測試環境
Manual Testing | 手動測試
🌐 Internationalization | 國際化
✅ Checklist | 檢查清單
Code Quality | 代碼質量
npm run build)npm run lint| 已運行npm run lintDocumentation | 文檔
Git
devbranch | 已 rebase 到最新dev分支By submitting this PR, I confirm | 提交此 PR,我確認:
🌟 Thank you for your contribution! | 感謝你的貢獻!