Skip to content

perf: 代码冗余&逻辑错误&测试脚本#73

Open
cjy0812 wants to merge 6 commits into
plusfrom
perf
Open

perf: 代码冗余&逻辑错误&测试脚本#73
cjy0812 wants to merge 6 commits into
plusfrom
perf

Conversation

@cjy0812

@cjy0812 cjy0812 commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

Release Notes

  • New Features

    • 为快照“查看”操作新增工具提示交互,并将“查看”改为直接在新窗口打开。
  • Refactor

    • 调整快照列表的预览与删除流程:使用受控的预览/删除回调与加载态展示。
    • 精简页面操作区域,并更新路由页面的组织结构(含删除部分“plus”路径页面外壳)。
  • Tests

    • 新增全局测试桩与挂载/断言工具,增强 Vue+Vitest 用例稳定性与覆盖。

cjy0812 added 2 commits June 14, 2026 15:27
1. 按钮 -> Tooltip
2. DeviceSnapshotGroups 被“去业务化”
3. useDevicePlus 删除两个功能
4. HomeSnapshotGroups 删除重复“查看”
5. useHomePlus
6. Router 清理
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

previewSnapshotdeleteSnapshotuseDevicePlus composable 内部上提为 DeviceSnapshotGroups 的 props,同步移除 useHomePlus 中的 goToSnapshot 跳转能力;删除 plus/ 路径下的 SelectorPage/SvgPage 包装组件并更新路由指向;新增测试基础设施(setup.tsutils.ts)并重构合约测试桩。

Changes

快照操作 Prop 上提

Layer / File(s) Summary
Composable 移除操作逻辑
src/composables/plus/useDevicePlus.ts, src/composables/plus/useHomePlus.ts
useDevicePlus 删除 previewSnapshot/deleteSnapshotuseBatchTask 实现及 useRouter 依赖,从返回对象中撤销暴露;useHomePlus 删除 filterQuery/route/routergoToSnapshot 函数,移除对应返回成员。
DeviceSnapshotGroups 新增 props 并切换绑定
src/components/plus/device/DeviceSnapshotGroups.vue
defineProps 新增 previewSnapshot/deleteSnapshot 对象属性(各含 loading 映射与 invoke 回调);从 useDevicePlus 解构中移除这两项;"查看"按钮改为 NTooltip 包裹并由 props.previewSnapshot 驱动,"删除"按钮改用 props.deleteSnapshot
HomeSnapshotGroups 移除跳转 UI
src/components/plus/home/HomeSnapshotGroups.vue
移除 SvgIcon 导入与 goToSnapshot 解构,快照行操作区域从"跳转按钮 + ActionCard"简化为仅 ActionCard(增加 ml-auto shrink-0 布局类)。
ActionCard 查看按钮改用 NTooltip
src/components/ActionCard.vue
showPreview 为真时,"查看"交互从锚点直接包裹 NButton+title 属性改为 NTooltip 包裹触发器锚点,文案通过 tooltip 展示。
DevicePage slot 暴露并透传操作
src/views/DevicePage.vue, src/views/plus/DevicePage.vue
基础 DevicePage.vuecontent slot 补充暴露 previewSnapshot/deleteSnapshotplus/DevicePage.vue 增加对应解构,并以 :preview-snapshot/:delete-snapshot 传给 DeviceSnapshotGroups

Plus 包装页删除与路由精简

Layer / File(s) Summary
路由组件路径更新
src/router.ts, src/types/plus/index.d.ts
删除 src/views/plus/SelectorPage.vuesrc/views/plus/SvgPage.vue 包装组件;路由 /selector/svg 直接指向 @/views/*.vue;移除一行冗余 ESLint 注释。

测试基础设施与合约测试更新

Layer / File(s) Summary
全局测试 setup
src/test/setup.ts
新增 console mock、SvgIcon 桩、naive-ui 完整组件桩(NTooltip/NButton/NModal/NSpin/NSpace/NCheckbox/NInput/NSelect/NMessageProvider/NDialogProvider 含事件透传)、@vueuse/core mock 及 store mock,提供稳定测试运行时环境。
测试工具函数库
src/test/utils.ts
新增 createStubComponentcreateMockFncreateSpiesmountWithStubs(注入默认 NTooltip/NButton/SvgIcon 桩)以及 DOM/spy 断言辅助函数(expectElementExists/expectElementText/expectSpyCalled 等)。
合约测试更新
src/views/plus/__tests__/adapter.contract.test.ts
改用 mountWithStubs/createStubComponent;为 HomePage/DevicePage/HomeSnapshotGroups/DeviceSnapshotGroups/SettingsModal 桩增加显式 TypeScript 类型;DevicePage 桩插槽入参新增 previewSnapshot/deleteSnapshot 占位。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • cjy0812/inspect-plus#72:同样修改了 ActionCard.vue 的预览链接逻辑(previewUrl 跳转至 /i/{importId}),与本 PR 对"查看"按钮 UI 渲染结构的调整直接关联。
  • cjy0812/inspect-plus#48:两者都在 src/views/plus/DevicePage.vue 层重构快照状态/动作来源,本 PR 将预览/删除能力下沉到 DeviceSnapshotGroups props,属于同一代码路径上的相关修改。

Poem

🗂️ 操作权交付 Props 之手,
路由精简不再绕弯路,
goToSnapshot 悄然退场,
NTooltip 接替旧 title 讲。
测试桩齐整如砌墙砖,
代码疆界,清晰又明朗 ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive 标题过于宽泛且缺乏具体信息,使用了"代码冗余&逻辑错误&测试脚本"这样的模糊术语,未能清晰反映PR的核心变更内容。 建议将标题修改为更具体、清晰的表述,如"Refactor: 移除冗余代码并重构快照预览/删除逻辑"或"Refactor: 将快照操作逻辑从composable下沉到组件props",以更准确地反映代码结构调整的意图。
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 perf

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 and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5a0e66443

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/components/plus/device/DeviceSnapshotGroups.vue Outdated

@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: 6

🤖 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/components/ActionCard.vue`:
- Around line 108-116: The `<a>` tag with `target="_blank"` is missing the
`rel="noopener noreferrer"` attribute, which creates a security vulnerability
allowing the new page to access the original page through `window.opener`
(reverse tabnabbing attack). Add `rel="noopener noreferrer"` to the anchor tag
that opens the preview URL to prevent this security risk.

In `@src/components/plus/home/HomeSnapshotGroups.vue`:
- Around line 318-322: The ActionCard component in the HomeSnapshotGroups.vue
file has a default showPreview=true, which re-exposes the view/jump feature that
was meant to be removed as part of this change. Add an explicit
:showPreview="false" prop to the ActionCard component (lines 318-322) to ensure
the preview entrance is disabled and consistent with the goal of removing the
jump capability.

In `@src/test/setup.ts`:
- Around line 178-184: The mock for useEventListener in the vi.mock call for
`@vueuse/core` is currently returning undefined by default, but the real API
returns a cleanup function. Update the useEventListener mock to return a no-op
function (the stop function) instead of undefined, so that if tested code calls
the return value expecting a cleanup function, it will receive a valid function
instead of throwing an error. Change useEventListener from vi.fn() to vi.fn(()
=> vi.fn()) to maintain API contract consistency with the actual `@vueuse/core`
behavior.
- Around line 87-155: The component stubs in this file (NCheckbox, NInput, and
NSelect) are using the modelValue/update:modelValue two-way binding pattern,
which does not match the actual Naive UI v2.x API contracts. Update the
NCheckbox stub to use a checked property and emit update:checked events instead
of modelValue. Update the NInput stub to use a value property and emit
update:value events instead of modelValue. Update the NSelect stub to use a
value property and emit update:value events instead of modelValue. Ensure all
prop definitions, emits declarations, and onChange handlers are aligned with
their respective event names to match the production Naive UI component
behavior.

In `@src/test/utils.ts`:
- Around line 122-130: The `mountWithStubs` function has an option merge order
issue where spreading `...options` at the end overwrites the previously
constructed `global.stubs` object. When a caller provides `options.global`, the
default stubs for `NTooltip/NButton/SvgIcon` are lost. To fix this, restructure
the merge logic by first spreading `options`, then explicitly constructing the
`global` property to deeply merge user-provided stubs with the default stubs,
ensuring that default stubs like `NTooltip`, `NButton`, and `SvgIcon` are
preserved when users pass their own `global.stubs`.
- Around line 39-41: The custom render branch in the createStubComponent setup()
function is directly returning the result of options.render(renderProps) as a
VNode, but Vue 3's setup() must return a render function, not a VNode directly.
This causes reactive state changes to not trigger re-renders. Fix this by
wrapping the options.render(renderProps) call in a function (e.g., an arrow
function) so that setup() returns a render function instead of a VNode, making
it consistent with the default render function logic in the subsequent else
branch.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c976d11c-fc7b-4ebf-9eac-e03453ab3d02

📥 Commits

Reviewing files that changed from the base of the PR and between 49c9ec3 and e5a0e66.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by none and included by none
  • vitest.config.ts is excluded by none and included by none
📒 Files selected for processing (14)
  • src/components/ActionCard.vue
  • src/components/plus/device/DeviceSnapshotGroups.vue
  • src/components/plus/home/HomeSnapshotGroups.vue
  • src/composables/plus/useDevicePlus.ts
  • src/composables/plus/useHomePlus.ts
  • src/router.ts
  • src/test/setup.ts
  • src/test/utils.ts
  • src/types/plus/index.d.ts
  • src/views/DevicePage.vue
  • src/views/plus/DevicePage.vue
  • src/views/plus/SelectorPage.vue
  • src/views/plus/SvgPage.vue
  • src/views/plus/__tests__/adapter.contract.test.ts
💤 Files with no reviewable changes (4)
  • src/views/plus/SvgPage.vue
  • src/views/plus/SelectorPage.vue
  • src/composables/plus/useHomePlus.ts
  • src/composables/plus/useDevicePlus.ts
📜 Review details
🔇 Additional comments (6)
src/components/plus/device/DeviceSnapshotGroups.vue (1)

11-18: LGTM!

Also applies to: 239-253, 302-303

src/views/DevicePage.vue (1)

537-538: LGTM!

src/views/plus/DevicePage.vue (1)

68-74: LGTM!

Also applies to: 80-81

src/router.ts (1)

100-100: LGTM!

Also applies to: 105-105

src/types/plus/index.d.ts (1)

10-10: LGTM!

src/views/plus/__tests__/adapter.contract.test.ts (1)

4-4: LGTM!

Also applies to: 14-19, 39-44, 47-48, 65-67, 84-92, 107-107, 117-130, 150-150, 161-161, 174-174

Comment thread src/components/ActionCard.vue
Comment thread src/components/plus/home/HomeSnapshotGroups.vue
Comment thread src/test/setup.ts
Comment thread src/test/setup.ts
Comment thread src/test/utils.ts
Comment thread src/test/utils.ts
cjy0812 added 2 commits June 14, 2026 16:48
target="_blank" 缺少 rel,存在反向标签劫持风险。
- 修正 NCheckbox 测试桩为 checked/update:checked
- 修正 NInput、NSelect 测试桩为 value/update:value
- 修复 createStubComponent 返回值错误
- 为 useEventListener 补充清理函数模拟
- 优化 mountWithStubs 的 global 合并逻辑
- 在测试桩中放宽类型以兼容 Vue 3.5 的 slots 类型限制

@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

🤖 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/test/setup.ts`:
- Around line 47-52: The NModal stub component in the setup function declares a
`show` prop with default false but never uses it in the render logic, causing
the modal content to always render regardless of the prop value. This differs
from the real naive-ui NModal behavior where show=false should hide content,
allowing visibility-related bugs to go undetected in tests. To fix, modify the
setup function to accept the props parameter (instead of ignoring it with _:
unknown), then conditionally render the modal div and its content only when
props.show is true, ensuring the stub behaves consistently with the production
NModal component.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d0e1667b-7176-4394-b62a-5def0f8ac5d4

📥 Commits

Reviewing files that changed from the base of the PR and between e5a0e66 and 65dbc10.

📒 Files selected for processing (3)
  • src/components/ActionCard.vue
  • src/test/setup.ts
  • src/test/utils.ts
📜 Review details
🔇 Additional comments (2)
src/test/utils.ts (1)

20-33: LGTM!

Also applies to: 105-114

src/components/ActionCard.vue (1)

110-110: LGTM!

Comment thread src/test/setup.ts
cjy0812 added 2 commits June 14, 2026 18:12
当一个被选中的快照被删除后,checkedRowKeys 仍然包含已删除的 ID,导致批量操作栏显示过时的计数,后续批量删除可能尝试删除已不存在的快照
fix: 根据 props.show 的值来决定是否渲染
@cjy0812 cjy0812 changed the title Perf perf: 代码冗余&逻辑错误&测试脚本 Jun 14, 2026
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.

1 participant