Skip to content
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

feat(show-notification): support inlineLink #1483

Merged
merged 1 commit into from
Jan 21, 2025
Merged

Conversation

weareoutman
Copy link
Member

@weareoutman weareoutman commented Jan 21, 2025

依赖检查

组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。

请勾选以下两组选项其中之一:

  • 本次 MR 没有使用上游组件(例如框架、后台组件等)的较新版本提供的特性。

或者:

  • 本次 MR 使用了上游组件(例如框架、后台组件等)的较新版本提供的特性。
  • 在对应的文件中更新了该上游组件的依赖版本(或确认了当前声明的依赖版本已包含本次 MR 使用的新特性)。

提交信息检查

Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。

破坏性变更是针对于下游使用者而言,可以通过本次改动对下游使用者的影响来识别变更类型:

  • 下游使用者不做任何改动,仍可以正常工作时,那么它属于普通变更。
  • 反之,下游使用者不做改动就无法正常工作时,那么它属于破坏性变更。

例如,构件修改了一个属性名,小产品 Storyboard 中需要使用新属性名才能工作,那么它就是破坏性变更。
又例如,构件还没有任何下游使用者,那么它的任何变更都是普通变更。

破坏性变更:

  • ⚠️ 本次 MR 包含破坏性变更的提交,请继续确认以下所有选项:
  • 没有更好的兼容方案,必须做破坏性变更。
  • 使用了 feat 作为提交类型。
  • 标注了 BREAKING CHANGE: 你的变更说明
  • 同时更新了本仓库中所有下游使用者的调用。
  • 同时更新了本仓库中所有下游使用者对该子包的依赖为即将发布的 major 版本。
  • 同时为其它仓库的 Migrating 做好了准备,例如文档或批量改动的方法。
  • 手动验证过破坏性变更在 Migrate 后可以正常工作。
  • 破坏性变更所在的提交没有意外携带其它子包的改动。

新特性:

  • 本次 MR 包含新特性的提交,且该提交不带有破坏性变更,并使用了 feat 作为提交类型。
  • 给新特性添加了单元测试。
  • 手动验证过新特性可以正常工作。

问题修复:

  • 本次 MR 包含问题修复的提交,且该提交不带有新特性或破坏性变更,并使用了 fix 作为提交类型。
  • 给问题修复添加了单元测试。
  • 手动验证过问题修复得到解决。

杂项工作:

即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:

  • 本次 MR 包含杂项工作的提交,且该提交不带有问题修复、新特性或破坏性变更,并使用了 chore, docs, test 等作为提交类型。

Summary by CodeRabbit

  • 新功能

    • 通知系统现支持在通知消息中添加内联链接
    • 可以自定义链接文本、URL、目标和跳转行为
  • 测试

    • 新增测试用例验证内联链接在通知中的正确渲染
    • 确保链接属性(如文本和跳转地址)能够正确设置

Copy link

coderabbitai bot commented Jan 21, 2025

概述

该变更为通知系统引入了内联链接功能,允许在通知消息中添加可点击的链接。新增了 inlineLink 属性,使通知组件能够在消息旁边渲染一个链接元素。

变更

文件 变更说明
bricks/basic/.../show-notification.tsx 1. 在 NotificationOptions 接口中新增可选的 inlineLink 属性
2. 更新通知组件渲染逻辑,支持条件性显示内联链接
bricks/basic/.../show-notification.spec.tsx 新增测试用例 "内联链接",验证内联链接的正确渲染和属性设置

详细解析

接口变更

  • NotificationOptions 中新增 inlineLink 属性,包含 texturlhreftarget 字段
  • 这一变更允许在通知中可选地包含一个可点击的链接

渲染逻辑

  • 通知组件现在支持根据 inlineLink 属性的存在,在消息旁边渲染链接
  • 使用 lodash 的 pick 函数确保只传递必要的链接属性

测试

  • 添加了专门测试内联链接功能的测试用例
  • 验证链接文本为 "查看详情"
  • 确认链接的 href 属性正确设置为 "https://example.com"

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 13 changed files in this pull request and generated no comments.

Files not reviewed (8)
  • bricks/basic/package.json: Language not supported
  • bricks/basic/src/alert-notifications/styles.shadow.css: Language not supported
  • bricks/basic/src/bootstrap.ts: Evaluated as low risk
  • bricks/basic/src/data-providers/show-notification/show-notification.tsx: Evaluated as low risk
  • bricks/basic/src/alert-notifications/interfaces.ts: Evaluated as low risk
  • bricks/basic/src/data-providers/show-notification/show-notification.spec.tsx: Evaluated as low risk
  • bricks/basic/src/alert-notifications/index.tsx: Evaluated as low risk
  • bricks/basic/src/alert-notifications/SpeechNotifications.ts: Evaluated as low risk
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.47%. Comparing base (3a2949e) to head (0eda238).
Report is 5 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1483   +/-   ##
=======================================
  Coverage   90.47%   90.47%           
=======================================
  Files         124      124           
  Lines        2762     2762           
  Branches      379      379           
=======================================
  Hits         2499     2499           
  Misses        169      169           
  Partials       94       94           
Files with missing lines Coverage Δ
...-providers/show-notification/show-notification.tsx 100.00% <ø> (ø)

coderabbitai[bot]

This comment was marked as outdated.

Copy link

github-actions bot commented Jan 21, 2025

@github-actions github-actions bot temporarily deployed to pull request January 21, 2025 02:21 Inactive

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

@github-actions github-actions bot temporarily deployed to pull request January 21, 2025 03:41 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
bricks/basic/src/alert-notifications/index.ts (2)

9-11: 建议重构服务初始化逻辑

建议将服务初始化逻辑移至单独的方法中,以提高可测试性和代码组织性。这样可以更好地处理用户认证状态的变化。

-const { username } = auth.getAuth();
-// istanbul ignore next
-const alertService = username ? new AlertService(username) : null;
+class AlertNotifications extends NextElement {
+  private alertService: AlertService | null = null;
+
+  private initializeService(): void {
+    const { username } = auth.getAuth();
+    if (username) {
+      this.alertService = new AlertService(username);
+    }
+  }

21-28: 建议增强生命周期方法的健壮性

建议添加以下增强:

  1. 为订阅操作添加错误处理
  2. 添加日志记录以便调试
 connectedCallback() {
   super._markConnectedCallbackCalled();
-  alertService?.subscribe();
+  try {
+    alertService?.subscribe();
+    console.debug("[alert-notifications] Successfully subscribed to alerts");
+  } catch (error) {
+    console.error("[alert-notifications] Failed to subscribe to alerts:", error);
+  }
 }

 disconnectedCallback() {
-  alertService?.unsubscribe();
+  try {
+    alertService?.unsubscribe();
+    console.debug("[alert-notifications] Successfully unsubscribed from alerts");
+  } catch (error) {
+    console.error("[alert-notifications] Failed to unsubscribe from alerts:", error);
+  }
 }
bricks/basic/src/alert-notifications/AlertService.ts (2)

82-86: 防止内存泄漏

subscribe 方法在重复调用时可能导致重复订阅。建议在 #enable 方法中保存 messageDispatcher.subscribe 的返回值并在 #disable 中清理。

  #enable() {
    if (!this.#active) {
-     messageDispatcher.subscribe(CHANNEL, {
+     const disposeSubscription = messageDispatcher.subscribe(CHANNEL, {
        system: "msgsender",
        topic: `monitor.alert.notify.${this.#username}`,
      });
      this.#disposeOnMessage = messageDispatcher.onMessage(
        CHANNEL,
        this.#callback
      );
+     this.#disposeSubscription = disposeSubscription;
      this.#active = true;
    }
  }

66-71: 语音通知的可访问性考虑

语音通知功能需要考虑以下几点:

  1. 是否需要提供音量控制
  2. 是否需要提供语速控制
  3. 是否需要支持多语言
bricks/basic/src/alert-notifications/AlertService.spec.ts (1)

27-33: 补充错误处理测试

建议添加测试用例验证 showNotification 失败时的错误处理逻辑。

it("should handle notification errors gracefully", async () => {
  showNotification.mockRejectedValueOnce(new Error("测试错误"));
  // ... 测试步骤
  expect(console.error).toHaveBeenCalled();
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77e4a23 and 4ddf883.

📒 Files selected for processing (7)
  • bricks/basic/deploy-default/package.conf.yaml (1 hunks)
  • bricks/basic/src/alert-notifications/AlertBuffer.spec.ts (1 hunks)
  • bricks/basic/src/alert-notifications/AlertBuffer.ts (1 hunks)
  • bricks/basic/src/alert-notifications/AlertService.spec.ts (1 hunks)
  • bricks/basic/src/alert-notifications/AlertService.ts (1 hunks)
  • bricks/basic/src/alert-notifications/index.spec.ts (1 hunks)
  • bricks/basic/src/alert-notifications/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • bricks/basic/src/alert-notifications/index.spec.ts
  • bricks/basic/src/alert-notifications/AlertBuffer.spec.ts
  • bricks/basic/src/alert-notifications/AlertBuffer.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
bricks/basic/src/alert-notifications/AlertService.ts

[warning] 59-59: bricks/basic/src/alert-notifications/AlertService.ts#L59
Added line #L59 was not covered by tests

bricks/basic/src/alert-notifications/index.ts

[warning] 30-30: bricks/basic/src/alert-notifications/index.ts#L30
Added line #L30 was not covered by tests

🔇 Additional comments (6)
bricks/basic/src/alert-notifications/index.ts (2)

16-20: 代码实现规范,符合最佳实践

组件定义遵循了命名空间规范,样式引入方式正确,继承关系合理。


30-32: 建议完善空方法的文档说明和测试覆盖

  1. 建议添加详细的文档注释,说明为什么该方法不需要实现。
  2. 即使是空方法,也应该添加相应的单元测试以提高测试覆盖率。
+/**
+ * 该组件不需要渲染UI元素,仅负责处理告警通知的订阅。
+ * @override
+ */
 _render() {
   // Do nothing
 }

建议添加以下测试用例:

it("should not render any UI elements", () => {
  const element = new AlertNotifications();
  element._render();
  expect(element.shadowRoot?.children.length).toBe(0);
});
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-30: bricks/basic/src/alert-notifications/index.ts#L30
Added line #L30 was not covered by tests

bricks/basic/deploy-default/package.conf.yaml (1)

5-5: 验证依赖版本更新的兼容性

依赖版本从 ^2.90.33 || ^3.8.38 更新到 ^2.90.33 || ^3.19.23,请确认:

  1. 新版本是否包含不兼容的更改
  2. 是否需要更新其他相关依赖
bricks/basic/src/alert-notifications/AlertService.ts (1)

59-61: 改进错误处理机制

在显示通知时捕获到的错误被静默忽略,这可能导致问题难以排查。建议至少记录错误信息。

  .catch((error) => {
-   /* Do nothing */
+   console.error('显示通知时发生错误:', error);
  })
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 59-59: bricks/basic/src/alert-notifications/AlertService.ts#L59
Added line #L59 was not covered by tests

bricks/basic/src/alert-notifications/AlertService.spec.ts (2)

71-107: 改进时间相关的测试

使用固定时间戳进行测试可能导致测试不稳定。建议使用 Jest 的时间模拟功能。

- time: Math.round(+new Date("2025-01-21") / 1000),
+ time: Math.round(Date.UTC(2025, 0, 21, 8, 0, 0) / 1000),

109-145: 补充语音通知测试

语音通知的测试用例需要验证 SpeechNotifications 的调用。

expect(mockSpeechNotifications.play).toHaveBeenCalledWith(
  "2025-01-21 08:00:00【Warning】test target-test origin content"
);

bricks/basic/src/alert-notifications/AlertService.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request January 21, 2025 03:57 Inactive
@weareoutman weareoutman changed the title feat(): alert notifications feat(show-notification): support inlineLink Jan 21, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
bricks/basic/src/data-providers/show-notification/show-notification.tsx (1)

251-261: 建议将样式迁移到 CSS 模块中

当前实现逻辑清晰,但建议将内联样式 marginLeft: "0.5em" 移至 CSS 模块中,以保持样式的一致性和可维护性。

- style={{ marginLeft: "0.5em" }}
+ className={styles.inlineLink}

请在 notification.module.css 中添加:

.inlineLink {
  margin-left: 0.5em;
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 255-255: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ddf883 and 0eda238.

📒 Files selected for processing (2)
  • bricks/basic/src/data-providers/show-notification/show-notification.spec.tsx (1 hunks)
  • bricks/basic/src/data-providers/show-notification/show-notification.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bricks/basic/src/data-providers/show-notification/show-notification.spec.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
bricks/basic/src/data-providers/show-notification/show-notification.tsx

[error] 255-255: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build docs (20.x)
  • GitHub Check: Size check (20.x)
🔇 Additional comments (2)
bricks/basic/src/data-providers/show-notification/show-notification.tsx (2)

21-21: 接口设计清晰明确!

新增的 inlineLink 接口设计合理,类型定义完整,并且与现有代码风格保持一致。使用 lodash 的 pick 函数来提取特定属性也是一个很好的做法。

Also applies to: 41-46


251-261: HTML 内容安全处理符合最佳实践

虽然静态分析工具标记了 dangerouslySetInnerHTML 的使用,但代码中已经正确使用 DOMPurify 进行了安全处理,这是处理 HTML 内容的最佳实践。

🧰 Tools
🪛 Biome (1.9.4)

[error] 255-255: Avoid passing content using the dangerouslySetInnerHTML prop.

Setting content using code can expose users to cross-site scripting (XSS) attacks

(lint/security/noDangerouslySetInnerHtml)

@WHChen-Alex WHChen-Alex merged commit 533f39c into master Jan 21, 2025
8 checks passed
@WHChen-Alex WHChen-Alex deleted the steve/alert branch January 21, 2025 04:14
@github-actions github-actions bot temporarily deployed to pull request January 21, 2025 04:14 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants