feat- 活跃告警列表顶部工具栏新增 “显示触发时值” 开关,打开后可展示触发时值。 - #2237
Conversation
开关存储值到localstorage中,变量名为:alert_cur_events_show_trigger_value
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
💤 Files with no reviewable changes (5)
📝 WalkthroughWalkthroughThe alert event table now always shows trigger values after the duration column. Locale files provide the corresponding ChangesTrigger-value column
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/pages/alertCurEvent/pages/List/index.tsx (1)
400-410: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse Tailwind for the new toolbar layout.
Spacewas added only to align the label and switch. Replace it with a Tailwind wrapper such as<div className='flex items-center gap-2'>.As per coding guidelines,
src/**/*.{ts,tsx}requires Tailwind utility classes for container layout: “Use Tailwind utility classes for container layout (flex, grid, gap, padding, margin, alignment).”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/alertCurEvent/pages/List/index.tsx` around lines 400 - 410, Replace the Ant Design Space wrapper around the show-trigger-value label and Switch with a div using Tailwind layout utilities such as flex, items-center, and gap-2, while preserving the existing label, switch behavior, and spacing.Source: Coding guidelines
src/pages/alertCurEvent/pages/List/AlertTable.tsx (1)
222-222: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the new
anycast.The cast at Line 222 disables type checking for the trigger-value column. Type the columns collection with the table column type and keep the renderer value typed explicitly. This prevents mismatches between the API field and the renderer.
As per coding guidelines, TypeScript components must use explicit interfaces and avoid
any.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/alertCurEvent/pages/List/AlertTable.tsx` at line 222, Remove the any cast from the columns definition near the trigger-value column in AlertTable. Type the columns collection with the table’s column type, and explicitly type the renderer value so the API field and renderer remain type-checked without using any.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/pages/alertCurEvent/pages/List/AlertTable.tsx`:
- Around line 207-224: Update the column construction around the
showTriggerValue insertion and the production-only claimant insertion so
claimant remains after duration regardless of whether trigger_value is shown.
Insert claimant relative to the duration column or compose the columns without
fixed numeric indices, preserving the existing order in both switch states.
In `@src/pages/alertCurEvent/pages/List/index.tsx`:
- Around line 400-410: Add an accessible name to the Switch in the
show-trigger-value control by setting its aria-label from
t('show_trigger_value'), while preserving the existing checked state and
onChange behavior.
---
Nitpick comments:
In `@src/pages/alertCurEvent/pages/List/AlertTable.tsx`:
- Line 222: Remove the any cast from the columns definition near the
trigger-value column in AlertTable. Type the columns collection with the table’s
column type, and explicitly type the renderer value so the API field and
renderer remain type-checked without using any.
In `@src/pages/alertCurEvent/pages/List/index.tsx`:
- Around line 400-410: Replace the Ant Design Space wrapper around the
show-trigger-value label and Switch with a div using Tailwind layout utilities
such as flex, items-center, and gap-2, while preserving the existing label,
switch behavior, and spacing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 000da82b-efde-477c-9eb2-5ad839898fc8
📒 Files selected for processing (8)
src/pages/alertCurEvent/constants.tssrc/pages/alertCurEvent/locale/en_US.tssrc/pages/alertCurEvent/locale/ja_JP.tssrc/pages/alertCurEvent/locale/ru_RU.tssrc/pages/alertCurEvent/locale/zh_CN.tssrc/pages/alertCurEvent/locale/zh_HK.tssrc/pages/alertCurEvent/pages/List/AlertTable.tsxsrc/pages/alertCurEvent/pages/List/index.tsx
| if (showTriggerValue) { | ||
| columns.splice(1, 0, { | ||
| title: t('trigger_value'), | ||
| dataIndex: 'trigger_value', | ||
| render(value) { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| minWidth: getTextWidth(t('trigger_value')), | ||
| }} | ||
| > | ||
| {value} | ||
| </div> | ||
| ); | ||
| }, | ||
| } as any); | ||
| } | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep the production column order stable.
When showTriggerValue is true, this insertion shifts duration to index 3. The existing production-only insertion at Line 226 still uses index 3, so claimant is placed before duration. When the switch is off, claimant remains after duration. Insert claimant relative to duration or compose the columns without hard-coded positions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/pages/alertCurEvent/pages/List/AlertTable.tsx` around lines 207 - 224,
Update the column construction around the showTriggerValue insertion and the
production-only claimant insertion so claimant remains after duration regardless
of whether trigger_value is shown. Insert claimant relative to the duration
column or compose the columns without fixed numeric indices, preserving the
existing order in both switch states.
| <Space> | ||
| <span className='text-sm text-fc-text-3'>{t('show_trigger_value')}</span> | ||
| <Switch | ||
| size='small' | ||
| checked={showTriggerValue} | ||
| onChange={(checked) => { | ||
| localStorage.setItem(SHOW_TRIGGER_VALUE_CACHE_KEY, String(checked)); | ||
| setShowTriggerValue(checked); | ||
| }} | ||
| /> | ||
| </Space> |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate file =="
git ls-files | rg '^src/pages/alertCurEvent/pages/List/index\.tsx$' || true
echo "== relevant lines =="
if [ -f src/pages/alertCurEvent/pages/List/index.tsx ]; then
nl -ba src/pages/alertCurEvent/pages/List/index.tsx | sed -n '360,440p'
fi
echo "== imports and SWITCH deps =="
nl -ba src/pages/alertCurEvent/pages/List/index.tsx | sed -n '1,80p'
rg -n "from 'antd'|from \"antd\"|import .*Switch|SHOW_TRIGGER_VALUE_CACHE_KEY|showTriggerValue" src/pages/alertCurEvent/pages/List/index.tsxRepository: n9e/fe
Length of output: 268
🌐 Web query:
React aria-label inaccessible name verification assistive technology aria-label switch antd Switch accessibility
💡 Result:
The "inaccessible name" issue in React and the use of aria-label with components like Ant Design's Switch are governed by established web accessibility (WCAG) standards. Accessible Name Requirements Assistive technologies, such as screen readers, identify interactive elements by their "accessible name." When an element is interactive (e.g., a switch or button), it must have a clear, descriptive name [1][2]. The "inaccessible name" error typically occurs when an element lacks this identifier [1][3]. Best Practices for Naming 1. Native Labels First: Always prefer native HTML labels (like for inputs) [1][3]. 2. Visible Text: If a control has visible text (e.g., a "Save" button), the accessible name should ideally match or include that text [4]. WCAG 2.1 Success Criterion 2.5.3 (Label in Name) mandates that if visible text exists, the accessible name must contain it [4]. 3. aria-labelledby: Use this attribute to reference existing visible text on the page [5][2]. This is preferred over aria-label because it supports automatic translation if the page text is translated [5]. 4. aria-label: Use this only as a fallback when no visible text exists (e.g., icon-only buttons) [5][2][3]. It is not automatically translated by browser tools, which can cause accessibility gaps for non-English speakers [5]. Ant Design (antd) Switch Accessibility The antd Switch component is designed to toggle between two states [6][7]. Because it is a custom interactive component, you must ensure it has an accessible name [1]. - If the Switch has no visible label, you should provide an accessible name via the aria-label attribute [1][2]. - While the antd Switch API (as seen in its source code and documentation) does not explicitly expose an aria-label prop in its public type definitions, you can pass it through via HTML attribute passthrough (standard React behavior for native attributes) or by wrapping it in a labeled structure [8][6][7]. Troubleshooting "Missing Display Name" The "Component definition is missing display name" error you may be encountering while working with custom components or wrappers is a linting warning, not a functional accessibility error [9][10]. It occurs when ESLint cannot automatically infer the name of a component (common with React.forwardRef or anonymous arrow functions) [9][11][12]. You can resolve this by: - Setting the displayName property explicitly: MyComponent.displayName = 'MyComponent'; [10][11][12] - Using a named function instead of an anonymous arrow function [11][13]. Verification To verify your accessibility implementation: - Use Browser DevTools to inspect the "Accessibility" tree and check the "computed name" of your element [3]. - Test with screen readers (e.g., NVDA, VoiceOver) to ensure the component is announced correctly [3]. - Ensure your implementation does not violate the "Label in Name" rule if visible text is present [4]. Sources: [1][4][5][2][3][8][14][6][7][15][9][10][11][12][13]
Citations:
- 1: https://reactspectrum.blob.core.windows.net/reactspectrum/33946eb4d799eceb12c57205c900db1629430340/docs/react-aria/accessibility.html
- 2: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-label
- 3: https://www.levelaccess.com/blog/aria-labels-and-accessible-names-a-developers-guide/
- 4: https://rocketvalidator.com/accessibility-validation/axe/4.11/label-content-name-mismatch
- 5: https://devencyclopedia.com/blog/aria-in-react-accessibility
- 6: https://ant-design.antgroup.com/components/switch
- 7: https://ant.design/components/switch.md
- 8: https://github.com/ant-design/ant-design/blob/master/components/switch/index.tsx
- 9: https://stackoverflow.com/questions/52992932/component-definition-is-missing-display-name-react-display-name
- 10: https://bobbyhadz.com/blog/react-component-is-missing-display-name
- 11: https://stackoverflow.com/questions/71877298/how-to-fix-the-component-definition-is-missing-display-name-error
- 12: https://www.eslint-react.xyz/docs/rules/no-missing-component-display-name
- 13: https://stackoverflow.com/questions/67992894/component-definition-is-missing-display-name-for-forwardref
- 14: https://ant.design/components/switch/?locale=en-US
- 15: https://ant.design/components/switch/?amp=1
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== relevant content =="
awk 'NR>=360 && NR<=440 { printf "%5d: %s\n", NR, $0 }' src/pages/alertCurEvent/pages/List/index.tsx
echo "== imports and related usages =="
awk 'NR>=1 && NR<=120 { printf "%5d: %s\n", NR, $0 }' src/pages/alertCurEvent/pages/List/index.tsx
echo "== Switch usage and cache key =="
rg -n "from ['\"]antd['\"]|import .*Switch|SHOW_TRIGGER_VALUE_CACHE_KEY|showTriggerValue|aria-|label" src/pages/alertCurEvent/pages/List/index.tsxRepository: n9e/fe
Length of output: 11802
Give the Switch an accessible name.
The text label is a sibling of the Switch, so it is not announced as the control’s label. Add aria-label={t('show_trigger_value')} to the Switch or associate it with the label explicitly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/pages/alertCurEvent/pages/List/index.tsx` around lines 400 - 410, Add an
accessible name to the Switch in the show-trigger-value control by setting its
aria-label from t('show_trigger_value'), while preserving the existing checked
state and onChange behavior.
|
改成始终展示吧,不用加 "显示触发时值" 开关 |

开关存储值到localstorage中,变量名为:alert_cur_events_show_trigger_value


Summary by CodeRabbit