Skip to content

feat: revamp alert mute form with sections, auto-naming, quick durations and empty guide - #2197

Merged
jsers merged 3 commits into
mainfrom
optimize-mute-rule
Jul 22, 2026
Merged

feat: revamp alert mute form with sections, auto-naming, quick durations and empty guide#2197
jsers merged 3 commits into
mainfrom
optimize-mute-rule

Conversation

@710leo

@710leo 710leo commented Jul 21, 2026

Copy link
Copy Markdown
Member
image

Summary by CodeRabbit

  • New Features
    • Enhanced shield-rule setup UI with collapsible section headers and optional header summaries.
    • Added periodic mute scheduling with multi-select weekdays and quick presets (everyday/workday/weekend).
    • Improved rule naming via clearer auto-generation and in-form mute/filter summaries.
  • Bug Fixes
    • Prevented empty-state flashes during initial shield-rule loading.
    • Updated shield-rule loading so rule title is no longer prefilled from the quick-mute value.
    • Improved preview/save/try validation flow and modal display behavior.
  • Tests
    • Added unit tests for mute scope/title formatting and duration logic.
  • Documentation / Localization
    • Expanded guidance and validation copy across supported locales (including empty-state and timing tips).

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Shield rule form is refactored into collapsible sections with generated summaries, quick-duration and periodic mute controls, centralized validation, preview feedback, and expanded localization. The Shield list gains improved loading, documentation, add eligibility, and empty-state behavior.

Changes

Shield rule configuration

Layer / File(s) Summary
Mute scope utilities and validation coverage
src/pages/warning/shield/components/utils.ts, src/pages/warning/shield/components/utils.summary.test.ts
Adds helpers for formatting mute tags, severities, scopes, and durations, with tests covering precedence and edge cases.
Sectioned Shield form and periodic mute controls
src/pages/alertRules/FormNG/components/SectionCard/index.tsx, src/pages/warning/shield/components/operateForm.tsx, src/pages/warning/shield/components/DaysOfWeekSelect.tsx
Refactors the form into collapsible sections, adds automatic titles, quick durations, expanded validation, and periodic mute scheduling with weekday presets.
Preview validation and modal feedback
src/pages/warning/shield/components/PreviewMutedEvents.tsx
Routes preview validation through the form-level callback, handles failures, and adds informational modal content.
Shield page states, initialization, and localized copy
src/pages/warning/shield/index.tsx, src/pages/warning/shield/add.tsx, src/pages/warning/shield/locale/*
Improves loading and empty states, documentation access, add eligibility, title initialization, and translations across supported locales.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant OperateForm
  participant SectionCard
  participant PreviewMutedEvents
  User->>OperateForm: Submit preview or test
  OperateForm->>OperateForm: Validate fields
  OperateForm->>SectionCard: Expand sections containing errors
  OperateForm->>PreviewMutedEvents: Continue preview flow
Loading

Possibly related PRs

  • n9e/fe#2144: Introduces the related FormNG SectionCard component.
  • n9e/fe#2195: Also updates SectionCard props and collapse behavior.
  • n9e/fe#2198: Also adds and uses collapsed-header summary content in SectionCard.

Suggested reviewers: jsers

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: sectioned mute form, auto-naming, quick durations, and the empty-state guide.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch optimize-mute-rule

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/warning/shield/components/PreviewMutedEvents.tsx (1)

122-124: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Clear local state when the modal closes.

As per coding guidelines, modal components must explicitly clean up local state (such as temporary selection values) on unmount to prevent stale data from appearing on re-open. If a user selects rows, cancels, and then triggers the preview again, the old selectedRowKeys will persist, which could lead to accidental deletions of unrelated events.

Use the afterClose prop on the Modal to reliably clear the local states.

🧹 Proposed fix
       <Modal
         title={t('alertMutes:preview_muted_title')}
         visible={visible}
+        afterClose={() => {
+          setSelectedRowKeys([]);
+          setData([]);
+        }}
         footer={[
🤖 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/warning/shield/components/PreviewMutedEvents.tsx` around lines 122
- 124, Update the Modal in PreviewMutedEvents to use its afterClose callback to
reset selectedRowKeys and any other temporary local state, ensuring cancelled or
reopened previews never retain stale selections.

Source: Coding guidelines

🧹 Nitpick comments (1)
src/pages/warning/shield/components/utils.ts (1)

21-25: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update the interface to reflect runtime types.

The formatMuteTag function below checks if tag.value is an array, but the interface explicitly types it as string. To prevent TypeScript errors for consumers passing array values (e.g., for in or not in operators), consider updating the type.

💡 Proposed fix
 export interface MuteTagItem {
   key?: string;
   func?: string;
-  value?: string;
+  value?: string | string[];
 }
🤖 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/warning/shield/components/utils.ts` around lines 21 - 25, Update
the MuteTagItem.value property type to include the array shape accepted by
formatMuteTag, while preserving support for string and optional values. Ensure
the interface matches runtime inputs used by in and not in operators so
consumers can pass arrays without TypeScript errors.
🤖 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/warning/shield/locale/en_US.ts`:
- Around line 27-48: Add the missing mute_type.days_of_week_msg translation to
the mute_type locale block in src/pages/warning/shield/locale/en_US.ts (lines
27-48), src/pages/warning/shield/locale/ja_JP.ts (lines 27-48), and
src/pages/warning/shield/locale/ru_RU.ts (lines 27-43), providing the required
periodic days-of-week validation message in each locale.

---

Outside diff comments:
In `@src/pages/warning/shield/components/PreviewMutedEvents.tsx`:
- Around line 122-124: Update the Modal in PreviewMutedEvents to use its
afterClose callback to reset selectedRowKeys and any other temporary local
state, ensuring cancelled or reopened previews never retain stale selections.

---

Nitpick comments:
In `@src/pages/warning/shield/components/utils.ts`:
- Around line 21-25: Update the MuteTagItem.value property type to include the
array shape accepted by formatMuteTag, while preserving support for string and
optional values. Ensure the interface matches runtime inputs used by in and not
in operators so consumers can pass arrays without TypeScript errors.
🪄 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

Run ID: 662c066a-abe2-4481-b0c9-6e4d7572ff48

📥 Commits

Reviewing files that changed from the base of the PR and between d466664 and b932203.

📒 Files selected for processing (13)
  • src/pages/alertRules/FormNG/components/SectionCard/index.tsx
  • src/pages/warning/shield/add.tsx
  • src/pages/warning/shield/components/DaysOfWeekSelect.tsx
  • src/pages/warning/shield/components/PreviewMutedEvents.tsx
  • src/pages/warning/shield/components/operateForm.tsx
  • src/pages/warning/shield/components/utils.summary.test.ts
  • src/pages/warning/shield/components/utils.ts
  • src/pages/warning/shield/index.tsx
  • src/pages/warning/shield/locale/en_US.ts
  • src/pages/warning/shield/locale/ja_JP.ts
  • src/pages/warning/shield/locale/ru_RU.ts
  • src/pages/warning/shield/locale/zh_CN.ts
  • src/pages/warning/shield/locale/zh_HK.ts

Comment on lines 27 to +48
mute_type: {
label: 'Mute type',
0: 'Fixed time',
1: 'Periodic time',
days_of_week: 'Mute time',
days_preset: {
everyday: 'Every day',
workday: 'Workdays',
weekend: 'Weekend',
},
start: 'Start time',
start_msg: 'Start time is required',
end: 'End time',
end_msg: 'End time is required',
periodic_tip: 'A periodic mute never expires, alerts matched in the time ranges above are muted every week. Same start and end time means the whole day',
},
mute_method: {
label: 'Mute method',
0: 'Mute events and notifications',
'0_desc': '(no event, no notification)',
1: 'Mute notifications only',
'1_desc': '(events are still recorded)',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify days_of_week_msg exists across all shield locale files
fd . src/pages/warning/shield/locale --extension ts \
  --exec sh -c 'echo "== $1 =="; rg -n "days_of_week_msg|days_of_week\b" "$1"' _ {}

Repository: n9e/fe

Length of output: 592


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== operateForm usage =="
rg -n "days_of_week_msg|mute_type\.days_of_week|periodic" src/pages/warning/shield -S

echo
echo "== locale files with mute_type blocks =="
for f in src/pages/warning/shield/locale/*.ts; do
  echo "---- $f ----"
  sed -n '20,60p' "$f"
done

Repository: n9e/fe

Length of output: 12248


Add mute_type.days_of_week_msg to the shield locales. operateForm.tsx uses this key for the periodic days-of-week required message, and all shield locale blocks (en_US.ts, ja_JP.ts, ru_RU.ts, zh_CN.ts, zh_HK.ts) still omit it, so an empty value falls back to the raw key string.

📍 Affects 3 files
  • src/pages/warning/shield/locale/en_US.ts#L27-L48 (this comment)
  • src/pages/warning/shield/locale/ja_JP.ts#L27-L48
  • src/pages/warning/shield/locale/ru_RU.ts#L27-L43
🤖 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/warning/shield/locale/en_US.ts` around lines 27 - 48, Add the
missing mute_type.days_of_week_msg translation to the mute_type locale block in
src/pages/warning/shield/locale/en_US.ts (lines 27-48),
src/pages/warning/shield/locale/ja_JP.ts (lines 27-48), and
src/pages/warning/shield/locale/ru_RU.ts (lines 27-43), providing the required
periodic days-of-week validation message in each locale.

710leo added 2 commits July 22, 2026 12:27
- 固定时间模式下周期屏蔽区块被隐藏,其 required 校验也随之关闭,
  避免用户切到周期模式加了空行再切回固定时间后,保存被隐藏字段拦住且看不到错误
- 「全部业务组」或非叶子节点下的空态提示改为指向具体业务组,五种语言同步
- 事件等级未全选也算一种筛选,与订阅规则口径一致,
  避免只收敛级别时仍提示「将屏蔽所有告警事件」
- 起止时间联动的 validateFields(['etime']) 与预览保存回调补上 catch,
  避免校验失败时控制台出现 Uncaught (in promise) 报错

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/warning/shield/components/operateForm.tsx (1)

152-158: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Match day presets with calendar arithmetic

activeQuickDuration compares elapsed milliseconds, but quickDurationChange builds 1d/3d/7d/30d with moment.add, which preserves wall-clock time across DST. That can leave a day-based preset unselected around DST boundaries. Compare against moment(btime).clone().add(num, unit) instead.

🤖 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/warning/shield/components/operateForm.tsx` around lines 152 - 158,
Update the activeQuickDuration matcher to use calendar arithmetic consistent
with quickDurationChange: clone moment(btime), add the parsed num and unit, and
compare the resulting time with etime instead of comparing elapsed milliseconds.
Preserve the existing undefined behavior when btime or etime is missing and the
QUICK_DURATIONS lookup.
🧹 Nitpick comments (2)
src/pages/warning/shield/components/operateForm.tsx (2)

384-384: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Tailwind utilities for the new layout rules.

The new visibility, widths, flex layout, and spacing are directly expressible with Tailwind; keeping them inline fragments the component styling approach.

  • src/pages/warning/shield/components/operateForm.tsx#L384-L384: replace the inline display toggle with conditional hidden/block classes.
  • src/pages/warning/shield/components/operateForm.tsx#L435-L435: replace the inline display toggle with conditional hidden/block classes.
  • src/pages/warning/shield/components/operateForm.tsx#L440-L469: replace width, flex, and bottom-margin styles with Tailwind utilities.
  • src/pages/warning/shield/components/operateForm.tsx#L475-L501: replace fixed-width Form.Item styles with Tailwind width utilities.

As per coding guidelines, use Tailwind utility classes for container layout and component-specific display styles.

🤖 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/warning/shield/components/operateForm.tsx` at line 384, Update
operateForm.tsx at lines 384 and 435 to replace inline display toggles with
conditional hidden/block Tailwind classes; replace inline width, flex, and
margin styles at lines 440-469 with equivalent Tailwind utilities; and replace
fixed-width Form.Item styles at lines 475-501 with Tailwind width utilities.

Source: Coding guidelines


63-63: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use the declared props type.

Props is defined but bypassed with : any, so detail and type lose type checking inside the component. Type the destructured parameter as Props and make the default detail value conform to its declared shape.

As per coding guidelines, Component Props must use interface for explicit declaration 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/warning/shield/components/operateForm.tsx` at line 63, Update the
OperateForm component to destructure its parameter as the declared Props type
instead of any, and ensure the default detail value matches Props.detail’s
declared shape. Define Props as an interface if it is currently another
declaration form, preserving type checking for both detail and type.

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.

Outside diff comments:
In `@src/pages/warning/shield/components/operateForm.tsx`:
- Around line 152-158: Update the activeQuickDuration matcher to use calendar
arithmetic consistent with quickDurationChange: clone moment(btime), add the
parsed num and unit, and compare the resulting time with etime instead of
comparing elapsed milliseconds. Preserve the existing undefined behavior when
btime or etime is missing and the QUICK_DURATIONS lookup.

---

Nitpick comments:
In `@src/pages/warning/shield/components/operateForm.tsx`:
- Line 384: Update operateForm.tsx at lines 384 and 435 to replace inline
display toggles with conditional hidden/block Tailwind classes; replace inline
width, flex, and margin styles at lines 440-469 with equivalent Tailwind
utilities; and replace fixed-width Form.Item styles at lines 475-501 with
Tailwind width utilities.
- Line 63: Update the OperateForm component to destructure its parameter as the
declared Props type instead of any, and ensure the default detail value matches
Props.detail’s declared shape. Define Props as an interface if it is currently
another declaration form, preserving type checking for both detail and type.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7bc349be-e926-499a-9d9f-f15d11694ae7

📥 Commits

Reviewing files that changed from the base of the PR and between e301ff1 and 2bb0dcd.

📒 Files selected for processing (3)
  • src/pages/warning/shield/components/operateForm.tsx
  • src/pages/warning/shield/components/utils.summary.test.ts
  • src/pages/warning/shield/components/utils.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/pages/warning/shield/components/utils.summary.test.ts
  • src/pages/warning/shield/components/utils.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants