Admin search gives every setting result of an extension the id "<extension>-[object Object]"
维护者通常 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
- In the admin, open the search and type part of a setting label, for example
like their own. - Inspect the result's
<li>. Itsdata-idisflarum-likes-[object Object]. - 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
flarum/framework 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Admin search ignores a settings or permissions item's own link可能已有人在做 @GBra-4-669 于 13 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
type/extensibility
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
type/bug
难度 2/5 1-3 小时 新手友好度 90/100
维护者通常 1 天内回复
相似的 Issue
-
Prerender check returns HTTP 500 when the request URI or Referer header is longer than PHP_MAXPATHLEN可能已有人在做 @lbajsarowicz 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
-
security/tailscale: add description to restart service可能已有人在做 @drpsyko101 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
Unleash/unleash-php-sdk#264 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
-
Add search field to Scheduled Tasks可能已有人在做 @WorstPIlot 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
openmediavault/openmediavault#2309 ·