-
Notifications
You must be signed in to change notification settings - Fork 823
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
make dropdownFieldThreshold configurable on DBForeignKey #7789
make dropdownFieldThreshold configurable on DBForeignKey #7789
Conversation
4276ac4
to
8d84cb3
Compare
Updated rightTitle because I noticed it was |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m in favour of taking this in. I’d also suggest adding a note to the PHPDoc for the config var like:
If you are tweaking this value, you should also consider constructing your form field manually rather than allowing it to be scaffolded
src/ORM/FieldType/DBForeignKey.php
Outdated
* @config | ||
* @var int | ||
*/ | ||
private static $dropdownFieldThreshold = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config vars should always be $lower_case_underscore
(except for when they’re not, many_many_extraFields
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snek_case_like_a_good_boi
src/ORM/FieldType/DBForeignKey.php
Outdated
$field = new DropdownField($this->name, $title, $list->map('ID', $titleField)); | ||
$field->setEmptyString(' '); | ||
} else { | ||
$field = new NumericField($this->name, $title); | ||
$field->setRightTitle( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think we should show a message like this to content authors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about admins? Part of the complaint was visibility over the issue. Happy for it to be wrapped in if ($isAdmin)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe just something more generic - remove the bit about the config var maybe. It'll save a fair bit of time for both parties if there is an "error message". A good dev will search the codebase for the error message anyway, right? 😉
8d84cb3
to
9b9437a
Compare
src/ORM/FieldType/DBForeignKey.php
Outdated
$field->setRightTitle( | ||
'This field has been converted to a NumericField as there are at least ' . $threshold | ||
. ' related object(s). This can be set with the config variable' | ||
. ' SilverStripe\ORM\FieldTypeDBForeignKey::dropdown_field_threshold' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this description belongs on the field, since it's for CMS users rather than developers. This message likely to confuse the user more than anything. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see it was raised by @kinglozzer too. My vote is to remove this and leave the configurable limit in place without this message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was intended for phpdoc not for the user, right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, no, not really. The problem raised was that the issue was invisible:
This becomes extremely frustrating from a UX Point of View where the CMS works and looks nice, but if the client adds more than 100 objects then it breaks the experience.
I agree that we shouldn't be exposing the config stuff straight to the user, but it was complicated and not necessarily intuitive to find this particular block of code to figure out what was going on, so I'd argue that some sort of message leaves a much better experience for both the CMS user and the dev.
Even something like "Too many objects for dropdown, fallback used" would help enormously in debugging, and give the user something useful to pass to their dev, who in turn has something to search for when they are looking to fix it.
Otherwise you end up with a field that seems to have mysteriously changed for what is an invisible reason, which is frustrating and confusing.
The other options I see as viable:
- move this functionality to
DropdownField
itself - which is where one would assume that the config var is located if you were to guess - add some specific documentation around the issue and the config var
Ultimately up to you, but I think making this less "magical" is better
Degrading to a numericfield is a UX nightmare. How many content authors know the IDs of the related objects they need off the top of their head? or are able to map the titles to IDs without having to navigate away / inspect URLs, etc? When clients/users see what used to be a dropdown become a numeric field for no obvious reason the reaction (naturally) is to think something has broken or even someone has changed something (like a dev deploying bad code). Of course a dropdown that's so large it causes memory exhaustion or locks up the CMS is a worse experience (completely broken vs unfriendly) but we should be looking at a more friendly mid-point solution. 100 rows seems like a very small number (I'd vote to increase the limit to 1000 in this PR) and I support the idea that the CMS shows some kind of message to inform the user why they are experiencing a degraded experience. |
Just make an autocomplete field with ajax endpoint for searching records. We already do this with ListBox / TreeDropdownField; We just need a basic single select, no hierarchy version. |
9b9437a
to
578ee5d
Compare
@tractorcow would you propose this change to I have to say that the idea of a searchable That being said, this is maybe creeping outside the scope of the PR. I have reduced it down to adding the config field and a user-friendly message - pretty sure the behat failures are unrelated. |
Short of someone taking the time to build an autocomplete field for core, I think this as good as it’s gonna get right now. I still don’t like showing a dev-related message to CMS authors, but in this context it probably does more good than harm. @tractorcow Do you agree that this is an improvement? Even if hopefully some kind soul will eventually replace this with an autocomplete field... |
src/ORM/FieldType/DBForeignKey.php
Outdated
$field = new DropdownField($this->name, $title, $list->map('ID', $titleField)); | ||
$field->setEmptyString(' '); | ||
} else { | ||
$field = new NumericField($this->name, $title); | ||
$field->setRightTitle('Too many related objects; fallback field in use'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be localised string not fixed english sentence.
Current behat failure fixed with #7860, not the fault of this PR. |
Slightly fixes #7788 by making it a configurable option and adding a description as to why this has changed.