Admin search gives every setting result of an extension the id "<extension>-[object Object]"
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
The bad id comes from the lookup() method in framework/core/js/src/admin/components/GeneralSearchSource.tsx, around line 116. Read how setting is typed there, then use its key property instead of the whole object when building the id. Add a case to GeneralSearchSource.test.ts with two matching settings from one extension, and check that their ids differ. Done when the rendered li shows an id like flarum-likes-flarum-likes.like_own_post. Nearby lines are changed by #5260 and #5294, so rebase before editing.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- PHP
- Stars
- 6.8k
- Forks
- 892
- Avg merge
- 23h 6m
- Merged PRs (30d)
- 210
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from flarum/framework
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Admin search ignores a settings or permissions item's own linkPossibly taken @GBra-4-669 claimed this 14 days ago. Opentype/bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
type/extensibility
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
All issues in flarum/framework
Similar issues
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
JSON:API resource collections fail for resources that wrap a non-model objectPossibly taken @lazerg claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Recognise PHP_CodeSniffer (`phpcs`) as a linterPossibly taken @HarshRajSinghania claimed this today. Openenhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
MustacheCase/zanadir#507 ·
Maintainers usually reply within 1 day
-
Developer Tooling/Infrastructure type: infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
woocommerce/woocommerce#70544 ·
Maintainers usually reply within 1 day