Admin search gives every setting result of an extension the id "<extension>-[object Object]"

未关闭 适合新手
#5,362 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript
领域
frontend

调研方向

错误的 id 来自 framework/core/js/src/admin/components/GeneralSearchSource.tsx 第 116 行附近的 lookup() 方法。阅读 setting 在那里的类型定义,然后在构造 id 时使用它的 key 属性,而不是整个对象。在 GeneralSearchSource.test.ts 中添加一个用例,包含来自同一扩展的两个匹配设置,并检查它们的 id 不同。当渲染出的 li 显示类似 flarum-likes-flarum-likes.like_own_post 的 id 时即完成。附近的行正被 #5260 和 #5294 修改,因此编辑前请先 rebase。

由索引模型根据 Issue 内容生成。

描述

Current Behavior

In the admin search, every setting result of an extension gets the same id, for example flarum-likes-[object Object]. GeneralSearchSource.lookup() builds the id from the whole setting object instead of its key:

// framework/core/js/src/admin/components/GeneralSearchSource.tsx:116
const id = extensionId + '-' + ('setting' in setting ? setting : 'id' in setting ? setting.id : '');

setting is the registry's settings object here, so the string concatenation calls its toString(). The rendered result shows it:

<li class="GeneralSearchResult" data-index="general-flarum-likes-[object Object]" data-id="flarum-likes-[object Object]">

Nothing visibly breaks today. Keyboard selection in SearchModal falls back to the item's position, because parseInt('general-…') is NaN. But GeneralSearchResult.id, data-id and data-index aren't unique across an extension's settings, so anything that tells results apart by id gets the wrong answer. That includes extensions extending the search, tests, and future keying of the list.

Steps to Reproduce
  1. In the admin, open the search and type part of a setting label, for example like their own.
  2. Inspect the result's <li>. Its data-id is flarum-likes-[object Object].
  3. Search for anything that matches two settings of the same extension: both results have the same id.
Expected Behavior

Each result has its own id built from the setting's key, for example flarum-likes-flarum-likes.like_own_post.

Environment
  • Flarum version: 2.x (present on current 2.x)
Possible Solution
const id = extensionId + '-' + ('setting' in setting ? setting.setting : 'id' in setting ? setting.id : '');

A test in GeneralSearchSource.test.ts could assert that two matching settings of one extension get different ids.

Additional Context

#5260 and #5294 change the result's link a few lines further down, in the same function.

主要语言
PHP
星标
6.8k
派生
892
平均合并
20 小时 26 分钟
30 天内合并 PR
185

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

flarum/framework 的其他 Issue

查看 flarum/framework 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。